ewatercycle.util module¶
- ewatercycle.util.find_closest_point(grid_longitudes: Iterable[float], grid_latitudes: Iterable[float], point_longitude: float, point_latitude: float) Tuple[int, int] ¶
Find closest grid cell to a point based on Geographical distances.
It uses Spherical Earth projected to a plane formula: https://en.wikipedia.org/wiki/Geographical_distance
- Parameters
grid_longitudes – 1d array of model grid longitudes in degrees
grid_latitudes – 1d array of model grid latitudes in degrees
point_longitude – longitude in degrees of target coordinate
point_latitude – latitude in degrees of target coordinate
- Returns
index of closest grid point in the original longitude array idx_lat: index of closest grid point in the original latitude array
- Return type
idx_lon
- ewatercycle.util.get_time(time_iso: str) datetime.datetime ¶
Return a datetime in UTC.
Convert a date string in ISO format to a datetime and check if it is in UTC.
- ewatercycle.util.get_extents(shapefile: Any, pad=0) Dict[str, float] ¶
Get lat/lon extents from shapefile and add padding.
- Parameters
shapefile – Path to shapfile
pad – Optional padding
- Returns
Dict with start_longitude, start_latitude, end_longitude, end_latitude
- ewatercycle.util.data_files_from_recipe_output(recipe_output: esmvalcore.experimental.recipe_output.RecipeOutput) Tuple[str, Dict[str, str]] ¶
Get data files from a ESMVaLTool recipe output
Expects first diagnostic task to produce files with single var each.
- Parameters
recipe_output – ESMVaLTool recipe output
- Returns
Tuple with directory of files and a dict where key is cmor short name and value is relative path to NetCDF file
- ewatercycle.util.to_absolute_path(input_path: str, parent: Optional[pathlib.Path] = None, must_exist: bool = False, must_be_in_parent=True) pathlib.Path ¶
Parse input string as
pathlib.Path
object.- Parameters
input_path – Input string path that can be a relative or absolute path.
parent – Optional parent path of the input path
must_exist – Optional argument to check if the input path exists.
must_be_in_parent – Optional argument to check if the input path is subpath of parent path
- Returns
The input path that is an absolute path and a
pathlib.Path
object.