예제 #1
0
def test_o1():
    o = obs80.parseOpt(
        '00433         A1893 10 29.4132  06 08 59.32 +53 39 04.2                 HA053802'
    )  # noqa E501
    assert o.num == '00433'
    assert o.desig == ''
    assert o.disc == ''
    assert o.note1 == ''
    assert o.note2 == 'A'
    t = astropy.time.Time(o.jdutc, format='jd').datetime
    assert t.year == 1893
    assert t.month == 10
    assert t.day == 29
    assert numpy.isclose(
        .4132, (t.hour + (t.minute +
                          (t.second + t.microsecond / 1e6) / 60) / 60) / 24)
    h, m, s = astropy.coordinates.Angle(o.ra, unit='h').hms
    assert h == 6
    assert m == 8
    assert numpy.isclose(s, 59.32)
    sign, d, m, s = astropy.coordinates.Angle(o.dec, unit='deg').signed_dms
    assert sign == 1
    assert d == 53
    assert m == 39
    assert numpy.isclose(s, 4.2)
    assert o.mag is None
    assert o.band == ''
    assert o.cod == "802"
예제 #2
0
def test_o2():
    """negative dec"""
    o = obs80.parseOpt(
        '00433         A1894 02 17.1174  07 36 21.35 -00 38 13.2                 HA053802'
    )  # noqa E501
    sign, d, m, s = astropy.coordinates.Angle(o.dec, unit='deg').signed_dms
    assert sign == -1
    assert d == 0
    assert m == 38
    assert numpy.isclose(s, 13.2)
예제 #3
0
def test_hc():
    hc = obs80hc.HCAnnotator(obscode.siteXYZ(obscode.read5c('obscode.dat')),
                             leapsec.LeapSeconds('leap-seconds.list'))
    o = obs80.parseOpt(
        '00433        2C2012 05 02.13978010 34 59.368-23 08 51.92         10.89Vg~15MD689'
    )  # noqa E501
    xyz = hc._xyzOpt(o)
    # test values from JPL Horizons.  They pass with isclose defaults, but
    # there's still some discrepancy.
    assert numpy.isclose(xyz[0], -7.494457783619181E-01)
    assert numpy.isclose(xyz[1], -6.182950688586435E-01)
    assert numpy.isclose(xyz[2], -2.680185245982367E-01)
예제 #4
0
def test_o4():
    """one decimal place in sec of ra, no decimal places in sec dec"""
    o = obs80.parseOpt(
        '00433         A1898 08 14.96732 21 31 50.8  -05 57 43            11.0   AN147537'
    )  # noqa E501
    h, m, s = astropy.coordinates.Angle(o.ra, unit='h').hms
    assert h == 21
    assert m == 31
    assert numpy.isclose(s, 50.8)
    sign, d, m, s = astropy.coordinates.Angle(o.dec, unit='deg').signed_dms
    assert sign == -1
    assert d == 5
    assert m == 57
    assert numpy.isclose(s, 43)
예제 #5
0
def test_o3():
    """decimal minutes in RA, missing seconds in dec, mag, no band"""
    o = obs80.parseOpt(
        '00433         A1898 08 13.89338 21 33.8     -05 58               10.0   AN147020'
    )  # noqa E501
    h, m, s = astropy.coordinates.Angle(o.ra, unit='h').hms
    assert h == 21
    assert numpy.isclose(m + s / 60., 33.8)
    sign, d, m, s = astropy.coordinates.Angle(o.dec, unit='deg').signed_dms
    assert sign == -1
    assert d == 5
    assert m == 58
    assert numpy.isclose(s, 0)
    assert o.mag == 10
    assert o.band == ''
예제 #6
0
def test_o6():
    """both perm and prov, disc *, very coarse time, ra, dec, one dp in mag"""
    o = obs80.parseOpt(
        '00433J56P00C* A1956 08 07.14    19 43.6     -20 47               14.4   M1581760'
    )  # noqa E501
    assert o.num == '00433'
    assert o.desig == 'J56P00C'
    assert o.disc == '*'
    t = astropy.time.Time(o.jdutc, format='jd').datetime
    assert t.year == 1956
    assert t.month == 8
    assert t.day == 7
    assert numpy.isclose(
        .14, (t.hour + (t.minute +
                        (t.second + t.microsecond / 1e6) / 60) / 60) / 24)
    h, m, s = astropy.coordinates.Angle(o.ra, unit='h').hms
    assert h == 19
    assert numpy.isclose(m + s / 60., 43.6)
    sign, d, m, s = astropy.coordinates.Angle(o.dec, unit='deg').signed_dms
    assert sign == -1
    assert d == 20
    assert m == 47
    assert numpy.isclose(s, 0)
    assert o.mag == 14.4
