Skip to content

Commit

Permalink
twoD analysis for incomplete datasets closes #80
Browse files Browse the repository at this point in the history
  • Loading branch information
AdriaanRol committed Feb 22, 2018
1 parent faa5583 commit cffb1aa
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 9 deletions.
5 changes: 4 additions & 1 deletion pycqed/analysis/analysis_toolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -1682,7 +1682,10 @@ def color_plot(x, y, z, fig, ax, cax=None,
cmap = plt.get_cmap(kw.pop('cmap', cmap_chosen))
# CMRmap is our old default

clim = kw.get('clim', [None, None])
# Empty values in the array are filled with np.nan, this ensures
# the plot limits are set correctly.
clim = kw.get('clim', [np.nanmin(z), np.nanmax(z)])

if log:
norm = colors.LogNorm()
else:
Expand Down
10 changes: 10 additions & 0 deletions pycqed/analysis/measurement_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,14 @@ def get_naming_and_values_2D(self):
x = self.data[0]
y = self.data[1]
cols = np.unique(x).shape[0]

# Adding np.nan for prematurely interupted experiments
nr_missing_values = 0
if len(x)%cols != 0:
nr_missing_values = cols - len(x)%cols
x = np.append(x, np.zeros(nr_missing_values)+np.nan)
y = np.append(y, np.zeros(nr_missing_values)+np.nan)

# X,Y,Z can be put in colormap directly
self.X = x.reshape(-1, cols)
self.Y = y.reshape(-1, cols)
Expand All @@ -836,13 +844,15 @@ def get_naming_and_values_2D(self):

if len(self.value_names) == 1:
z = self.data[2]
z = np.append(z, np.zeros(nr_missing_values)+np.nan)
self.Z = z.reshape(-1, cols)
self.measured_values = [self.Z.T]
else:
self.Z = []
self.measured_values = []
for i in range(len(self.value_names)):
z = self.data[2+i]
z = np.append(z, np.zeros(nr_missing_values)+np.nan)
Z = z.reshape(-1, cols)
self.Z.append(Z)
self.measured_values.append(Z.T)
Expand Down
18 changes: 10 additions & 8 deletions pycqed/analysis_v2/cryo_scope_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,10 @@ def extract_data(self):
label=self.labels)

self.raw_data_dict = OrderedDict()

a=ma_old.TwoD_Analysis(timestamp=self.timestamps[0], auto=False)
# auto is True for the TwoD analysis as the heatmap can be useful
# for debugging the data
a=ma_old.TwoD_Analysis(timestamp=self.timestamps[0], auto=True,
close_file=False)
a.get_naming_and_values_2D()
# FIXME: this is hardcoded and should be an argument in options dict
amp_key = 'Snapshot/instruments/AWG8_8005/parameters/awgs_0_outputs_1_amplitude'
Expand All @@ -149,7 +151,7 @@ def extract_data(self):


def process_data(self):
phase = np.mean(np.unwrap(self.raw_data_dict['phases'][::-1],
phase = np.nanmean(np.unwrap(self.raw_data_dict['phases'][::-1],
discont=180, axis=1)[::-1], axis=1)
phase_err = sem(np.unwrap(self.raw_data_dict['phases'],
discont=180, axis=1), axis=1)
Expand All @@ -160,8 +162,8 @@ def process_data(self):
self.proc_data_dict['t'] = self.raw_data_dict['times']

if self.amp_to_freq is not None and self.freq_to_amp is not None:
mean_phase = np.mean(phase[len(phase)//2:])
# mean_phase = np.mean(phase[:])
mean_phase = np.nanmean(phase[len(phase)//2:])
# mean_phase = np.nanmean(phase[:])

detuning_rad_s = (np.deg2rad(phase-mean_phase)/
self.sliding_pulse_duration)
Expand All @@ -181,7 +183,7 @@ def prepare_plots(self):
'phase_err': self.proc_data_dict['phase_err'],
'title':"Sliding pulses\n"+self.timestamps[0]}
if self.amp_to_freq is not None and self.freq_to_amp is not None:
self.plot_dicts['FluxArc'] = {
self.plot_dicts['normalized_amp_plot'] = {
'plotfn': make_amp_err_plot,
't': self.proc_data_dict['t'],
'amp': self.proc_data_dict['amp'],
Expand All @@ -199,7 +201,7 @@ def make_phase_plot(t, phase, phase_err, title, ylim=None, ax=None, **kw):
set_xlabel(ax, 'Gate separtion', 's')
set_ylabel(ax, 'Phase', 'deg')

mean_phase_tail = np.mean(phase[10:])
mean_phase_tail = np.nanmean(phase[10:])

ax.axhline(mean_phase_tail, ls='-', c='grey', linewidth=.5)
ax.axhline(mean_phase_tail+10, ls=':', c='grey', label=r'$\pm$10 deg', linewidth=0.5)
Expand All @@ -217,7 +219,7 @@ def make_amp_err_plot(t, amp, timestamp, ax=None, **kw):
if ax ==None:
f, ax =plt.subplots()

mean_amp = np.mean(amp[len(amp)//2])
mean_amp = np.nanmean(amp[len(amp)//2])
ax.plot(t, amp/mean_amp, marker='.')

ax.axhline(1.001, ls='--', c='grey', label=r'$\pm$0.1%')
Expand Down
44 changes: 44 additions & 0 deletions pycqed/tests/analysis/test_basics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import unittest
import pycqed as pq
import os
import numpy as np
from pycqed.analysis import measurement_analysis as ma


class Test_TwoDAnalysis(unittest.TestCase):

@classmethod
def setUpClass(self):
self.datadir = os.path.join(pq.__path__[0], 'tests', 'test_data')
ma.a_tools.datadir = self.datadir

def test_incomplete_twoD(self):
a = ma.TwoD_Analysis(timestamp='20180222_135055')

extracted_vals = a.measured_values[0][4]

# critical part here is that nan's get appended
expected_vals = np.array(
[148.17970988, 140.84035328, 135.46773387, 140.18987364, np.nan])

np.testing.assert_array_almost_equal(extracted_vals, expected_vals)

exp_sweep_points = np.array(
[2.40000000e-07, 2.45000000e-07, 2.50000000e-07,
2.55000000e-07, 2.60000000e-07, 2.65000000e-07,
2.70000000e-07, 2.75000000e-07, 2.80000000e-07,
2.85000000e-07, 2.90000000e-07, 2.95000000e-07,
3.00000000e-07, 3.05000000e-07, 3.10000000e-07,
3.15000000e-07, 3.20000000e-07, 3.25000000e-07,
3.30000000e-07, 3.35000000e-07, 3.40000000e-07,
3.45000000e-07, 3.50000000e-07, 3.55000000e-07,
3.60000000e-07, 3.65000000e-07, 3.70000000e-07,
3.75000000e-07, 3.80000000e-07, 3.85000000e-07,
3.90000000e-07, 3.95000000e-07, 4.00000000e-07,
4.01000000e-07, 4.51000000e-07, 5.01000000e-07,
5.51000000e-07, 6.01000000e-07, 6.51000000e-07,
7.01000000e-07, 7.51000000e-07, 8.01000000e-07,
8.51000000e-07, 9.01000000e-07, 9.51000000e-07])
np.testing.assert_array_almost_equal(a.sweep_points, exp_sweep_points)

np.testing.assert_array_almost_equal(a.sweep_points_2D, np.arange(5.))
Binary file not shown.

0 comments on commit cffb1aa

Please sign in to comment.