import numpy as np
import matplotlib.pyplot as plt
import re

path_to_data = './m_data/02062017_nrcl/raw/'
data_file = 'm7_5GHz_closer.dat'
# data_file = 'm7_3GHz_further.dat'

# loading the data
data_raw = np.loadtxt(path_to_data+data_file, comments='#')


# parsing the header
excitation_freq = 0
x_offset, x_multiplier = 0, 0
y_offset, y_multiplier = 0, 0
freq_min, freq_max = 0, 0
x_axis_name = ''
file_info = ''
position = 0
ext_field = -80
with open(path_to_data+data_file, 'r') as f:
    for line in f:
        if not line.startswith('#'):
            break
        if 'Agilent_E8257D - FREQUENCY (Hz) - value:' in line:
            excitation_freq = float(re.findall(r"[+-]? *(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?", line)[1])
            excitation_freq /= 1000000000
            print(excitation_freq)
        if 'x offset/multiplier:' in line:
            numbers = re.findall(r"[+-]? *(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?", line)
            # print(numbers)
            x_offset = float(numbers[0])
            x_multiplier = float(numbers[1])
        if 'y offset/multiplier:' in line:
            numbers = re.findall(r"[+-]? *(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?", line)
            # print(numbers)
            y_offset = float(numbers[0])
            y_multiplier = float(numbers[1])
        if 'Frequency between:' in line:
            numbers = re.findall(r"[+-]? *(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?", line)
            # print(numbers)
            freq_min = float(numbers[0])
            freq_max = float(numbers[1])
        if 'x axis:' in line:
            x_axis_name = line[9:]
            print(x_axis_name)
        if 'data file:' in line:
            file_info = line[12:]
            print(file_info)
        if 'MICROSCOPE - ScanDimension_1 - value:' in line:
            numbers = re.findall(r"[+-]? *(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?", line)
            position = float(numbers[1])
            print(numbers)
        if 'linked controls - field - Control Voltage Kepco - value:' in line:
            numbers = re.findall(r"[+-]? *(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?", line)
            ext_field = int(float(numbers[0]))
        # print(line)

# plotting the data
fig1 = plt.figure(figsize=(12, 4), dpi=100)
ax1 = fig1.add_subplot(111)
pos_f = ''
if position == 2.0:
    pos = 'close'
    pos_f = 'close'
else:
    pos = '1' + r'$\mu m$' + ' from'
    pos_f = '1um_from'
# fig1.suptitle('BLS Spectrum '+pos+' antenna\n'+'excitation at '+str(excitation_freq)+' GHz')

cmap = plt.get_cmap('magma')
cmap.set_under('black')
# cmap.set_over('black')
eps1 = np.spacing(0)
im = ax1.imshow(data_raw.T, origin='lower', aspect='auto', vmin=eps1, vmax=400, cmap=cmap, interpolation='nearest',
                extent=(0, 100, freq_min, freq_max))

print(data_raw.T.shape)

# adjusting the axes ticks

# y_ticks = np.arange(0, data_raw.T.shape[0], 16)
# freq_tick_labels = np.linspace(freq_min, freq_max, len(y_ticks))
# freq_tick_labels = ["{0:.1f}".format(y_tick) for y_tick in freq_tick_labels]
# ax1.set_yticks(y_ticks)
# ax1.set_yticklabels(freq_tick_labels)

ax1.set_ylim([-excitation_freq-1, -excitation_freq+1])
ax1.set_xlim([0, 100])

x_ticks = np.arange(0, data_raw.T.shape[1], 11)

x_line1 = np.array([51 for i in range(10000)])
y_line1 = np.linspace(-excitation_freq-1, -excitation_freq+1, 10000)
ax1.plot(x_line1, y_line1, linestyle='--', linewidth=4.0, color='green', alpha=0.6)

# x_tick_labels = np.linspace(x_offset, (data_raw.T.shape[1] - 1) * x_multiplier + x_offset, len(x_ticks))

x_tick_labels = np.linspace(0, 16.5, 10)
print(x_tick_labels)
x_tick_labels = ["{0:.1f}".format(x_tick) for x_tick in x_tick_labels]
ax1.set_xticks(x_ticks)
ax1.set_xticklabels(x_tick_labels)


ax1.set_xlabel('position along antenna '+r'$(\mu m)$')
# ax1.set_xlabel(x_axis_name)
ax1.set_ylabel('BLS Frequency (GHz)')

cbar = fig1.colorbar(im)
cbar.set_label('Intensity (a.u.)', rotation=270)
cbar.ax.get_yaxis().labelpad = 15
# cbar.ax.set_yticklabels('')

