Skip to content

Commit 2bc52d2

Browse files
authored
Merge pull request #79 from ajdawson/cdms-gaussian-fix
Use the same grid check in all interfaces
2 parents 3272e97 + a6641db commit 2bc52d2

File tree

1 file changed

+3
-32
lines changed

1 file changed

+3
-32
lines changed

lib/windspharm/cdms.py

+3-32
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""Spherical harmonic vector wind computations (`cdms2` interface)."""
2-
# Copyright (c) 2012-2016 Andrew Dawson
2+
# Copyright (c) 2012-2017 Andrew Dawson
33
#
44
# Permission is hereby granted, free of charge, to any person obtaining a copy
55
# of this software and associated documentation files (the "Software"), to deal
@@ -24,6 +24,7 @@
2424
import cdms2
2525

2626
from . import standard
27+
from ._common import inspect_gridtype
2728

2829

2930
class VectorWind(object):
@@ -84,7 +85,7 @@ def __init__(self, u, v, rsphere=6.3712e6):
8485
lat = u.getLatitude()
8586
if lon is None or lat is None:
8687
raise ValueError('a latitude-longitude grid is required')
87-
gridtype = self._gridtype(lat)
88+
gridtype = inspect_gridtype(lat[:])
8889
# Store the shape and axes when data is in the API order.
8990
self.ishape = u.shape
9091
self.axes = u.getAxisList()
@@ -95,36 +96,6 @@ def __init__(self, u, v, rsphere=6.3712e6):
9596
self.api = standard.VectorWind(u, v, gridtype=gridtype,
9697
rsphere=rsphere)
9798

98-
def _gridtype(self, lat):
99-
"""Determines the type of grid from the latitude dimension.
100-
101-
Performs basic checks to make sure the axis is valid for
102-
spherical harmonic computations.
103-
104-
"""
105-
nlat = len(lat)
106-
d = np.abs(np.diff(lat))
107-
if (np.abs(d - d[0]) > 0.001).any():
108-
# Might be a Gaussian axis, construct one and check.
109-
gax = cdms2.createGaussianAxis(nlat)
110-
d = np.abs(np.abs(lat) - np.abs(gax))
111-
if (d > 0.001).any():
112-
raise ValueError('non-evenly-spaced '
113-
'latitudes are not Gaussian')
114-
gridtype = 'gaussian'
115-
else:
116-
# Grid is evenly spaced, does it match what we expect?
117-
if nlat % 2:
118-
eax = np.linspace(-90, 90, nlat)
119-
else:
120-
dlat = 180. / nlat
121-
eax = np.linspace(-90 + 0.5 * dlat, 90 - 0.5 * dlat, nlat)
122-
d = np.abs(np.abs(lat) - np.abs(eax))
123-
if (d > 0.001).any():
124-
raise ValueError('evenly-spaced grid is invalid')
125-
gridtype = 'regular'
126-
return gridtype
127-
12899
def _metadata(self, var, **attributes):
129100
"""Re-shape and re-order raw results, and add meta-data."""
130101
if 'id' not in attributes.keys():

0 commit comments

Comments
 (0)