Пример #1
0
def plot_profiles():
    obs_base_dir = Path("/home/huziy/skynet3_rech1/nemo_obs_for_validation/data_from_Ram_Yerubandi/ADCP-profiles")
    obs_dir_list = [
        str(obs_base_dir.joinpath("105.317")),
        str(obs_base_dir.joinpath("155.289"))
    ]

    obs_var_col = AdcpProfileObs.vmag_col
    model_var_name = FLOW_SPEED

    model_folder = "/home/huziy/skynet3_rech1/offline_glk_output_daily_1979-2012"

    manager_nemo_u = NemoYearlyFilesManager(folder=model_folder, suffix="_U.nc")
    manager_nemo_v = NemoYearlyFilesManager(folder=model_folder, suffix="_V.nc")
    manager_nemo_w = NemoYearlyFilesManager(folder=model_folder, suffix="_W.nc")



    fig = plt.figure()
    gs = GridSpec(len(obs_dir_list), 5, width_ratios=[1, 1, 0.05, 1, 0.05])


    cmap = cm.get_cmap("jet", 10)
    diff_cmap = cm.get_cmap("RdBu_r", 10)

    for i, obs_dir in enumerate(obs_dir_list):

        adcp = AdcpProfileObs()

        dates, levels, obs_data = adcp.get_acdp_profiles(folder=obs_dir, data_column=obs_var_col)

        dates_m, levs_m, u_cs = manager_nemo_u.get_tz_crosssection_for_the_point(
            lon=adcp.longitude, lat=adcp.latitude,
            start_date=dates[0], end_date=dates[-1],
            var_name="vozocrtx", zlist=levels
        )

        dates_m, levs_m, v_cs = manager_nemo_v.get_tz_crosssection_for_the_point(
            lon=adcp.longitude, lat=adcp.latitude,
            start_date=dates[0], end_date=dates[-1],
            var_name="vomecrty", zlist=levels
        )

        dates_m, levs_m, w_cs = manager_nemo_w.get_tz_crosssection_for_the_point(
            lon=adcp.longitude, lat=adcp.latitude,
            start_date=dates[0], end_date=dates[-1],
            var_name="vovecrtz", zlist=levels
        )




        numdates = date2num(dates.tolist())
        print("Obs dates are: {} ... {}".format(dates[0], dates[-1]))
        print([num2date([n for n in numdates if n not in dates_m])])
        zz, tt = np.meshgrid(levels, numdates)

        umag_mod_cs = (u_cs ** 2 + v_cs ** 2 + w_cs ** 2) ** 0.5 * 100.0

        all_axes = []
        # Obs
        ax = fig.add_subplot(gs[i, 0])
        ax.set_title("Obs")
        cs = ax.contourf(tt, zz, obs_data, cmap=cmap)
        ax.set_ylabel("({:.1f}, {:.1f})".format(adcp.longitude, adcp.latitude))
        all_axes.append(ax)


        # Model
        ax = fig.add_subplot(gs[i, 1])
        ax.set_title("NEMO-offline")
        cs = ax.contourf(tt, zz, umag_mod_cs, levels=cs.levels, cmap=cmap)
        all_axes.append(ax)

        plt.colorbar(cs, cax=fig.add_subplot(gs[i, 2]))

        # Bias
        ax = fig.add_subplot(gs[i, 3])
        ax.set_title("Model - Obs.")
        delta = umag_mod_cs - obs_data

        vmax = np.abs(delta).max()
        vmin = -vmax
        locator = MaxNLocator(nbins=diff_cmap.N, symmetric=True)

        cs = ax.contourf(tt, zz, delta, levels=locator.tick_values(vmin, vmax), cmap=diff_cmap)
        plt.colorbar(cs, cax=fig.add_subplot(gs[i, 4]))
        all_axes.append(ax)


        for the_ax in all_axes:
            the_ax.xaxis.set_major_formatter(DateFormatter("%b"))
            the_ax.xaxis.set_major_locator(MonthLocator())
            the_ax.invert_yaxis()

    img_folder = Path("nemo/adcp")
    if not img_folder.is_dir():
        img_folder.mkdir(parents=True)

    img_file = img_folder.joinpath("adcp_profiles.pdf")
    fig.tight_layout()
    fig.savefig(str(img_file), bbox_inches="tight")
Пример #2
0
def main_plot_all_temp_profiles_in_one_figure(
    folder_path="/home/huziy/skynet3_rech1/nemo_obs_for_validation/data_from_Ram_Yerubandi/T-profiles"
):
    """

    figure layout:
        Obs     Model  (Model - Obs)
    p1

    p2

    ...

    pn

            Point Positions map

    :param folder_path: Path to the text files containing observed temperature profiles
    """
    folder_path = os.path.expanduser(folder_path)

    temperature_profile_file_prefixes = [
        "08-01T-004A024.120.290",
        # "08-01T-013A054.120.290", "08-00T-012A017.105.317",
        "08-00T-004A177.106.286"
    ]

    # nemo_manager = NemoYearlyFilesManager(folder="/home/huziy/skynet3_rech1/offline_glk_output_daily_1979-2012")
    # nemo_manager = NemoYearlyFilesManager(folder="/RESCUE/skynet3_rech1/huziy/NEMO_OFFICIAL/dev_v3_4_STABLE_2012/NEMOGCM/CONFIG/GLK_LIM3/EXP_GLK_LIM3_1980/zdf_gls_dt_and_sbc_5min")
    # nemo_manager = NemoYearlyFilesManager(folder="/BIG1/huziy/CRCM5_NEMO_coupled_sim_nemo_outputs/NEMO")
    #nemo_manager = NemoYearlyFilesManager(folder="/HOME/huziy/skynet3_rech1/NEMO_OFFICIAL/dev_v3_4_STABLE_2012/NEMOGCM/CONFIG/GLK_LIM3_CC_drivenby_CRCM5_CanESM2_RCP85/EXP00/cc_canesm2_outputs")
    # nemo_manager = NemoYearlyFilesManager(
    #     folder="/RESCUE/skynet3_rech1/huziy/NEMO_OFFICIAL/dev_v3_4_STABLE_2012/NEMOGCM/CONFIG/GLK_LIM3/EXP_GLK_LIM3_1980/zdf_gls_dt_and_sbc_30min")

    # nemo_manager = NemoYearlyFilesManager(
    #     folder="/HOME/huziy/skynet3_rech1/NEMO_OFFICIAL/dev_v3_4_STABLE_2012/NEMOGCM/CONFIG/GLK_LIM3/EXP_GLK_LIM3_1980/zdf_gls_dt_and_sbc_30min_1980-2010")

    nemo_manager = NemoYearlyFilesManager(
        folder=
        "/HOME/huziy/skynet3_rech1/NEMO_OFFICIAL/Simulations/cc_canesm2_nemo_offline_gathered_corrected_from_guillimin"
    )

    nemo_manager.get_coords_and_basemap(resolution="i")

    plot_utils.apply_plot_params(font_size=12,
                                 width_pt=None,
                                 width_cm=35,
                                 height_cm=30)
    fig = plt.figure()
    gs = GridSpec(len(temperature_profile_file_prefixes) + 2,
                  4,
                  width_ratios=[1, 1, 1, 0.05],
                  height_ratios=len(temperature_profile_file_prefixes) * [
                      1.0,
                  ] + [
                      0.05,
                      2,
                  ],
                  top=0.90,
                  wspace=0.2,
                  hspace=0.2)

    color_levels = np.arange(0, 30, 0.5)
    diff_levels = np.arange(-7, 8, 2)
    diff_cmap = cm.get_cmap("bwr", len(diff_levels) - 1)
    axes_list = []
    imvalues = None
    imdiff = None
    titles = ["Obs", "Model", "Model - Obs"]
    labels = [
        "P{}".format(p) for p in range(len(temperature_profile_file_prefixes))
    ]

    nupper_levs_to_plot = 5

    obs_point_list = []
    start_date, end_date = None, None
    for row, prefix in enumerate(temperature_profile_file_prefixes):
        # Get the data for plots
        po = obs.get_profile_for_prefix(prefix, folder=folder_path)
        obs_point_list.append(po)

        tto, zzo, obs_profile = po.get_tz_section_data()

        start_date = po.get_start_date()
        end_date = po.get_end_date()

        tt, zz, model_profile_interp = nemo_manager.get_tz_crosssection_for_the_point(
            lon=po.longitude,
            lat=po.latitude,
            zlist=po.levels,
            var_name="votemper",
            start_date=start_date,
            end_date=end_date)

        ttm, zzm, model_profile = nemo_manager.get_tz_crosssection_for_the_point(
            lon=po.longitude,
            lat=po.latitude,
            zlist=None,
            var_name="votemper",
            start_date=start_date,
            end_date=end_date)

        print("Unique model levels: ", np.unique(zzm))

        # obs
        ax = fig.add_subplot(gs[row, 0])
        ax.contourf(tto, zzo, obs_profile, levels=color_levels)
        axes_list.append(ax)
        ax.set_ylabel(labels[row])
        common_ylims = ax.get_ylim()

        # model (not interpolated)
        ax = fig.add_subplot(gs[row, 1])
        imvalues = ax.contourf(ttm, zzm, model_profile, levels=color_levels)
        ax.set_ylim(common_ylims)
        ax.yaxis.set_ticklabels([])
        axes_list.append(ax)

        # model profile (interpolated to the observation levels) - obs profile
        ax = fig.add_subplot(gs[row, 2])
        diff = model_profile_interp - obs_profile
        imdiff = ax.contourf(tt[:, :nupper_levs_to_plot],
                             zz[:, :nupper_levs_to_plot],
                             diff[:, :nupper_levs_to_plot],
                             levels=diff_levels,
                             cmap=diff_cmap,
                             extend="both")
        # ax.yaxis.set_ticklabels([])
        axes_list.append(ax)

        if not row:
            for axi, title in zip(axes_list, titles):
                axi.set_title(title)


    title_suffix = " {}-{}".format(start_date.year, end_date.year) if start_date.year < end_date.year \
        else " {}".format(start_date.year)
    fig.suptitle("Temperature, " + title_suffix,
                 font_properties=FontProperties(weight="bold"))

    # plot colorbars
    cb = plt.colorbar(imvalues,
                      cax=fig.add_subplot(
                          gs[len(temperature_profile_file_prefixes), :2]),
                      orientation="horizontal")

    plt.colorbar(imdiff,
                 cax=fig.add_subplot(
                     gs[:len(temperature_profile_file_prefixes), 3]))

    # Format dates
    dfmt = DateFormatter("%b")
    for i, ax in enumerate(axes_list):
        ax.xaxis.set_major_formatter(dfmt)
        ax.yaxis.set_major_locator(MaxNLocator(nbins=5))
        ax.invert_yaxis()

    for ax in axes_list[:-3]:
        ax.xaxis.set_ticklabels([])

    # Plot station positions
    lons, lats, bmp = nemo_manager.get_coords_and_basemap(resolution="i")
    ax = fig.add_subplot(gs[len(temperature_profile_file_prefixes) + 1, :-2])

    for i, po, label in zip(list(range(len(obs_point_list))), obs_point_list,
                            labels):
        xx, yy = bmp(po.longitude, po.latitude)
        bmp.scatter(xx, yy, c="r")

        multiplier = 0.5 if i % 2 else 1
        if i > 1:
            multiplier *= -4

        ax.annotate(label,
                    xy=(xx, yy),
                    xytext=(-20 * multiplier, 20 * multiplier),
                    textcoords='offset points',
                    ha='right',
                    va='bottom',
                    font_properties=FontProperties(size=14),
                    bbox=dict(boxstyle='round,pad=0.5', fc='yellow'),
                    arrowprops=dict(arrowstyle='->',
                                    connectionstyle='arc3,rad=0'))

    bmp.drawcoastlines(linewidth=0.5, ax=ax)
    # fig.tight_layout()

    if not img_dir.exists():
        img_dir.mkdir(parents=True)

    img_path = img_dir / "T-profiles.pdf"

    print("Saving plots to {}".format(img_path))
    fig.savefig(str(img_path), transparent=True, bbox_inches="tight", dpi=300)
