1
1
"""Spherical harmonic vector wind computations (`cdms2` interface)."""
2
- # Copyright (c) 2012-2016 Andrew Dawson
2
+ # Copyright (c) 2012-2017 Andrew Dawson
3
3
#
4
4
# Permission is hereby granted, free of charge, to any person obtaining a copy
5
5
# of this software and associated documentation files (the "Software"), to deal
24
24
import cdms2
25
25
26
26
from . import standard
27
+ from ._common import inspect_gridtype
27
28
28
29
29
30
class VectorWind (object ):
@@ -84,7 +85,7 @@ def __init__(self, u, v, rsphere=6.3712e6):
84
85
lat = u .getLatitude ()
85
86
if lon is None or lat is None :
86
87
raise ValueError ('a latitude-longitude grid is required' )
87
- gridtype = self . _gridtype (lat )
88
+ gridtype = inspect_gridtype (lat [:] )
88
89
# Store the shape and axes when data is in the API order.
89
90
self .ishape = u .shape
90
91
self .axes = u .getAxisList ()
@@ -95,36 +96,6 @@ def __init__(self, u, v, rsphere=6.3712e6):
95
96
self .api = standard .VectorWind (u , v , gridtype = gridtype ,
96
97
rsphere = rsphere )
97
98
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
-
128
99
def _metadata (self , var , ** attributes ):
129
100
"""Re-shape and re-order raw results, and add meta-data."""
130
101
if 'id' not in attributes .keys ():
0 commit comments