Commit 994ab29d authored by Guillaume Blanchy's avatar Guillaume Blanchy
Browse files

Fix full-waveform save in csv or in zip

Showing with 67 additions and 66 deletions
+67 -66
......@@ -85,10 +85,10 @@ if within_ohmpi:
print('Starting test with OhmPi.')
k = OhmPi()
# k.get_data()
# k.load_sequence(os.path.join(os.path.dirname(__file__), '../sequences/wenner16.txt'))
# k.reset_mux()
k.load_sequence(os.path.join(os.path.dirname(__file__), '../sequences/wenner16.txt'))
k.reset_mux()
# k.run_multiple_sequences(sequence_delay=20, nb_meas=3)
# k.run_sequence(injection_duration=0.2)
k.run_sequence(injection_duration=0.2)
# k.rs_check(tx_volt=4)
# k.test_mux(mux_id=None, activation_time=0.2)
# k._hw.switch_mux([A, B, M, N], state='on')
......
......@@ -7,6 +7,7 @@ API reference
.. automodule:: ohmpi.ohmpi
:members:
.. automodule:: ohmpi.hardware_system
:members:
......@@ -141,6 +141,8 @@
module
<ul>
<li><a href="source_rst/api.html#module-ohmpi.hardware_system">ohmpi.hardware_system</a>
</li>
<li><a href="source_rst/api.html#module-ohmpi.ohmpi">ohmpi.ohmpi</a>
</li>
</ul></li>
......@@ -152,6 +154,13 @@
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="source_rst/api.html#ohmpi.ohmpi.OhmPi">OhmPi (class in ohmpi.ohmpi)</a>
</li>
<li>
ohmpi.hardware_system
<ul>
<li><a href="source_rst/api.html#module-ohmpi.hardware_system">module</a>
</li>
</ul></li>
</ul></td>
<td style="width: 33%; vertical-align: top;"><ul>
<li>
......
No preview for this file type
......@@ -96,6 +96,11 @@
<td>
<code class="xref">ohmpi</code></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
<a href="source_rst/api.html#module-ohmpi.hardware_system"><code class="xref">ohmpi.hardware_system</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
......
This diff is collapsed.
......@@ -646,7 +646,7 @@ Parameters can be:
</dd></dl>
</section>
<span class="target" id="module-ohmpi.hardware_system"></span></section>
</div>
......
......@@ -8,5 +8,3 @@ API reference
:members:
......@@ -21,57 +21,38 @@ r_shunt = 2.
HARDWARE_CONFIG = {
'ctl': {'model': 'raspberry_pi'},
'pwr': {'model': 'pwr_batt', 'voltage': 12., 'interface_name': 'none'},
'tx': {'model': 'mb_2023_0_X',
'tx': {'model': 'mb_2024_0_2',
'voltage_max': 50., # Maximum voltage supported by the TX board [V]
'current_max': 4.80/(50*r_shunt), # Maximum voltage read by the current ADC on the TX board [A]
'r_shunt': r_shunt, # Shunt resistance in Ohms
'interface_name': 'i2c'
},
'rx': {'model': 'mb_2023_0_X',
'coef_p2': 2.50, # slope for conversion for ADS, measurement in V/V
'sampling_rate': 50., # number of samples per second
'interface_name': 'i2c',
'rx': {'model': 'mb_2024_0_2',
'latency': 0.010, # latency in seconds in continuous mode
'sampling_rate': 50, # number of samples per second
'interface_name': 'i2c'
},
'mux': # default properties given in config are system properties that will be
# overwritten by properties defined in each the board dict below.
# if defined in board specs, values out of specs will be bounded to remain in specs
# omitted properties in config will be set to board specs default values if they exist
{'boards':
{'mux_A':
{'model': 'mux_2023_0_X',
'mux_tca_address': 0x70,
'roles': {'A': 'X'},
'cabling': {(i, j): ('mux_A', i) for j in ['A'] for i in range(1, 65)},
'voltage_max': 12.},
'mux_B':
{'model': 'mux_2023_0_X',
'mux_tca_address': 0x71,
'roles': {'B': 'X'},
'cabling': {(i, j): ('mux_B', i) for j in ['B'] for i in range(1, 65)},
'voltage_max': 12.},
'mux_M':
{'model': 'mux_2023_0_X',
'mux_tca_address': 0x72,
'roles': {'M': 'X'},
'cabling': {(i, j): ('mux_M', i) for j in ['M'] for i in range(1, 65)},
'voltage_max': 12.},
'mux_N':
{'model': 'mux_2023_0_X',
'mux_tca_address': 0x73,
'roles': {'N': 'X'},
'cabling': {(i, j): ('mux_N', i) for j in ['N'] for i in range(1, 65)},
'voltage_max': 12.},
'mux': {'boards':
{'mux_00':
{'model': 'mux_2024_0_X',
'tca_address': None,
'tca_channel': 0,
'addr2': 'down',
'addr1': 'down',
'roles': {'A': 'X', 'B': 'Y', 'M': 'XX', 'N': 'YY'},
'cabling': {(i+0, j): ('mux_00', i) for j in ['A', 'B', 'M', 'N'] for i in range(1, 9)},
'voltage_max': 12.}
},
'default': {'interface_name': 'i2c',
'voltage_max': 12.,
'default': {'interface_name': 'i2c_ext',
'voltage_max': 100.,
'current_max': 3.}
}
}
}
}
# SET THE LOGGING LEVELS, MQTT BROKERS AND MQTT OPTIONS ACCORDING TO YOUR NEEDS
# Execution logging configuration
EXEC_LOGGING_CONFIG = {
'logging_level': logging.INFO, # TODO: set logging level back to INFO
'logging_level': logging.INFO,
'log_file_logging_level': logging.DEBUG,
'logging_to_console': True,
'file_name': f'exec{logging_suffix}.log',
......@@ -95,8 +76,8 @@ DATA_LOGGING_CONFIG = {
# State of Health logging configuration (For a future release)
SOH_LOGGING_CONFIG = {
'logging_level': logging.INFO,
'logging_to_console': True,
'log_file_logging_level': logging.DEBUG,
'logging_to_console': True,
'file_name': f'soh{logging_suffix}.log',
'max_bytes': 16777216,
'backup_count': 1024,
......
......@@ -82,7 +82,8 @@ class OhmPi(object):
self.update_settings(os.path.join(os.path.split(os.path.dirname(__file__))[0],'settings/default.json'))
# read in acquisition settings
self.update_settings(settings)
if settings is not None:
self.update_settings(settings)
self.exec_logger.debug('Initialized with settings:' + str(self.settings))
# read quadrupole sequence
......@@ -189,7 +190,7 @@ class OhmPi(object):
fw_filename = filename.replace('.csv', '_fw.csv')
if not os.path.exists(fw_filename): # new file, write headers first
with open(fw_filename, 'w') as f:
f.write('A,B,M,N,t,pulse,polarity,current,voltage\n')
f.write('A,B,M,N,t,current,voltage\n')
# write full data
with open(fw_filename, 'a') as f:
dd = last_measurement['full_waveform']
......@@ -198,7 +199,7 @@ class OhmPi(object):
mm = np.repeat(last_measurement['M'], dd.shape[0])
nn = np.repeat(last_measurement['N'], dd.shape[0])
fwdata = np.c_[aa, bb, mm, nn, dd]
np.savetxt(f, fwdata, fmt=['%d', '%d', '%d', '%d', '%.3f', '%.3f', '%.3f'])
np.savetxt(f, fwdata, delimiter=',', fmt=['%d', '%d', '%d', '%d', '%.3f', '%.3f', '%.3f'])
if fw_in_csv:
d = last_measurement['full_waveform']
......@@ -712,42 +713,48 @@ class OhmPi(object):
# file management
if fw_in_csv: # make sure we have the same number of columns
with open(filename, '.csv', 'r') as f:
with open(filename, 'r') as f:
x = f.readlines()
# get column of start of full-waveform
icol = 0
for i, col in enumerate(x[0].split(',')):
if col == 't1':
if col == 'i0':
icol = i
break
# get longest possible line
max_length = np.max([len(row.split(',')) for row in x]) - icol
nreadings = max_length // 5
print('-----', nreadings, max_length)
nreadings = max_length // 3
# create padding array for full-waveform # TODO test this!
with open(filename, '.csv', 'w') as f:
with open(filename, 'w') as f:
# write back headers
xs = x[0].split(',')
f.write(','.join(xs[:icol]))
for col in ['t','s','p','v','i']:
f.write(','.join([col + str(j+1) for j in range(nreadings)]))
f.write('\n')
f.write(',')
for i, col in enumerate(['t', 'i','v']):
f.write(','.join([col + str(j) for j in range(nreadings)]))
if col == 'v':
f.write('\n')
else:
f.write(',')
# write back rows
for i, row in enumerate(x[1:]):
xs = row.split(',')
f.write(','.join(xs[:icol]))
f.write(',')
fw = np.array(xs[icol:])
fw_pad = fw.reshape((5, -1))
fw_padded = np.zeros((max_length, 5))
fw_pad = fw.reshape((3, -1)).T
fw_padded = np.zeros((nreadings, 3), dtype=fw_pad.dtype)
fw_padded[:fw_pad.shape[0], :] = fw_pad
f.write(','.join(fw_padded.flatten()) + '\n')
f.write(','.join(fw_padded.T.flatten()).replace('\n', '') + '\n')
if fw_in_zip:
with ZipFile(filename.replace('.csv', '_fw.zip'), 'w') as myzip:
myzip.write(filename.replace('.csv', '_fw.csv'))
os.remove(filename.replace('.csv', '_fw.csv'))
fwfilename = filename.replace('.csv', '_fw')
with ZipFile(fwfilename + '.zip', 'w') as myzip:
myzip.write(fwfilename + '.csv', os.path.basename(fwfilename) + '.csv')
os.remove(fwfilename + '.csv')
# reset to idle if we didn't interrupt the sequence
if self.status != 'stopping':
......
......@@ -7,7 +7,7 @@
"tx_volt": 5,
"duty_cycle": 0.5,
"strategy": "constant",
"fw_in_csv": false,
"fw_in_csv": true,
"fw_in_zip": true,
"export_path": "data/measurements.csv"
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment