Beispiel #1
0
    def __init__(self, pair):
        self.pair = pair
        self.path = os.path.join(ABR_DIR, pair)
        self.error = False

        # yaml config file
        sensor1 = (pair.split('_')[0]).split('+')[1]
        sensor2 = (pair.split('_')[1]).split('+')[1]

        # load yaml config file
        plt_cfg_file = os.path.join(MainPath,
                                    '%s_%s.yaml' % (sensor1, sensor2))
        self.plt_cfg = pb_io.loadYamlCfg(plt_cfg_file)
        if self.plt_cfg is None:
            self.error = True
Beispiel #2
0
def run(pair, date_s, date_e):
    '''
    pair: sat1+sensor1_sat2+sensor2
    date_s: datetime of start date
            None  处理 从发星 到 有数据的最后一天
    date_e: datetime of end date
            None  处理 从发星 到 有数据的最后一天
    '''
    isLaunch = False
    if date_s is None or date_e is None:
        isLaunch = True
    part1, part2 = pair.split('_')
    sat1, sensor1 = part1.split('+')
    sat2, sensor2 = part2.split('+')

    # load yaml config file
    plt_cfg_file = os.path.join(MainPath, '%s_%s.yaml' % (sensor1, sensor2))
    plt_cfg = pb_io.loadYamlCfg(plt_cfg_file)
    if plt_cfg is None:
        return

    # must be in 'all', 'day', 'night'
    Day_Night = ['all', 'day', 'night']
    if "day_night" in plt_cfg.keys():
        Day_Night = plt_cfg['day_night']
        for each in Day_Night:
            if each not in ['all', 'day', 'night']:
                Day_Night.remove(each)

    Bias = ["tbb"]
    if "bias" in plt_cfg.keys():
        Bias = plt_cfg["bias"]

    co = coeff_abr(pair)
    if co.error: return

    for each in plt_cfg['plot']:
        xname, yname = each.split('-')
        if 'tbb' in xname and 'tbb' in yname:
            o_name = 'TBBCalCoeff'
        elif 'ref' in xname and 'ref' in yname:
            o_name = 'CorrcCoeff'
        elif 'dn' in xname and 'ref' in yname:
            o_name = 'CalCoeff'
        else:
            continue

        for DayOrNight in Day_Night:

            if DayOrNight == 'all':
                DayOrNight = DayOrNight.upper()  # all -> ALL
            else:
                DayOrNight = DayOrNight[0].upper() + DayOrNight[1:]

            co.loadCoeff(o_name, DayOrNight)
            if co.error: continue
            date_D = co.Coeff_D['date']
            date_M = co.Coeff_M['date']
            if isLaunch:
                if sat1 in inCfg['LUANCH_DATE']:
                    date_s = pb_time.ymd2date(str(inCfg['LUANCH_DATE'][sat1]))
                else:
                    Log.error(
                        '%s not in LUANCH_DATE of Cfg, use the first day in txt instead.'
                    )
                    date_s = date_D[0]
                date_e = date_D[-1]

            ymd_s, ymd_e = date_s.strftime('%Y%m%d'), date_e.strftime('%Y%m%d')
            Log.info(u"----- Start Drawing ABC TBBias Pic, PAIR: {}, YMD: {}-{}: " \
                     u"{}-----".format(pair, ymd_s, ymd_e, DayOrNight))

            idx_D = np.where(np.logical_and(date_D >= date_s,
                                            date_D <= date_e))
            idx_M = np.where(
                np.logical_and(date_M >= pb_time.ymd2date(ymd_s[:6] + '01'),
                               date_M <= date_e))

            for i, chan in enumerate(plt_cfg['chan']):
                a_D = co.Coeff_D['a_%s' % chan]
                b_D = co.Coeff_D['b_%s' % chan]
                c_D = np.log10(co.Coeff_D['c_%s' % chan])
                a_M = co.Coeff_M['a_%s' % chan]
                b_M = co.Coeff_M['b_%s' % chan]
                c_M = np.log10(co.Coeff_M['c_%s' % chan])
                # plot slope Intercept count ------------------------
                title = 'Time Series of Slope Intercept & Counts  %s  %s\n(%s = Slope * %s + Intercept)' % \
                         (chan, DayOrNight,
                          part1.replace('+', '_'),
                          part2.replace('+', '_'))

                if isLaunch:
                    picPath = os.path.join(
                        ABC_DIR, pair, '%s_%s_ABC_%s_%s_Launch.png' %
                        (pair, o_name, chan, DayOrNight))
                else:
                    picPath = os.path.join(
                        ABC_DIR, pair, ymd_e, '%s_%s_ABC_%s_%s_Year_%s.png' %
                        (pair, o_name, chan, DayOrNight, ymd_e))
                plot_abc(date_D[idx_D], a_D[idx_D], b_D[idx_D], c_D[idx_D],
                         date_M[idx_M], a_M[idx_M], b_M[idx_M], c_M[idx_M],
                         picPath, title, date_s, date_e, each)

                # plot TBBias ------------------------
                if "tbb" not in Bias:
                    continue

                reference_list = plt_cfg['tbb']['reference'][i]
                for ref_temp in reference_list:
                    ref_temp_f = float(ref_temp)

                    # plot since launch
                    #                 bias_D = ref_temp_f - np.divide((ref_temp_f - b_D), a_D)
                    #                 bias_M = ref_temp_f - np.divide((ref_temp_f - b_M), a_M)
                    # 20161122 change to FY2 - IASI
                    bias_D = ref_temp_f - (ref_temp_f * a_D + b_D)
                    bias_M = ref_temp_f - (ref_temp_f * a_M + b_M)

                    title = 'Time Series of Brightness Temperature Bias Between\n%s  %s  %s  %sK' % \
                            (pair, chan, DayOrNight, ref_temp)
                    if isLaunch:
                        picPath = os.path.join(
                            OMB_DIR, pair, '%s_TBBias_%s_%s_Launch_%dK.png' %
                            (pair, chan, DayOrNight, ref_temp))
                    else:
                        # plot latest year
                        picPath = os.path.join(
                            OMB_DIR, pair, ymd_e,
                            '%s_TBBias_%s_%s_Year_%s_%dK.png' %
                            (pair, chan, DayOrNight, ymd_e, ref_temp))
                    plot_tbbias(date_D[idx_D], bias_D[idx_D], date_M[idx_M],
                                bias_M[idx_M], picPath, title, date_s, date_e,
                                sat1)

                # plot interpolated TBBias img (obs minus backgroud) -------------
                title = 'Brightness Temperature Correction\n%s  %s  %s' % \
                         (pair, chan, DayOrNight)

                if isLaunch:
                    picPath = os.path.join(
                        OMB_DIR, pair, '%s_TBBOMB_%s_%s_Launch.png' %
                        (pair, chan, DayOrNight))
                else:
                    picPath = os.path.join(
                        OMB_DIR, pair, ymd_e, '%s_TBBOMB_%s_%s_Year_%s.png' %
                        (pair, chan, DayOrNight, ymd_e))
                plot_omb(date_D[idx_D], a_D[idx_D], b_D[idx_D], picPath, title,
                         date_s, date_e)
Beispiel #3
0
def run(pair, ymd):
    '''
    pair: sat1+sensor1_sat2+sensor2
    ymd: str YYYYMMDD
    '''
    part1, part2 = pair.split('_')
    sat1, sensor1 = part1.split('+')
    sat2, sensor2 = part2.split('+')

    if 'FY2' in part1 or 'FY4' in part1:
        ReadMatchNC = ReadMatchNC_FY2
        Type = "GEOLEO"
    elif 'FY3' in part1:
        ReadMatchNC = ReadMatchNC_FY3
        Type = "LEOLEO"
    else:
        return

    # load yaml
    plt_cfg_file = os.path.join(MainPath, '%s_%s.yaml' % (sensor1, sensor2))
    plt_cfg = pb_io.loadYamlCfg(plt_cfg_file)
    if plt_cfg is None:
        return

    # Day_Night must be in 'all', 'day', 'night'
    Day_Night = ['all', 'day', 'night']  # default
    if "day_night" in plt_cfg.keys():
        Day_Night = plt_cfg['day_night']
        for each in Day_Night:
            if each not in ['all', 'day', 'night']:
                Day_Night.remove(each)

    Bias = []
    if "bias" in plt_cfg.keys():
        Bias = plt_cfg["bias"]

    PERIOD = calendar.monthrange(int(ymd[:4]), int(ymd[4:6]))[1]  # 当月天数
    ym = ymd[:6]
    ymd = ym + '%02d' % PERIOD  # 当月最后一天

    Log.info(u"----- Start Drawing Monthly TBBias Analysis Pic, PAIR: {}, YMD: {}" \
             u" -----".format(pair, ymd))

    for idx, chan in enumerate(plt_cfg['chan']):
        Log.info(u"Start Drawing Channel {}".format(chan))
        oneNC = ReadMatchNC()
        # load Matched NC
        num_file = PERIOD
        for daydelta in xrange(PERIOD):
            cur_ymd = pb_time.ymd_plus(ymd, -daydelta)
            nc_name = 'COLLOC+%sIR,%s_C_BABJ_%s.NC' % (Type, pair, cur_ymd)
            filefullpath = os.path.join(MATCH_DIR, pair, nc_name)
            if not os.path.isfile(filefullpath):
                Log.info(u"NC not found: {}".format(filefullpath))
                num_file -= 1
                continue

            if oneNC.LoadData(filefullpath, chan) == False:
                Log.error('Error occur when reading %s of %s' %
                          (chan, filefullpath))

        if num_file == 0:
            Log.error(u"No file found.")
            continue
        elif num_file != PERIOD:
            Log.info(u"{} of {} file(s) found.".format(num_file, PERIOD))

        # 输出目录
        cur_path = os.path.join(MBA_DIR, pair, ymd[:6])

        # find out day and night
        if ('day' in Day_Night
                or 'night' in Day_Night) and len(oneNC.time) > 0:
            jd = oneNC.time / 24. / 3600.  # jday from 1993/01/01 00:00:00
            hour = ((jd - jd.astype('int8')) * 24).astype('int8')
            day_index = (hour < 10)  # utc hour<10 is day
            night_index = np.logical_not(day_index)
        else:
            day_index = None
            night_index = None
        for each in Bias:
            # get threhold, unit, names...
            xname, yname = each, each
            #             xname_l = plt_cfg[xname]['name']
            xname_l = xname.upper()
            xunit = plt_cfg[xname]['unit']
            xlimit = plt_cfg[xname]['thhold'][idx]
            xmin, xmax = xlimit.split('-')
            xmin = int(xmin)
            xmax = int(xmax)

            # get x
            dset_name = xname + "1"
            if hasattr(oneNC, dset_name):
                x = getattr(oneNC, dset_name)
            else:
                Log.error("Can't plot, no %s in NC class" % dset_name)
                continue
            # get y
            dset_name = yname + "2"
            if hasattr(oneNC, dset_name):
                y = getattr(oneNC, dset_name)
            else:
                Log.error("Can't plot, no %s in NC class" % dset_name)
                continue
            if 'rad' == each:
                o_name = 'RadBiasMonthStats'
            elif 'tbb' == each:
                o_name = 'TBBiasMonthStats'
            elif 'ref' == each:
                o_name = 'RefBiasMonthStats'
            else:
                o_name = 'DUMMY'

            if x.size < 10:
                Log.error("Not enough match point to draw.")
                continue

            # rad-specified regression starts
            reference_list = []
            if "reference" in plt_cfg[each]:
                reference_list = plt_cfg[each]['reference'][idx]

            if 'all' in Day_Night:
                o_file = os.path.join(
                    cur_path, '%s_%s_%s_ALL_%s' % (pair, o_name, chan, ym))
                plot(x, y, o_file, part1, part2, chan, ym, 'ALL',
                     reference_list, xname, xname_l, xunit, xmin, xmax)

            # ------- day ----------
            if 'day' in Day_Night:
                if day_index is not None and np.where(day_index)[0].size > 10:
                    # rad-specified
                    o_file = os.path.join(
                        cur_path, '%s_%s_%s_Day_%s' % (pair, o_name, chan, ym))
                    x_d = x[day_index]
                    y_d = y[day_index]

                    plot(x_d, y_d, o_file, part1, part2, chan, ym, 'Day',
                         reference_list, xname, xname_l, xunit, xmin, xmax)
            if 'night' in Day_Night:
                # ---------night ------------
                if night_index is not None and np.where(
                        night_index)[0].size > 10:
                    # rad-specified
                    o_file = os.path.join(
                        cur_path,
                        '%s_%s_%s_Night_%s' % (pair, o_name, chan, ym))
                    x_n = x[night_index]
                    y_n = y[night_index]
                    plot(x_n, y_n, o_file, part1, part2, chan, ym, 'Night',
                         reference_list, xname, xname_l, xunit, xmin, xmax)
Beispiel #4
0
def run(pair, ymd):
    '''
    pair: sat1+sensor1_sat2+sensor2
    ymd: YYYYMMDD
    '''
    part1, part2 = pair.split('_')
    sat1, sensor1 = part1.split('+')
    sat2, sensor2 = part2.split('+')

    # TODO: for now only support FY2 FY4
    if 'FY2' in part1 or 'FY4' in part1:
        pass
    else:
        return

    # load yaml config file
    plt_cfg_file = os.path.join(MainPath, '%s_%s.yaml' % (sensor1, sensor2))
    plt_cfg = pb_io.loadYamlCfg(plt_cfg_file)
    if plt_cfg is None:
        return
    PERIOD = plt_cfg['days']

    Log.info(u"----- Start Drawing Matched Map-Pic, PAIR: {}, YMD: {}, PERIOD: " \
             u"{} -----".format(pair, ymd, PERIOD))

    fy2_orbit = Sat_Orbit(inCfg['SAT_S2L'][sat1], ymd, ORBIT_DIR)
    if fy2_orbit.error:
        return
    fy2_orbit.get_orbit(ymd)
    if fy2_orbit.error:
        return
    fy2_lon = fy2_orbit.orbit['Lon'][0]
    fy2_lat = fy2_orbit.orbit['Lat'][0]

    if len(plt_cfg['chan']) > 3:
        chan = plt_cfg['chan'][2]  # FY2 IR3 has the most matchpoint
    else:
        chan = plt_cfg['chan'][0]

    NC = ReadMatchNC()
    num_file = PERIOD
    for daydelta in xrange(PERIOD):
        cur_ymd = pb_time.ymd_plus(ymd, -daydelta)
        filename = 'COLLOC+GEOLEOIR,%s_C_BABJ_%s.NC' % (pair, cur_ymd)
        filefullpath = os.path.join(MATCH_DIR, pair, filename)

        if not os.path.isfile(filefullpath):
            Log.info(u"File not found: {}".format(filefullpath))
            num_file -= 1
            continue

        if NC.LoadData(filefullpath, chan, PERIOD - daydelta) == False:
            Log.error('Error occur when reading %s of %s' % (chan, filefullpath))

    if num_file == 0:
        Log.error(u"No file found.")
        return
    elif num_file != PERIOD:
        Log.error(u"{} of {} file(s) found.".format(num_file, PERIOD))

    cur_path = os.path.join(DMS_DIR, pair, ymd)



    # FY2F+VISSR-MetopA+IASI_MatchedPoints_ALL_20150226.png

    # find out day and night
    jd = NC.time / 24. / 3600.  # jday from 1993/01/01 00:00:00
    hour = ((jd - jd.astype('int8')) * 24).astype('int8')
    day_index = (hour < 10)  # utc hour<10 is day
    night_index = np.logical_not(day_index)

    x = NC.lon
    y = NC.lat
    d = NC.days.astype('uint8')  # trans to int
    if len(d) == 0:
        Log.error('No days info in NC.')
        return

    # ------- day ----------
    if np.where(day_index)[0].size > 0 :
        o_file = os.path.join(cur_path,
                              '%s-%s_MatchedPoints_Day_%s' % (part1, part2, ymd))
        x_d = x[day_index]
        y_d = y[day_index]
        d_d = d[day_index]
        draw_butterfly(part1, part2, cur_ymd, ymd, fy2_lon, fy2_lat, x_d, y_d, d_d, o_file)
    # ---------night ------------
    if np.where(night_index)[0].size > 0 :
        o_file = os.path.join(cur_path,
                              '%s-%s_MatchedPoints_Night_%s' % (part1, part2, ymd))
        x_n = x[night_index]
        y_n = y[night_index]
        d_n = d[night_index]
        draw_butterfly(part1, part2, cur_ymd, ymd, fy2_lon, fy2_lat, x_n, y_n, d_n, o_file)

    # ------- ALL ----------
    if np.where(day_index)[0].size != 0 and np.where(night_index)[0].size != 0:
        o_file = os.path.join(cur_path,
                              '%s_%s_MatchedPoints_ALL_%s' % (part1, part2, ymd))
        draw_butterfly(part1, part2, cur_ymd, ymd, fy2_lon, fy2_lat, x, y, d, o_file)
    Log.info(u"Success")