fig1.tight_layout()
fig1.subplots_adjust(top=0.94, bottom=0.15)

file_info = file_info.split('\\')
print(file_info)
save_name = file_info[-1][:-5] + '_' + str(excitation_freq)[0] + 'GHz_' + pos_f + '_RAW' + '.pdf'
# save_name = save_name.replace('both', pos)
print(save_name)
plt.savefig('./output_pics/nrcl/'+save_name, format='pdf', dpi=100)
plt.show()
eaf67b1eff32010952005b8dd21e0117c71e909c
<mask token>

<mask token>
with open(path_to_data + data_file, 'r') as f:
    for line in f:
        if not line.startswith('#'):
            break
        if 'Agilent_E8257D - FREQUENCY (Hz) - value:' in line:
            excitation_freq = float(re.findall(
                '[+-]? *(?:\\d+(?:\\.\\d*)?|\\.\\d+)(?:[eE][+-]?\\d+)?',
                line)[1])
            excitation_freq /= 1000000000
            print(excitation_freq)
        if 'x offset/multiplier:' in line:
            numbers = re.findall(
                '[+-]? *(?:\\d+(?:\\.\\d*)?|\\.\\d+)(?:[eE][+-]?\\d+)?', line)
            x_offset = float(numbers[0])
            x_multiplier = float(numbers[1])
        if 'y offset/multiplier:' in line:
            numbers = re.findall(
                '[+-]? *(?:\\d+(?:\\.\\d*)?|\\.\\d+)(?:[eE][+-]?\\d+)?', line)
            y_offset = float(numbers[0])
            y_multiplier = float(numbers[1])
        if 'Frequency between:' in line:
            numbers = re.findall(
                '[+-]? *(?:\\d+(?:\\.\\d*)?|\\.\\d+)(?:[eE][+-]?\\d+)?', line)
            freq_min = float(numbers[0])
            freq_max = float(numbers[1])
        if 'x axis:' in line:
            x_axis_name = line[9:]
            print(x_axis_name)
        if 'data file:' in line:
            file_info = line[12:]
            print(file_info)
        if 'MICROSCOPE - ScanDimension_1 - value:' in line:
            numbers = re.findall(
                '[+-]? *(?:\\d+(?:\\.\\d*)?|\\.\\d+)(?:[eE][+-]?\\d+)?', line)
            position = float(numbers[1])
            print(numbers)
        if 'linked controls - field - Control Voltage Kepco - value:' in line:
            numbers = re.findall(
                '[+-]? *(?:\\d+(?:\\.\\d*)?|\\.\\d+)(?:[eE][+-]?\\d+)?', line)
            ext_field = int(float(numbers[0]))
<mask token>
if position == 2.0:
    pos = 'close'
    pos_f = 'close'
else:
    pos = '1' + '$\\mu m$' + ' from'
    pos_f = '1um_from'
<mask token>
cmap.set_under('black')
<mask token>
print(data_raw.T.shape)
ax1.set_ylim([-excitation_freq - 1, -excitation_freq + 1])
ax1.set_xlim([0, 100])
<mask token>
ax1.plot(x_line1, y_line1, linestyle='--', linewidth=4.0, color='green',
    alpha=0.6)
<mask token>
print(x_tick_labels)
<mask token>
ax1.set_xticks(x_ticks)
ax1.set_xticklabels(x_tick_labels)
ax1.set_xlabel('position along antenna ' + '$(\\mu m)$')
ax1.set_ylabel('BLS Frequency (GHz)')
<mask token>
cbar.set_label('Intensity (a.u.)', rotation=270)
<mask token>
fig1.tight_layout()
fig1.subplots_adjust(top=0.94, bottom=0.15)
<mask token>
print(file_info)
<mask token>
print(save_name)
plt.savefig('./output_pics/nrcl/' + save_name, format='pdf', dpi=100)
plt.show()

