Beispiel #1
0
def plot(x, y, weight, o_file, num_file, part1, part2, chan, ymd,
         xname, xname_l, xunit, xmin, xmax, yname, yname_l, yunit, ymin, ymax,
         is_diagonal, is_monthly):
    plt.style.use(os.path.join(dvPath, "dv_pub_regression_dev.mplstyle"))

    # 过滤 正负 delta+8 倍 std 的杂点 ------------------------
    w = 1.0 / weight if weight is not None else None
    RadCompare = G_reg1d(x, y, w)
    reg_line = x * RadCompare[0] + RadCompare[1]
    delta = np.abs(y - reg_line)
    mean_delta = np.mean(delta)
    std_delta = np.std(delta)
    max_y = reg_line + mean_delta + std_delta * 8
    min_y = reg_line - mean_delta - std_delta * 8

    idx = np.logical_and(y < max_y, y > min_y)
    x = x[idx]
    y = y[idx]
    w = w[idx] if weight is not None else None
    # -----------------------------------------
    RadCompare = G_reg1d(x, y, w)
    length_rad = len(x)

    bias_and_md = []  # 当 bias 没有被计算的时候,不输出 bias
    if not is_monthly and is_diagonal:
        # return [len(x), RadCompare[0], RadCompare[1], RadCompare[4]]
        fig = plt.figure(figsize=(14, 4.5))
        # fig.subplots_adjust(top=0.90)
        ax1 = plt.subplot2grid((1, 3), (0, 0))
        ax2 = plt.subplot2grid((1, 3), (0, 1))
        ax3 = plt.subplot2grid((1, 3), (0, 2))
        # 图片 Title
        titleName = "%s-%s" % (xname.upper(), yname.upper())
        title = "{} Regression {} Days {}_{} {} {}".format(
            titleName, num_file, part1, part2, chan, ymd)

        # 画回归图 -----------------------------------------------
        print "draw regression"
        regress_xmin = xmin
        regress_xmax = xmax
        regress_ymin = ymin
        regress_ymax = ymax
        regress_axislimit = {
            "xlimit": (regress_xmin, regress_xmax),
            "ylimit": (regress_ymin, regress_ymax),
        }

        if xunit != "":
            xlabel = "{} {} (${}$)".format(part1, xname_l, xunit)
        else:
            xlabel = "{} {}".format(part1, xname_l)

        if yunit != "":
            ylabel = "{} {} (${}$)".format(part2, yname_l, yunit)
        else:
            ylabel = "{} {}".format(part2, yname_l)

        regress_label = {
            "xlabel": xlabel, "ylabel": ylabel, "fontsize": 14,
        }

        if xname == "tbb":
            regress_locator = {"locator_x": (None, None),
                               "locator_y": (None, 5)}
        elif xname == "ref":
            regress_locator = {"locator_x": (None, None),
                               "locator_y": (None, 5)}
        else:
            regress_locator = None

        regress_annotate = {
            "left": ["{:10}: {:7.4f}".format("Slope", RadCompare[0]),
                     "{:10}: {:7.4f}".format("Intercept", RadCompare[1]),
                     "{:10}: {:7.4f}".format("Cor-Coef", RadCompare[4]),
                     "{:10}: {:7d}".format("Number", length_rad)],
            "fontsize": 14,
        }

        regress_tick = {"fontsize": 14, }

        regress_diagonal = {"line_color": "#808080", "line_width": 1.2}

        regress_regressline = {"line_color": "r", "line_width": 1.2}

        scatter_point = {"scatter_alpha": 0.8}

        dv_pub_3d_dev.draw_regression(
            ax1, x, y, label=regress_label, ax_annotate=regress_annotate, tick=regress_tick,
            axislimit=regress_axislimit, locator=regress_locator,
            diagonal=regress_diagonal, regressline=regress_regressline,
            scatter_point=scatter_point,
        )

        # 画偏差分布图 ---------------------------------------------
        print "draw distribution"

        distri_xmin = xmin
        distri_xmax = xmax
        if xname == "tbb":
            distri_ymin = -4
            distri_ymax = 4
        elif xname == "ref":
            distri_ymin = -0.08
            distri_ymax = 0.08
        else:
            distri_ymin = None
            distri_ymax = None
        distri_limit = {
            "xlimit": (distri_xmin, distri_xmax),
            "ylimit": (distri_ymin, distri_ymax),
        }

        # x y 轴标签
        xlabel = "{}".format(xname_l)
        if xname == "tbb":
            ylabel = "{} bias {}_{} ".format(xname.upper(), part1, part2, )
        elif xname == "ref":
            ylabel = "{} bias {}_{} ".format(xname.capitalize(), part1, part2, )
        else:
            ylabel = "{} bias {}_{} ".format(xname, part1, part2, )
        distri_label = {
            "xlabel": xlabel, "ylabel": ylabel, "fontsize": 14,
        }

        # 获取 MeanBias 信息
        bias_range = 0.15
        boundary = xmin + (xmax - xmin) * 0.15
        bias_info = bias_information(x, y, boundary, bias_range)

        # 格式化 MeanBias 信息
        info_lower = "MeanBias(<={:d}%Range)=\n    {:.4f}±{:.4f}@{:.4f}".format(
            int(bias_range * 100), bias_info.get("md_lower"),
            bias_info.get("std_lower"), bias_info.get("mt_lower"))
        info_greater = "MeanBias(>{:d}%Range)=\n    {:.4f}±{:.4f}@{:.4f}".format(
            int(bias_range * 100), bias_info.get("md_greater"),
            bias_info.get("std_greater"), bias_info.get("mt_greater"))

        # 绝对偏差和相对偏差信息 TBB=250K  REF=0.25
        ab = RadCompare
        a = ab[0]
        b = ab[1]
        if xname == "tbb":
            bias = 250 - (250 * a + b)
            bias_info_md = "TBB Bias(250K):{:.4f}K".format(bias)
        elif xname == "ref":
            bias = (0.25 - (0.25 * a + b)) / 0.25 * 100
            bias_info_md = "Relative Bias(REF0.25):{:.4f}%".format(bias)
        else:
            bias = np.NaN  # RMD or TBB bias
            bias_info_md = ""
        bias_and_md.append(bias)

        # Range Mean : 偏差图的 MD 信息
        if xname == "tbb":
            md_greater = bias_info.get("md_greater", np.NaN)
            md = md_greater
        elif xname == "ref":
            md_greater = bias_info.get("md_greater")
            mt_greater = bias_info.get("mt_greater")
            if md_greater is not None and mt_greater is not None:
                md = (md_greater / mt_greater) * 100
            else:
                md = np.NaN
        else:
            md = np.NaN
        bias_and_md.append(md)

        # 添加注释信息
        distri_annotate = {"left": [], "leftbottom": [], "right": [], "fontsize": 14, }

        distri_annotate.get("left").append(bias_info_md)
        distri_annotate.get("leftbottom").append(info_lower)
        distri_annotate.get("leftbottom").append(info_greater)

        # 添加 tick 信息
        distri_tick = {"fontsize": 14, }

        # 添加间隔数量
        if xname == "tbb":
            distri_locator = {"locator_x": (None, None), "locator_y": (8, 5)}
        elif xname == "ref":
            distri_locator = {"locator_x": (None, None), "locator_y": (8, 5)}
        else:
            distri_locator = None

        # y=0 线配置
        zeroline = {"line_color": "#808080", "line_width": 1.0}

        # 偏差点配置
        scatter_delta = {
            "scatter_marker": "o", "scatter_size": 5, "scatter_alpha": 0.8,
            "scatter_linewidth": 0, "scatter_zorder": 100,
            "scatter_color": BLUE,
        }

        # 偏差回归线配置
        regressline = {"line_color": "r", "line_width": 1.2}
        dv_pub_3d_dev.draw_distribution(ax2, x, y, label=distri_label,
                                        ax_annotate=distri_annotate,
                                        tick=distri_tick,
                                        axislimit=distri_limit,
                                        locator=distri_locator,
                                        zeroline=zeroline,
                                        scatter_delta=scatter_delta,
                                        regressline=regressline,
                                        )

        # 画直方图 --------------------------------------------------
        print "draw histogram"
        histogram_xmin = xmin
        histogram_xmax = xmax
        histogram_axislimit = {
            "xlimit": (histogram_xmin, histogram_xmax),
        }

        histogram_xlabel = "{}".format(xname_l)
        histogram_ylabel = "match point numbers"
        histogram_label = {
            "xlabel": histogram_xlabel, "ylabel": histogram_ylabel, "fontsize": 14,
        }

        # 添加间隔数量
        if xname == "tbb":
            histogram_locator = {"locator_x": (None, None),
                                 "locator_y": (None, 5)}
        elif xname == "ref":
            histogram_locator = {"locator_x": (None, None),
                                 "locator_y": (None, 5)}
        else:
            histogram_locator = None

        histogram_x = {
            "label": part1, "color": "red", "alpha": 0.4, "bins": 100, "fontsize": 14,
        }
        histogram_y = {
            "label": part2, "color": "blue", "alpha": 0.4, "bins": 100,"fontsize": 14,
        }

        histogram_tick = {"fontsize": 14, }

        dv_pub_3d_dev.draw_histogram(
            ax3, x, label=histogram_label, locator=histogram_locator, tick=histogram_tick,
            axislimit=histogram_axislimit, histogram=histogram_x,
        )

        dv_pub_3d_dev.draw_histogram(
            ax3, y, label=histogram_label, locator=histogram_locator, tick=histogram_tick,
            axislimit=histogram_axislimit, histogram=histogram_y,
        )

    elif not is_monthly and not is_diagonal:
        fig = plt.figure(figsize=(4.5, 4.5))
        # fig.subplots_adjust(bottom=0.12, top=0.86)
        ax1 = plt.subplot2grid((1, 1), (0, 0))
        # 图片 Title
        titleName = "%s-%s" % (xname.upper(), yname.upper())
        title = "{} Regression {} Days\n{}_{} {} {}".format(
            titleName, num_file, part1, part2, chan, ymd)
        # 画回归图 ----------------------------------------------------
        print "draw regression"
        regress_xmin = xmin
        regress_xmax = xmax
        regress_ymin = ymin
        regress_ymax = ymax
        regress_axislimit = {
            "xlimit": (regress_xmin, regress_xmax),
            "ylimit": (regress_ymin, regress_ymax),
        }

        if xunit != "":
            xlabel = "{} {} (${}$)".format(part1, xname_l, xunit)
        else:
            xlabel = "{} {}".format(part1, xname_l)

        if yunit != "":
            ylabel = "{} {} (${}$)".format(part2, yname_l, yunit)
        else:
            ylabel = "{} {}".format(part2, yname_l)

        regress_label = {
            "xlabel": xlabel, "ylabel": ylabel, "fontsize": 14,
        }

        if xname == "tbb":
            regress_locator = {"locator_x": (5, None), "locator_y": (5, 5)}
        elif xname == "ref":
            regress_locator = {"locator_x": (None, None),
                               "locator_y": (None, 5)}
        elif xname == "dn":
            regress_locator = {"locator_x": (5, None),
                               "locator_y": (None, 5)}
        else:
            regress_locator = None

        regress_annotate = {
            "left": ["{:10}: {:7.4f}".format("Slope", RadCompare[0]),
                     "{:10}: {:7.4f}".format("Intercept", RadCompare[1]),
                     "{:10}: {:7.4f}".format("Cor-Coef", RadCompare[4]),
                     "{:10}: {:7d}".format("Number", length_rad)],
            "fontsize": 14,
        }

        regress_tick = {"fontsize": 14, }

        regress_diagonal = {"line_color": "#808080", "line_width": 1.2}

        regress_regressline = {"line_color": "r", "line_width": 1.2}

        scatter_point = {"scatter_alpha": 0.8}

        dv_pub_3d_dev.draw_regression(
            ax1, x, y, label=regress_label, ax_annotate=regress_annotate, tick=regress_tick,
            axislimit=regress_axislimit, locator=regress_locator,
            diagonal=regress_diagonal, regressline=regress_regressline,
            scatter_point=scatter_point,
        )
    elif is_monthly:
        o_file = o_file + "_density"

        fig = plt.figure(figsize=(4.5, 4.5))
        # fig.subplots_adjust(bottom=0.12, top=0.86)
        ax1 = plt.subplot2grid((1, 1), (0, 0))
        # 图片 Title Label
        titleName = "%s-%s" % (xname.upper(), yname.upper())
        title = "{} Regression {} Days\n{}_{} {} {}".format(
            titleName, num_file, part1, part2, chan, ymd)
        # 画密度图 -----------------------------------------------------
        print "draw density"
        density_xmin = xmin
        density_xmax = xmax
        density_ymin = ymin
        density_ymax = ymax
        density_axislimit = {
            "xlimit": (density_xmin, density_xmax),
            "ylimit": (density_ymin, density_ymax),
        }

        if xunit != "":
            xlabel = "{} {} (${}$)".format(part1, xname_l, xunit)
        else:
            xlabel = "{} {}".format(part1, xname_l)

        if yunit != "":
            ylabel = "{} {} (${}$)".format(part2, yname_l, yunit)
        else:
            ylabel = "{} {}".format(part2, yname_l)

        density_label = {
            "xlabel": xlabel, "ylabel": ylabel, "fontsize": 14,
        }

        if xname == "tbb":
            density_locator = {"locator_x": (5, None), "locator_y": (5, 5)}
        elif xname == "ref":
            density_locator = {"locator_x": (None, None),
                               "locator_y": (None, 5)}
        elif xname == "dn":
            density_locator = {"locator_x": (5, None),
                               "locator_y": (None, 5)}
        else:
            density_locator = None

        density_annotate = {
            "left": ["{:10}: {:7.4f}".format("Slope", RadCompare[0]),
                     "{:10}: {:7.4f}".format("Intercept", RadCompare[1]),
                     "{:10}: {:7.4f}".format("Cor-Coef", RadCompare[4]),
                     "{:10}: {:7d}".format("Number", length_rad)],
            "fontsize": 14,
        }

        density_tick = {"fontsize": 14, }

        density_diagonal = {"line_color": "#808080", "line_width": 1.2}

        density_regressline = {"line_color": "r", "line_width": 1.2}

        density = {
            "size": 5, "marker": "o", "alpha": 1
        }
        dv_pub_3d_dev.draw_regression(
            ax1, x, y, label=density_label, ax_annotate=density_annotate, tick=density_tick,
            axislimit=density_axislimit, locator=density_locator,
            diagonal=density_diagonal, regressline=density_regressline,
            density=density,
        )
    else:
        print "::::::No output Pic {} : ".format(ymd)
        return

    # 自动调整子图间距
    plt.tight_layout()

    if not is_monthly and is_diagonal:
        fig.subplots_adjust(top=0.90)
    elif not is_monthly and not is_diagonal:
        fig.subplots_adjust(bottom=0.12, top=0.86)
    elif is_monthly:
        fig.subplots_adjust(bottom=0.12, top=0.86)

    FONT1.set_size(14)
    fig.suptitle(title, fontsize=14, fontproperties=FONT1)
    pb_io.make_sure_path_exists(os.path.dirname(o_file))

    fig.savefig(o_file, dpi=100)
    print o_file + ".png"
    print "-" * 100
    fig.clear()
    plt.close()

    return [len(x), RadCompare[0], RadCompare[1],
            RadCompare[4]], bias_and_md  # num, a, b, r, bias and md
