Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsaveClass.py
More file actions
Latest commit
115 lines (100 loc) · 4.84 KB
/
Copy pathsaveClass.py
File metadata and controls
115 lines (100 loc) · 4.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
importholoviewsashv
importnumpyasnp
fromIPython.displayimportdisplay
classsavedData:
def__init__(self, result, metadata, name, description):
"""Object used to hold resulting plot from a measurement, basic description of measurement, and metadata about system state."""
self._plot=result
self._metadata=metadata
self.name=name
#This assumes that object always created with the date as the name (which is the current functionality)
self.date=name
self.description=description
self.comment=None
return
@property
defdata(self):
"""Returns raw data as pandas dataframe"""
returnself.plot.dframe()
@property
defstate(self):
"""Returns state of all instruments at time of measurement as a dictionary, based off snapshot feature of QCoDeS instruments"""
returnself._metadata
@property
defreadableState(self):
"""Prints clean and simplified state of all instruments."""
forinstinself._metadata:
snapshot=self._metadata[inst]
iftype(snapshot) ==dict:
self._print_readable_snapshot(snapshot)
else:
print(inst+':\n')
display(snapshot)
print('\n')
return
@property
defplot(self):
"""Returns the plot associated with the given measurement. With Holoviews objects this should also display the plot inline"""
iftype(self._plot) ==hv.Image:
returnself._plot.opts(norm=dict(framewise=True), plot=dict(colorbar=True), style=dict(cmap='jet'))
returnself._plot
def__repr__(self):
ifself.comment:
returnself.comment
else:
returnself.description
def_print_readable_snapshot(self, snapshot, update: bool=False,
max_chars: int=80) ->None:
"""
Prints a readable version of the snapshot.
The readable snapshot includes the name, value and unit of each
parameter.
A convenience function to quickly get an overview of the
status of an instrument.
Args:
update: If True, update the state by querying the
instrument. If False, just use the latest values in memory.
This argument gets passed to the snapshot function.
max_chars: the maximum number of characters per line. The
readable snapshot will be cropped if this value is exceeded.
Defaults to 80 to be consistent with default terminal width.
"""
floating_types= (float, np.integer, np.floating)
#snapshot = self.snapshot(update=update)
par_lengths= [len(p) forpinsnapshot['parameters']]
# Min of 50 is to prevent a super long parameter name to break this
# function
par_field_len=min(max(par_lengths)+1, 50)
print(snapshot['parameters']['IDN']['instrument_name'] +':')
print('{0:<{1}}'.format('\tparameter ', par_field_len) +'value')
print('-'*max_chars)
forparinsorted(snapshot['parameters']):
name=snapshot['parameters'][par]['name']
msg='{0:<{1}}:'.format(name, par_field_len)
# in case of e.g. ArrayParameters, that usually have
# snapshot_value == False, the parameter may not have
# a value in the snapshot
val=snapshot['parameters'][par].get('value', 'Not available')
unit=snapshot['parameters'][par].get('unit', None)
ifunitisNone:
# this may be a multi parameter
unit=snapshot['parameters'][par].get('units', None)
ifisinstance(val, floating_types):
msg+='\t{:.5g} '.format(val)
else:
msg+='\t{} '.format(val)
ifunitisnot'': # corresponds to no unit
msg+='({})'.format(unit)
# Truncate the message if it is longer than max length
iflen(msg) >max_charsandnotmax_chars==-1:
msg=msg[0:max_chars-3] +'...'
print(msg)
forsubmoduleinsnapshot['submodules'].values():
print_readable_snapshot(submodule)
#if hasattr(submodule, '_channels'):
# submodule = cast('ChannelList', submodule)
# if submodule._snapshotable:
# for channel in submodule._channels:
# channel.print_readable_snapshot()
#else:
# submodule.print_readable_snapshot(update, max_chars)