sandialabs / pyscan

Scientific Measurement Toolbox
https://pyscan.readthedocs.io/en/latest/
MIT License
4 stars 4 forks source link

added a json converter class in json_encoder.py to pyscan/general. Th… #184

Closed rsbrost closed 3 weeks ago

rsbrost commented 1 month ago

…is is now implemented in the save_metadata method of abstract_experiment.py which enables numpy values to be used as data inputs before saving. The converter changes the numpy values to standard python values and no longer throws the same type error as before.

rsbrost commented 4 weeks ago

Got it working sufficiently, but Andy says he wants it as a json-converter in place of the recursive_to_dict function. I had issues when trying this at first; however, I will try to solve them exhaustively before reopening this pull request.

rsbrost commented 4 weeks ago

The specific type error issue from before was: "TypeError: Object of type wrapper_descriptor is not JSON serializable." Looking into overcoming this now. I think it has to do with not properly omitting certain keys from the converter data, such as those with keys: ['logger', 'expt_thread', 'data_path', 'instrument', 'module_id_string', 'spec']. Not sure how to best handle this yet, although again, the original issue detailing how numpy values were not saveable by json has been addressed and is currently working with recursive_to_dict as mentioned above.

rsbrost commented 3 weeks ago

encoder has been added to replace recursive_to_dict, as well as encoder to replace recursive_to_item_attribute.