Beispiel #2
0
def plot(x, y, weight, picPath,
         part1, part2, chan, ym, DayOrNight, reference_list,
         xname, xname_l, xunit, xmin, xmax):
    """
    x: 参考卫星传感器数据
    y: FY数据
    """
    plt.style.use(os.path.join(dvPath, 'dv_pub_regression.mplstyle'))
    if xname_l == "TBB":
        xname_l = "TB"

    # 过滤 正负 delta+8倍std 的杂点 ------------
    w = 1.0 / weight if weight is not None else None
    RadCompare = G_reg1d(x, y, w)

    reg_line = x * RadCompare[0] + RadCompare[1]
    delta = np.abs(y - reg_line)
    mean_delta = np.mean(delta)
    std_delta = np.std(delta)
    max_y = reg_line + mean_delta + std_delta * 8
    min_y = reg_line - mean_delta - std_delta * 8

    idx = np.logical_and(y < max_y, y > min_y)
    x = x[idx]
    y = y[idx]
    w = w[idx] if weight is not None else None
    # -----------------------------------------

    if xname == "tbb":
        step = 5
    else:
        step = 0.1

    # 计算回归信息: 斜率,截距,R
    RadCompare = G_reg1d(x, y, w)

    # 开始绘图
    fig = plt.figure(figsize=(6, 5))
    ax1 = plt.subplot2grid((2, 1), (0, 0))
    ax2 = plt.subplot2grid((2, 1), (1, 0))
    # 图片 Title
    title = '%s Bias Monthly Statistics\n%s Minus %s  %s  %s' % \
            (xname_l, part1, part2, chan, DayOrNight)

    # plot 偏差分布图 -------------------------------------------------
    # x y 轴范围
    distri_xmin = xmin
    distri_xmax = xmax
    if xname == "tbb":
        distri_ymin = -4
        distri_ymax = 4
    elif xname == "ref":
        distri_ymin = -0.08
        distri_ymax = 0.08
    else:
        distri_ymin = None
        distri_ymax = None

    distri_limit = {
        "xlimit": (distri_xmin, distri_xmax),
        "ylimit": (distri_ymin, distri_ymax),
    }

    distri_locator = {
        "locator_x": (None, None), "locator_y": (8, 5)
    }
    # Distri label
    distri_label = {}
    if xunit != "":
        ylabel = 'D{}({})'.format(xname_l, xunit)
    else:
        ylabel = "D{}".format(xname_l)
    distri_label["ylabel"] = ylabel

    ref_temp = reference_list[0]  # 获取拟合系数

    # 获取 MeanBias 信息
    bias_range = 0.15
    boundary = xmin + (xmax - xmin) * 0.15
    bias_info = bias_information(x, y, boundary, bias_range)

    # 绝对偏差和相对偏差信息 TBB=250K  REF=0.25
    ab = RadCompare
    a = ab[0]
    b = ab[1]
    if xname == 'tbb':
        bias_info_md = "TBB Bias ({} K) : {:.4f} K".format(
            ref_temp, ref_temp - (ref_temp * a + b))
    elif xname == 'ref':
        bias_info_md = "Relative Bias (REF {}) : {:.4f} %".format(
            ref_temp, (ref_temp - (ref_temp * a + b)) / ref_temp * 100)
    else:
        bias_info_md = ""

    # 配置注释信息
    distri_annotate = {"left": [bias_info.get("info_lower"),
                                bias_info.get("info_greater"),
                                bias_info_md]}
    # 注释线配置
    if xname == "tbb":
        avxline = {
            'line_x': ref_temp, 'line_color': '#4cd964', 'line_width': 0.7,
            'word': str(ref_temp) + xunit, 'word_color': EDGE_GRAY,
            'word_size': 6, 'word_location': (ref_temp, -3.5)
        }
    elif xname == "ref":
        avxline = {
            'line_x': ref_temp, 'line_color': '#4cd964', 'line_width': 0.7,
            'word': str(ref_temp) + xunit, 'word_color': EDGE_GRAY,
            'word_size': 6, 'word_location': (ref_temp, -0.07)
        }
    else:
        avxline = None
        distri_annotate = None

    # y=0 线配置
    zeroline = {"line_color": '#808080', "line_width": 1.0}

    # 偏差点配置
    scatter_delta = {
        "scatter_marker": 'o', "scatter_size": 1.5, "scatter_alpha": 0.5,
        "scatter_linewidth": 0, "scatter_zorder": 100, "scatter_color": BLUE,
    }
    # 偏差 fill 配置
    background_fill = {
        "fill_marker": 'o-', "fill_size": 6, "fill_alpha": 0.5,
        "fill_linewidth": 0.6, "fill_zorder": 50, "fill_color": RED,
        "fill_step": step,
    }

    dv_pub_3d_dev.draw_distribution(ax1, x, y, label=distri_label, ax_annotate=distri_annotate,
                                    axislimit=distri_limit, locator=distri_locator,
                                    zeroline=zeroline,
                                    scatter_delta=scatter_delta,
                                    avxline=avxline,
                                    background_fill=background_fill,
                                    )

    # 绘制 Bar 图 -------------------------------------------------
    bar_xmin = distri_xmin
    bar_xmax = distri_xmax
    bar_ymin = 0
    bar_ymax = 7

    bar_limit = {
        "xlimit": (bar_xmin, bar_xmax),
        "ylimit": (bar_ymin, bar_ymax),
    }

    if xname == "tbb":
        bar_locator = {
            "locator_x": (None, None), "locator_y": (7, 5)
        }
    elif xname == "ref":
        bar_locator = {
            "locator_x": (None, None), "locator_y": (7, 5)
        }
    else:
        bar_locator = None

    # bar 的宽度
    if xname == "tbb":
        width = 3
    elif xname == "ref":
        width = 0.07
    else:
        width = 1
    # bar 配置
    bar = {
        "bar_width": width, "bar_color": BLUE, "bar_linewidth": 0,
        "text_size": 6, "text_font": FONT_MONO, "bar_step": step,
    }

    bar_annotate = {
        "left": ['Total Number: %7d' % len(x)]
    }
    bar_label = {
        "xlabel": '%s %s' % (part2, xname_l) + (
            '($%s$)' % xunit if xunit != "" else ""),
        "ylabel": 'Number of sample points\nlog (base = 10)'
    }

    dv_pub_3d_dev.draw_bar(ax2, x, y, label=bar_label, ax_annotate=bar_annotate,
                           axislimit=bar_limit, locator=bar_locator,
                           bar=bar,
                           )

    # ---------------
    plt.tight_layout()
    # 将 ax1 的 xticklabels 设置为不可见
    plt.setp(ax1.get_xticklabels(), visible=False)

    # 子图的底间距
    fig.subplots_adjust(bottom=0.16, top=0.90)
    FONT1.set_size(11)
    fig.suptitle(title, fontsize=11, fontproperties=FONT1)
    fig.text(0.6, 0.02, '%s' % ym, fontsize=11, fontproperties=FONT0)
    fig.text(0.8, 0.02, ORG_NAME, fontsize=11, fontproperties=FONT0)
    # ---------------

    pb_io.make_sure_path_exists(os.path.dirname(picPath))
    fig.savefig(picPath)
    print picPath
    plt.close()
    fig.clear()
