Skip to content

Commit 514b560

Browse files
committed
ERA5 grid support.
1 parent 130c8d0 commit 514b560

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

Diff for: esmgrids/base_grid.py

+9
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,21 @@ def __init__(self, **kwargs):
9898
# pole to be fixed.
9999
self.fix_pole_holes()
100100

101+
# The base class may implement this if the corner latitudes overrun the
102+
# poles
103+
self.fix_pole_overruns()
104+
101105
if self.area_t is None and self.calc_areas:
102106
self.area_t = calc_area_of_polygons(self.clon_t, self.clat_t)
103107

104108
def fix_pole_holes(self):
105109
pass
106110

111+
112+
def fix_pole_overruns(self):
113+
pass
114+
115+
107116
@classmethod
108117
def fromgrid(cls, grid):
109118
"""

Diff for: esmgrids/era5_grid.py

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
import numpy as np
3+
import netCDF4 as nc
4+
5+
from .base_grid import BaseGrid
6+
7+
8+
class Era5Grid(BaseGrid):
9+
10+
def __init__(self, h_grid_def, description='ERA5 regular grid'):
11+
self.type = 'Arakawa A'
12+
self.full_name = 'ERA5'
13+
14+
with nc.Dataset(h_grid_def) as f:
15+
x_t = f.variables['longitude'][:]
16+
# ERA5 puts latitudes the wrong way around
17+
y_t = np.flipud(f.variables['latitude'][:])
18+
19+
super(Era5Grid, self).__init__(x_t=x_t, y_t=y_t, calc_areas=False,
20+
description=description)
21+
22+
def fix_pole_overruns(self):
23+
"""
24+
ERA5 has grid cell centres at latitudes of -90, 90.
25+
"""
26+
27+
self.clat_t[np.where(self.clat_t > 90)] = 90
28+
self.clat_t[np.where(self.clat_t < -90)] = -90

Diff for: esmgrids/util.py

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ def calc_area_of_polygons(clons, clats):
1414
and then calculate the area of flat polygon.
1515
1616
This is slow we should do some caching to avoid recomputing.
17+
18+
FIXME: compare against a Haversine method for speed and accuracy
1719
"""
1820

1921
areas = np.zeros(clons.shape[1:])

0 commit comments

Comments
 (0)