def populate_obs_type_image_COVIMS_duration(**kwargs): metadata = kwargs['metadata'] index_row = metadata['index_row'] inst_mod = index_row['INSTRUMENT_MODE_ID'] if inst_mod != 'IMAGE': return None phase_name = metadata['phase_name'] ir_exp = import_util.safe_column(index_row, 'IR_EXPOSURE') vis_exp = import_util.safe_column(index_row, 'VIS_EXPOSURE') if phase_name == 'IR': if ir_exp is None: return None if ir_exp < 0: import_util.log_nonrepeating_warning(f'IR Exposure {ir_exp} is < 0') return None return ir_exp/1000 if vis_exp is None: return None if vis_exp < 0: import_util.log_nonrepeating_warning(f'VIS Exposure {vis_exp} is < 0') return None return vis_exp/1000
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_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_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_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_HSTACS_spec_size_OBS(**kwargs): filter1, filter2 = _decode_filters(**kwargs) if not filter1.startswith('G') and not filter1.startswith('PR'): return None # We can't use WAVELENGTH_RESOLUTION because it's too aggressive. # Instead we use the Resolving Power (lambda / d-lambda) from ACS Inst # Handbook Table 3.5 if filter1 == 'G800L': # G800L's resolving power depends on the channel and order, which we # don't know import_util.log_nonrepeating_warning( 'G800L filter used, but not enough information available to '+ 'compute spec_size') wr = 8000. / 120 * .0001 # Average 100 and 140 bw = (10500-5500) * .0001 elif filter1 == 'PR200L': wr = 2500. / 59 * .0001 bw = (3900-1700) * .0001 elif filter1 == 'PR110L': wr = 1500. / 79 * .0001 bw = (1800-1150) * .0001 elif filter1 == 'PR130L': wr = 1500. / 96 * .0001 bw = (1800-1250) * .0001 else: assert False, filter1 return bw // wr
def populate_obs_mission_hubble_HSTACS_filter_type(**kwargs): filter1, filter2 = _decode_filters(**kwargs) # We only care about filter1 since the second is (almost) always a # polarizer if filter2 is not None and not filter2.startswith('POL'): import_util.log_nonrepeating_warning( f'Filter combination {filter1}+{filter2} does not have a' +' polarizer as the second filter - filter_type may be wrong') # From ACS Inst handbook Table 3.3 if filter1 in ['F475W', 'F625W', 'F775W', 'F850LP', 'F435W', 'F555W', 'F550M', 'F606W', 'F814W', 'F220W', 'F250W', 'F330W', 'CLEAR']: return 'W' if filter1 in ['F658N', 'F502N', 'F660N', 'F344N', 'F892N']: return 'N' if filter1.startswith('FR'): return 'FR' if filter1 in ['G800L', 'PR200L', 'PR110L', 'PR130L']: return 'SP' if filter1 in ['F122M']: return 'M' if filter1 in ['F115LP', 'F125LP', 'F140LP', 'F150LP', 'F165LP']: return 'LP' # ACS doesn't have any CH4 filters import_util.log_nonrepeating_error( f'Unknown filter {filter1} while determining filter type') return None
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_general_COUVIS_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_warning( 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_COUVIS_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_warning( 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_type_image_COVIMS_duration_OBS(**kwargs): metadata = kwargs['metadata'] index_row = metadata['index_row'] inst_mod = index_row['INSTRUMENT_MODE_ID'] if inst_mod != 'IMAGE': return None phase_name = metadata['phase_name'] ir_exp = import_util.safe_column(index_row, 'IR_EXPOSURE') vis_exp = import_util.safe_column(index_row, 'VIS_EXPOSURE') if phase_name == 'IR': if ir_exp is None: return None if ir_exp < 0: import_util.log_nonrepeating_warning(f'IR Exposure {ir_exp} is < 0') return None return ir_exp/1000 if vis_exp is None: return None if vis_exp < 0: import_util.log_nonrepeating_warning(f'VIS Exposure {vis_exp} is < 0') return None return vis_exp/1000
def populate_obs_mission_cassini_COVIMS_spacecraft_clock_count1(**kwargs): metadata = kwargs['metadata'] index_row = metadata['index_row'] count = index_row['SPACECRAFT_CLOCK_START_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 return sc_cvt
def populate_obs_mission_cassini_COVIMS_spacecraft_clock_count1_OBS(**kwargs): metadata = kwargs['metadata'] index_row = metadata['index_row'] count = index_row['SPACECRAFT_CLOCK_START_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 return sc_cvt
def populate_obs_pds_COUVIS_product_creation_time(**kwargs): metadata = kwargs['metadata'] index_label = metadata['index_label'] pct = index_label['PRODUCT_CREATION_TIME'] try: pct_sec = julian.tai_from_iso(pct) except Exception as e: import_util.log_nonrepeating_warning( f'Bad product creation time format "{pct}": {e}') return None return pct_sec
def populate_obs_mission_cassini_rev_no_cvt(**kwargs): metadata = kwargs['metadata'] cassini_row = metadata['obs_mission_cassini_row'] rev_no = cassini_row['rev_no'] if rev_no is None: return None try: rev_no_cvt = opus_support.parse_cassini_orbit(rev_no) except Exception as e: import_util.log_nonrepeating_warning( f'Unable to parse Cassini orbit "{rev_no}": {e}') return None return rev_no_cvt
def populate_obs_mission_cassini_COUVIS_spacecraft_clock_count1_OCC(**kwargs): metadata = kwargs['metadata'] supp_index_row = metadata['supp_index_row'] sc = supp_index_row['SPACECRAFT_CLOCK_START_COUNT'] if sc == 'UNK': return None 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 return sc_cvt
def populate_obs_mission_cassini_COUVIS_spacecraft_clock_count2(**kwargs): metadata = kwargs['metadata'] index_row = metadata['index_row'] count = index_row['SPACECRAFT_CLOCK_START_COUNT'] count = helper_fix_cassini_sclk(count) general_row = metadata['obs_general_row'] time1 = general_row['time1'] time2 = general_row['time2'] try: count_sec = opus_support.parse_cassini_sclk(count) except Exception as e: import_util.log_nonrepeating_warning( f'Unable to parse Cassini SCLK "{count}": {e}') return None new_count_sec = count_sec + (time2-time1) return new_count_sec
def populate_obs_general_HSTx_observation_type_OBS(**kwargs): metadata = kwargs['metadata'] instrument = kwargs['instrument_name'] index_row = metadata['index_row'] obs_type = index_row['OBSERVATION_TYPE'] # XXX Temporary fix for issue pds-webserver/10 if obs_type not in ('IMAGE', 'IMAGING', 'SPECTRUM', 'SPECTROSCOPIC'): import_util.log_nonrepeating_error( f'Unknown HST OBSERVATION_TYPE "{obs_type}"') return None if obs_type in ('IMAGING', 'SPECTROSCOPIC'): import_util.log_nonrepeating_warning( f'Converting bad observation_type {obs_type}') if obs_type.startswith('SPEC'): # Covers bad "SPECTROSCOPIC" value return 'SPI' # Spectral Image (2-D with spectral information) return 'IMG' # Image
def populate_obs_general_COUVIS_time1(**kwargs): metadata = kwargs['metadata'] index_row = metadata['index_row'] start_time = import_util.safe_column(index_row, 'START_TIME') if start_time is None: return None try: start_time_sec = julian.tai_from_iso(start_time) except Exception as e: import_util.log_nonrepeating_warning( f'Bad start time format "{start_time}": {e}') return None return start_time_sec
def populate_obs_mission_cassini_COUVIS_spacecraft_clock_count2(**kwargs): metadata = kwargs['metadata'] index_row = metadata['index_row'] count = index_row['SPACECRAFT_CLOCK_START_COUNT'] count = helper_fix_cassini_sclk(count) general_row = metadata['obs_general_row'] time1 = general_row['time1'] time2 = general_row['time2'] try: count_sec = opus_support.parse_cassini_sclk(count) except Exception as e: import_util.log_nonrepeating_warning( f'Unable to parse Cassini SCLK "{count}": {e}') return None new_count_sec = count_sec + (time2 - time1) return new_count_sec
def populate_obs_mission_cassini_COCIRS_spacecraft_clock_count1(**kwargs): metadata = kwargs['metadata'] index_row = metadata['index_row'] sc = index_row['SPACECRAFT_CLOCK_START_COUNT'] sc = helper_fix_cassini_sclk(sc) if not sc.startswith('1/') or sc[2] == ' ': import_util.log_nonrepeating_warning( f'Badly formatted SPACECRAFT_CLOCK_START_COUNT "{sc}"') return None 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 return sc_cvt
def populate_obs_mission_cassini_COUVIS_spacecraft_clock_count1(**kwargs): metadata = kwargs['metadata'] index_row = metadata['index_row'] sc = index_row['SPACECRAFT_CLOCK_START_COUNT'] sc = helper_fix_cassini_sclk(sc) if not sc.startswith('1/'): import_util.log_nonrepeating_warning( f'Badly formatted SPACECRAFT_CLOCK_START_COUNT "{sc}"') return None 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 return sc_cvt
def populate_obs_mission_cassini_ert1(**kwargs): metadata = kwargs['metadata'] index_row = metadata['index_row'] # START_TIME isn't available for COUVIS start_time = index_row.get('EARTH_RECEIVED_START_TIME', None) if start_time is None: return None try: ert_sec = julian.tai_from_iso(start_time) except Exception as e: import_util.log_nonrepeating_warning( f'Bad earth received start time format "{start_time}": {e}') return None return ert_sec
def populate_obs_mission_cassini_COVIMS_spacecraft_clock_count1_OCC(**kwargs): metadata = kwargs['metadata'] supp_index_row = metadata['supp_index_row'] sc = supp_index_row['SPACECRAFT_CLOCK_START_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 down if '.' in sc: sc = sc.split('.')[0] + '.000' 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 return sc_cvt
def populate_obs_mission_hubble_aperture_type(**kwargs): metadata = kwargs['metadata'] instrument = kwargs['instrument_name'] index_row = metadata['index_row'] aperture = index_row['APERTURE_TYPE'] # Temporary fix for issue #491 XXX old_aperture = aperture if aperture == 'NIC1FIX': aperture = 'NIC1-FIX' elif aperture == 'NIC2FIX': aperture = 'NIC2-FIX' elif aperture == 'NIC3FIX': aperture = 'NIC3-FIX' if old_aperture != aperture: import_util.log_nonrepeating_warning( f'Replaced bad aperture {old_aperture} with {aperture}') ret = instrument[3:] + '-' + aperture return (ret, ret)
def _COISS_wavelength_helper(inst, filter1, filter2): key = (inst, filter1, filter2) if key in _COISS_FILTER_WAVELENGTHS: return _COISS_FILTER_WAVELENGTHS[key] # If we don't have the exact key combination, try to set polarization equal # to CLEAR for lack of anything better to do. nfilter1 = filter1 if filter1.find('P') == -1 else 'CL1' nfilter2 = filter2 if filter2.find('P') == -1 else 'CL2' key2 = (inst, nfilter1, nfilter2) if key2 in _COISS_FILTER_WAVELENGTHS: import_util.log_nonrepeating_warning( 'Using CLEAR instead of polarized filter for unknown COISS ' + f'filter combination {key[0]}/{key[1]}/{key[2]}') return _COISS_FILTER_WAVELENGTHS[key2] import_util.log_nonrepeating_warning( 'Ignoring unknown COISS filter combination ' + f'{key[0]}/{key[1]}/{key[2]}') return None, None, None
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_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_wavelength_COUVIS_wavelength2(**kwargs): channel, image_time = _COUVIS_channel_time_helper(**kwargs) if channel == 'HSP': return 0.19 if channel == 'HDAC': return 0.180 metadata = kwargs['metadata'] supp_index_row = metadata.get('supp_index_row', None) if supp_index_row is None: return None band2 = import_util.safe_column(supp_index_row, 'MINIMUM_BAND_NUMBER') if band2 is None: return None if channel == 'EUV': return 0.0558 + (band2 + 1) * 0.0000607422 if channel == 'FUV': return 0.11 + (band2 + 1) * 0.000078125 import_util.log_nonrepeating_warning( f'obs_wavelength_COUVIS_wavelength1 has unknown channel type ' + f' {channel}') return None
def _COUVIS_is_image(**kwargs): channel, image_time = _COUVIS_channel_time_helper(**kwargs) metadata = kwargs['metadata'] index_row = metadata['index_row'] slit_state = index_row['SLIT_STATE'] if channel == 'HSP' or channel == 'HDAC': return False assert channel == 'EUV' or channel == 'FUV' if slit_state == 'OCCULTATION': return False supp_index_row = metadata['supp_index_row'] if supp_index_row is None: import_util.log_nonrepeating_warning( f'_COUVIS_is_image has channel EUV or FUV but no ' + f'DATA_OBJECT_TYPE available') return False object_type = supp_index_row['DATA_OBJECT_TYPE'] if object_type == 'SPECTRUM': return False return True
def _COUVIS_is_image(**kwargs): channel, image_time = _COUVIS_channel_time_helper(**kwargs) metadata = kwargs['metadata'] index_row = metadata['index_row'] slit_state = index_row['SLIT_STATE'] if channel == 'HSP' or channel == 'HDAC': return False assert channel == 'EUV' or channel == 'FUV' if slit_state == 'OCCULTATION': return False supp_index_row = metadata['supp_index_row'] if supp_index_row is None: import_util.log_nonrepeating_warning( f'_COUVIS_is_image has channel EUV or FUV but no '+ f'DATA_OBJECT_TYPE available') return False object_type = supp_index_row['DATA_OBJECT_TYPE'] if object_type == 'SPECTRUM': return False return True
def populate_obs_wavelength_COUVIS_wavelength2(**kwargs): channel, image_time = _COUVIS_channel_time_helper(**kwargs) if channel == 'HSP': return 0.19 if channel == 'HDAC': return 0.180 metadata = kwargs['metadata'] supp_index_row = metadata.get('supp_index_row', None) if supp_index_row is None: return None band2 = import_util.safe_column(supp_index_row, 'MINIMUM_BAND_NUMBER') if band2 is None: return None if channel == 'EUV': return 0.0558 + (band2 + 1) * 0.0000607422 if channel == 'FUV': return 0.11 + (band2 + 1) * 0.000078125 import_util.log_nonrepeating_warning( f'obs_wavelength_COUVIS_wavelength1 has unknown channel type '+ f' {channel}') return None
def populate_obs_general_preview_images(**kwargs): metadata = kwargs['metadata'] general_row = metadata['obs_general_row'] file_spec = general_row['primary_file_spec'] # XXX if file_spec.startswith('NH'): file_spec = file_spec.replace('.lbl', '.fit') file_spec = file_spec.replace('.LBL', '.FIT') elif file_spec.startswith('COUVIS'): file_spec = file_spec.replace('.LBL', '.DAT') elif file_spec.startswith('VGISS'): file_spec = file_spec.replace('.LBL', '.IMG') pdsf = pdsfile.PdsFile.from_filespec(file_spec) try: viewset = pdsf.viewset except ValueError as e: import_util.log_nonrepeating_warning( f'ViewSet threw ValueError for "{file_spec}": {e}') if pdsfile.PdsFile.LAST_EXC_INFO != (None, None, None): trace_str = traceback.format_exception( *pdsfile.PdsFile.LAST_EXC_INFO) import_util.log_nonrepeating_warning( 'PdsFile had internal error: '+''.join(trace_str)) pdsfile.PdsFile.LAST_EXC_INFO = (None, None, None) viewset = None if viewset: browse_data = viewset.to_dict() if not impglobals.ARGUMENTS.import_ignore_missing_images: if not viewset.thumbnail: import_util.log_nonrepeating_warning( f'Missing thumbnail browse/diagram image for "{file_spec}"') if not viewset.small: import_util.log_nonrepeating_warning( f'Missing small browse/diagram image for "{file_spec}"') if not viewset.medium: import_util.log_nonrepeating_warning( f'Missing medium browse/diagram image for "{file_spec}"') if not viewset.full_size: import_util.log_nonrepeating_warning( f'Missing full_size browse/diagram image for "{file_spec}"') else: if impglobals.ARGUMENTS.import_fake_images: # impglobals.LOGGER.log('debug', # f'Faking browse/diagram images for "{file_spec}"') base_path = os.path.splitext(pdsf.logical_path)[0] if base_path.find('CIRS') != -1: base_path = base_path.replace('volumes', 'diagrams') base_path = base_path.replace('DATA/APODSPEC/SPEC', 'BROWSE/TARGETS/IMG') else: base_path = base_path.replace('volumes', 'previews') base_path = 'holdings/'+base_path ext = 'jpg' if (base_path.find('VIMS') != -1 or base_path.find('UVIS') != -1): ext = 'png' browse_data = {'viewables': [{'url': base_path+'_thumb.'+ext, 'bytes': 500, 'width': 100, 'height': 100}, {'url': base_path+'_small.'+ext, 'bytes': 1000, 'width': 256, 'height': 256}, {'url': base_path+'_med.'+ext, 'bytes': 2000, 'width': 512, 'height': 512}, {'url': base_path+'_full.'+ext, 'name': 'full', 'bytes': 4000, 'width': 1024, 'height': 1024} ] } else: browse_data = {'viewables': []} if not impglobals.ARGUMENTS.import_ignore_missing_images: import_util.log_nonrepeating_warning( f'Missing all browse/diagram images for "{file_spec}"') ret = json.dumps(browse_data) return ret
def _log_nonrepeating_warning(self, *args, **kwargs): log_nonrepeating_warning(*args, **kwargs)
def populate_obs_general_preview_images(**kwargs): metadata = kwargs['metadata'] volset = kwargs['volset'] general_row = metadata['obs_general_row'] file_spec = general_row['primary_file_spec'] # XXX if file_spec.startswith('NH'): file_spec = file_spec.replace('.lbl', '.fit') file_spec = file_spec.replace('.LBL', '.FIT') elif file_spec.startswith('COUVIS'): file_spec = file_spec.replace('.LBL', '.DAT') elif file_spec.startswith('VGISS'): file_spec = file_spec.replace('.LBL', '.IMG') elif file_spec.startswith('CORSS'): file_spec = file_spec.replace('.LBL', '.TAB') pdsf = pdsfile.PdsFile.from_filespec(file_spec) try: viewset = pdsf.viewset except ValueError as e: import_util.log_nonrepeating_warning( f'ViewSet threw ValueError for "{file_spec}": {e}') if pdsfile.PdsFile.LAST_EXC_INFO != (None, None, None): trace_str = traceback.format_exception( *pdsfile.PdsFile.LAST_EXC_INFO) import_util.log_nonrepeating_warning( 'PdsFile had internal error: '+''.join(trace_str)) pdsfile.PdsFile.LAST_EXC_INFO = (None, None, None) viewset = None if viewset: browse_data = viewset.to_dict() if not impglobals.ARGUMENTS.import_ignore_missing_images: if not viewset.thumbnail: import_util.log_nonrepeating_warning( f'Missing thumbnail browse/diagram image for "{file_spec}"') if not viewset.small: import_util.log_nonrepeating_warning( f'Missing small browse/diagram image for "{file_spec}"') if not viewset.medium: import_util.log_nonrepeating_warning( f'Missing medium browse/diagram image for "{file_spec}"') if not viewset.full_size: import_util.log_nonrepeating_warning( f'Missing full_size browse/diagram image for "{file_spec}"') else: if impglobals.ARGUMENTS.import_fake_images: # impglobals.LOGGER.log('debug', # f'Faking browse/diagram images for "{file_spec}"') base_path = os.path.splitext(pdsf.logical_path)[0] if base_path.find('CIRS') != -1: base_path = base_path.replace('volumes', 'diagrams') base_path = base_path.replace('DATA/APODSPEC/SPEC', 'BROWSE/TARGETS/IMG') else: base_path = base_path.replace('volumes', 'previews') base_path = 'holdings/'+base_path ext = 'jpg' if (base_path.find('VIMS') != -1 or base_path.find('UVIS') != -1): ext = 'png' browse_data = {'viewables': [{'url': base_path+'_thumb.'+ext, 'bytes': 500, 'width': 100, 'height': 100}, {'url': base_path+'_small.'+ext, 'bytes': 1000, 'width': 256, 'height': 256}, {'url': base_path+'_med.'+ext, 'bytes': 2000, 'width': 512, 'height': 512}, {'url': base_path+'_full.'+ext, 'name': 'full', 'bytes': 4000, 'width': 1024, 'height': 1024} ] } else: browse_data = {'viewables': []} if (volset in VOLSETS_WITH_PREVIEWS and not impglobals.ARGUMENTS.import_ignore_missing_images): import_util.log_nonrepeating_warning( f'Missing all browse/diagram images for "{file_spec}"') ret = json.dumps(browse_data) return ret