Esempio n. 1
0
    def createFromSqlResult(proposal_id, result):
        """
        Creates a new Session instance initialized using the request from
        an SQL query.
        """

        c = Conversions()

        epoch = SourceCoordinateEpoch.objects.get(epoch = result['coordinate'])
        sys = SourceCoordinateSystem.objects.get(system = result['coordinate_system'])
        vType = SourceVelocityType.objects.get(type = result['velocity_type'])
        ref = SourceReferenceFrame.objects.get(frame = result['referenceFrame'])
        con = SourceConvention.objects.get(convention = result['convention'])
        
        # Occasionally this string can be something dumb like '?'
        try:
            vRedshift = float(result['velocity_redshift'])
        except:
            vRedshift = None

        source = Source(pst_source_id = result['source_id']
                          # Don't use result's because that's for the
                          # PST, not our GB PHT DB!
                        , proposal_id = proposal_id 
                        , target_name = result['target_name']
                        , ra = c.sexHrs2rad(result['right_ascension'])
                        , ra_range = c.sexHrs2rad(result['right_ascension_range'])
                        , dec = c.sexDeg2rad(result['declination'])
                        , dec_range = c.sexDeg2rad(result['declination_range'])
                        , coordinate_epoch = epoch 
                        , coordinate_system = sys 
                        , velocity_units = vType 
                        , velocity_redshift = vRedshift 
                        , convention = con 
                        , reference_frame = ref 
                        , pst_ra = result['right_ascension']
                        , pst_ra_range = result['right_ascension_range']
                        , pst_dec = result['declination']
                        , pst_dec_range = result['declination_range']
                        )

        source.save()
        return source