<mask token>
path_to_data = './m_data/02062017_nrcl/raw/'
data_file = 'm7_5GHz_closer.dat'
data_raw = np.loadtxt(path_to_data + data_file, comments='#')
excitation_freq = 0
x_offset, x_multiplier = 0, 0
y_offset, y_multiplier = 0, 0
freq_min, freq_max = 0, 0
x_axis_name = ''
file_info = ''
position = 0
ext_field = -80
with open(path_to_data + data_file, 'r') as f:
    for line in f:
        if not line.startswith('#'):
            break
        if 'Agilent_E8257D - FREQUENCY (Hz) - value:' in line:
            excitation_freq = float(re.findall(
                '[+-]? *(?:\\d+(?:\\.\\d*)?|\\.\\d+)(?:[eE][+-]?\\d+)?',
                line)[1])
            excitation_freq /= 1000000000
            print(excitation_freq)
        if 'x offset/multiplier:' in line:
            numbers = re.findall(
                '[+-]? *(?:\\d+(?:\\.\\d*)?|\\.\\d+)(?:[eE][+-]?\\d+)?', line)
            x_offset = float(numbers[0])
            x_multiplier = float(numbers[1])
        if 'y offset/multiplier:' in line:
            numbers = re.findall(
                '[+-]? *(?:\\d+(?:\\.\\d*)?|\\.\\d+)(?:[eE][+-]?\\d+)?', line)
            y_offset = float(numbers[0])
            y_multiplier = float(numbers[1])
        if 'Frequency between:' in line:
            numbers = re.findall(
                '[+-]? *(?:\\d+(?:\\.\\d*)?|\\.\\d+)(?:[eE][+-]?\\d+)?', line)
            freq_min = float(numbers[0])
            freq_max = float(numbers[1])
        if 'x axis:' in line:
            x_axis_name = line[9:]
            print(x_axis_name)
        if 'data file:' in line:
            file_info = line[12:]
            print(file_info)
        if 'MICROSCOPE - ScanDimension_1 - value:' in line:
            numbers = re.findall(
                '[+-]? *(?:\\d+(?:\\.\\d*)?|\\.\\d+)(?:[eE][+-]?\\d+)?', line)
            position = float(numbers[1])
            print(numbers)
        if 'linked controls - field - Control Voltage Kepco - value:' in line:
            numbers = re.findall(
                '[+-]? *(?:\\d+(?:\\.\\d*)?|\\.\\d+)(?:[eE][+-]?\\d+)?', line)
            ext_field = int(float(numbers[0]))
fig1 = plt.figure(figsize=(12, 4), dpi=100)
ax1 = fig1.add_subplot(111)
pos_f = ''
if position == 2.0:
    pos = 'close'
    pos_f = 'close'
else:
    pos = '1' + '$\\mu m$' + ' from'
    pos_f = '1um_from'
cmap = plt.get_cmap('magma')
cmap.set_under('black')
eps1 = np.spacing(0)
im = ax1.imshow(data_raw.T, origin='lower', aspect='auto', vmin=eps1, vmax=
    400, cmap=cmap, interpolation='nearest', extent=(0, 100, freq_min,
    freq_max))
print(data_raw.T.shape)
ax1.set_ylim([-excitation_freq - 1, -excitation_freq + 1])
ax1.set_xlim([0, 100])
x_ticks = np.arange(0, data_raw.T.shape[1], 11)
x_line1 = np.array([(51) for i in range(10000)])
y_line1 = np.linspace(-excitation_freq - 1, -excitation_freq + 1, 10000)
ax1.plot(x_line1, y_line1, linestyle='--', linewidth=4.0, color='green',
    alpha=0.6)
x_tick_labels = np.linspace(0, 16.5, 10)
print(x_tick_labels)
x_tick_labels = ['{0:.1f}'.format(x_tick) for x_tick in x_tick_labels]
ax1.set_xticks(x_ticks)
ax1.set_xticklabels(x_tick_labels)
ax1.set_xlabel('position along antenna ' + '$(\\mu m)$')
ax1.set_ylabel('BLS Frequency (GHz)')
cbar = fig1.colorbar(im)
cbar.set_label('Intensity (a.u.)', rotation=270)
cbar.ax.get_yaxis().labelpad = 15
fig1.tight_layout()
fig1.subplots_adjust(top=0.94, bottom=0.15)
file_info = file_info.split('\\')
print(file_info)
save_name = file_info[-1][:-5] + '_' + str(excitation_freq)[0
    ] + 'GHz_' + pos_f + '_RAW' + '.pdf'
print(save_name)
plt.savefig('./output_pics/nrcl/' + save_name, format='pdf', dpi=100)
plt.show()