Beispiel #5
0
def run(pair, ymd, isMonthly):
    '''
    pair: sat1+sensor1_sat2+sensor2
    ymd: str YYYYMMDD
    '''
    part1, part2 = pair.split('_')
    sat1, sensor1 = part1.split('+')
    sat2, sensor2 = part2.split('+')

    if 'FY2' in part1 or 'FY4' in part1:
        ReadMatchNC = ReadMatchNC_FY2
        Type = "GEOLEO"
    elif 'FY3' in part1:
        ReadMatchNC = ReadMatchNC_FY3
        Type = "LEOLEO"
    else:
        return

    # load yaml config file
    plt_cfg_file = os.path.join(MainPath, '%s_%s.yaml' % (sensor1, sensor2))
    plt_cfg = pb_io.loadYamlCfg(plt_cfg_file)
    if plt_cfg is None:
        return

    if isMonthly:
        PERIOD = calendar.monthrange(int(ymd[:4]), int(ymd[4:6]))[1]  # 当月天数
        ymd = ymd[:6] + '%02d' % PERIOD  # 当月最后一天
    else:
        PERIOD = plt_cfg['days']

    # must be in 'all', 'day', 'night'
    Day_Night = ['all', 'day', 'night']
    if "day_night" in plt_cfg.keys():
        Day_Night = plt_cfg['day_night']
        for each in Day_Night:
            if each not in ['all', 'day', 'night']:
                Day_Night.remove(each)

    Log.info(u"----- Start Drawing Regression-Pic, PAIR: {}, YMD: {}, PERIOD: " \
             u"{} -----".format(pair, ymd, PERIOD))
    dict_cabr = {}
    dict_cabr_d = {}
    dict_cabr_n = {}

    for idx, chan in enumerate(plt_cfg['chan']):
        Log.info(u"Start Drawing Channel {}".format(chan))
        oneNC = ReadMatchNC()
        num_file = PERIOD

        for daydelta in xrange(PERIOD):
            cur_ymd = pb_time.ymd_plus(ymd, -daydelta)
            nc_name = 'COLLOC+%sIR,%s_C_BABJ_%s.NC' % (Type, pair, cur_ymd)
            filefullpath = os.path.join(MATCH_DIR, pair, nc_name)

            if not os.path.isfile(filefullpath):
                Log.info(u"File not found: {}".format(filefullpath))
                num_file -= 1
                continue

            if oneNC.LoadData(filefullpath, chan) == False:
                Log.error('Error occur when reading %s of %s' % (chan, filefullpath))

        if num_file == 0:
            Log.error(u"No file found.")
            continue
        elif num_file != PERIOD:
            Log.error(u"{} of {} file(s) found.".format(num_file, PERIOD))

        if isMonthly:
            str_time = ymd[:6]
            cur_path = os.path.join(MRA_DIR, pair, str_time)
        else:
            str_time = ymd
            cur_path = os.path.join(DRA_DIR, pair, str_time)

        # delete 0 in std
        if len(oneNC.rad1_std) > 0.0001:  # TODO: 有些极小的std可能是异常值,而导致权重极大,所以 std>0 改成 std>0.0001
            deletezeros = np.where(oneNC.rad1_std > 0.0001)
            oneNC.rad1_std = oneNC.rad1_std[deletezeros]
            oneNC.rad1 = oneNC.rad1[deletezeros] if len(oneNC.rad1) > 0 else oneNC.rad1
            oneNC.rad2 = oneNC.rad2[deletezeros] if len(oneNC.rad2) > 0 else oneNC.rad2
            oneNC.tbb1 = oneNC.tbb1[deletezeros] if len(oneNC.tbb1) > 0 else oneNC.tbb1
            oneNC.tbb2 = oneNC.tbb2[deletezeros] if len(oneNC.tbb2) > 0 else oneNC.tbb2
            oneNC.time = oneNC.time[deletezeros] if len(oneNC.time) > 0 else oneNC.time

        if len(oneNC.ref1_std) > 0.0001:
            deletezeros = np.where(oneNC.ref1_std > 0.0001)
            oneNC.ref1_std = oneNC.ref1_std[deletezeros]
            oneNC.ref1 = oneNC.ref1[deletezeros] if len(oneNC.ref1) > 0 else oneNC.ref1
            oneNC.ref2 = oneNC.ref2[deletezeros] if len(oneNC.ref2) > 0 else oneNC.ref2

        # find out day and night
        if ('day' in Day_Night or 'night' in Day_Night) and len(oneNC.time) > 0:
            jd = oneNC.time / 24. / 3600.  # jday from 1993/01/01 00:00:00
            hour = ((jd - jd.astype('int8')) * 24).astype('int8')
            day_index = (hour < 10)  # utc hour<10 is day
            night_index = np.logical_not(day_index)
        else:
            day_index = None
            night_index = None

        for each in plt_cfg['plot']:
            # get threhold, unit, names...
            xname, yname = each.split('-')
            xname_l = plt_cfg[xname]['name']
            xunit = plt_cfg[xname]['unit']
            xlimit = plt_cfg[xname]['thhold'][idx]
            xmin, xmax = xlimit.split('-')
            xmin = float(xmin)
            xmax = float(xmax)
            yname_l = plt_cfg[yname]['name']
            yunit = plt_cfg[yname]['unit']
            ylimit = plt_cfg[yname]['thhold'][idx]
            ymin, ymax = ylimit.split('-')
            ymin = float(ymin)
            ymax = float(ymax)

            weight = None
            if 'rad' in xname:
                x = oneNC.rad1
            elif 'tbb' in xname:
                x = oneNC.tbb1
            elif 'ref' in xname:
                x = oneNC.ref1
            elif 'dn' in xname:
                x = oneNC.dn1
            else:
                Log.error("Can't plot %s" % each)
                continue
            if 'rad' in yname:
                y = oneNC.rad2
            elif 'tbb' in yname:
                y = oneNC.tbb2
            elif 'ref' in yname:
                y = oneNC.ref2
            else:
                Log.error("Can't plot %s" % each)
                continue

            if 'rad' in xname and 'rad' in yname:
                if len(oneNC.rad1_std) > 0:
                    weight = oneNC.rad1_std
                o_name = 'RadCalCoeff'
            elif 'tbb' in xname and 'tbb' in yname:
                o_name = 'TBBCalCoeff'
            elif 'ref' in xname and 'ref' in yname:
                if len(oneNC.ref1_std) > 0:
                    weight = oneNC.ref1_std
                o_name = 'CorrcCoeff'
            elif 'dn' in xname and 'ref' in yname:
                o_name = 'CalCoeff'

            # 画对角线
            if xname == yname:
                diagonal = True
            else:
                diagonal = False

            if 'all' in Day_Night and o_name not in dict_cabr:
                dict_cabr[o_name] = {}
            if 'day' in Day_Night and o_name not in dict_cabr_d:
                dict_cabr_d[o_name] = {}
            if 'night' in Day_Night and o_name not in dict_cabr_n:
                dict_cabr_n[o_name] = {}

            if x.size < 10:
                Log.error("Not enough match point to draw.")
                if 'all' in Day_Night:
                    dict_cabr[o_name][chan] = [0, np.NaN, np.NaN, np.NaN]
                if 'day' in Day_Night:
                    dict_cabr_d[o_name][chan] = [0, np.NaN, np.NaN, np.NaN]
                if 'night' in Day_Night:
                    dict_cabr_n[o_name][chan] = [0, np.NaN, np.NaN, np.NaN]
                continue

            # regression starts
            if 'all' in Day_Night:
                o_file = os.path.join(cur_path,
                                          '%s_%s_%s_ALL_%s' % (pair, o_name, chan, str_time))
                abr = plot(x, y, weight, o_file,
                     num_file, part1, part2, chan, str_time,
                     xname, xname_l, xunit, xmin, xmax,
                     yname, yname_l, yunit, ymin, ymax, diagonal)
                if abr:
                    dict_cabr[o_name][chan] = abr
                else:
                    dict_cabr[o_name][chan] = [0, np.NaN, np.NaN, np.NaN]
            # ------- day ----------
            if 'day' in Day_Night:
                if day_index is not None and np.where(day_index)[0].size > 10 :
                    #
                    o_file = os.path.join(cur_path,
                                              '%s_%s_%s_Day_%s' % (pair, o_name, chan, str_time))
                    x_d = x[day_index]
                    y_d = y[day_index]
                    w_d = weight[day_index] if weight is not None else None
                    abr = plot(x_d, y_d, w_d, o_file,
                         num_file, part1, part2, chan, str_time,
                         xname, xname_l, xunit, xmin, xmax,
                         yname, yname_l, yunit, ymin, ymax, diagonal)
                    if abr:
                        dict_cabr_d[o_name][chan] = abr
                    else:
                        dict_cabr_n[o_name][chan] = [0, np.NaN, np.NaN, np.NaN]
                else:
                    dict_cabr_d[o_name][chan] = [0, np.NaN, np.NaN, np.NaN]
            # ---------night ------------
            if 'night' in Day_Night:
                if night_index is not None and np.where(night_index)[0].size > 10 :
                    #
                    o_file = os.path.join(cur_path,
                                              '%s_%s_%s_Night_%s' % (pair, o_name, chan, str_time))
                    x_n = x[night_index]
                    y_n = y[night_index]
                    w_n = weight[night_index] if weight is not None else None
                    abr = plot(x_n, y_n, w_n, o_file,
                         num_file, part1, part2, chan, str_time,
                         xname, xname_l, xunit, xmin, xmax,
                         yname, yname_l, yunit, ymin, ymax, diagonal)
                    if abr:
                        dict_cabr_n[o_name][chan] = abr
                    else:
                        dict_cabr_n[o_name][chan] = [0, np.NaN, np.NaN, np.NaN]
                else:
                    dict_cabr_n[o_name][chan] = [0, np.NaN, np.NaN, np.NaN]

        oneNC.clear()
    # write txt
    lock.acquire()

    if 'all' in Day_Night:
        for o_name in dict_cabr:
            writeTxt(plt_cfg, part1, part2, o_name, str_time, dict_cabr, 'ALL', isMonthly)
    if 'day' in Day_Night:
        for o_name in dict_cabr_d:
            writeTxt(plt_cfg, part1, part2, o_name, str_time, dict_cabr_d, 'Day', isMonthly)
    if 'night' in Day_Night:
        for o_name in dict_cabr_n:
            writeTxt(plt_cfg, part1, part2, o_name, str_time, dict_cabr_n, 'Night', isMonthly)
    lock.release()
