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.
- 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.geographical_distances(point_longitude: float, point_latitude: float, lon_vectors: numpy.ndarray, lat_vectors: numpy.ndarray, radius=6373.0) numpy.ndarray
It uses Spherical Earth projected to a plane formula: https://en.wikipedia.org/wiki/Geographical_distance
- Parameters
point_longitude – longitude in degrees of target coordinate
point_latitude – latitude in degrees of target coordinate
lon_vectors – 1d array of longitudes in degrees
lat_vectors – 1d array of latitudes in degrees
radius – Radius of a sphere in km. Default is Earths approximate radius.
- Returns
array of geographical distance of point to all vector members
- Return type
distances
- ewatercycle.util.get_time(time_iso: str) 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.fit_extents_to_grid(extents, step=0.1, offset=0.05, ndigits=2) Dict[str, float]
Get lat/lon extents fitted to a grid.
- Parameters
extents – Dict with start_longitude, start_latitude, end_longitude, end_latitude
step – Distance between to grid cells
offset – Offset to pad with after rounding extent to step.
ndigits – Number of digits to return
- 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[Path] = None, must_exist: bool = False, must_be_in_parent=True) 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.
- ewatercycle.util.reindex(source_file: str, var_name: str, mask_file: str, target_file: str)
Conform the input file onto the indexes of a mask file, writing the results to the target file.
- Parameters
source_file – Input string path of the file that needs to be reindexed.
var_name – Variable name in the source_file dataset.
mask_file – Input string path of the mask file.
target_file – Output string path of the
reindexed. (file that is) –