import numpy as np
import matplotlib.pyplot as plt
import re
path_to_data = './m_data/02062017_nrcl/raw/'
data_file = 'm7_5GHz_closer.dat'
data_raw = np.loadtxt(path_to_data + data_file, comments='#')
excitation_freq = 0
x_offset, x_multiplier = 0, 0
y_offset, y_multiplier = 0, 0
freq_min, freq_max = 0, 0
x_axis_name = ''
file_info = ''
position = 0
ext_field = -80
with open(path_to_data + data_file, 'r') as f:
    for line in f:
        if not line.startswith('#'):
            break
        if 'Agilent_E8257D - FREQUENCY (Hz) - value:' in line:
            excitation_freq = float(re.findall(
                '[+-]? *(?:\\d+(?:\\.\\d*)?|\\.\\d+)(?:[eE][+-]?\\d+)?',
                line)[1])
            excitation_freq /= 1000000000
            print(excitation_freq)
        if 'x offset/multiplier:' in line:
            numbers = re.findall(
                '[+-]? *(?:\\d+(?:\\.\\d*)?|\\.\\d+)(?:[eE][+-]?\\d+)?', line)
            x_offset = float(numbers[0])
            x_multiplier = float(numbers[1])
        if 'y offset/multiplier:' in line:
            numbers = re.findall(
                '[+-]? *(?:\\d+(?:\\.\\d*)?|\\.\\d+)(?:[eE][+-]?\\d+)?', line)
            y_offset = float(numbers[0])
            y_multiplier = float(numbers[1])
        if 'Frequency between:' in line:
            numbers = re.findall(
                '[+-]? *(?:\\d+(?:\\.\\d*)?|\\.\\d+)(?:[eE][+-]?\\d+)?', line)
            freq_min = float(numbers[0])
            freq_max = float(numbers[1])
        if 'x axis:' in line:
            x_axis_name = line[9:]
            print(x_axis_name)
        if 'data file:' in line:
            file_info = line[12:]
            print(file_info)
        if 'MICROSCOPE - ScanDimension_1 - value:' in line:
            numbers = re.findall(
                '[+-]? *(?:\\d+(?:\\.\\d*)?|\\.\\d+)(?:[eE][+-]?\\d+)?', line)
            position = float(numbers[1])
            print(numbers)
        if 'linked controls - field - Control Voltage Kepco - value:' in line:
            numbers = re.findall(
                '[+-]? *(?:\\d+(?:\\.\\d*)?|\\.\\d+)(?:[eE][+-]?\\d+)?', line)
            ext_field = int(float(numbers[0]))
fig1 = plt.figure(figsize=(12, 4), dpi=100)
ax1 = fig1.add_subplot(111)
pos_f = ''
if position == 2.0:
    pos = 'close'
    pos_f = 'close'
else:
    pos = '1' + '$\\mu m$' + ' from'
    pos_f = '1um_from'
cmap = plt.get_cmap('magma')
cmap.set_under('black')
eps1 = np.spacing(0)
im = ax1.imshow(data_raw.T, origin='lower', aspect='auto', vmin=eps1, vmax=
    400, cmap=cmap, interpolation='nearest', extent=(0, 100, freq_min,
    freq_max))
print(data_raw.T.shape)
ax1.set_ylim([-excitation_freq - 1, -excitation_freq + 1])
ax1.set_xlim([0, 100])
x_ticks = np.arange(0, data_raw.T.shape[1], 11)
x_line1 = np.array([(51) for i in range(10000)])
y_line1 = np.linspace(-excitation_freq - 1, -excitation_freq + 1, 10000)
ax1.plot(x_line1, y_line1, linestyle='--', linewidth=4.0, color='green',
    alpha=0.6)
x_tick_labels = np.linspace(0, 16.5, 10)
print(x_tick_labels)
x_tick_labels = ['{0:.1f}'.format(x_tick) for x_tick in x_tick_labels]
ax1.set_xticks(x_ticks)
ax1.set_xticklabels(x_tick_labels)
ax1.set_xlabel('position along antenna ' + '$(\\mu m)$')
ax1.set_ylabel('BLS Frequency (GHz)')
cbar = fig1.colorbar(im)
cbar.set_label('Intensity (a.u.)', rotation=270)
cbar.ax.get_yaxis().labelpad = 15
fig1.tight_layout()
fig1.subplots_adjust(top=0.94, bottom=0.15)
file_info = file_info.split('\\')
print(file_info)
save_name = file_info[-1][:-5] + '_' + str(excitation_freq)[0
    ] + 'GHz_' + pos_f + '_RAW' + '.pdf'
print(save_name)
plt.savefig('./output_pics/nrcl/' + save_name, format='pdf', dpi=100)
plt.show()

import numpy as np
import matplotlib.pyplot as plt
import re

path_to_data = './m_data/02062017_nrcl/raw/'
data_file = 'm7_5GHz_closer.dat'
# data_file = 'm7_3GHz_further.dat'

# loading the data
data_raw = np.loadtxt(path_to_data+data_file, comments='#')


