def get_isis_translation(label): """ Compute the ISIS serial number for a given image using the input cube or the label extracted from the cube. Parameters ---------- label : dict or str A PVL dict object or file name to extract the PVL object from Returns ------- translation : dict A PVLModule object containing the extracted translation file """ # Instantiate a DB session if not already instantiated if not hasattr(plio, 'data_session'): print(get_data('data.db')) plio.data_session = setup_db_session(get_data('data.db')) # Grab the label is not already read if not isinstance(label, PVLModule): label = pvl.load(label) # Grab the spacecraft name and run it through the ISIS lookup spacecraft_name = find_in_dict(label, 'SpacecraftName') for row in plio.data_session.query(StringToMission).filter( StringToMission.key == spacecraft_name): spacecraft_name = row.value.lower() # Try and pull an instrument identifier try: instrumentid = find_in_dict(label, 'InstrumentId').capitalize() except: instrumentid = None translation = None # Grab the translation PVL object using the lookup for row in plio.data_session.query(Translations).filter( Translations.mission == spacecraft_name, Translations.instrument == instrumentid): # Convert the JSON back to a PVL object translation = PVLModule(row.translation) return translation
def get_isis_translation(label): """ Compute the ISIS serial number for a given image using the input cube or the label extracted from the cube. Parameters ---------- label : dict or str A PVL dict object or file name to extract the PVL object from Returns ------- translation : dict A PVLModule object containing the extracted translation file """ # Instantiate a DB session if not already instantiated if not hasattr(plio, 'data_session'): print(get_data('data.db')) plio.data_session = setup_db_session(get_data('data.db')) # Grab the label is not already read if not isinstance(label, PVLModule): label = pvl.load(label) # Grab the spacecraft name and run it through the ISIS lookup spacecraft_name = find_in_dict(label, 'SpacecraftName') for row in plio.data_session.query(StringToMission).filter(StringToMission.key==spacecraft_name): spacecraft_name = row.value.lower() # Try and pull an instrument identifier try: instrumentid = find_in_dict(label, 'InstrumentId').capitalize() except: instrumentid = None translation = None # Grab the translation PVL object using the lookup for row in plio.data_session.query(Translations).filter(Translations.mission==spacecraft_name, Translations.instrument==instrumentid): # Convert the JSON back to a PVL object translation = PVLModule(row.translation) return translation
def test_setup_session(self): print(get_data('data.db')) data_session = io_db.setup_db_session(get_data('data.db')) self.assertIsInstance(data_session, session.Session)