From 5d58258bf25b4510d4c0bac2d1714260595449fb Mon Sep 17 00:00:00 2001 From: Robert Jordens Date: Thu, 12 May 2016 12:59:36 +0200 Subject: [PATCH] examples: reconstruct scans when analyze()ing HDF5 files --- .../master/repository/flopping_f_simulation.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/artiq/examples/master/repository/flopping_f_simulation.py b/artiq/examples/master/repository/flopping_f_simulation.py index 0315ef2d8..5f22656a6 100644 --- a/artiq/examples/master/repository/flopping_f_simulation.py +++ b/artiq/examples/master/repository/flopping_f_simulation.py @@ -57,8 +57,17 @@ class FloppingF(EnvExperiment): def analyze(self): # Use get_dataset so that analyze can be run stand-alone. - frequency = self.get_dataset("flopping_f_frequency") brightness = self.get_dataset("flopping_f_brightness") + try: + frequency = self.get_dataset("flopping_f_frequency") + except KeyError: + # Since flopping_f_frequency is not saved, it is missing if + # analyze() is run on HDF5 data. But assuming that the arguments + # have been loaded from that same HDF5 file, we can reconstruct it. + frequency = np.fromiter(self.frequency_scan, np.float) + assert frequency.shape == brightness.shape + self.set_dataset("flopping_f_frequency", frequency, + broadcast=True, save=False) popt, pcov = curve_fit(model_numpy, frequency, brightness, p0=[self.get_dataset("flopping_freq", 1500.0)])