Exemple #1
0
def test_ocean_mean_iw_plot():
    dirs = "../result_h/test/test_ocean/"
    mkdir(dirs)

    start_list_plus_1month = start_list + [20170901]
    for i, start in enumerate(start_list):
        print("*******************  {}/{}  *******************".format(
            i + 1, M))
        month_end = start_list_plus_1month[i + 1]
        month_end = date(month_end // 10000, (month_end % 10000) // 100,
                         (month_end % 10000) % 100) - timedelta(days=1)
        end = start + month_end.day - 1

        #csv_Helmert_90の当該月のcsvを読み込む
        hermert_file_name_90 = "../data/csv_Helmert_both_90/Helmert_both_90_" + str(
            start)[:6] + ".csv"
        helmert_90_data = pd.read_csv(hermert_file_name_90).dropna()
        #csv_Helmert_30の当該月のcsvを読み込む
        hermert_file_name_30 = "../data/csv_Helmert_30/Helmert_30_" + str(
            start)[:6] + ".csv"
        helmert_30_data = pd.read_csv(hermert_file_name_30).dropna()
        #木村のcsvの読み込み(90)
        coeff_file_name_90 = "../data/csv_A_90/ssc_amsr_ads" + str(
            start)[2:6] + "_90_fin.csv"
        coeff_90_data = calc_data.get_1month_coeff_data(
            coeff_file_name_90).dropna()
        #木村のcsvの読み込み(30)
        coeff_file_name_30 = "../data/csv_A_30/ssc_amsr_ads" + str(
            start)[2:6] + "_30_fin.csv"
        coeff_30_data = calc_data.get_1month_coeff_data(
            coeff_file_name_30).dropna()

        ocean_90_h_u = helmert_90_data["ocean_u"].values
        ocean_90_h_v = helmert_90_data["ocean_v"].values
        ocean_90_h_speed = np.sqrt(ocean_90_h_u**2 + ocean_90_h_v**2)
        ocean_30_h_u = helmert_30_data["ocean_u"].values
        ocean_30_h_v = helmert_30_data["ocean_v"].values
        ocean_30_h_speed = np.sqrt(ocean_30_h_u**2 + ocean_30_h_v**2)
        ocean_90_c_u = coeff_90_data["mean_ocean_u"].values
        ocean_90_c_v = coeff_90_data["mean_ocean_v"].values
        ocean_90_c_speed = np.sqrt(ocean_90_c_u**2 + ocean_90_c_v**2)
        ocean_30_c_u = coeff_30_data["mean_ocean_u"].values
        ocean_30_c_v = coeff_30_data["mean_ocean_v"].values
        ocean_30_c_speed = np.sqrt(ocean_30_c_u**2 + ocean_30_c_v**2)

        fig, axes = plt.subplots(1, 2)
        axes[0].hist(ocean_90_c_speed / ocean_90_h_speed)
        axes[1].hist(ocean_30_c_speed / ocean_30_h_speed)
        plt.savefig(dirs + "hist_ocean_" + str(start)[:6] + ".png", dpi=450)
        plt.close()
