scikit-spectra
scikit-spectra copied to clipboard
jsonify
If I replace pickle with json, it should make it possible to use stored states after changing program versions. Not sure if htis just works out of hte box or if it's too hard it implement. Inspired by PyGnome serialization.
Will prolly need numpy compat json
import json import numpy as np class NumpyAwareJSONEncoder(json.JSONEncoder): def default(self, obj): if isinstance(obj, np.ndarray): return obj.tolist() return json.JSONEncoder.default(self, obj) with open('figure.json', 'w') as outfile: json.dump(figure, outfile, cls=NumpyAwareJSONEncoder)
After do this, don't forget to update script. Right now, it's outputting csv_cropped outside of the apply_parameters method where it originally was. That's because if I do intervals from csv, I cannot recover the original timestamps. Once jsonifying data, won't need to output this csv file; although could keep it in. I'd rather it be like:
full_data.json baseline_sub_index_cropped_as_interval.json
As to what is output test that the interval version can still fully recover the timestamps
GeoPandasDataframe has to_json(), may help
https://github.com/geopandas/geopandas/blob/master/geopandas/geodataframe.py