diff --git a/cdci_data_analysis/analysis/instrument.py b/cdci_data_analysis/analysis/instrument.py index ec3658586..0d7bd8c2c 100644 --- a/cdci_data_analysis/analysis/instrument.py +++ b/cdci_data_analysis/analysis/instrument.py @@ -586,8 +586,11 @@ def set_catalog(self, par_dic): except RuntimeError: raise RequestNotUnderstood('format not valid, a catalog should be provided as a FITS (typical standard OSA catalog) or ' 'ECSV table.') - self.set_par('user_catalog', catalog_object) - self.set_par('selected_catalog', json.dumps(catalog_object.get_dictionary())) + # normalize catalog + normalized_user_catalog = normalize_catalog(catalog_object) + + self.set_par('user_catalog', normalized_user_catalog) + self.set_par('selected_catalog', json.dumps(normalized_user_catalog.get_dictionary())) # not needed in the frontend par_dic.pop('user_catalog_file', None) else: @@ -600,6 +603,7 @@ def set_catalog(self, par_dic): raise RequestNotUnderstood("the selected catalog is wrongly formatted, please check your inputs") else: catalog_selected_objects = None + if 'selected_catalog' in par_dic.keys(): catalog_dic = json.loads(par_dic['selected_catalog']) try: @@ -607,13 +611,26 @@ def set_catalog(self, par_dic): except ValueError as e: e_message = str(e) raise RequestNotUnderstood(e_message) - self.set_par('user_catalog', user_catalog) + # normalize catalog + normalized_user_catalog = normalize_catalog(user_catalog) + self.set_par('user_catalog', normalized_user_catalog) + +# TODO consider if better to move those three functions inside catalog module def load_user_catalog(user_catalog_file): return BasicCatalog.from_file(user_catalog_file) +# TODO here I would apply the normalization +def normalize_catalog(catalog_object): + if isinstance(catalog_object, BasicCatalog): + catalog_object = catalog_object.get_dictionary() + normalized_catalog_object = dict() + + return build_catalog(normalized_catalog_object) + + def build_catalog(cat_dic,catalog_selected_objects=None): from astropy import units as u from astropy.coordinates import Angle, Latitude, Longitude diff --git a/tests/test_server_basic.py b/tests/test_server_basic.py index 67f6653a5..98b24e282 100644 --- a/tests/test_server_basic.py +++ b/tests/test_server_basic.py @@ -934,6 +934,22 @@ def test_catalog_file(dispatcher_live_fixture, correct_format): assert jdata['error_message'] == error_message +def test_catalog_normalization(): + from cdci_data_analysis.analysis.instrument import normalize_catalog + + catalog_first_format_str = "{\"cat_frame\": \"fk5\", \"cat_coord_units\": \"deg\", \"cat_column_list\": [[6, 15, 17, 20, 65, 75, 76], [\"3A 0114+650\", \"Cas A\", \"Gam Cas\", \"IGR J00234+6141\", \"RX J0146.9+6121\", \"Swift J0243.6+6124\", \"V709 Cas\"], [23.42287254333496, 11.746102333068848, 14.557199478149414, 7.326473712921143, 8.661062240600586, 22.566688537597656, 20.007556915283203], [19.539852142333984, 350.8506164550781, 14.176933288574219, 5.745247840881348, 26.80240249633789, 40.95994567871094, 7.214724063873291], [65.28630828857422, 58.809852600097656, 60.71382522583008, 61.7390022277832, 61.40255355834961, 61.441776275634766, 59.295379638671875], [-32768, -32768, -32768, -32768, -32768, -32768, -32768], [2, 2, 1, 2, 2, 2, 2], [0, 1, 0, 0, 0, 0, 0], [2.9999999242136255e-05, 0.00016999999934341758, 0.02500000037252903, 0.00018000000272877514, 0.0005600000149570405, 0.00041666667675599456, 0.0002800000074785203]], \"cat_column_names\": [\"meta_ID\", \"src_names\", \"significance\", \"ra\", \"dec\", \"NEW_SOURCE\", \"ISGRI_FLAG\", \"FLAG\", \"ERR_RAD\"], \"cat_column_descr\": [[\"meta_ID\", \"f4\"],[\"ra\",\">f4\"],[\"dec\",\">f4\"],[\"NEW_SOURCE\",\">i2\"],[\"ISGRI_FLAG\",\"