Exemple #2
0
def main_data(start, end, **kwargs):
    span = kwargs["span"]
    region = kwargs["region"]
    get_columns = kwargs["get_columns"]
    accumulate = kwargs["accumulate"]

    date_ax, date_ax_str = get_date_ax(start, end)
    N = len(date_ax_str)
    skipping_date_str = []
    accumulate_data = []
    data = []
    for i, day in enumerate(date_ax_str):
        print("{}/{}: {}".format(i + 1, N, day))
        print("start: {}, end: {}".format(start, end))
        year = day[2:4]
        month = day[4:6]

        #ファイル名の生成
        wind_file_name = "../data/csv_w/ecm" + day[2:] + ".csv"
        ice_file_name = "../data/csv_iw/" + day[2:] + ".csv"
        ic0_145_file_name = "../data/csv_ic0/IC0_" + day + ".csv"
        sit_145_file_name = "../data/csv_sit/SIT_" + day + ".csv"
        coeff_file_name = "../data/csv_A_30/ssc_amsr_ads" + str(year) + str(
            month) + "_" + str(span) + "_fin.csv"
        hermert_file_name = "../data/csv_Helmert_30/Helmert_30_" + str(
            day)[:6] + ".csv"
        # wind10m_file_name = "../data/netcdf4/" + day[2:] + ".csv"
        # t2m_file_name = "../data/netcdf4/" + day[2:] + ".csv"

        skipping_boolean = ("coeff" not in get_columns) and (not all([
            os.path.isfile(wind_file_name),
            os.path.isfile(ice_file_name),
            os.path.isfile(coeff_file_name)
        ]))
        if ("ic0_145" in get_columns):
            skipping_boolean = ("coeff" not in get_columns) and (not all([
                os.path.isfile(wind_file_name),
                os.path.isfile(ice_file_name),
                os.path.isfile(coeff_file_name),
                os.path.isfile(ic0_145_file_name)
            ]))
        if ("sit_145" in get_columns):
            skipping_boolean = ("coeff" not in get_columns) and (not all([
                os.path.isfile(wind_file_name),
                os.path.isfile(ice_file_name),
                os.path.isfile(coeff_file_name),
                os.path.isfile(sit_145_file_name)
            ]))

        if skipping_boolean == True:
            print("\tSkipping " + day + " file...")
            date_ax_str.remove(day)
            bb = date(int(day[:4]), int(day[4:6]), int(day[6:]))
            date_ax.remove(bb)
            skipping_date_str.append(day)
            continue

        data = pd.DataFrame({"data_idx": np.array(ocean_grid_145).ravel()})
        if "ex_1" in get_columns:
            print("\t{}\n\t{}\n\t{}\n\t{}".format(wind_file_name,
                                                  ice_file_name,
                                                  coeff_file_name))
            tmp = calc_data.get_w_regression_data(wind_file_name,
                                                  ice_file_name,
                                                  coeff_file_name)
            data = pd.concat([data, tmp], axis=1)
        if "ex_2" in get_columns:
            print("\t{}\n\t{}\n\t{}\n\t{}".format(wind_file_name,
                                                  ice_file_name,
                                                  hermert_file_name))
            tmp = calc_data.get_w_hermert_data(wind_file_name, ice_file_name,
                                               hermert_file_name)
            data = pd.concat([data, tmp], axis=1)
        if "w" in get_columns:
            print("\t{}".format(wind_file_name))
            tmp = calc_data.get_1day_w_data(wind_file_name)
            data = pd.concat([data, tmp], axis=1)
        if "iw" in get_columns:
            print("\t{}".format(ice_file_name))
            tmp = calc_data.get_1day_iw_data(ice_file_name)
            data = pd.concat([data, tmp], axis=1)
        if "ic0_145" in get_columns:
            print("\t{}".format(ic0_145_file_name))
            tmp = calc_data.get_1day_ic0_data(ic0_145_file_name)
            data = pd.concat([data, tmp], axis=1)
        if "sit_145" in get_columns:
            print("\t{}".format(sit_145_file_name))
            tmp = calc_data.get_1day_sit_data(sit_145_file_name)
            data = pd.concat([data, tmp], axis=1)
        if "coeff" in get_columns:
            print("\t{}".format(coeff_file_name))
            tmp = calc_data.get_1month_coeff_data(coeff_file_name)
            data = pd.concat([data, tmp], axis=1)
        if "hermert" in get_columns:
            print("\t{}".format(hermert_file_name))
            tmp = calc_data.get_1month_hermert_data(hermert_file_name)
            data = pd.concat([data, tmp], axis=1)
        """
		if "w10m" in get_columns:
			tmp = calc_data.get_1day_w10m_data(wind10m_file_name)
			data = pd.concat([data, tmp], axis=1)
		if "t2m" in get_columns:
			tmp = calc_data.get_1day_t2m_data(t2m_file_name)
			data = pd.concat([data, tmp], axis=1)
		"""

        data = calc_data.get_masked_region_data(data, region)

        if ("coeff" in get_columns):
            print("\tSelected only coeff data. Getting out of the loop...")
            continue

        if accumulate == True:
            data_1 = data.drop("data_idx", axis=1)
            print("\t{}".format(data_1.columns))
            accumulate_data.append(np.array(data_1))

    if accumulate == True:
        print("accumulate: True\tdata type: array")
        return date_ax, date_ax_str, skipping_date_str, accumulate_data
    else:
        print("accumulate: False\tdata type: DataFrame")
        return date_ax, date_ax_str, skipping_date_str, data
