Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion unseen/fileio.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ def open_dataset(
metadata_file=None,
variables=[],
regrid_name=None,
regrid_lat_offset=0.0,
regrid_lon_offset=0.0,
regrid_method="conservative",
point_selection=None,
lat_bnds=None,
Expand Down Expand Up @@ -78,6 +80,10 @@ def open_dataset(
Name of grid for sptial regridding in AUSXXXi format.
e.g. AUS005i is a 0.05 x 0.05 lat/lon grid
e.g. AUS300i is a 3.00 x 3.00 lat/lon grid
regrid_lat_offset : float, optional
Add latitude offset to named grid latitude axis
regrid_lon_offset : float, optional
Add longitude offset to named grid longitude axis
regrid_method : {"conservative", "bilinear", "nearest_s2d", "nearest_d2s"}, default "conservative"
Name of grid for sptial regridding in AUSXXXi format.
point_selection : list, optional
Expand Down Expand Up @@ -192,7 +198,9 @@ def open_dataset(

# Spatial regridding
if regrid_name:
new_grid = general_utils.create_grid(regrid_name)
new_grid = general_utils.create_grid(
regrid_name, lat_offset=regrid_lat_offset, lon_offset=regrid_lon_offset
)
ds = general_utils.regrid(ds, new_grid, method=regrid_method)

# Spatial subsetting and aggregation
Expand Down Expand Up @@ -728,6 +736,18 @@ def _parse_command_line():
default=None,
help="Name of grid for sptial regridding in AUSXXXi format",
)
parser.add_argument(
"--regrid_lat_offset",
type=float,
default=0.0,
help="Latitude offset to add to named grid latitude axis",
)
parser.add_argument(
"--regrid_lon_offset",
type=float,
default=0.0,
help="Longitude offset to add to named grid longitude axis",
)
parser.add_argument(
"--regrid_method",
type=str,
Expand Down Expand Up @@ -882,6 +902,8 @@ def _main():
"metadata_file": args.metadata_file,
"variables": args.variables,
"regrid_name": args.regrid_name,
"regrid_lat_offset": args.regrid_lat_offset,
"regrid_lon_offset": args.regrid_lon_offset,
"regrid_method": args.regrid_method,
"point_selection": args.point_selection,
"lat_bnds": args.lat_bnds,
Expand Down
38 changes: 19 additions & 19 deletions unseen/general_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,17 @@ def convert_units(da, target_units):
return da


def create_grid(grid_name):
def create_grid(grid_name, lat_offset=0.0, lon_offset=0.0):
"""Create a regular lat/lon grid.

Parameters
----------
grid_name : str
Name of the grid.
lat_offset : float, optional
Add latitude offset to named grid latitude axis
lon_offset : float, optional
Add longitude offset to named grid longitude axis

Returns
-------
Expand All @@ -92,7 +96,7 @@ def create_grid(grid_name):

Notes
-----
The only valid grids are in the AUSXXi format. e.g:
The only valid grids are in the AUSXXXi format. e.g:
- AUS005i is a 0.05 x 0.05 grid across Australia.
- AUS050i is a 0.50 x 0.50 grid across Australia.
- AUS300i is a 3.00 x 3.00 grid across Australia.
Expand All @@ -101,27 +105,23 @@ def create_grid(grid_name):
assert len(grid_name) == 7, "grid_name must be AUSXXXi format"
assert grid_name[0:3] == "AUS", "AUSXXXi grids only"
# AGCD bounds
south_lat = -44.5
north_lat = -10
west_lon = 112
east_lon = 156.25
agcd_south_limit = -44.5
agcd_north_limit = -10
agcd_west_limit = 112
agcd_east_limit = 156.25

step_start = grid_name[3]
step_end = grid_name[4:6]
step = float(f"{step_start}.{step_end}")

ds_grid = xr.Dataset(
{
"lat": (
["lat"],
np.round(np.arange(south_lat, north_lat + step, step), decimals=2),
),
"lon": (
["lon"],
np.round(np.arange(west_lon, east_lon + step, step), decimals=2),
),
}
)
offset = step / 2.0
south_lat = agcd_south_limit + offset
north_lat = agcd_north_limit - offset
west_lon = agcd_west_limit + offset
east_lon = agcd_east_limit - offset

lats = np.round(np.arange(south_lat, north_lat, step), decimals=2) + lat_offset
lons = np.round(np.arange(west_lon, east_lon, step), decimals=2) + lon_offset
ds_grid = xr.Dataset({"lat": (["lat"], lats), "lon": (["lon"], lons)})
ds_grid["lat"].attrs = {
"standard_name": "latitude",
"long_name": "latitude",
Expand Down
6 changes: 3 additions & 3 deletions unseen/moments.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ def calc_moments(sample_da, **kwargs):
moments["skew"] = float(scipy.stats.skew(sample_da))
moments["kurtosis"] = float(scipy.stats.kurtosis(sample_da))
gev_shape, gev_loc, gev_scale = eva.fit_gev(sample_da, **kwargs)
moments["GEV shape"] = gev_shape
moments["GEV location"] = gev_loc
moments["GEV scale"] = gev_scale
moments["GEV shape"] = float(gev_shape)
moments["GEV location"] = float(gev_loc)
moments["GEV scale"] = float(gev_scale)

return moments

Expand Down
Loading