Skip to content

Commit

Permalink
Converting the process run configuations dictionary so that quantitie…
Browse files Browse the repository at this point in the history
…s can be stored as strings in the archive save file. For issue #69. Now need to make sure they are read back in correctly.

Signed-off-by: David Turner <turne540@msu.edu>
  • Loading branch information
DavidT3 committed Sep 2, 2024
1 parent 8f3f0bd commit a3a121b
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions daxa/archive/base.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# This code is a part of the Democratising Archival X-ray Astronomy (DAXA) module.
# Last modified by David J Turner (turne540@msu.edu) 02/09/2024, 18:40. Copyright (c) The Contributors
# Last modified by David J Turner (turne540@msu.edu) 02/09/2024, 19:02. Copyright (c) The Contributors

import json
import os
from copy import deepcopy
from shutil import rmtree
from typing import List, Union, Tuple
from warnings import warn
Expand Down Expand Up @@ -274,7 +275,6 @@ def __init__(self, archive_name: str, missions: Union[List[BaseMission], BaseMis
self._process_warnings = info_dict['process_warnings']
self._process_extra_info = info_dict['process_extra_info']
self._process_run_config = info_dict['process_run_config']
self._process_run_config = {}
self._use_this_obs = info_dict['use_this_obs']

# The raw logs and errors are different, as they are stored in human-readable formats in the
Expand Down Expand Up @@ -1799,8 +1799,23 @@ def save(self):
'obs_summaries': self.observation_summaries,
'final_process_success': self.final_process_success, 'process_errors': self.process_errors,
'process_warnings': self.process_warnings, 'process_extra_info': self.process_extra_info,
'use_this_obs': self.process_observation,
'process_run_config': self.process_configurations}
'use_this_obs': self.process_observation}

# We need to do a little pre-processing on the process configuration dictionary, because some of the parameters
# passed to some of the processing functions will be astropy quantities, and you cannot just stick them
# in a dictionary
pr_confs = deepcopy(self.process_configurations)
# Unfortunately ugly nested for loops, but life goes on - this will turn any non-json-storable data types
# into something that we can put in a json file and then reconstitute as the intended data type when
# we read back in
for mn in pr_confs:
for proc in pr_confs[mn]:
for par in pr_confs[mn][proc]:
if isinstance(pr_confs[mn][proc][par], Quantity):
# We add 'Quantity' to the front of the string to ensure that it is very easy to identify
# these when we load back in, as we'll need to turn them back into quantities
pr_confs[mn][proc][par] = "Quantity " + par.to_string()
process_data['process_run_config'] = pr_confs

with open(self._arch_meta_path + 'process_info.json', 'w') as processo:
pretty_string = json.dumps(process_data, indent=4)
Expand Down

0 comments on commit a3a121b

Please sign in to comment.