From faec74558c5510b62597b4e3913ce1868821615a Mon Sep 17 00:00:00 2001 From: Bob Yantosca Date: Wed, 8 Jan 2025 11:23:03 -0500 Subject: [PATCH] Fixed type errors in calc_rectilinear_{lon,lat}_edge routines gcpy/grid.py - In routine calc_rectilinear_lon_edge: - Renamed n_lon to n_lon_edge - Cast n_lon_edge from float to int (for input to np.linspace) - Updated pydoc comments - In routine calc_rectilinear_lat_edge: - Added n_lat_edge variable to hold the length of the output vector - Cast n_lat_edge from float to int (for input to np.linspace) - Updated pydoc comments - In routine calc_rectilinear_grid_area: - Updated pydoc comments Signed-off-by: Bob Yantosca --- CHANGELOG.md | 1 + gcpy/grid.py | 56 +++++++++++++++++++++------------------------------- 2 files changed, 23 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f4c9f0..ff27ea9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - Now flag differences greater than +/- 10% in benchmark timing table outputs - Fixed error in computation of dynamic ratio plot min & max values in `plot/six_plot.py` - Fixed erroneous species classification in `gcpy/benchmark/modules/benchmark_categories.yml` +- Fixed type errors in `calc_rectilinear_lon_edge` and `calc_rectangular_lat_edge` by casting the length of the output array from `float` to `int` ### Removed - Removed `gcpy/benchmark/modules/species_database.yml` file and corresponding code pointing to this diff --git a/gcpy/grid.py b/gcpy/grid.py index 20e0269..b5cbeae 100644 --- a/gcpy/grid.py +++ b/gcpy/grid.py @@ -949,7 +949,9 @@ def make_grid_SG(csres, stretch_factor, target_lon, target_lat): def calc_rectilinear_lon_edge(lon_stride, center_at_180): - """ Compute longitude edge vector for a rectilinear grid. + """ + Compute longitude edge vector for a rectilinear grid. + Parameters ---------- lon_stride: float @@ -959,26 +961,20 @@ def calc_rectilinear_lon_edge(lon_stride, center_at_180): Whether or not the grid should have a cell center at 180 degrees (i.e. on the date line). If true, the first grid cell is centered on the date line; if false, the first grid edge is on the date line. + Returns ------- Longitudes of cell edges in degrees East. + Notes ----- All values are forced to be between [-180,180]. For a grid with N cells in each band, N+1 edges will be returned, with the first and last value being duplicates. - Examples - -------- - >>> from gcpy.grid.horiz import calc_rectilinear_lon_edge - >>> calc_rectilinear_lon_edge(5.0,true) - np.array([177.5,-177.5,-172.5,...,177.5]) - See Also - -------- - [NONE] """ - n_lon = np.round(360.0 / lon_stride) - lon_edge = np.linspace(-180.0, 180.0, num=n_lon + 1) + n_lon_edge = int(np.round(360.0 / lon_stride)) + 1 + lon_edge = np.linspace(-180.0, 180.0, num=n_lon_edge) if center_at_180: lon_edge = lon_edge - (lon_stride / 2.0) @@ -989,7 +985,9 @@ def calc_rectilinear_lon_edge(lon_stride, center_at_180): def calc_rectilinear_lat_edge(lat_stride, half_polar_grid): - """ Compute latitude edge vector for a rectilinear grid. + """ + Compute latitude edge vector for a rectilinear grid. + Parameters ---------- lat_stride: float @@ -1000,22 +998,16 @@ def calc_rectilinear_lat_edge(lat_stride, half_polar_grid): half the size). In either case the grid will start and end at -/+ 90, but when half_polar_grid is True, the first and last bands will have a width of 1/2 the normal lat_stride. + Returns ------- Latitudes of cell edges in degrees North. + Notes ----- All values are forced to be between [-90,90]. For a grid with N cells in each band, N+1 edges will be returned, with the first and last value being duplicates. - Examples - -------- - >>> from gcpy.grid.horiz import calc_rectilinear_lat_edge - >>> calc_rectilinear_lat_edge(4.0,true) - np.array([-90,-88,-84,-80,...,84,88,90]) - See Also - -------- - [NONE] """ if half_polar_grid: @@ -1023,8 +1015,9 @@ def calc_rectilinear_lat_edge(lat_stride, half_polar_grid): else: start_pt = 90.0 - lat_edge = np.linspace(-1.0 * start_pt, start_pt, - num=1 + np.round(2.0 * start_pt / lat_stride)) + n_lat_edge = int(np.round(2.0 * start_pt / lat_stride)) + 1 + + lat_edge = np.linspace(-1.0 * start_pt, start_pt, num=n_lat_edge) # Force back onto +/- 90 lat_edge[lat_edge > 90.0] = 90.0 @@ -1034,22 +1027,17 @@ def calc_rectilinear_lat_edge(lat_stride, half_polar_grid): def calc_rectilinear_grid_area(lon_edge, lat_edge): - """ Compute grid cell areas (in m2) for a rectilinear grid. + """ + Compute grid cell areas (in m2) for a rectilinear grid. + Parameters ---------- - #TODO + lon_edge : float : Grid box longitude edges (in degrees north) + lat_edge : float : Grid box latitude edges (in degrees east) + Returns ------- - #TODO - Notes - ----- - #TODO - Examples - -------- - #TODO - See Also - -------- - [NONE] + area : float : Array of grid box areas in m2. """ # Convert from km to m