def test_ocean_plot():
    dirs = "../result_h/test/test_iw/"
    mkdir(dirs)

    start_list_plus_1month = start_list + [20170901]
    for i, start in enumerate(start_list):
        print("*******************  {}/{}  *******************".format(
            i + 1, M))
        month_end = start_list_plus_1month[i + 1]
        month_end = date(month_end // 10000, (month_end % 10000) // 100,
                         (month_end % 10000) % 100) - timedelta(days=1)
        end = start + month_end.day - 1

        try:
            #csv_Helmert_90の当該月のcsvを読み込む
            #hermert_file_name_90 = "../data/csv_Helmert_both_90/Helmert_both_90_" + str(start)[:6] + ".csv"
            #helmert_90_data = pd.read_csv(hermert_file_name_90)
            #csv_Helmert_30の当該月のcsvを読み込む
            hermert_file_name_30 = "../data/csv_Helmert_30/Helmert_30_" + str(
                start)[:6] + ".csv"
            helmert_30_data = pd.read_csv(hermert_file_name_30)
            #木村のcsvの読み込み(90)
            #coeff_file_name_90 = "../data/csv_A_90/ssc_amsr_ads" + str(start)[2:6] + "_90_fin.csv"
            #coeff_90_data = calc_data.get_1month_coeff_data(coeff_file_name_90)
            #木村のcsvの読み込み(30)
            coeff_file_name_30 = "../data/csv_A_30/ssc_amsr_ads" + str(
                start)[2:6] + "_30_fin.csv"
            coeff_30_data = calc_data.get_1month_coeff_data(coeff_file_name_30)
        except:
            continue
        #ocean_90_h_u = helmert_90_data["ocean_u_90"].values
        #ocean_90_h_v = helmert_90_data["ocean_v_90"].values
        #ocean_90_h_speed = np.sqrt(ocean_90_h_u**2 + ocean_90_h_v**2)
        ocean_30_h_u = helmert_30_data["ocean_u"].values
        ocean_30_h_v = helmert_30_data["ocean_v"].values
        ocean_30_h_speed = np.sqrt(ocean_30_h_u**2 + ocean_30_h_v**2)
        #ocean_90_c_u = coeff_90_data["mean_ocean_u"].values
        #ocean_90_c_v = coeff_90_data["mean_ocean_v"].values
        #ocean_90_c_speed = np.sqrt(ocean_90_c_u**2 + ocean_90_c_v**2)
        ocean_30_c_u = coeff_30_data["mean_ocean_u"].values
        ocean_30_c_v = coeff_30_data["mean_ocean_v"].values
        ocean_30_c_speed = np.sqrt(ocean_30_c_u**2 + ocean_30_c_v**2)
        """
		fig, axes = plt.subplots(1, 2)
		ratio_90 = ocean_90_c_speed/ocean_90_h_speed
		ratio_30 = ocean_30_c_speed/ocean_30_h_speed
		axes[0].hist(ratio_30[ocean_idx][~np.isnan(ratio_30[ocean_idx])], range=(0,3), bins=150)
		axes[1].hist(ratio_90[ocean_idx][~np.isnan(ratio_90[ocean_idx])], range=(0,3), bins=150)
		"""
        ratio_w = ocean_30_c_u / ocean_30_h_u

        N_c_h = helmert_30_data["mean_iw_v"].values
        N_c_c = coeff_30_data["mean_ice_v"].values
        N_c_diff = N_c_h - N_c_c
        #plt.hist(N_c_diff[~np.isnan(N_c_diff)], range=(-5,5), bins=11, alpha=0.5)
        #tmp = N_c_diff[~np.isnan(N_c_diff)]
        #print(len(np.where(tmp>0)[0]))

        m = Basemap(lon_0=180,
                    boundinglat=50,
                    resolution='l',
                    projection='npstere')
        m.drawcoastlines(color='0.15')
        m.fillcontinents(color='#555555')
        lon = np.array(latlon_ex.Lon)
        lat = np.array(latlon_ex.Lat)
        x, y = m(lon, lat)
        x1 = np.reshape(x, (145, 145), order='F')
        y1 = np.reshape(y, (145, 145), order='F')
        dx1 = (x1[1, 0] - x1[0, 0]) / 2
        dy1 = (y1[0, 1] - y1[0, 0]) / 2
        x2 = np.linspace(x1[0, 0], x1[144, 0], 145)
        y2 = np.linspace(y1[0, 0], y1[0, 144], 145)
        xx, yy = np.meshgrid(x2, y2)
        xx, yy = xx.T, yy.T
        xx = np.hstack([xx, xx[:, 0].reshape(145, 1)])
        xx_ex = np.vstack([xx, (xx[144, :] + (xx[1, 0] - xx[0, 0]))])
        yy = np.vstack([yy, yy[0, :]])
        yy_ex = np.hstack([(yy[:, 0].reshape(146, 1) + (yy[0, 0] - yy[0, 1])),
                           yy])

        data = np.ma.masked_invalid(N_c_diff)
        data1 = np.reshape(data, (145, 145), order='F')
        m.pcolormesh(xx_ex - dx1,
                     yy_ex + dy1,
                     data1,
                     cmap=plt.cm.jet,
                     vmax=0.5,
                     vmin=-0.5)
        #fig.colorbar(im, ax=ax)
        m.colorbar()

        #plt.hist(N_c_c[~np.isnan(N_c_c)], range=(20,35), bins=16)
        plt.savefig(dirs + "iw_v_" + str(start)[:6] + ".png", dpi=450)
        plt.close()
