Пример #1
0
    def get_synop(self):
        """Get the list of synop data that matches the time of the satellite data"""

        synopfiles = glob(os.path.join(SYNOP_DATADIR, self.obstime.strftime('%Y%m')) +
                          "/sy_*_%s.qc" % self.obstime.strftime('%Y%m%d'))
        if self.obstime.hour >= 23:
            tslot = self.obstime + timedelta(days=1)
            synopfiles = (synopfiles +
                          glob(os.path.join(SYNOP_DATADIR, tslot.strftime('%Y%m')) +
                               "/sy_*_%s.qc" % tslot.strftime('%Y%m%d')))
        if self.obstime.hour <= 1:
            tslot = self.obstime - timedelta(days=1)
            synopfiles = (synopfiles +
                          glob(os.path.join(SYNOP_DATADIR, tslot.strftime('%Y%m')) +
                               "/sy_*_%s.qc" % tslot.strftime('%Y%m%d')))

        if len(synopfiles) == 0:
            print("No synop files found! " +
                  "Synop data dir = %s" % SYNOP_DATADIR)
            return False

        print("Synop files considered: " +
              str([os.path.basename(s) for s in synopfiles]))

        items = []
        for filename in synopfiles:
            items.append(get_data(filename))

        self.synops = pd.concat(items, ignore_index=True)

        # Select only those observations that fit within time window:
        t1_ = self.obstime - time_thr_swath
        t2_ = self.obstime + time_thr_swath
        newsynops = self.synops[self.synops['date'] < t2_]
        self.synops = newsynops[newsynops['date'] > t1_]

        return True
    starttime = datetime(2009, 11, 4, 9, 0)
    #starttime = datetime(2009, 11, 4, 0, 0)
    endtime = datetime(2009, 11, 4, 23, 59)

    synopfiles = glob(os.path.join(SYNOP_DATADIR, "sy_*20091104.qc"))
    print synopfiles

    if len(synopfiles) == 0:
        raise IOError("No synop files found! " +
                      "Synop data dir = %s" % SYNOP_DATADIR)
    print("Synop files considered: " +
          str([os.path.basename(s) for s in synopfiles]))

    items = []
    for filename in synopfiles:
        items.append(get_data(filename))

    synops = pd.concat(items, ignore_index=True)

    lonpos = []
    latpos = []

    # Go through all synops
    for synop in synops.iterrows():
        tup = (synop[1]['lon'], synop[1]['lat'], synop[1]['station'],
               synop[1]['date'].to_datetime(), synop[1]['total_cloud_cover'])
        lon, lat, station_name, dtobj, total_cloud_cover = tup

        if dtobj > endtime or dtobj < starttime:
            continue
    starttime = datetime(2009, 11, 4, 9, 0)
    #starttime = datetime(2009, 11, 4, 0, 0)
    endtime = datetime(2009, 11, 4, 23, 59)

    synopfiles = glob(os.path.join(SYNOP_DATADIR, "sy_*20091104.qc"))
    print synopfiles

    if len(synopfiles) == 0:
        raise IOError("No synop files found! " +
                      "Synop data dir = %s" % SYNOP_DATADIR)
    print("Synop files considered: " +
          str([os.path.basename(s) for s in synopfiles]))

    items = []
    for filename in synopfiles:
        items.append(get_data(filename))

    synops = pd.concat(items, ignore_index=True)

    lonpos = []
    latpos = []

    # Go through all synops
    for synop in synops.iterrows():
        tup = (synop[1]['lon'], synop[1]['lat'],
               synop[1]['station'], synop[1]['date'].to_datetime(),
               synop[1]['total_cloud_cover'])
        lon, lat, station_name, dtobj, total_cloud_cover = tup

        if dtobj > endtime or dtobj < starttime:
            continue