예제 #7
0
def test_o9():
    """note2, extra precision, band"""
    o = obs80.parseOpt(
        '00433         T1988 10 05.04698200 52 27.557+38 16 05.91         10.74V CMC05950'
    )  # noqa E501
    assert o.note2 == 'T'
    t = astropy.time.Time(o.jdutc, format='jd').datetime
    assert t.year == 1988
    assert t.month == 10
    assert t.day == 5
    assert numpy.isclose(
        .046982, (t.hour + (t.minute +
                            (t.second + t.microsecond / 1e6) / 60) / 60) / 24)
    h, m, s = astropy.coordinates.Angle(o.ra, unit='h').hms
    assert h == 0
    assert m == 52
    assert numpy.isclose(s, 27.557)
    sign, d, m, s = astropy.coordinates.Angle(o.dec, unit='deg').signed_dms
    assert sign == 1
    assert d == 38
    assert m == 16
    assert numpy.isclose(s, 5.91)
    assert o.mag == 10.74
    assert o.band == 'V'
예제 #8
0
def test_o5():
    """empty note2"""
    o = obs80.parseOpt(
        '00433          1898 09 20.88897 20 42 53.05 -05 59 42.4                m24429000'
    )  # noqa E501
    assert o.note2 == ''
예제 #9
0
def test_o10():
    """note2"""
    o = obs80.parseOpt(
        '00433         C1993 09 29.84946 19 43 43.22 -14 20 51.0                z22620107'
    )  # noqa E501
    assert o.note2 == 'C'
예제 #10
0
def test_o8():
    """note1"""
    o = obs80.parseOpt(
        '00433        4A1979 08 27.24896 21 15 51.51 -05 15 55.5                 M5026688'
    )  # noqa E501
    assert o.note1 == '4'
예제 #11
0
def test_o7():
    """note2"""
    o = obs80.parseOpt(
        '00433         E1975 01 24.01889007 44 23.906+24 23 59.87                v4566244'
    )  # noqa E501
    assert o.note2 == 'E'
