Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix type errors in calc_rectilinear_lon_edge and calc_rectilinear_lat_edge in grid.py #347

Merged
merged 1 commit into from
Jan 9, 2025
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
56 changes: 22 additions & 34 deletions gcpy/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand All @@ -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
Expand All @@ -1000,31 +998,26 @@ 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:
start_pt = 90.0 + (lat_stride / 2.0)
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
Expand All @@ -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
Expand Down
Loading