Beispiel #3
0
def plot_omb(date_D, a_D, b_D, picPath, title, date_s, date_e):
    """
    画偏差时序彩色图
    """
    plt.style.use(os.path.join(dvPath, 'dv_pub_timeseries.mplstyle'))
    if (np.isnan(a_D)).all():
        Log.error('Everything is NaN: %s' % picPath)
        return

    ylim_min, ylim_max = 210, 330
    y_res = 0.2
    x_size = (date_e - date_s).days
    yy = np.arange(ylim_min, ylim_max, y_res) + y_res / 2.  # 一列的y值
    grid = np.ones(len(date_D)) * yy.reshape(-1, 1)

    aa = a_D * np.ones((len(grid), 1))
    bb = b_D * np.ones((len(grid), 1))

    grid = grid - np.divide((grid - bb), aa)

    # zz = np.zeros((len(yy), x_size))  # 2D, 要画的值
    zz = np.full((len(yy), x_size), -65535)  # 将值填充为 - ,以前填充0
    zz = np.ma.masked_where(zz == -65535, zz)

    j = 0
    xx = []  # 一行的x值
    for i in xrange(x_size):  # 补充缺失数据的天
        date_i = date_s + relativedelta(days=i)
        xx.append(date_i)
        if j < len(date_D) and date_D[j] == date_i:
            zz[:, i] = grid[:, j]
            j = j + 1

    fig = plt.figure(figsize=(6, 4))
    ax = fig.add_subplot(111)

    norm = mpl.colors.Normalize(vmin=-4.0, vmax=4.0)
    xx = np.array(xx)
    plt.pcolormesh(xx, yy, zz, cmap='jet', norm=norm, shading='flat', zorder=0)
    plt.grid(True, zorder=10)

    xlim_min = date_s
    xlim_max = date_e
    plt.xlim(xlim_min, xlim_max)
    plt.ylim(ylim_min, ylim_max)
    plt.ylabel('TB($K$)', fontsize=11, fontproperties=FONT0)

    # format the ticks
    setXLocator(ax, xlim_min, xlim_max)
    set_tick_font(ax)

    # title
    plt.title(title, fontsize=12, fontproperties=FONT0)

    plt.tight_layout()
    # --------------------
    fig.subplots_adjust(bottom=0.25)

    # -------add colorbar ---------
    fig.canvas.draw()
    point_bl = ax.get_position().get_points()[0]  # 左下
    point_tr = ax.get_position().get_points()[1]  # 右上
    cbar_height = 0.05
    colorbar_ax = fig.add_axes([
        point_bl[0] - 0.05, 0.05, (point_tr[0] - point_bl[0]) / 2.2,
        cbar_height
    ])

    mpl.colorbar.ColorbarBase(colorbar_ax,
                              cmap='jet',
                              norm=norm,
                              orientation='horizontal')
    # ---font of colorbar-----------
    for l in colorbar_ax.xaxis.get_ticklabels():
        l.set_fontproperties(FONT0)
        l.set_fontsize(9)
    # ------Time and ORG_NAME----------------
    ymd_s, ymd_e = date_s.strftime('%Y%m%d'), date_e.strftime('%Y%m%d')
    if ymd_s != ymd_e:
        fig.text(0.52, 0.05, '%s-%s' % (ymd_s, ymd_e), fontproperties=FONT0)
    else:
        fig.text(0.52, 0.05, '%s' % ymd_s, fontproperties=FONT0)

    fig.text(0.82, 0.05, ORG_NAME, fontproperties=FONT0)
    # ---------------

    pb_io.make_sure_path_exists(os.path.dirname(picPath))
    plt.savefig(picPath)
    print picPath
    fig.clear()
    plt.close()
