Commit 809d1080 authored by Eva Börgens's avatar Eva Börgens
Browse files

Add corner case in function get_grid_area

parent c1217ed4
......@@ -24,7 +24,7 @@ Please clone this repository and install the [environment and the dependencies](
## Usage:
sh tws_covariances.sh [-h] -f FILENAME -r REGION -o OUTPUT [-m] [-u] [-t]
sh tws_covariances.sh [-h] -f FILENAME -r REGION -o OUTPUT [-m] [-u] [-t]
arguments:
......
......@@ -30,9 +30,19 @@ def get_grid_area(lon : np.ndarray, lat : np.ndarray) -> np.ndarray:
area per grid point
"""
area = np.zeros(len(lat))
delta_lon = np.abs(np.unique(lon)[1]-np.unique(lon)[0])
delta_lat = np.abs(np.unique(lat)[1] - np.unique(lat)[0])
if len(np.unique(lon)) == 1 and len(np.unique(lat)) > 1:
delta_lat = np.abs(np.unique(lat)[1] - np.unique(lat)[0])
delta_lon = delta_lat
elif len(np.unique(lon)) > 1 and len(np.unique(lat)) == 1:
delta_lon = np.abs(np.unique(lon)[1] - np.unique(lon)[0])
delta_lat = delta_lon
elif len(np.unique(lon)) == 1 and len(np.unique(lat)) == 1:
delta_lon = 1
delta_lat = 1
else:
delta_lon = np.abs(np.unique(lon)[1] - np.unique(lon)[0])
delta_lat = np.abs(np.unique(lat)[1] - np.unique(lat)[0])
for i, lat_i in enumerate(lat):
area[i] = get_area(0, lat_i-delta_lat/2, delta_lon, lat_i+delta_lat/2)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment