Skip to content

Commit

Permalink
ERA5 grid support.
Browse files Browse the repository at this point in the history
  • Loading branch information
nichannah committed Apr 1, 2022
1 parent 130c8d0 commit 514b560
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
9 changes: 9 additions & 0 deletions esmgrids/base_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,21 @@ def __init__(self, **kwargs):
# pole to be fixed.
self.fix_pole_holes()

# The base class may implement this if the corner latitudes overrun the
# poles
self.fix_pole_overruns()

if self.area_t is None and self.calc_areas:
self.area_t = calc_area_of_polygons(self.clon_t, self.clat_t)

def fix_pole_holes(self):
pass


def fix_pole_overruns(self):
pass


@classmethod
def fromgrid(cls, grid):
"""
Expand Down
28 changes: 28 additions & 0 deletions esmgrids/era5_grid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

import numpy as np
import netCDF4 as nc

from .base_grid import BaseGrid


class Era5Grid(BaseGrid):

def __init__(self, h_grid_def, description='ERA5 regular grid'):
self.type = 'Arakawa A'
self.full_name = 'ERA5'

with nc.Dataset(h_grid_def) as f:
x_t = f.variables['longitude'][:]
# ERA5 puts latitudes the wrong way around
y_t = np.flipud(f.variables['latitude'][:])

super(Era5Grid, self).__init__(x_t=x_t, y_t=y_t, calc_areas=False,
description=description)

def fix_pole_overruns(self):
"""
ERA5 has grid cell centres at latitudes of -90, 90.
"""

self.clat_t[np.where(self.clat_t > 90)] = 90
self.clat_t[np.where(self.clat_t < -90)] = -90
2 changes: 2 additions & 0 deletions esmgrids/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ def calc_area_of_polygons(clons, clats):
and then calculate the area of flat polygon.
This is slow we should do some caching to avoid recomputing.
FIXME: compare against a Haversine method for speed and accuracy
"""

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

0 comments on commit 514b560

Please sign in to comment.