Beispiel #6
0
def run(pair, ymd):
    '''
    pair: sat1+sensor1_sat2+sensor2
    ymd: YYYYMMDD
    '''
    part1, part2 = pair.split('_')
    sat1, sensor1 = part1.split('+')
    sat2, sensor2 = part2.split('+')

    #     # TODO: for now only support FY3
    if 'FY3' in part1:
        Type = "LEOLEO"
    else:
        return

    # load yaml config file
    plt_cfg_file = os.path.join(MainPath, '%s_%s.yaml' % (sensor1, sensor2))
    plt_cfg = pb_io.loadYamlCfg(plt_cfg_file)
    if plt_cfg is None:
        return


#     PERIOD = plt_cfg['days']
    PERIOD = 1

    Log.info(u"----- Start Drawing Matched Map-Pic, PAIR: {}, YMD: {}, PERIOD: " \
             u"{} -----".format(pair, ymd, PERIOD))

    chan = plt_cfg['chan'][0]

    NC = ReadMatchNC()
    num_file = PERIOD
    for daydelta in xrange(PERIOD):
        cur_ymd = pb_time.ymd_plus(ymd, -daydelta)
        filename = "COLLOC+%sIR,%s+%s_%s+%s_C_BABJ_%s.NC" % (
            Type, sat1, sensor1, sat2, sensor2, cur_ymd)
        filefullpath = os.path.join(MATCH_DIR, pair, filename)

        if not os.path.isfile(filefullpath):
            Log.info(u"File not found: {}".format(filefullpath))
            num_file -= 1
            continue

        if NC.LoadData(filefullpath, chan) == False:
            Log.error('Error occur when reading %s of %s' %
                      (chan, filefullpath))

    if num_file == 0:
        Log.error(u"No file found.")
        return
    elif num_file != PERIOD:
        Log.error(u"{} of {} file(s) found.".format(num_file, PERIOD))

    cur_path = os.path.join(DMS_DIR, pair, ymd)

    o_file = os.path.join(cur_path,
                          '%s_%s_MatchedPoints_ALL_%s' % (part1, part2, ymd))

    # FY2F+VISSR-MetopA+IASI_MatchedPoints_ALL_20150226.png

    # find out day and night
    jd = NC.time / 24. / 3600.  # jday from 1993/01/01 00:00:00
    hour = ((jd - jd.astype('int8')) * 24).astype('int8')
    day_index = (hour < 10)  # utc hour<10 is day
    night_index = np.logical_not(day_index)

    x = NC.lon
    y = NC.lat
    #     d = NC.days.astype('uint8')  # trans to int
    #     if len(d) == 0:
    #         Log.error('No days info in NC.')
    #         return
    draw_butterfly(part1, part2, cur_ymd, ymd, x, y, o_file)

    # ------- day ----------
    if np.where(day_index)[0].size > 0:
        o_file = os.path.join(
            cur_path, '%s-%s_MatchedPoints_Day_%s' % (part1, part2, ymd))
        x_d = x[day_index]
        y_d = y[day_index]
        #         d_d = d[day_index]
        draw_butterfly(part1, part2, cur_ymd, ymd, x_d, y_d, o_file)
    # ---------night ------------
    if np.where(night_index)[0].size > 0:
        o_file = os.path.join(
            cur_path, '%s-%s_MatchedPoints_Night_%s' % (part1, part2, ymd))
        x_n = x[night_index]
        y_n = y[night_index]
        #         d_n = d[night_index]
        draw_butterfly(part1, part2, cur_ymd, ymd, x_n, y_n, o_file)
    Log.info(u"Success")