Example #1
0
 def __get_dim_var_variables(self):
     '''
     :return dimension's variables and feature's variables
     :return:
     '''
     dim_variables = OrderedDict()
     var_variables = OrderedDict()
     for v_name in self.variables.keys():
         if v_name in self.dimensions.keys():
             dim_variables[v_name] = self.variables[v_name]
         else:
             var_variables[v_name] = self.variables[v_name]
     return dim_variables, var_variables
def main():

    """
    Prepare sand clay and depth to bedrock in netcdf for MH
    """


    gconfig_to_infile = OrderedDict([
        # (default_domains.bc_mh_011, "/RESCUE/skynet3_rech1/huziy/directions_for_ManitobaHydro/20170320/rpn/geophys_CORDEX_NA_0.11deg_695x680_filled_grDes_barBor_Crop2Gras_peat"),
        # (default_domains.bc_mh_022, "/RESCUE/skynet3_rech1/huziy/directions_for_ManitobaHydro/20170320/rpn/geophys_CORDEX_NA_0.22deg_filled_grDes_barBor_Crop2Gras_peat"),
        (default_domains.bc_mh_044, "/RESCUE/skynet3_rech1/huziy/directions_for_ManitobaHydro/20170320/rpn/geophys_CORDEX_NA_0.44d_filled_grDes_barBor_Crop2Gras_peat"),
    ])


    # gconfig_to_infile = {
    #     default_domains.bc_mh_011: "/HOME/data/Simulations/CRCM5/North_America/NorthAmerica_0.11deg_ERA40-Int0.75_B1/Samples/NorthAmerica_0.11deg_ERA40-Int0.75_B1_195801/pm1958010100_00000000p",
    #     default_domains.bc_mh_022: "/HOME/data/Simulations/CRCM5/North_America/NorthAmerica_0.22deg_ERA40-Int0.75_B1/Samples/NorthAmerica_0.22deg_ERA40-Int0.75_B1_195801/pm1958010100_00000000p",
    #     default_domains.bc_mh_044: "/HOME/data/Simulations/CRCM5/North_America/NorthAmerica_0.44deg_ERA40-Int0.75_B1/Samples/NorthAmerica_0.44deg_ERA40-Int0.75_B1_195801/pm1958010100_00000000p",
    # }

    gconfig_to_dirfile = {
        # default_domains.bc_mh_011: "/HOME/huziy/skynet3_rech1/directions_for_ManitobaHydro/20170310/netcdf/directions_bc-mh_0.11deg_new_hsfix.nc",
        # default_domains.bc_mh_022: "/HOME/huziy/skynet3_rech1/directions_for_ManitobaHydro/20170310/netcdf/directions_bc-mh_0.22deg_new_hsfix.nc",
        default_domains.bc_mh_044: "/HOME/huziy/skynet3_rech1/directions_for_ManitobaHydro/20170310/netcdf/directions_bc-mh_0.44deg_new_hsfix.nc",

    }


    out_dir = Path("mh/sand_clay_dpth_fields_levels")
    if not out_dir.is_dir():
        out_dir.mkdir(parents=True)


    # selection criteria
    selection = {
        "SAND": 1,
        "CLAY": 1,
        "DPTH": None
    }


    # ----
    print(gconfig_to_infile)
    print(gconfig_to_dirfile)


    for gc, rpn_path in gconfig_to_infile.items():
        select_data_to_nc(gc, in_rpn_path=rpn_path, in_directions_path=gconfig_to_dirfile[gc], selection=selection, out_dir=out_dir, levels=list(range(26)))
Example #3
0
    def __get_variables(self):
        '''
        get variables,OrderedDict
        :return:
        '''
        group_variables = OrderedDict()
        if len(self.groups) == 0:  # 不包含group信息,只包含variables和groups
            group_variables = self.dataset.variables

        else:
            for group in self.groups.keys():
                variables = OrderedDict()
                for variable in self.groups[group].variables:
                    variables[variable] = self.groups[group].variables[variable]

                group_variables[group] = variables

        return group_variables
Example #4
0
    def __get_dimensions(self):
        '''
        get dimensions,OrderedDict
        :return:
        '''
        group_dimensions = OrderedDict()
        if len(self.groups) == 0:  # 不包含group信息,只包含variables和groups
            group_dimensions = self.dataset.dimensions

        else:
            for group in self.groups.keys():
                dimensions = OrderedDict()
                for dimension in self.groups[group].dimensions:
                    dimensions[dimension] = self.groups[group].dimensions[dimension]

                group_dimensions[group] = dimensions

        return group_dimensions
Example #5
0
    def __get_hdf_variable_data_by_name(self, groupname):
        '''
        get variable data array by name,return OrderedDict
        :param name:
        :return:
        '''
        data_array_dict = OrderedDict()
        for variable_name in self.groups[groupname].variables.keys():
            variable = self.get_variable_by_group_variable(groupname, variable_name)

            data_array_dict[variable_name] = variable[::]

        return data_array_dict
