Commit 916bd11a authored by Olivier Kaufmann's avatar Olivier Kaufmann
Browse files

Fixes dict d conversion to string

Showing with 17 additions and 11 deletions
+17 -11
...@@ -24,7 +24,7 @@ CONTROL_CONFIG = { ...@@ -24,7 +24,7 @@ CONTROL_CONFIG = {
# Execution logging configuration # Execution logging configuration
EXEC_LOGGING_CONFIG = { EXEC_LOGGING_CONFIG = {
'logging_level': logging.DEBUG, 'logging_level': logging.DEBUG,
'logging_to_console': False, 'logging_to_console': True,
'file_name': 'ohmpi_log', 'file_name': 'ohmpi_log',
'max_bytes': 262144, 'max_bytes': 262144,
'backup_count': 30, 'backup_count': 30,
...@@ -37,7 +37,6 @@ DATA_LOGGING_CONFIG = { ...@@ -37,7 +37,6 @@ DATA_LOGGING_CONFIG = {
'logging_level': logging.INFO, 'logging_level': logging.INFO,
'logging_to_console': True, 'logging_to_console': True,
'file_name': 'data_log', 'file_name': 'data_log',
'logging_to_console': False,
'max_bytes': 16777216, 'max_bytes': 16777216,
'backup_count': 1024, 'backup_count': 1024,
'when': 'd', 'when': 'd',
......
...@@ -83,21 +83,22 @@ class OhmPi(object): ...@@ -83,21 +83,22 @@ class OhmPi(object):
# default acquisition settings # default acquisition settings
self.settings = { self.settings = {
'injection_duration': 0.2, 'injection_duration': 0.2,
'nbr_meas': 100, 'nbr_meas': 1,
'sequence_delay': 1, 'sequence_delay': 1,
'nb_stack': 1, 'nb_stack': 1,
'export_path': 'data/measurement.csv' 'export_path': 'data/measurement.csv'
} }
print(self.settings)
# read in acquisition settings # read in acquisition settings
if settings is not None: if settings is not None:
self._update_acquisition_settings(settings) self._update_acquisition_settings(settings)
self.exec_logger.debug('Initialized with configuration:' + str(self.settings)) print(self.settings)
self.exec_logger.debug('Initialized with settings:' + str(self.settings))
# read quadrupole sequence # read quadrupole sequence
if sequence is None: if sequence is None:
self.sequence = np.array([[1, 2, 3, 4]]) self.sequence = np.array([[1, 2, 3, 4]], dtype=np.int32)
else: else:
self.read_quad(sequence) self.read_quad(sequence)
...@@ -232,7 +233,7 @@ class OhmPi(object): ...@@ -232,7 +233,7 @@ class OhmPi(object):
sequence : numpy.array sequence : numpy.array
Array of shape (number quadrupoles * 4). Array of shape (number quadrupoles * 4).
""" """
sequence = np.loadtxt(filename, delimiter=" ", dtype=int) # load quadrupole file sequence = np.loadtxt(filename, delimiter=" ", dtype=np.int32) # load quadrupole file
if sequence is not None: if sequence is not None:
self.exec_logger.debug('Sequence of {:d} quadrupoles read.'.format(sequence.shape[0])) self.exec_logger.debug('Sequence of {:d} quadrupoles read.'.format(sequence.shape[0]))
...@@ -496,8 +497,7 @@ class OhmPi(object): ...@@ -496,8 +497,7 @@ class OhmPi(object):
} }
else: # for testing, generate random data else: # for testing, generate random data
d = {'time': datetime.now().isoformat(), 'A': quad[0], 'B': quad[1], 'M': quad[2], 'N': quad[3], d = {'time': datetime.now().isoformat(), 'A': quad[0], 'B': quad[1], 'M': quad[2], 'N': quad[3],
'R [ohm]': np.abs(np.random.randn(1)) 'R [ohm]': np.abs(np.random.randn(1)).tolist()}
}
# round number to two decimal for nicer string output # round number to two decimal for nicer string output
output = [f'{k}\t' for k in d.keys()] output = [f'{k}\t' for k in d.keys()]
...@@ -510,7 +510,14 @@ class OhmPi(object): ...@@ -510,7 +510,14 @@ class OhmPi(object):
output += f'{val}\t' output += f'{val}\t'
output = output[:-1] output = output[:-1]
self.exec_logger.debug(output) self.exec_logger.debug(output)
self.data_logger.info(json.loads(d)) dd = d.copy()
dd.update({'A': str(dd['A'])})
dd.update({'B': str(dd['B'])})
dd.update({'M': str(dd['M'])})
dd.update({'N': str(dd['N'])})
print(np.dtype(d['A']))
print(json.dumps(dd))
self.data_logger.info(json.dumps(dd))
time.sleep(1) # NOTE: why this? time.sleep(1) # NOTE: why this?
return d return d
...@@ -798,4 +805,4 @@ print(current_time.strftime("%Y-%m-%d %H:%M:%S")) ...@@ -798,4 +805,4 @@ print(current_time.strftime("%Y-%m-%d %H:%M:%S"))
# for testing # for testing
if __name__ == "__main__": if __name__ == "__main__":
ohmpi = OhmPi(settings='ohmpi_param.json') ohmpi = OhmPi(settings='ohmpi_settings.json')
\ No newline at end of file
File moved
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