def w_1(): wind_files = sorted(glob.glob("../data/csv_iw/*.csv")) lon = latlon_ex.Lon lat = latlon_ex.Lat lon = np.array(lon) lat = np.array(lat) dirs = "../result/test_ice_wind/" try: os.makedirs(dirs) except: print('directory {} already exists'.format(dirs)) for item in wind_files: data = calc_data.get_1day_iw_data(item) save_name = dirs + item[15:21] + ".png" print(save_name) visualize.plot_map_once( data.loc[:, ["iw_u", "iw_v"]], data_type="type_wind", show=False, save_name=save_name, vmax=None, vmin=None, cmap=None)
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_w_iw_by_year(): dirs_1 = "../result_h/test/w_iw_by_year/" dirs_2 = "../result_h/test/w_iw_by_year_without_ocean/" if not os.path.exists(dirs_1): os.makedirs(dirs_1) if not os.path.exists(dirs_2): os.makedirs(dirs_2) y_list = [ "03", "04", "05", "06", "07", "08", "09", "10", "13", "14", "15", "16" ] month_list = [ "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12" ] for month in month_list: print("************" + month + "************") helmert_30_30_fname = "../data/csv_Helmert_both_30/Helmert_both_30_2003" + month + ".csv" data_30 = pd.read_csv(helmert_30_30_fname) #area_16_index = np.array(data_30.loc[data_30.area_label==16, :].index) area_16_index = np.array(data_30[(data_30.area_label.isin( list(range(17))))].dropna().index).tolist() plot_grids = random.sample(area_16_index, 15) print(plot_grids) gw_list = [] iw_list = [] iw_ocean_list = [] for year in y_list: helmert_file_name = "../data/csv_Helmert_both_30/Helmert_both_30_20" + year + month + ".csv" gw_file_name = "../data/csv_w/ecm" + year + month + "15.csv" iw_file_name = "../data/csv_iw/" + year + month + "15.csv" helmert_data = calc_data.get_1month_helmert_data(helmert_file_name) gw_data = calc_data.get_1day_w_data(gw_file_name) iw_data = calc_data.get_1day_iw_data(iw_file_name) gw_speed = np.array(gw_data.loc[plot_grids, "w_speed"]) iw_speed = np.array(iw_data.loc[plot_grids, "iw_speed"]) iw_ocean_u = np.array(iw_data.loc[plot_grids, "iw_u"] - helmert_data.loc[plot_grids, "ocean_u"]) iw_ocean_v = np.array(iw_data.loc[plot_grids, "iw_v"] - helmert_data.loc[plot_grids, "ocean_v"]) iw_speed_ocean = np.sqrt(iw_ocean_u**2 + iw_ocean_v**2) gw_list.append(gw_speed) iw_list.append(iw_speed) iw_ocean_list.append(iw_speed_ocean) gw_array = np.array(gw_list) iw_array = np.array(iw_list) iw_ocean_array = np.array(iw_ocean_list) for i in range(len(plot_grids)): gw = gw_array[:, i] iw = iw_array[:, i] iw_ocean = iw_ocean_array[:, i] save_name_1 = dirs_1 + month + "15_grid_" + str( plot_grids[i]) + ".png" save_name_2 = dirs_2 + month + "15_grid_" + str( plot_grids[i]) + ".png" try: sns.set_style("darkgrid") sns.jointplot(x=gw, y=iw, kind="reg") plt.savefig(save_name_1) plt.close() sns.set_style("darkgrid") sns.jointplot(x=gw, y=iw_ocean, kind="reg") plt.savefig(save_name_2) plt.close() except: continue