Пример #3
0
def main_plot_all_temp_profiles_in_one_figure(
        folder_path="/home/huziy/skynet3_rech1/nemo_obs_for_validation/data_from_Ram_Yerubandi/T-profiles"):
    """

    figure layout:
        Obs     Model  (Model - Obs)
    p1

    p2

    ...

    pn

            Point Positions map

    :param folder_path: Path to the text files containing observed temperature profiles
    """
    folder_path = os.path.expanduser(folder_path)

    temperature_profile_file_prefixes = [
        "08-01T-004A024.120.290",
        # "08-01T-013A054.120.290", "08-00T-012A017.105.317",
        "08-00T-004A177.106.286"
    ]

    nemo_manager = NemoYearlyFilesManager(folder="/home/huziy/skynet3_rech1/offline_glk_output_daily_1979-2012")

    plot_utils.apply_plot_params(font_size=16, width_pt=None, width_cm=40, height_cm=30)
    fig = plt.figure()
    gs = GridSpec(len(temperature_profile_file_prefixes) + 1, 5, width_ratios=[1, 1, 0.05, 1, 0.05],
                  height_ratios=len(temperature_profile_file_prefixes) * [1.0, ] + [3, ], top=0.90,
                  wspace=0.4, hspace=0.2)

    color_levels = np.arange(-1, 30, 1)
    diff_levels = np.arange(-10, 10.5, 0.5)
    diff_cmap = cm.get_cmap("RdBu_r", len(diff_levels) - 1)
    axes_list = []
    imvalues = None
    imdiff = None
    titles = ["Obs", "Model", "Model - Obs"]
    labels = ["P{}".format(p) for p in range(len(temperature_profile_file_prefixes))]

    obs_point_list = []
    start_date, end_date = None, None
    for row, prefix in enumerate(temperature_profile_file_prefixes):
        # Get the data for plots
        po = obs.get_profile_for_prefix(prefix, folder=folder_path)
        obs_point_list.append(po)

        tto, zzo, obs_profile = po.get_tz_section_data()

        start_date = po.get_start_date()
        end_date = po.get_end_date()

        tt, zz, model_profile_interp = nemo_manager.get_tz_crosssection_for_the_point(lon=po.longitude, lat=po.latitude,
                                                                                      zlist=po.levels,
                                                                                      var_name="votemper",
                                                                                      start_date=start_date,
                                                                                      end_date=end_date)

        ttm, zzm, model_profile = nemo_manager.get_tz_crosssection_for_the_point(lon=po.longitude, lat=po.latitude,
                                                                                 zlist=None,
                                                                                 var_name="votemper",
                                                                                 start_date=start_date,
                                                                                 end_date=end_date)

        print("Unique model levels: ", np.unique(zzm))

        # obs
        ax = fig.add_subplot(gs[row, 0])
        ax.contourf(tto, zzo, obs_profile, levels=color_levels)
        axes_list.append(ax)
        ax.set_ylabel(labels[row])
        common_ylims = ax.get_ylim()

        # model (not interpolated)
        ax = fig.add_subplot(gs[row, 1])
        imvalues = ax.contourf(ttm, zzm, model_profile, levels=color_levels)
        ax.set_ylim(common_ylims)
        ax.yaxis.set_ticklabels([])
        axes_list.append(ax)



        # model profile (interpolated to the observation levels) - obs profile
        ax = fig.add_subplot(gs[row, 3])
        diff = model_profile_interp - obs_profile
        imdiff = ax.contourf(tt, zz, diff, levels=diff_levels, cmap=diff_cmap, extend="both")
        ax.yaxis.set_ticklabels([])
        axes_list.append(ax)

        if not row:
            for axi, title in zip(axes_list, titles):
                axi.set_title(title)


    title_suffix = " {}-{}".format(start_date.year, end_date.year) if start_date.year < end_date.year \
        else " {}".format(start_date.year)
    fig.suptitle("Temperature, " + title_suffix, font_properties=FontProperties(weight="bold"))


    # plot colorbars
    cb = plt.colorbar(imvalues, cax=fig.add_subplot(gs[:-1, 2]))

    plt.colorbar(imdiff, cax=fig.add_subplot(gs[:-1, 4]))

    # Format dates
    dfmt = DateFormatter("%b")
    for i, ax in enumerate(axes_list):
        ax.xaxis.set_major_formatter(dfmt)
        ax.yaxis.set_major_locator(MaxNLocator(nbins=5))
        ax.invert_yaxis()


    for ax in axes_list[:-3]:
        ax.xaxis.set_ticklabels([])


    # Plot station positions
    lons, lats, bmp = nemo_manager.get_coords_and_basemap()
    ax = fig.add_subplot(gs[len(temperature_profile_file_prefixes), :-2])

    for i, po, label in zip(list(range(len(obs_point_list))), obs_point_list, labels):
        xx, yy = bmp(po.longitude, po.latitude)
        bmp.scatter(xx, yy, c="r")

        multiplier = 0.5 if i % 2 else 1
        if i > 1:
            multiplier *= -4

        ax.annotate(label, xy=(xx, yy), xytext=(-20 * multiplier, 20 * multiplier),
                    textcoords='offset points', ha='right', va='bottom',
                    font_properties=FontProperties(size=14),
                    bbox=dict(boxstyle='round,pad=0.5', fc='yellow'),
                    arrowprops=dict(arrowstyle='->', connectionstyle='arc3,rad=0'))

    bmp.drawcoastlines(linewidth=0.5, ax=ax)
    # plt.tight_layout()
    img_path = "nemo/T-profiles.pdf"

    fig.savefig(img_path, transparent=True, bbox_inches="tight")
