Пример #1
0
def gd2jd(datestr):
    """ Convert a string Gregorian date into a Julian date using Pylab.
        If no time is given (i.e., only a date), then noon is assumed.
        Timezones can be given, but UTC is assumed otherwise.

       :EXAMPLES:
          ::

            print gd2jd('Aug 11 2007')   #---------------> 2454324.5
            print gd2jd('Aug 11 2007, 12:00 PST')  #-----> 2454324.29167
            print gd2jd('12:00 PM, January 1, 2000')  #--> 2451545.0

       :REQUIREMENTS: :doc:`matplotlib`

       :SEE ALSO: :func:`jd2gd`
       """
# 2008-08-26 14:03 IJC: Created        
# 2010-12-08 13:00 IJC: Removed "+ 3442850" from num2julian call
# 2011-05-19 11:37 IJMC: Put the factor back in for error-catching...
    
    import matplotlib.dates as dates
    
    if datestr.__class__==str:
        d = dates.datestr2num(datestr)
        jd = dates.num2julian(d) 
        if jd<0:
            jd = dates.num2julian(d + 3442850)
            print "You are probably using an old version of Matplotlib..."
    else:
        jd = []

    return jd
Пример #2
0
def gd2jd(datestr):
    """ Convert a string Gregorian date into a Julian date using Pylab.
        If no time is given (i.e., only a date), then noon is assumed.
        Timezones can be given, but UTC is assumed otherwise.

       :EXAMPLES:
          ::

            print gd2jd('Aug 11 2007')   #---------------> 2454324.5
            print gd2jd('Aug 11 2007, 12:00 PST')  #-----> 2454324.29167
            print gd2jd('12:00 PM, January 1, 2000')  #--> 2451545.0

       :REQUIREMENTS: :doc:`matplotlib`

       :SEE ALSO: :func:`jd2gd`
       """
    # 2008-08-26 14:03 IJC: Created
    # 2010-12-08 13:00 IJC: Removed "+ 3442850" from num2julian call
    # 2011-05-19 11:37 IJMC: Put the factor back in for error-catching...

    import matplotlib.dates as dates

    if datestr.__class__ == str:
        d = dates.datestr2num(datestr)
        jd = dates.num2julian(d)
        if jd < 0:
            jd = dates.num2julian(d + 3442850)
            print "You are probably using an old version of Matplotlib..."
    else:
        jd = []

    return jd
Пример #3
0
def test_julian2num():
    mdates._reset_epoch_test_example()
    mdates.set_epoch('0000-12-31')
    # 2440587.5 is julian date for 1970-01-01T00:00:00
    # https://en.wikipedia.org/wiki/Julian_day
    assert mdates.julian2num(2440588.5) == 719164.0
    assert mdates.num2julian(719165.0) == 2440589.5
    # set back to the default
    mdates._reset_epoch_test_example()
    mdates.set_epoch('1970-01-01T00:00:00')
    assert mdates.julian2num(2440588.5) == 1.0
    assert mdates.num2julian(2.0) == 2440589.5
Пример #4
0
def doy2date(year, doy):
    """
    Convert day of year to date if year is known
    """
    date_0 = datetime
    jul_0 = dates.num2julian(dates.date2num(date_0.date(year, 1, 1)))
    date = dates.num2date(dates.julian2num(jul_0 + doy -
                                           1))  #jul2date(jul_0+doy-1)

    return date
Пример #5
0
 def get_era_interim_data_for_station_id(self,station_id):
     
     loc = self.session.query(Location).filter(Location.station_id==station_id).first()
     
     dataset = self.session.query(ERA_Interim_db.time,ERA_Interim_db.sm_l1,ERA_Interim_db.st_l1,ERA_Interim_db.snow_depth,ERA_Interim_db.air_temp).filter(ERA_Interim_db.gpi == loc.ecmwf_gpi).all()
     
     np_data=np.array(dataset)
     df = pd.DataFrame(np_data[:,1:5],np_data[:,0])
     df.columns = ['sm_l1', 'st_l1', 'snow_depth', 'air_temp']
     jd = mdates.num2julian(mdates.date2num(np_data[:,0]))
     df['jd']=jd
     
     return df
Пример #6
0
    def get_ascat_data_for_station_id(self,station_id):
        
        loc = self.session.query(Location).filter(Location.station_id==station_id).first()
        
        dataset = self.session.query(Ascat_ssm.time,Ascat_ssm.ssm,Ascat_ssm.ssf,Ascat_ssm.dir).filter(Ascat_ssm.gpi == loc.warp_gpi).all()

        np_data=np.array(dataset)
        
        df = pd.DataFrame(np_data[:,1:4],np_data[:,0])
        df.columns = ['sm', 'ssf', 'dir']
        jd = mdates.num2julian(mdates.date2num(np_data[:,0]))
        df['jd']=jd
        
        return df
