def populate_obs_mission_cassini_COISS_spacecraft_clock_count2(**kwargs): metadata = kwargs['metadata'] index_row = metadata['index_row'] partition = index_row['SPACECRAFT_CLOCK_CNT_PARTITION'] count = index_row['SPACECRAFT_CLOCK_STOP_COUNT'] sc = str(partition) + '/' + str(count) sc = helper_fix_cassini_sclk(sc) try: sc_cvt = opus_support.parse_cassini_sclk(sc) except Exception as e: import_util.log_nonrepeating_warning( f'Unable to parse Cassini SCLK "{sc}": {e}') return None cassini_row = metadata['obs_mission_cassini_row'] sc1 = cassini_row['spacecraft_clock_count1'] if sc1 is not None and sc_cvt < sc1: import_util.log_warning( f'spacecraft_clock_count1 ({sc1}) and spacecraft_clock_count2 ({sc_cvt}) ' + f'are in the wrong order - setting to count1') sc_cvt = sc1 else: index_row = metadata['index_row'] image_number = index_row['IMAGE_NUMBER'] sc2_int = int(sc_cvt) if int(image_number) != sc2_int: import_util.log_warning( f'spacecraft_clock_count2 ({sc_cvt}) and COISS IMAGE_NUMBER ' + f'({image_number}) don\'t match') return sc_cvt
def populate_obs_general_NHMVIC_time2(**kwargs): metadata = kwargs['metadata'] index_row = metadata['index_row'] stop_time = import_util.safe_column(index_row, 'STOP_TIME') if stop_time is None: return None try: stop_time_sec = julian.tai_from_iso(stop_time) except Exception as e: import_util.log_nonrepeating_error( f'Bad stop time format "{stop_time}": {e}') return None general_row = metadata['obs_general_row'] start_time_sec = general_row['time1'] if start_time_sec is not None and stop_time_sec < start_time_sec: start_time = import_util.safe_column(index_row, 'START_TIME') import_util.log_warning(f'time1 ({start_time}) and time2 ({stop_time}) ' f'are in the wrong order - setting to time1') stop_time_sec = start_time_sec return stop_time_sec
def populate_obs_general_COISS_time2(**kwargs): metadata = kwargs['metadata'] index_row = metadata['index_row'] stop_time = import_util.safe_column(index_row, 'STOP_TIME') if stop_time is None: return None try: stop_time_sec = julian.tai_from_iso(stop_time) except Exception as e: import_util.log_nonrepeating_error( f'Bad stop time format "{stop_time}": {e}') return None general_row = metadata['obs_general_row'] start_time_sec = general_row['time1'] if start_time_sec is not None and stop_time_sec < start_time_sec: start_time = import_util.safe_column(index_row, 'START_TIME') import_util.log_warning( f'time1 ({start_time}) and time2 ({stop_time}) ' f'are in the wrong order - setting to time1') stop_time_sec = start_time_sec return stop_time_sec
def create_cart(): # There's really no point in doing this as an import table first, # since we're just creating an empty table. db = impglobals.DATABASE if not db.table_exists('perm', 'obs_general'): # We can't create cart here, because it has a foreign key # constraint on obs_general. But we needed to have tried because we # need to be able to delete things from obs_general and have # cart be empty! Chicken and egg. # So what we do is check here to see if obs_general exists. If it does, # we can go ahead and remove and re-create cart. If it doesn't, # then we don't do anything right now but set a flag to say that we'll # try again at the end of the import. if impglobals.TRY_CART_LATER: # Oops! We've already been down this road once, and apparently the # creation of obs_general failed. So we can't do anything. import_util.log_error( 'Unable to create "cart" table because "obs_general" doesn\'t exist' ) return impglobals.TRY_CART_LATER = True import_util.log_warning( 'Unable to create "cart" table because "obs_general" doesn\'t exist' + ' - Will try again later') return cart_schema = import_util.read_schema_for_table('cart') db.drop_table('perm', 'cart') db.create_table('perm', 'cart', cart_schema, ignore_if_exists=False)
def populate_obs_mission_cassini_COCIRS_spacecraft_clock_count2(**kwargs): metadata = kwargs['metadata'] index_row = metadata['index_row'] sc = index_row['SPACECRAFT_CLOCK_STOP_COUNT'] sc = helper_fix_cassini_sclk(sc) cassini_row = metadata['obs_mission_cassini_row'] # For CIRS only, there are some badly formatted clock counts sc1 = cassini_row['spacecraft_clock_count1'] if not sc.startswith('1/') or sc[2] == ' ': import_util.log_nonrepeating_warning( f'Badly formatted SPACECRAFT_CLOCK_STOP_COUNT "{sc}"') return sc1 try: sc_cvt = opus_support.parse_cassini_sclk(sc) except Exception as e: import_util.log_nonrepeating_warning( f'Unable to parse Cassini SCLK "{sc}": {e}') return sc1 if sc1 is not None and sc_cvt < sc1: import_util.log_warning( f'spacecraft_clock_count1 ({sc1}) and spacecraft_clock_count2 ({sc_cvt}) ' + f'are in the wrong order - setting to count1') sc_cvt = sc1 return sc_cvt
def populate_obs_mission_cassini_COVIMS_spacecraft_clock_count2_OCC(**kwargs): metadata = kwargs['metadata'] supp_index_row = metadata['supp_index_row'] sc = supp_index_row['SPACECRAFT_CLOCK_STOP_COUNT'] if sc == 'UNK': return None # COVIMS_8001 SCLKs are in some weird units where the number to the right # of the decimal can be > 255, so we just round up if '.' in sc: sc = sc.split('.')[0] + '.000' try: sc_cvt = opus_support.parse_cassini_sclk(sc)+1 # Round up except Exception as e: import_util.log_nonrepeating_warning( f'Unable to parse Cassini SCLK "{sc}": {e}') return None cassini_row = metadata['obs_mission_cassini_row'] sc1 = cassini_row['spacecraft_clock_count1'] if sc1 is not None and sc_cvt < sc1: import_util.log_warning( f'spacecraft_clock_count1 ({sc1}) and spacecraft_clock_count2 ({sc_cvt}) ' +f'are in the wrong order - setting to count1') sc_cvt = sc1 return sc_cvt
def populate_obs_mission_voyager_spacecraft_clock_count2(**kwargs): metadata = kwargs['metadata'] supp_index_row = metadata['supp_index_row'] if supp_index_row is None: return None partition = import_util.safe_column(supp_index_row, 'SPACECRAFT_CLOCK_PARTITION_NUMBER') stop_time = supp_index_row['SPACECRAFT_CLOCK_STOP_COUNT'] sc = str(partition) + '/' + stop_time try: sc_cvt = opus_support.parse_voyager_sclk(sc) except Exception as e: import_util.log_nonrepeating_error( f'Unable to parse Voyager SCLK "{sc}": {e}') return None voyager_row = metadata['obs_mission_voyager_row'] sc1 = voyager_row['spacecraft_clock_count1'] if sc1 is not None and sc_cvt < sc1: import_util.log_warning( f'spacecraft_clock_count1 ({sc1}) and spacecraft_clock_count2 ({sc_cvt}) ' +f'are in the wrong order - setting to count1') sc_cvt = sc1 return sc_cvt
def populate_obs_mission_cassini_ert2(**kwargs): metadata = kwargs['metadata'] index_row = metadata['index_row'] # STOP_TIME isn't available for COUVIS stop_time = index_row.get('EARTH_RECEIVED_STOP_TIME', None) if stop_time is None: return None try: ert_sec = julian.tai_from_iso(stop_time) except Exception as e: import_util.log_nonrepeating_warning( f'Bad earth received stop time format "{stop_time}": {e}') return None cassini_row = metadata['obs_mission_cassini_row'] start_time_sec = cassini_row['ert1'] if start_time_sec is not None and ert_sec < start_time_sec: import_util.log_warning( f'cassini_ert1 ({start_time_sec}) and cassini_ert2 ({ert_sec}) ' +f'are in the wrong order - setting to ert1') ert_sec = start_time_sec return ert_sec
def populate_obs_mission_cassini_COCIRS_spacecraft_clock_count2(**kwargs): metadata = kwargs['metadata'] index_row = metadata['index_row'] sc = index_row['SPACECRAFT_CLOCK_STOP_COUNT'] sc = helper_fix_cassini_sclk(sc) cassini_row = metadata['obs_mission_cassini_row'] # For CIRS only, there are some badly formatted clock counts sc1 = cassini_row['spacecraft_clock_count1'] if not sc.startswith('1/') or sc[2] == ' ': import_util.log_nonrepeating_warning( f'Badly formatted SPACECRAFT_CLOCK_STOP_COUNT "{sc}"') return sc1 try: sc_cvt = opus_support.parse_cassini_sclk(sc) except Exception as e: import_util.log_nonrepeating_warning( f'Unable to parse Cassini SCLK "{sc}": {e}') return sc1 if sc1 is not None and sc_cvt < sc1: import_util.log_warning( f'spacecraft_clock_count1 ({sc1}) and spacecraft_clock_count2 ({sc_cvt}) ' +f'are in the wrong order - setting to count1') sc_cvt = sc1 return sc_cvt
def populate_obs_wavelength_HSTSTIS_wave_res1_OBS(**kwargs): metadata = kwargs['metadata'] index_row = metadata['index_row'] wr1 = import_util.safe_column(index_row, 'MAXIMUM_WAVELENGTH_RESOLUTION') wr2 = import_util.safe_column(index_row, 'MINIMUM_WAVELENGTH_RESOLUTION') # This is necessary because in some cases these are backwards in the table! if wr1 > wr2: import_util.log_warning( 'MAXIMUM_WAVELENGTH_RESOLUTION < MINIMUM_WAVELENGTH_RESOLUTION; ' +'swapping') return wr2 return wr1
def populate_obs_wavelength_HSTx_wavelength1_OBS(**kwargs): metadata = kwargs['metadata'] index_row = metadata['index_row'] wl1 = import_util.safe_column(index_row, 'MINIMUM_WAVELENGTH') wl2 = import_util.safe_column(index_row, 'MAXIMUM_WAVELENGTH') if wl1 is None or wl2 is None: return None # This is necessary because in some cases these are backwards in the table! if wl1 > wl2: import_util.log_warning( 'MAXIMUM_WAVELENGTH < MINIMUM_WAVELENGTH; swapping') return wl2 return wl1
def populate_obs_mission_cassini_COVIMS_spacecraft_clock_count2_OBS(**kwargs): metadata = kwargs['metadata'] index_row = metadata['index_row'] count = index_row['SPACECRAFT_CLOCK_STOP_COUNT'] sc = '1/' + count sc = helper_fix_cassini_sclk(sc) try: sc_cvt = opus_support.parse_cassini_sclk(sc) except Exception as e: import_util.log_nonrepeating_warning( f'Unable to parse Cassini SCLK "{sc}": {e}') return None cassini_row = metadata['obs_mission_cassini_row'] sc1 = cassini_row['spacecraft_clock_count1'] if sc1 is not None and sc_cvt < sc1: import_util.log_warning( f'spacecraft_clock_count1 ({sc1}) and spacecraft_clock_count2 ({sc_cvt}) ' +f'are in the wrong order - setting to count1') sc_cvt = sc1 return sc_cvt
def populate_obs_mission_cassini_COVIMS_spacecraft_clock_count2(**kwargs): metadata = kwargs['metadata'] index_row = metadata['index_row'] count = index_row['SPACECRAFT_CLOCK_STOP_COUNT'] sc = '1/' + count sc = helper_fix_cassini_sclk(sc) try: sc_cvt = opus_support.parse_cassini_sclk(sc) except Exception as e: import_util.log_nonrepeating_warning( f'Unable to parse Cassini SCLK "{sc}": {e}') return None cassini_row = metadata['obs_mission_cassini_row'] sc1 = cassini_row['spacecraft_clock_count1'] if sc1 is not None and sc_cvt < sc1: import_util.log_warning( f'spacecraft_clock_count1 ({sc1}) and spacecraft_clock_count2 ({sc_cvt}) ' +f'are in the wrong order - setting to count1') sc_cvt = sc1 return sc_cvt
def populate_obs_general_CORSS_time2_OCC(**kwargs): metadata = kwargs['metadata'] supp_index_row = metadata['supp_index_row'] stop_time = supp_index_row['EARTH_RECEIVED_STOP_TIME'] try: stop_time_sec = julian.tai_from_iso(stop_time) except Exception as e: import_util.log_nonrepeating_error( f'Bad stop time format "{stop_time}": {e}') return None general_row = metadata['obs_general_row'] start_time_sec = general_row['time1'] if start_time_sec is not None and stop_time_sec < start_time_sec: start_time = supp_index_row['SPACECRAFT_EVENT_START_TIME'] import_util.log_warning( f'time1 ({start_time}) and time2 ({stop_time}) ' f'are in the wrong order - setting to time1') stop_time_sec = start_time_sec return stop_time_sec
def _log_warning(self, *args, **kwargs): log_warning(*args, **kwargs)