def main_plot_all_temp_profiles_in_one_figure(
        folder_path="/home/huziy/skynet3_rech1/nemo_obs_for_validation/data_from_Ram_Yerubandi/T-profiles"):
    """

    figure layout:
        Obs     Model  (Model - Obs)
    p1

    p2

    ...

    pn

            Point Positions map

    :param folder_path: Path to the text files containing observed temperature profiles
    """
    folder_path = os.path.expanduser(folder_path)

    temperature_profile_file_prefixes = [
        "08-01T-004A024.120.290",
        # "08-01T-013A054.120.290", "08-00T-012A017.105.317",
        "08-00T-004A177.106.286"
    ]

    # nemo_manager = NemoYearlyFilesManager(folder="/home/huziy/skynet3_rech1/offline_glk_output_daily_1979-2012")
    # nemo_manager = NemoYearlyFilesManager(folder="/RESCUE/skynet3_rech1/huziy/NEMO_OFFICIAL/dev_v3_4_STABLE_2012/NEMOGCM/CONFIG/GLK_LIM3/EXP_GLK_LIM3_1980/zdf_gls_dt_and_sbc_5min")
    # nemo_manager = NemoYearlyFilesManager(folder="/BIG1/huziy/CRCM5_NEMO_coupled_sim_nemo_outputs/NEMO")
    #nemo_manager = NemoYearlyFilesManager(folder="/HOME/huziy/skynet3_rech1/NEMO_OFFICIAL/dev_v3_4_STABLE_2012/NEMOGCM/CONFIG/GLK_LIM3_CC_drivenby_CRCM5_CanESM2_RCP85/EXP00/cc_canesm2_outputs")
    # nemo_manager = NemoYearlyFilesManager(
    #     folder="/RESCUE/skynet3_rech1/huziy/NEMO_OFFICIAL/dev_v3_4_STABLE_2012/NEMOGCM/CONFIG/GLK_LIM3/EXP_GLK_LIM3_1980/zdf_gls_dt_and_sbc_30min")

    # nemo_manager = NemoYearlyFilesManager(
    #     folder="/HOME/huziy/skynet3_rech1/NEMO_OFFICIAL/dev_v3_4_STABLE_2012/NEMOGCM/CONFIG/GLK_LIM3/EXP_GLK_LIM3_1980/zdf_gls_dt_and_sbc_30min_1980-2010")


    nemo_manager = NemoYearlyFilesManager(
        folder="/HOME/huziy/skynet3_rech1/NEMO_OFFICIAL/Simulations/cc_canesm2_nemo_offline_gathered_corrected_from_guillimin")

    nemo_manager.get_coords_and_basemap(resolution="i")



    plot_utils.apply_plot_params(font_size=12, width_pt=None, width_cm=35, height_cm=30)
    fig = plt.figure()
    gs = GridSpec(len(temperature_profile_file_prefixes) + 2, 4, width_ratios=[1, 1, 1, 0.05],
                  height_ratios=len(temperature_profile_file_prefixes) * [1.0, ] + [0.05, 2, ], top=0.90,
                  wspace=0.2, hspace=0.2)

    color_levels = np.arange(0, 30, 0.5)
    diff_levels = np.arange(-7, 8, 2)
    diff_cmap = cm.get_cmap("bwr", len(diff_levels) - 1)
    axes_list = []
    imvalues = None
    imdiff = None
    titles = ["Obs", "Model", "Model - Obs"]
    labels = ["P{}".format(p) for p in range(len(temperature_profile_file_prefixes))]


    nupper_levs_to_plot = 5

    obs_point_list = []
    start_date, end_date = None, None
    for row, prefix in enumerate(temperature_profile_file_prefixes):
        # Get the data for plots
        po = obs.get_profile_for_prefix(prefix, folder=folder_path)
        obs_point_list.append(po)

        tto, zzo, obs_profile = po.get_tz_section_data()

        start_date = po.get_start_date()
        end_date = po.get_end_date()

        tt, zz, model_profile_interp = nemo_manager.get_tz_crosssection_for_the_point(lon=po.longitude, lat=po.latitude,
                                                                                      zlist=po.levels,
                                                                                      var_name="votemper",
                                                                                      start_date=start_date,
                                                                                      end_date=end_date)

        ttm, zzm, model_profile = nemo_manager.get_tz_crosssection_for_the_point(lon=po.longitude, lat=po.latitude,
                                                                                 zlist=None,
                                                                                 var_name="votemper",
                                                                                 start_date=start_date,
                                                                                 end_date=end_date)

        print("Unique model levels: ", np.unique(zzm))

        # obs
        ax = fig.add_subplot(gs[row, 0])
        ax.contourf(tto, zzo, obs_profile, levels=color_levels)
        axes_list.append(ax)
        ax.set_ylabel(labels[row])
        common_ylims = ax.get_ylim()

        # model (not interpolated)
        ax = fig.add_subplot(gs[row, 1])
        imvalues = ax.contourf(ttm, zzm, model_profile, levels=color_levels)
        ax.set_ylim(common_ylims)
        ax.yaxis.set_ticklabels([])
        axes_list.append(ax)



        # model profile (interpolated to the observation levels) - obs profile
        ax = fig.add_subplot(gs[row, 2])
        diff = model_profile_interp - obs_profile
        imdiff = ax.contourf(tt[:, :nupper_levs_to_plot], zz[:, :nupper_levs_to_plot], diff[:, :nupper_levs_to_plot], levels=diff_levels, cmap=diff_cmap, extend="both")
        # ax.yaxis.set_ticklabels([])
        axes_list.append(ax)

        if not row:
            for axi, title in zip(axes_list, titles):
                axi.set_title(title)


    title_suffix = " {}-{}".format(start_date.year, end_date.year) if start_date.year < end_date.year \
        else " {}".format(start_date.year)
    fig.suptitle("Temperature, " + title_suffix, font_properties=FontProperties(weight="bold"))


    # plot colorbars
    cb = plt.colorbar(imvalues, cax=fig.add_subplot(gs[len(temperature_profile_file_prefixes), :2]), orientation="horizontal")

    plt.colorbar(imdiff, cax=fig.add_subplot(gs[:len(temperature_profile_file_prefixes), 3]))

    # Format dates
    dfmt = DateFormatter("%b")
    for i, ax in enumerate(axes_list):
        ax.xaxis.set_major_formatter(dfmt)
        ax.yaxis.set_major_locator(MaxNLocator(nbins=5))
        ax.invert_yaxis()


    for ax in axes_list[:-3]:
        ax.xaxis.set_ticklabels([])


    # Plot station positions
    lons, lats, bmp = nemo_manager.get_coords_and_basemap(resolution="i")
    ax = fig.add_subplot(gs[len(temperature_profile_file_prefixes) + 1, :-2])

    for i, po, label in zip(list(range(len(obs_point_list))), obs_point_list, labels):
        xx, yy = bmp(po.longitude, po.latitude)
        bmp.scatter(xx, yy, c="r")

        multiplier = 0.5 if i % 2 else 1
        if i > 1:
            multiplier *= -4

        ax.annotate(label, xy=(xx, yy), xytext=(-20 * multiplier, 20 * multiplier),
                    textcoords='offset points', ha='right', va='bottom',
                    font_properties=FontProperties(size=14),
                    bbox=dict(boxstyle='round,pad=0.5', fc='yellow'),
                    arrowprops=dict(arrowstyle='->', connectionstyle='arc3,rad=0'))

    bmp.drawcoastlines(linewidth=0.5, ax=ax)
    # fig.tight_layout()


    if not img_dir.exists():
        img_dir.mkdir(parents=True)

    img_path = img_dir / "T-profiles.pdf"

    print("Saving plots to {}".format(img_path))
    fig.savefig(str(img_path), transparent=True, bbox_inches="tight", dpi=300)