Beispiel #4
0
def plot_rmd(
    date_d,
    data_d,
    date_m,
    data_m,
    std_m,
    pic_path,
    date_s,
    date_e,
    sat_name,
    pair,
    chan,
    day_or_night,
    ref_temp,
    xname,
    xname_l,
    xunit,
    yname,
    yname_l,
    yunit,
):
    if (np.isnan(data_d)).all():
        Log.error('Everything is NaN: %s' % pic_path)
        return
    plt.style.use(os.path.join(dvPath, 'dv_pub_timeseries.mplstyle'))
    fig = plt.figure(figsize=(6, 4))
    # fig.subplots_adjust(top=0.88, bottom=0.11, left=0.12, right=0.97)

    ax1 = plt.subplot2grid((1, 1), (0, 0))

    # 设置 title 参数
    part1, part2 = pair.split('_')

    title = 'Time Series of REF Relative Bias \n{} Minus {} {} {} REF={}'.format(
        part1, part2, chan, day_or_night, ref_temp)

    # plot timeseries --------------------------------------------------------
    timeseries_xmin = pb_time.ymd2date('%04d%02d01' %
                                       (date_s.year, date_s.month))
    timeseries_xmax = date_e

    if "FY2" in sat_name:
        timeseries_ymin = -20
        timeseries_ymax = 20
    elif "FY3" in sat_name:
        timeseries_ymin = -20
        timeseries_ymax = 20
    elif "FY4" in sat_name:
        timeseries_ymin = -20
        timeseries_ymax = 20
    else:
        timeseries_ymin = None
        timeseries_ymax = None
    timeseries_axislimit = {
        "xlimit": (timeseries_xmin, timeseries_xmax),
        "ylimit": (timeseries_ymin, timeseries_ymax),
    }

    # x y 轴标签
    timeseries_label = {}
    if xunit != "":
        ylabel = 'Relative Bias {}'.format(xunit)
    else:
        ylabel = "Relative Bias %"
    timeseries_label["ylabel"] = ylabel

    # x, y 轴大刻度的数量,和小刻度的数量
    timeseries_locator = {"locator_x": (None, None), "locator_y": (8, 2)}

    # y=0 线配置
    timeseries_zeroline = {"line_color": '#808080', "line_width": 1.0}

    timeseries_daily = {
        "marker": 'x',
        "color": BLUE,
        "linewidth": None,
        "markersize": 6,
        "markerfacecolor": None,
        "markeredgecolor": BLUE,
        "alpha": 0.8,
        "markeredgewidth": 0.3,
        "label": "Daily",
    }
    dv_pub_3d_dev.draw_timeseries(
        ax1,
        date_d,
        data_d,
        label=timeseries_label,
        axislimit=timeseries_axislimit,
        locator=timeseries_locator,
        zeroline=timeseries_zeroline,
        timeseries=timeseries_daily,
    )
    timeseries_monthly = {
        "marker": 'o-',
        "color": RED,
        "linewidth": 0.6,
        "markersize": 5,
        "markerfacecolor": None,
        "markeredgecolor": RED,
        "alpha": 0.8,
        "markeredgewidth": 0,
        "label": "Monthly",
    }
    background_fill_timeseries = {
        'x': date_m,
        'y': data_m - std_m,
        'y1': data_m + std_m,
        "color": RED,
    }
    dv_pub_3d_dev.draw_timeseries(
        ax1,
        date_m,
        data_m,
        label=timeseries_label,
        axislimit=timeseries_axislimit,
        locator=timeseries_locator,
        zeroline=timeseries_zeroline,
        timeseries=timeseries_monthly,
        background_fill=background_fill_timeseries,
    )
    # --------------------
    plt.tight_layout()
    fig.suptitle(title, fontsize=11, fontproperties=FONT0)
    fig.subplots_adjust(bottom=0.2, top=0.88)

    circle1 = mpatches.Circle((74, 15), 6, color=BLUE, ec=EDGE_GRAY, lw=0)
    circle2 = mpatches.Circle((164, 15), 6, color=RED, ec=EDGE_GRAY, lw=0)
    fig.patches.extend([circle1, circle2])

    fig.text(0.15, 0.02, 'Daily', color=BLUE, fontproperties=FONT0)
    fig.text(0.3, 0.02, 'Monthly', color=RED, fontproperties=FONT0)

    ymd_s, ymd_e = date_s.strftime('%Y%m%d'), date_e.strftime('%Y%m%d')
    if ymd_s != ymd_e:
        fig.text(0.50, 0.02, '%s-%s' % (ymd_s, ymd_e), fontproperties=FONT0)
    else:
        fig.text(0.50, 0.02, '%s' % ymd_s, fontproperties=FONT0)

    fig.text(0.8, 0.02, ORG_NAME, fontproperties=FONT0)
    # ---------------
    pb_io.make_sure_path_exists(os.path.dirname(pic_path))
    plt.savefig(pic_path)
    print pic_path
    fig.clear()
    plt.close()