Example #6
0
    def get_hdf_variables_data(self):
        '''
        return hdf all variables data array,return by OrderedDict
        OrderedDict key:group  name,value:variable data
        :return:
        '''
        variables_data_dict = OrderedDict()
        if not self.contains_group:
            for variable_name in self.variables:
                variables_data_dict[variable_name] = self.__get_hdf_variable_data_by_v_name(variable_name)

        for g_name in self.groups.keys():
            data_array_dict = self.__get_hdf_variable_data_by_name(g_name)
            variables_data_dict[g_name] = data_array_dict
        return variables_data_dict
Example #7
0
    def __get_variable_data_by_name(self, name):
        '''
        get variable data array by name,return OrderedDict
        :param name:
        :return:
        '''
        variable = self.get_variable_by_name(name)
        t_variable = self.get_nc_variables_t_by_attributes()
        data_array_dict = OrderedDict()
        if t_variable == None:
            # not have time  variable
            # print "not have time variable"
            data_array_dict["None"] = variable[::]
        else:
            i = 0

            for time in num2date(t_variable[::], t_variable.units):
                now_time_data = variable[i:i + 1:]
                data_array_dict[time] = now_time_data

                i += 1

        return data_array_dict
Example #8
0
def main():

    lon0, lat0 = -114.0708, 51.0486

    surf_gz_path = "/RESCUE/skynet3_rech1/huziy/hail/erainterim_0.75d/surface_geopotential.nc"
    gz_fields_path = "/HOME/data/Driving_data/Pilots/ERA-Interim_0.75/Pilots/era-interim_0.75d_198004"

    # --
    with Dataset(surf_gz_path) as ds:
        lons, lats = ds.variables["longitude"][:], ds.variables["latitude"][:]
        lats, lons = np.meshgrid(lats, lons)

        surface_elev = get_closest_value_for_point(
            lon0, lat0, lons, lats, ds.variables["z"][:].squeeze().T) / g_const

    # --
    with RPN(gz_fields_path) as r:
        assert isinstance(r, RPN)
        gz_data = r.get_4d_field("GZ", level_kind=level_kinds.PRESSURE)

        lons_r, lats_r = r.get_longitudes_and_latitudes_for_the_last_read_rec()

        dates = sorted(gz_data)

        lev_to_field = gz_data[dates[0]]

        levels = sorted(lev_to_field)

        pelevs = [
            get_closest_value_for_point(lon0, lat0, lons_r, lats_r,
                                        lev_to_field[lev]) * 10
            for lev in levels
        ]

    print(OrderedDict(list(zip(levels, pelevs))))
    print("surf elev = {}".format(surface_elev))
Example #9
0
def main():
    # nemo_manager = NemoYearlyFilesManager(folder="/home/huziy/skynet3_rech1/offline_glk_output_daily_1979-2012",
    # suffix="icemod.nc")
    # exp_label = "default-offline"

    nemo_manager = NemoYearlyFilesManager(
        folder="/home/huziy/skynet3_rech1/output_NEMO_offline_1979-2012_nosnow",
        suffix="icemod.nc")
    exp_label = "offline-nosnow"

    # Study period
    start_year = 2003
    end_year = 2006

    season_to_months = OrderedDict([("Winter", (12, 1, 2)),
                                    ("Spring", list(range(3, 6))),
                                    ("Summer", list(range(6, 9))),
                                    ("Fall", list(range(9, 12)))])

    nemo_manager.plot_comparisons_of_seasonal_sst_with_homa_obs(
        start_year=start_year,
        end_year=end_year,
        season_to_months=season_to_months,
        exp_label=exp_label)
Example #10
0
lake_to_folder_with_sim_data_1981_2000_seplakes_exp = {
    "Superior": "/skynet3_rech1/huziy/NEMO_OFFICIAL/Simulations/1981-2000_Sim_per_lake_100yr_spinup_LIM3/Superior",
    "Michigan": "/skynet3_rech1/huziy/NEMO_OFFICIAL/Simulations/1981-2000_Sim_per_lake_100yr_spinup_LIM3/Michigan",
    "Erie": "/skynet3_rech1/huziy/NEMO_OFFICIAL/Simulations/1981-2000_Sim_per_lake_100yr_spinup_LIM3/Erie",
    "Ontario": "/skynet3_rech1/huziy/NEMO_OFFICIAL/Simulations/1981-2000_Sim_per_lake_100yr_spinup_LIM3/Ontario",
    "Huron": "/skynet3_rech1/huziy/NEMO_OFFICIAL/Simulations/1981-2000_Sim_per_lake_100yr_spinup_LIM3/Huron"


}



season_to_months_default = OrderedDict([
    ("Winter", [12, 1, 2]),
    ("Spring", [3,  4, 5]),
    ("Summer", [6,  7, 8]),
    ("Fall",   [9, 10, 11]),
])





def get_clevs_and_cmap_for_name(name=""):
    clevs = varname_to_colorlevels.get(name, [])
    cmap = varname_to_cmapname.get(name, None)

    if cmap is not None:
        return clevs, cm.get_cmap(cmap, len(clevs) - 1)
    return None, None
Example #11
0
 def __get_variables_data(self):
     variables_data_dict = OrderedDict()
     for v_name in self.variables.keys():
         data_array_dict = self.__get_variable_data_by_name(v_name)
         variables_data_dict[v_name] = data_array_dict
     return variables_data_dict