Пример #1
0
    def from_fits_object(cls, fits_object, equivalency_threshold = 0.0001):
        session = object_session(fits_object)
        header = fits_object.fits_data[0].header
        filter1 = GMOSFilter.from_keyword(header['filter1'], session)
        filter2 = GMOSFilter.from_keyword(header['filter2'], session)

        grating = GMOSGrating.from_keyword(header['grating'], session)


        grating_central_wavelength = header['centwave']
        grating_slit_wavelength = header['grwlen']

        grating_tilt = header['grtilt']
        grating_order = header['grorder']

        instrument = Instrument.from_fits_object(fits_object)

        instrument_setup_object = 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)
                                                    / grating_central_wavelength) < equivalency_threshold,
            (func.abs(cls.grating_slit_wavelength_value - grating_slit_wavelength)
                                                    / grating_slit_wavelength) < equivalency_threshold,
            (func.abs(cls.grating_tilt_value - grating_tilt)
                                                    / grating_tilt) < equivalency_threshold).all()


        if instrument_setup_object == []:

            instrument_setup_object = cls(filter1.id, filter2.id, grating.id, grating_central_wavelength,
                                          grating_slit_wavelength, grating_tilt, grating_order, instrument.id)

            session.add(instrument_setup_object)
            session.commit()

            for fits_extension_id in xrange(1, len(fits_object.fits_data)):
                current_detector_id = GMOSDetector.from_fits_object(fits_object, fits_extension_id).id
                session.add(GMOSMOSInstrumentSetup2Detector(instrument_setup_id=instrument_setup_object.id,
                                                            fits_extension_id=fits_extension_id,
                                                            detector_id=current_detector_id))
            session.commit()



            return instrument_setup_object

        elif len(instrument_setup_object) == 1:
            return instrument_setup_object[0]

        else:
            raise ValueError('More than one Instrument setup with the same setup found: %s' % instrument_setup_object)
Пример #2
0
    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