Beispiel #5
0
def plot_abc(date_D, a_D, b_D, c_D, date_M, a_M, b_M, c_M, picPath, title,
             date_s, date_e, slope_min, slope_max, var):
    plt.style.use(os.path.join(dvPath, 'dv_pub_timeseries.mplstyle'))
    fig = plt.figure(figsize=(6, 6))
    ax1 = plt.subplot(311)
    ax2 = plt.subplot(312, sharex=ax1)
    ax3 = plt.subplot(313, sharex=ax1)

    # format the Xticks
    xlim_min = pb_time.ymd2date('%04d%02d01' % (date_s.year, date_s.month))
    xlim_max = date_e
    ax1.set_xlim(xlim_min, xlim_max)

    # format the Yticks\
    # Y 轴,坐标轴范围
    if var == "tbb-tbb" or var == "ref-ref":
        ax1.set_ylim(slope_min, slope_max)
        ax1.yaxis.set_major_locator(MultipleLocator(0.01))
        ax1.yaxis.set_minor_locator(MultipleLocator(0.002))
    elif var == "dn-ref":
        ax1.set_ylim(slope_min, slope_max)
        # 根据要求:dn-ref 的图,ax1 需要有两种坐标范围
        if slope_max >= 0.00030:
            ax1.yaxis.set_major_locator(MultipleLocator(0.00010))
            ax1.yaxis.set_minor_locator(MultipleLocator(0.00002))
        else:
            ax1.yaxis.set_major_locator(MultipleLocator(0.00002))
            ax1.yaxis.set_minor_locator(MultipleLocator(0.000004))
    if var == "tbb-tbb":
        ax2.set_ylim(-30, 30)
        ax2.yaxis.set_major_locator(MultipleLocator(10))
        ax2.yaxis.set_minor_locator(MultipleLocator(5))
    elif var == "ref-ref":
        ax2.set_ylim(-0.1, 0.1)
        ax2.yaxis.set_major_locator(MultipleLocator(0.02))
        ax2.yaxis.set_minor_locator(MultipleLocator(0.01))
    elif var == "dn-ref":
        ax2.set_ylim(-0.08, 0.08)
        ax2.yaxis.set_major_locator(MultipleLocator(0.02))
        ax2.yaxis.set_minor_locator(MultipleLocator(0.01))
    ax3.set_ylim(0, 7)
    ax3.yaxis.set_major_locator(MultipleLocator(1))
    ax3.yaxis.set_minor_locator(MultipleLocator(0.5))

    # plot ax1 -------------------------------------------------
    plt.sca(ax1)
    plt.plot(date_D,
             a_D,
             'x',
             ms=5,
             markerfacecolor=None,
             markeredgecolor=BLUE,
             alpha=0.8,
             mew=0.3,
             label='Daily')
    plt.plot(date_M, a_M, 'o-', ms=4, lw=0.6, c=RED, mew=0, label='Monthly')
    plt.ylabel('Slope', fontsize=11, fontproperties=FONT0)
    plt.grid(True)
    plt.title(title, fontsize=12, fontproperties=FONT0)
    set_tick_font(ax1)
    plt.setp(ax1.get_xticklabels(), visible=False)

    # plot ax2 -------------------------------------------------
    plt.sca(ax2)
    plt.plot(date_D,
             b_D,
             'x',
             ms=5,
             markerfacecolor=None,
             markeredgecolor=BLUE,
             alpha=0.8,
             mew=0.3,
             label='Daily')
    plt.plot(date_M, b_M, 'o-', ms=4, lw=0.6, c=RED, mew=0, label='Monthly')
    plt.ylabel('Intercept', fontsize=11, fontproperties=FONT0)
    plt.grid(True)
    set_tick_font(ax2)
    plt.setp(ax2.get_xticklabels(), visible=False)

    # point number -------------------------------------------------
    plt.sca(ax3)

    plt.fill_between(date_D, 0, c_D, edgecolor=BLUE, facecolor=BLUE, alpha=0.6)
    #     plt.fill_between(date_M, 0, c_M,
    #                  edgecolor=RED, facecolor=RED, alpha=0.5)
    #     plt.bar(date_M, c_M, width=1, align='edge',  # "center",
    #             color=RED, linewidth=0)
    plt.plot(date_M, c_M, 'o-', ms=4, lw=0.6, c=RED, mew=0, label='Monthly')
    plt.ylabel('Number of sample points\nlog (base = 10)',
               fontsize=11,
               fontproperties=FONT0)
    plt.grid(True)
    set_tick_font(ax3)

    setXLocator(ax3, xlim_min, xlim_max)

    #     circle1 = mpatches.Circle((430, 563), 5, color=BLUE, ec=EDGE_GRAY, lw=0)
    #     circle2 = mpatches.Circle((508, 563), 5, color=RED, ec=EDGE_GRAY, lw=0)
    #     fig.patches.extend([circle1, circle2])
    #
    #     fig.text(0.74, 0.93, 'Daily', color=BLUE, fontproperties=FONT0)
    #     fig.text(0.86, 0.93, 'Monthly', color=RED, fontproperties=FONT0)
    # ---------------
    plt.tight_layout()
    fig.subplots_adjust(bottom=0.14)

    circle1 = mpatches.Circle((74, 18), 6, color=BLUE, ec=EDGE_GRAY, lw=0)
    circle2 = mpatches.Circle((164, 18), 6, color=RED, ec=EDGE_GRAY, lw=0)
    fig.patches.extend([circle1, circle2])

    fig.text(0.15, 0.02, 'Daily', color=BLUE, fontproperties=FONT0)
    fig.text(0.3, 0.02, 'Monthly', color=RED, fontproperties=FONT0)

    ymd_s, ymd_e = date_s.strftime('%Y%m%d'), date_e.strftime('%Y%m%d')
    if ymd_s != ymd_e:
        fig.text(0.50, 0.02, '%s-%s' % (ymd_s, ymd_e), fontproperties=FONT0)
    else:
        fig.text(0.50, 0.02, '%s' % ymd_s, fontproperties=FONT0)

    fig.text(0.8, 0.02, ORG_NAME, fontproperties=FONT0)
    # ---------------

    pb_io.make_sure_path_exists(os.path.dirname(picPath))
    fig.savefig(picPath)
    print picPath
    plt.close()
    fig.clear()