# parsing the header
excitation_freq = 0
x_offset, x_multiplier = 0, 0
y_offset, y_multiplier = 0, 0
freq_min, freq_max = 0, 0
x_axis_name = ''
file_info = ''
position = 0
ext_field = -80
with open(path_to_data+data_file, 'r') as f:
    for line in f:
        if not line.startswith('#'):
            break
        if 'Agilent_E8257D - FREQUENCY (Hz) - value:' in line:
            excitation_freq = float(re.findall(r"[+-]? *(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?", line)[1])
            excitation_freq /= 1000000000
            print(excitation_freq)
        if 'x offset/multiplier:' in line:
            numbers = re.findall(r"[+-]? *(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?", line)
            # print(numbers)
            x_offset = float(numbers[0])
            x_multiplier = float(numbers[1])
        if 'y offset/multiplier:' in line:
            numbers = re.findall(r"[+-]? *(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?", line)
            # print(numbers)
            y_offset = float(numbers[0])
            y_multiplier = float(numbers[1])
        if 'Frequency between:' in line:
            numbers = re.findall(r"[+-]? *(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?", line)
            # print(numbers)
            freq_min = float(numbers[0])
            freq_max = float(numbers[1])
        if 'x axis:' in line:
            x_axis_name = line[9:]
            print(x_axis_name)
        if 'data file:' in line:
            file_info = line[12:]
            print(file_info)
        if 'MICROSCOPE - ScanDimension_1 - value:' in line:
            numbers = re.findall(r"[+-]? *(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?", line)
            position = float(numbers[1])
            print(numbers)
        if 'linked controls - field - Control Voltage Kepco - value:' in line:
            numbers = re.findall(r"[+-]? *(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?", line)
            ext_field = int(float(numbers[0]))
        # print(line)

# plotting the data
fig1 = plt.figure(figsize=(12, 4), dpi=100)
ax1 = fig1.add_subplot(111)
pos_f = ''
if position == 2.0:
    pos = 'close'
    pos_f = 'close'
else:
    pos = '1' + r'$\mu m$' + ' from'
    pos_f = '1um_from'
# fig1.suptitle('BLS Spectrum '+pos+' antenna\n'+'excitation at '+str(excitation_freq)+' GHz')

cmap = plt.get_cmap('magma')
cmap.set_under('black')
# cmap.set_over('black')
eps1 = np.spacing(0)
im = ax1.imshow(data_raw.T, origin='lower', aspect='auto', vmin=eps1, vmax=400, cmap=cmap, interpolation='nearest',
                extent=(0, 100, freq_min, freq_max))

print(data_raw.T.shape)

# adjusting the axes ticks

# y_ticks = np.arange(0, data_raw.T.shape[0], 16)
# freq_tick_labels = np.linspace(freq_min, freq_max, len(y_ticks))
# freq_tick_labels = ["{0:.1f}".format(y_tick) for y_tick in freq_tick_labels]
# ax1.set_yticks(y_ticks)
# ax1.set_yticklabels(freq_tick_labels)

ax1.set_ylim([-excitation_freq-1, -excitation_freq+1])
ax1.set_xlim([0, 100])

x_ticks = np.arange(0, data_raw.T.shape[1], 11)

x_line1 = np.array([51 for i in range(10000)])
y_line1 = np.linspace(-excitation_freq-1, -excitation_freq+1, 10000)
ax1.plot(x_line1, y_line1, linestyle='--', linewidth=4.0, color='green', alpha=0.6)

# x_tick_labels = np.linspace(x_offset, (data_raw.T.shape[1] - 1) * x_multiplier + x_offset, len(x_ticks))

x_tick_labels = np.linspace(0, 16.5, 10)
print(x_tick_labels)
x_tick_labels = ["{0:.1f}".format(x_tick) for x_tick in x_tick_labels]
ax1.set_xticks(x_ticks)
ax1.set_xticklabels(x_tick_labels)


ax1.set_xlabel('position along antenna '+r'$(\mu m)$')
# ax1.set_xlabel(x_axis_name)
ax1.set_ylabel('BLS Frequency (GHz)')

cbar = fig1.colorbar(im)
cbar.set_label('Intensity (a.u.)', rotation=270)
cbar.ax.get_yaxis().labelpad = 15
# cbar.ax.set_yticklabels('')

fig1.tight_layout()
fig1.subplots_adjust(top=0.94, bottom=0.15)

file_info = file_info.split('\\')
print(file_info)
save_name = file_info[-1][:-5] + '_' + str(excitation_freq)[0] + 'GHz_' + pos_f + '_RAW' + '.pdf'
# save_name = save_name.replace('both', pos)
print(save_name)
plt.savefig('./output_pics/nrcl/'+save_name, format='pdf', dpi=100)
plt.show()