Exemple #4
0
def main_data(start, end, **kwargs):
    span = kwargs["span"]
    region = kwargs["region"]
    get_columns = kwargs["get_columns"]
    accumulate = kwargs["accumulate"]

    date_ax, date_ax_str = get_date_ax(start, end)
    N = len(date_ax_str)
    skipping_date_str = []
    accumulate_data = []
    for i, day in enumerate(date_ax_str):
        print("{}/{}: {}".format(i + 1, N, day))
        year = day[2:4]
        month = day[4:6]

        #ファイル名の生成
        wind_file_name = "../data/wind_data/ecm" + day[2:] + ".csv"
        ice_file_name = "../data/ice_wind_data/" + day[2:] + ".csv"
        ic0_145_file_name = "../data/IC0_csv/2" + day + "A.csv"
        ic0_900_file_name = "../data/IC0_csv/2" + day + "A.csv"
        coeff_file_name = "../data/A_csv/ssc_amsr_ads" + str(year) + str(
            month) + "_" + str(span) + "_fin.csv"
        wind10m_file_name = "../data/netcdf4/" + day[2:] + ".csv"
        t2m_file_name = "../data/netcdf4/" + day[2:] + ".csv"

        if not all([
                os.path.isfile(wind_file_name),
                os.path.isfile(ice_file_name),
                os.path.isfile(ic0_145_file_name),
                os.path.isfile(coeff_file_name)
        ]):
            print("\tSkipping " + day + " file...")
            date_ax_str.remove(day)
            date_ax.remove(datetime(day[:4] + "-" + day[4:6] + "-" + day[6:]))
            skipping_date_str.append(day)
            continue

        data = pd.DataFrame({"data_idx": np.zeros(145 * 145)})
        iw_idx_t, ic0_idx_t = np.array([-1]), np.array([-1])
        if "ex_1" in get_columns:
            tmp = calc_data.get_w_regression_data(wind_file_name,
                                                  ice_file_name,
                                                  coeff_file_name)
            iw_idx_t = np.array(tmp["data_idx"])
            data = pd.concat([data, tmp.loc[:, ["A_by_day", "theta_by_day"]]],
                             axis=1)
        if "w" in get_columns:
            tmp = calc_data.get_1day_w_data(wind_file_name)
            data = pd.concat([data, tmp], axis=1)
        if "iw" in get_columns:
            tmp = calc_data.get_1day_ice_data(ice_file_name)
            iw_idx_t = np.array(tmp["iw_idx_t"])
            data = pd.concat([data, tmp.loc[:, ["iw_u", "iw_v", "iw_speed"]]],
                             axis=1)
        if "ic0_145" in get_columns:
            tmp = calc_data.get_1day_ic0_data(ic0_file_name,
                                              grid900to145_file_name)
            ic0_idx_t = np.array(tmp["ic0_idx_t"])
            data = pd.concat([data, tmp.loc[:, ["ic0_145"]]], axis=1)
        if "coeff" in get_columns:
            tmp = calc_data.get_1month_coeff_data(coeff_file_name)
            data = pd.concat([data, tmp], axis=1)
        if "w10m" in get_columns:
            tmp = calc_data.get_1day_w10m_data(wind10m_file_name)
            data = pd.concat([data, tmp], axis=1)
        if "t2m" in get_columns:
            tmp = calc_data.get_1day_t2m_data(t2m_file_name)
            data = pd.concat([data, tmp], axis=1)

        mat = iw_idx_t.ravel().tolist() + ic0_idx_t.ravel().tolist()
        data_t_idx = calc_data.get_non_nan_idx(mat, ocean_idx, strict=True)
        data.loc[data.data_idx, data_t_idx] = 1
        data = calc_data.get_masked_region_data(data, region)

        if ("coeff" in get_columns) and (len(get_columns) == 1):
            print("\tSelected only coeff data. Getting out of the loop...")
            continue

        if accumulate == True:
            data = data.loc[:, get_columns]
            print("\t{}".format(data.columns))
            accumulate_data.append(np.array(data))

    if accumulate == True:
        print("accumulate: True\tdata type: array")
        return date_ax, date_ax_str, skipping_date_str, accumulate_data
    else:
        print("accumulate: False\tdata type: DataFrame")
        return date_ax, date_ax_str, skipping_date_str, data