def load_map_info(self, map_file): """ Load map projection information and create latitude, longitude, x, y, i, and j grids for the projection. Args: map_file: File specifying the projection information. """ if self.ensemble_name.upper() == "SSEF": proj_dict, grid_dict = read_arps_map_file(map_file) self.dx = int(grid_dict["dx"]) mapping_data = make_proj_grids(proj_dict, grid_dict) for m, v in mapping_data.items(): setattr(self, m, v) self.i, self.j = np.indices(self.lon.shape) self.proj = get_proj_obj(proj_dict) elif self.ensemble_name.upper() in [ "NCAR", "NCARSTORM", "HRRR", "VSE", "HREFV2" ]: proj_dict, grid_dict = read_ncar_map_file(map_file) if self.member_name[ 0: 7] == "1km_pbl": # Don't just look at the first 3 characters. You have to differentiate '1km_pbl1' and '1km_on_3km_pbl1' grid_dict["dx"] = 1000 grid_dict["dy"] = 1000 grid_dict["sw_lon"] = 258.697 grid_dict["sw_lat"] = 23.999 grid_dict["ne_lon"] = 282.868269206236 grid_dict["ne_lat"] = 36.4822338520542 self.dx = int(grid_dict["dx"]) mapping_data = make_proj_grids(proj_dict, grid_dict) for m, v in mapping_data.items(): setattr(self, m, v) self.i, self.j = np.indices(self.lon.shape) self.proj = get_proj_obj(proj_dict)
def __init__(self, ensemble_name, model_name, member, run_date, variable, start_date, end_date, path, single_step, size_distribution_training_path, watershed_obj, map_file=None, condition_model_name=None, condition_threshold=0.5): self.ensemble_name = ensemble_name self.model_name = model_name self.member = member self.run_date = run_date self.variable = variable self.start_date = start_date self.end_date = end_date self.times = pd.DatetimeIndex(start=self.start_date, end=self.end_date, freq="1H") self.forecast_hours = (self.times - self.run_date).astype('timedelta64[h]').values self.path = path self.single_step = single_step self.size_distribution_training_path = size_distribution_training_path self.watershed_obj = watershed_obj self.track_forecasts = None self.data = None self.map_file = map_file self.proj_dict = None self.grid_dict = None self.mapping_data = None self.condition_model_name = condition_model_name self.condition_threshold = condition_threshold self.percentiles = None self.num_samples = None self.percentile_data = None if self.map_file is not None: if self.map_file[-3:] == "map": self.proj_dict, self.grid_dict = read_arps_map_file(self.map_file) else: self.proj_dict, self.grid_dict = read_ncar_map_file(self.map_file) self.mapping_data = make_proj_grids(self.proj_dict, self.grid_dict) self.units = "" self.nc_patches = None self.hail_forecast_table = None
def create_map_grid(map_file): if map_file[-3:] == "map": proj_dict, grid_dict = read_arps_map_file(map_file) else: proj_dict, grid_dict = read_ncar_map_file(map_file) mapping_data = make_proj_grids(proj_dict, grid_dict) return mapping_data, proj_dict, grid_dict
def __init__(self, ml_model_name, members, run_date, variable, start_date, end_date, grid_shape, forecast_bins, forecast_json_path, condition_model_name=None, map_file=None): self.track_forecasts = {} self.grid_shape = grid_shape self.forecast_bins = forecast_bins self.condition_model_name = condition_model_name self.percentile = None if map_file is not None: if map_file[-3:] == "map": self.proj_dict, self.grid_dict = read_arps_map_file(map_file) else: self.proj_dict, self.grid_dict = read_ncar_map_file(map_file) else: self.proj_dict = None self.grid_dict = None super(MachineLearningEnsembleProducts, self).__init__(ml_model_name, members, run_date, variable, start_date, end_date, forecast_json_path, single_step=False)
def interpolate_mrms_day(start_date, variable, interp_type, mrms_path, map_filename, out_path): """ For a given day, this module interpolates hourly MRMS data to a specified latitude and longitude grid, and saves the interpolated grids to CF-compliant netCDF4 files. Args: start_date (datetime.datetime): Date of data being interpolated variable (str): MRMS variable interp_type (str): Whether to use maximum neighbor or spline mrms_path (str): Path to top-level directory of MRMS GRIB2 files map_filename (str): Name of the map filename. Supports ARPS map file format and netCDF files containing latitude and longitude variables out_path (str): Path to location where interpolated netCDF4 files are saved. """ try: print(start_date, variable) end_date = start_date + timedelta(hours=23) mrms = MRMSGrid(start_date, end_date, variable, mrms_path) if mrms.data is not None: if map_filename[-3:] == "map": mapping_data = make_proj_grids(*read_arps_map_file(map_filename)) mrms.interpolate_to_netcdf(mapping_data['lon'], mapping_data['lat'], out_path, interp_type=interp_type) elif map_filename[-3:] == "txt": mapping_data = make_proj_grids(*read_ncar_map_file(map_filename)) mrms.interpolate_to_netcdf(mapping_data["lon"], mapping_data["lat"], out_path, interp_type=interp_type) else: lon, lat = load_map_coordinates(map_filename) mrms.interpolate_to_netcdf(lon, lat, out_path, interp_type=interp_type) except Exception as e: # This exception catches any errors when run in multiprocessing, prints the stack trace, # and ends the process. Otherwise the process will stall. print(traceback.format_exc()) raise e
def create_map_grid(map_file): if map_file[-3:] == "map": proj_dict, grid_dict = read_arps_map_file(map_file) else: proj_dict, grid_dict = read_ncar_map_file(map_file) mapping_data = make_proj_grids(proj_dict, grid_dict) return mapping_data, proj_dict, grid_dict
def load_map_info(self, map_file): if self.ensemble_name.upper() == "SSEF": proj_dict, grid_dict = read_arps_map_file(map_file) self.dx = int(grid_dict["dx"]) mapping_data = make_proj_grids(proj_dict, grid_dict) for m, v in mapping_data.iteritems(): setattr(self, m, v) self.i, self.j = np.indices(self.lon.shape) self.proj = get_proj_obj(proj_dict) elif self.ensemble_name.upper() == "NCAR": proj_dict, grid_dict = read_ncar_map_file(map_file) self.dx = int(grid_dict["dx"]) mapping_data = make_proj_grids(proj_dict, grid_dict) for m, v in mapping_data.iteritems(): setattr(self, m, v) self.i, self.j = np.indices(self.lon.shape) self.proj = get_proj_obj(proj_dict)
def interpolate_mrms_day(start_date, variable, interp_type, mrms_path, map_filename, out_path): """ For a given day, this module interpolates hourly MRMS data to a specified latitude and longitude grid, and saves the interpolated grids to CF-compliant netCDF4 files. Args: start_date (datetime.datetime): Date of data being interpolated variable (str): MRMS variable interp_type (str): Whether to use maximum neighbor or spline mrms_path (str): Path to top-level directory of MRMS GRIB2 files map_filename (str): Name of the map filename. Supports ARPS map file format and netCDF files containing latitude and longitude variables out_path (str): Path to location where interpolated netCDF4 files are saved. """ try: print(start_date, variable) end_date = start_date + timedelta(hours=23) mrms = MRMSGrid(start_date, end_date, variable, mrms_path) if mrms.data is not None: if map_filename[-3:] == "map": mapping_data = make_proj_grids( *read_arps_map_file(map_filename)) mrms.interpolate_to_netcdf(mapping_data['lon'], mapping_data['lat'], out_path, interp_type=interp_type) elif map_filename[-3:] == "txt": mapping_data = make_proj_grids( *read_ncar_map_file(map_filename)) mrms.interpolate_to_netcdf(mapping_data["lon"], mapping_data["lat"], out_path, interp_type=interp_type) else: lon, lat = load_map_coordinates(map_filename) mrms.interpolate_to_netcdf(lon, lat, out_path, interp_type=interp_type) except Exception as e: # This exception catches any errors when run in multiprocessing, prints the stack trace, # and ends the process. Otherwise the process will stall. print(traceback.format_exc()) raise e
def __init__(self, ml_model_name, members, run_date, variable, start_date, end_date, grid_shape, forecast_bins, forecast_json_path, condition_model_name=None, map_file=None): self.track_forecasts = {} self.grid_shape = grid_shape self.forecast_bins = forecast_bins self.condition_model_name = condition_model_name self.percentile = None if map_file is not None: if map_file[-3:] == "map": self.proj_dict, self.grid_dict = read_arps_map_file(map_file) else: self.proj_dict, self.grid_dict = read_ncar_map_file(map_file) else: self.proj_dict = None self.grid_dict = None super(MachineLearningEnsembleProducts, self).__init__(ml_model_name, members, run_date, variable, start_date, end_date, forecast_json_path, single_step=False)
def load_map_info(self, map_file): """ Load map projection information and create latitude, longitude, x, y, i, and j grids for the projection. Args: map_file: File specifying the projection information. """ if self.ensemble_name.upper() == "SSEF": proj_dict, grid_dict = read_arps_map_file(map_file) self.dx = int(grid_dict["dx"]) mapping_data = make_proj_grids(proj_dict, grid_dict) for m, v in mapping_data.items(): setattr(self, m, v) self.i, self.j = np.indices(self.lon.shape) self.proj = get_proj_obj(proj_dict) elif self.ensemble_name.upper() == "NCAR": proj_dict, grid_dict = read_ncar_map_file(map_file) self.dx = int(grid_dict["dx"]) mapping_data = make_proj_grids(proj_dict, grid_dict) for m, v in mapping_data.items(): setattr(self, m, v) self.i, self.j = np.indices(self.lon.shape) self.proj = get_proj_obj(proj_dict)