def from_fits_file(cls, fits_file, session, tilt_equivalency_threshold=0.001, wavelength_equivalency_threshold=0.0001): header = fits.getheader(fits_file) filter1 = GMOSFilter.from_keyword(header['filter1'], session) filter2 = GMOSFilter.from_keyword(header['filter2'], session) grating = GMOSGrating.from_keyword(header['grating'], session) instrument = Instrument.from_keyword(header['instrume'], session) grating_central_wavelength = header['centwave'] grating_slit_wavelength = header['grwlen'] grating_tilt = header['grtilt'] grating_order = header['grorder'] #Checking if the same instrument setup already exists instrument_setup_query = session.query(cls).filter( cls.filter1_id==filter1.id, cls.filter2_id==filter2.id, cls.grating_id==grating.id, cls.instrument_id==instrument.id, func.abs(cls.grating_central_wavelength_value - grating_central_wavelength) < wavelength_equivalency_threshold, func.abs(cls.grating_slit_wavelength_value - grating_slit_wavelength) < wavelength_equivalency_threshold, func.abs(cls.grating_tilt_value - grating_tilt) < tilt_equivalency_threshold) instrument_setup_object = instrument_setup_query.first() if instrument_setup_object is None: instrument_setup_object = cls( filter1_id=filter1.id, filter2_id=filter2.id, grating_id=grating.id, grating_central_wavelength_value=grating_central_wavelength, grating_slit_wavelength_value=grating_slit_wavelength, grating_tilt_value=grating_tilt, grating_order=grating_order, instrument_id=instrument.id) session.add(instrument_setup_object) session.commit() return instrument_setup_object