예제 #12
0
def _process_detections(dataList, numberString,
                        dict_of_Strings_keyed_on_orbitID):
    '''
        We are reading data that was created from a query of the mpc obs-table in the postgres database ...
        
        The contents of dataList look like ...
        provid_pkd,obsid,trkid,obs80
        K17A00000Z,L1UJng000000Crte0100001m7,00000VF-fh,     K17A00Z 5C2014 04 28.98950 13 24 42.05 -19 38 29.3                L~2ClrW84
        
        
        dict_of_Strings_keyed_on_orbitID was created by _process_orbits
    '''

    # data containers
    detDict = {}
    trkDict = {}
    orbitID_Dict = {}
    outputListOfStringsForDetections,outputListOfStringsForTracklets, outputListOfStringsForTrackletsHeader  = [], [], []

    # create the header line & append it to the output container
    detectionKeys = sorted(data.detection_field_definitions.keys())
    outputListOfStringsForDetections.append("# " + " , ".join(detectionKeys))
    print(outputListOfStringsForDetections)

    trackletKeys = sorted(data.tracklet_field_definitions.keys())
    outputListOfStringsForTrackletsHeader.append("# " +
                                                 " , ".join(trackletKeys))
    print(outputListOfStringsForTrackletsHeader)
    countTrkIDs = 0

    prev_trkID = ''
    for l, line in enumerate(dataList):
        totLen = len(dataList)
        if len(line) < 150:

            # immediately try to split the line & parse the obs80 part and use this as a guage of success
            try:
                orbitID, detID, trkID, obs80 = line.split(',')
                obs80 = o.parseOpt(obs80)
                detDict['detID'] = detID
                detDict['trkID'] = trkID
                if 'K10C00077F' == orbitID:
                    print(' orbitID, detID, trkID, obs80 === \n\t', orbitID,
                          detID, trkID, obs80)
                PROCEED = True
            except:
                PROCEED = False

            if PROCEED and trkID not in ["", " ", '""', '\"\"', None]:

                # At this point we know the orbitID, so we will only both to proceed if the orbitID is contained in ...
                # ... the dict_of_Strings_keyed_on_orbitID created by _process_orbits
                if orbitID in dict_of_Strings_keyed_on_orbitID:

                    # --- TRACKLET-LEVEL QUANTITIES ------------------
                    # look for new trkIDs so that we know when it is a good time to periodically write
                    if trkID != prev_trkID:
                        countTrkIDs += 1

                        # arbitrarily choose to write-out every 1000 tracklets
                        critCount = 1000
                        if countTrkIDs % critCount == 0:
                            print(" ... l=%15d, countTrkIDs=%10d" %
                                  (l, countTrkIDs),
                                  flush=True)
                            # do_tracklet_calculations_on_accumulated_contents_of_tracklet_dictionary
                            outputListOfStringsForTracklets = do_tracklet_calculations_on_contents_of_tracklet_dictionary(
                                trkDict, trackletKeys)

                            # write the detection & tracklet strings to file
                            if countTrkIDs == critCount:
                                temp_string_list = outputListOfStringsForTracklets
                                outputListOfStringsForTracklets = outputListOfStringsForTrackletsHeader
                                outputListOfStringsForTracklets.extend(
                                    temp_string_list)
                            append_strings_to_files(
                                outputListOfStringsForDetections,
                                outputListOfStringsForTracklets, numberString)

                            # reset the strings to ""
                            outputListOfStringsForDetections,outputListOfStringsForTracklets  = [], []

                            # reset the trkDict to zero
                            trkDict = {}
                            trkDict[trkID] = {'timeUTC': [], 'UV': []}

                    # --- DETECTION-LEVEL QUANTITIES ------------------
                    # Try to parse each detection
                    # - But if anything goes wrong with any of the detections, flag the entire tracklet as something to be ignored
                    try:

                        # parse the obs80 line
                        detDict['timeUTC'] = obs80.jdutc
                        detDict['Vmag'] = obs80.mag
                        detDict['obsCode'] = obs80.cod

                        RA, Dec = obs80.ra * 15., obs80.dec

                        # convert RA, Dec to unit vector (ecliptic coords)
                        UV = unitvector_equatorial_to_unitvector_ecliptic(
                            radec_to_unitvector_equatorial(
                                RA, Dec))  # [None,None,None]
                        detDict['UV_X'] = UV[0]
                        detDict['UV_Y'] = UV[1]
                        detDict['UV_Z'] = UV[2]

                        # generate_observatory_position_Heliocentric_Ecliptic_Coordinates
                        obsPosn = calc_heliocentric_position_of_observatory_in_ecliptic_coords(
                            calc_heliocentric_position_of_observatory_in_equatorial_coords(
                                obs80.cod, obs80.jdutc))
                        detDict['Obs_X'] = obsPosn[0]
                        detDict['Obs_Y'] = obsPosn[1]
                        detDict['Obs_Z'] = obsPosn[2]

                        # calculate_ecliptic_latitude() : [RADIANS]
                        detDict['eclipticLat'] = np.arctan(
                            detDict['UV_Z'] /
                            (detDict['UV_X']**2 + detDict['UV_Y']**2)**0.5)

                        # calculate_solar_elongation [RADIANS] :
                        UobsPosn = obsPosn / (obsPosn[0]**2 + obsPosn[1]**2 +
                                              obsPosn[2]**2)**0.5
                        detDict['solarElong'] = np.pi - angle_unitvectors(
                            UV, UobsPosn)[0]

                        # save the data line as a string
                        outputstr = " , ".join(
                            [str(detDict[key]) for key in detectionKeys])
                        outputListOfStringsForDetections.append(outputstr)

                        # -------- Now store tracklet quantities --------------------
                        if trkID not in trkDict:
                            trkDict[trkID] = {'timeUTC': [], 'UV': []}
                        trkDict[trkID]['timeUTC'].append(detDict['timeUTC'])
                        trkDict[trkID]['UV'].append(UV)
                        trkDict[trkID]['objectID'] = orbitID

                        # reset the prev_trkID variable
                        prev_trkID = trkID

                        # save the orbitID (because it may be useful later on ... )
                        orbitID_Dict[orbitID] = True

                    except:
                        # If anything goes wrong with any of the detections, flag the entire tracklet as something to be ignored
                        if trkID not in trkDict:
                            trkDict[trkID] = {'timeUTC': [], 'UV': []}
                        trkDict[trkID]['ACCEPT'] = False
    # if anything remains in trkDict ...
    # ...do_tracklet_calculations_on_accumulated_contents_of_tracklet_dictionary
    outputListOfStringsForTracklets = do_tracklet_calculations_on_contents_of_tracklet_dictionary(
        trkDict, trackletKeys)
    # ...write the detection & tracklet strings to file
    append_strings_to_files(outputListOfStringsForDetections,
                            outputListOfStringsForTracklets, numberString)

    return orbitID_Dict