dpn
Apologies for the code posted below. I do not understand how to format it properly in the code brackets here. I keep trying and failing...
I think we get the philosophy. But that workflow can be suboptimal depending on how sophisticated the measurements are. For instance, let's imagine a control script with the ability to run 200 different nested for loops. This is completely unmanageable/doesn't scale with the current nested loop approach (unless I am missing something). It is also a real challenge when data is manually recorded. Where does that get put? So the extremes of high level automation and manual data entry don't work great with the current workflow.
I'll give an example for a high level of sophistication since the manual case is obvious.
A much cleaner way to handle loops ( and change the order of the loops) would be to use numpy's meshgrid and a function like this to create the nested loops and make it easy to alter the order.
`
def loops(arrs):
'''Creates nested for loops for arbitrary numbers of arguments,
the first argument is the first loop, and the last is the last '''
return np.transpose(np.meshgrid(arrs)).reshape(-1, len(arrs))
loop_array = loops(x,y,z)
`
Then to track it these loops i.e. generate metadata maybe we want to throw this into a dataframe with column names
'
scan_df = pd.DataFrame(loop_array,columns = column_names)
scan_df.to_csv(direc+'scan_params.csv')
'
.
Now the 200 nested loops of the script is replaced with a single for loop. Each "state" of the experimental parameters is now recorded in the loops array.
It would notionally be nice to throw the loop metadata into the H5 file. However, my understanding of the H5 file is that it is written after a scan and that the datasets in the environment don't support dataframes. Hence, we would like the ability to alter the default directory structure. I.e. It would be better, to make folders with the RID , default save the H5 file in that folder and then add other structures as needed in that new directory.
For similar reasons, I think it would be an upgrade to the core language to explicitly make the scan object NoScan explicitly have a .sequence value. This would make the syntax identical to the other scan objects and it would make it easier to generate the sequence for the scans described above. To me it is not a "NoScan", it is a "Repeat Scan" that repeats x times or possibly x*y times if in a nested loop.
`
class RepeatScan(ScanObject):
def init(self, value, repetitions=1):
self.value = value
self.repetitions = repetitions
self.sequence = np.ones(self.repetitions) * self.value
def _gen(self):
for i in range(self.repetitions):
yield self.value
def __iter__(self):
return self._gen()
def __len__(self):
return self.repetitions
def describe(self):
return {
"ty": "BScan2",
"value": self.value,
"repetitions": self.repetitions
}
`