Пример #7
0
    def read(self, timestamp=None, **kwargs):
        raw_data, nNodes = ASPS.read_ASPS_L2(self.filename)

        DSR = raw_data['dsr']['prod']
        nDSR = DSR.size
        nMeas = DSR['node']['sigmaf'].flatten().size

        # check data set records for trailing zeros
        Zeros = (DSR['node']['sigmaf'].flatten() == 0).astype(np.uint8)
        nZeros = np.sum(Zeros)
        indZeros = np.flatnonzero(Zeros)

        if nZeros > 0:
            if (nZeros % nNodes) != 0:
                raise ValueError("Number of trailing zero-records " +
                                 "not a multiple of nodes per line")
            if (nMeas - nZeros) != indZeros[0] or \
               (nMeas - 1) != indZeros[-1]:
                raise ValueError(
                    "Zeros records found in non-trailing data records")
            nDSR = raw_data['mph']['nPDR'][0] - (nZeros / nNodes)
            DSR = DSR[0:nDSR - 1]
            nMeas = DSR['node']['sigmaf'].flatten().size

        # get julian dates of each node
        obsTime = DSR['dsrhdr']['utct'].flatten()
        obsTime = [datetime.strptime(x, "%d-%b-%Y %H:%M:%S.%f")
                   for x in obsTime]
        obsTime = np.array(obsTime)
        jd = mpl_dates.num2julian(mpl_dates.date2num(obsTime))
        jd = np.repeat(jd, nNodes, axis=0)

        lat = DSR['node']['lat'].flatten() * 10 ** (-3)
        lon = DSR['node']['lon'].flatten() * 10 ** (-3)
        westernLon = (lon > 180)
        lon[westernLon] -= 360

        data = {}
        data['jd'] = jd
        data['swath'] = np.full(nMeas, 1)
        data['line_num'] = np.repeat(DSR['dsrhdr']['num'],
                                     nNodes, axis=1).flatten()
        data['node_num'] = np.tile(np.arange(0, nNodes), nDSR)

        passInd = (DSR['dsrhdr']['azi'].flatten() > 270000).astype(np.uint8)
        data['as_des_pass'] = np.repeat(passInd, nNodes, axis=0)

        gcd = np.unpackbits(np.reshape(DSR['node']['gcd'].flatten(),
                                       (DSR['node']['gcd'].flatten().size, 1)), axis=1)
        data['f_land'] = gcd[:, -1]

        ncd1_1 = np.unpackbits(np.reshape(DSR['node']['ncd1']['1'].flatten(),
                                          (DSR['node']['ncd1']['1'].flatten().size, 1)),
                               axis=1)
        ncd2_1 = np.unpackbits(np.reshape(DSR['node']['ncd2']['1'].flatten(),
                                          (DSR['node']['ncd2']['1'].flatten().size, 1)),
                               axis=1)
        ncd = ncd1_1[:, -2] + ncd2_1[:, -3] + ncd2_1[:, -4] + ncd2_1[:, -5] + \
            ncd2_1[:, -6] + ncd2_1[:, -7] + ncd2_1[:, -8]
        data['f_usable'] = np.uint8((ncd > 0)) * 2

        fields = [('incf', 'incf', 0.1),
                  ('incm', 'incm', 0.1),
                  ('inca', 'inca', 0.1),
                  ('sigf', 'sigmaf', 10 ** (-7)),
                  ('sigm', 'sigmam', 10 ** (-7)),
                  ('siga', 'sigmaa', 10 ** (-7)),
                  ('azif', 'lookf', 0.1),
                  ('azim', 'lookm', 0.1),
                  ('azia', 'looka', 0.1),
                  ('kpf', 'kpf', 10 ** (-3)),
                  ('kpm', 'kpm', 10 ** (-3)),
                  ('kpa', 'kpa', 10 ** (-3))]
        for field in fields:
            data[field[0]] = DSR['node'][field[1]].flatten() * field[2]

        data['abs_orbit_nr'] = np.repeat(raw_data['mph']['orbitnr'][0],
                                         data[field[0]].size)
        data['spacecraft_id'] = np.repeat(raw_data['mph']['sat'][0],
                                          data[field[0]].size)

        # get metdata
        metadata = {}
        metadata['station_id'] = raw_data['mph']['stid'][0]
        metadata['nDSR'] = nDSR
        metadata['nNodes'] = nNodes

        return Image(lon, lat, data, metadata, timestamp)
Пример #8
0
def date2jul(date):
        return dates.num2julian( dates.date2num(date) )
Пример #9
0
def doy2date(year, doy):
    date_0 = datetime
    jul_0 = dates.num2julian( dates.date2num(date_0.date(year,1,1)) )
    date = dates.num2date(dates.julian2num(jul_0+doy-1)) #jul2date(jul_0+doy-1)
    return date