def plot_profiles():
    obs_base_dir = Path("/home/huziy/skynet3_rech1/nemo_obs_for_validation/data_from_Ram_Yerubandi/ADCP-profiles")
    obs_dir_list = [
        str(obs_base_dir.joinpath("105.317")),
        str(obs_base_dir.joinpath("155.289"))
    ]

    obs_var_col = AdcpProfileObs.vmag_col
    model_var_name = FLOW_SPEED

    # model_folder = "/home/huziy/skynet3_rech1/offline_glk_output_daily_1979-2012"
    model_folder = "/RESCUE/skynet3_rech1/huziy/NEMO_OFFICIAL/dev_v3_4_STABLE_2012/NEMOGCM/CONFIG/GLK_LIM3/EXP_GLK_LIM3_1980/zdf_gls_dt_and_sbc_5min"

    manager_nemo_u = NemoYearlyFilesManager(folder=model_folder, suffix="_U.nc")
    manager_nemo_v = NemoYearlyFilesManager(folder=model_folder, suffix="_V.nc")
    manager_nemo_w = NemoYearlyFilesManager(folder=model_folder, suffix="_W.nc")



    fig = plt.figure()
    gs = GridSpec(len(obs_dir_list), 5, width_ratios=[1, 1, 0.05, 1, 0.05])


    cmap = cm.get_cmap("jet", 10)
    diff_cmap = cm.get_cmap("RdBu_r", 10)

    for i, obs_dir in enumerate(obs_dir_list):

        adcp = AdcpProfileObs()

        dates, levels, obs_data = adcp.get_acdp_profiles(folder=obs_dir, data_column=obs_var_col)

        dates_m, levs_m, u_cs = manager_nemo_u.get_tz_crosssection_for_the_point(
            lon=adcp.longitude, lat=adcp.latitude,
            start_date=dates[0], end_date=dates[-1],
            var_name="vozocrtx", zlist=levels
        )

        dates_m, levs_m, v_cs = manager_nemo_v.get_tz_crosssection_for_the_point(
            lon=adcp.longitude, lat=adcp.latitude,
            start_date=dates[0], end_date=dates[-1],
            var_name="vomecrty", zlist=levels
        )

        dates_m, levs_m, w_cs = manager_nemo_w.get_tz_crosssection_for_the_point(
            lon=adcp.longitude, lat=adcp.latitude,
            start_date=dates[0], end_date=dates[-1],
            var_name="vovecrtz", zlist=levels
        )




        numdates = date2num(dates.tolist())
        print("Obs dates are: {} ... {}".format(dates[0], dates[-1]))
        print([num2date([n for n in numdates if n not in dates_m])])
        zz, tt = np.meshgrid(levels, numdates)

        umag_mod_cs = (u_cs ** 2 + v_cs ** 2 + w_cs ** 2) ** 0.5 * 100.0

        all_axes = []
        # Obs
        ax = fig.add_subplot(gs[i, 0])
        ax.set_title("Obs")
        cs = ax.contourf(tt, zz, obs_data, cmap=cmap)
        ax.set_ylabel("({:.1f}, {:.1f})".format(adcp.longitude, adcp.latitude))
        all_axes.append(ax)


        # Model
        ax = fig.add_subplot(gs[i, 1])
        ax.set_title("NEMO-offline")
        cs = ax.contourf(tt, zz, umag_mod_cs, levels=cs.levels, cmap=cmap)
        all_axes.append(ax)

        plt.colorbar(cs, cax=fig.add_subplot(gs[i, 2]))

        # Bias
        ax = fig.add_subplot(gs[i, 3])
        ax.set_title("Model - Obs.")
        delta = umag_mod_cs - obs_data

        vmax = np.abs(delta).max()
        vmin = -vmax
        locator = MaxNLocator(nbins=diff_cmap.N, symmetric=True)

        cs = ax.contourf(tt, zz, delta, levels=locator.tick_values(vmin, vmax), cmap=diff_cmap)
        plt.colorbar(cs, cax=fig.add_subplot(gs[i, 4]))
        all_axes.append(ax)


        for the_ax in all_axes:
            the_ax.xaxis.set_major_formatter(DateFormatter("%b"))
            the_ax.xaxis.set_major_locator(MonthLocator())
            the_ax.invert_yaxis()

    img_folder = Path("nemo/adcp/zdf_gls_dt_and_sbc_5min")
    if not img_folder.is_dir():
        img_folder.mkdir(parents=True)

    img_file = img_folder.joinpath("adcp_profiles.pdf")
    fig.tight_layout()

    print("Saving plots to {}".format(img_file))
    fig.savefig(str(img_file), bbox_inches="tight")