-
Notifications
You must be signed in to change notification settings - Fork 103
/
shgeoid.py
162 lines (146 loc) · 6.25 KB
/
shgeoid.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
"""
Class for the height of the geoid.
"""
from __future__ import absolute_import as _absolute_import
from __future__ import division as _division
from __future__ import print_function as _print_function
import numpy as _np
import matplotlib as _mpl
import matplotlib.pyplot as _plt
import copy as _copy
from .shcoeffsgrid import SHGrid as _SHGrid
class SHGeoid(object):
"""
Class for the height of the geoid. The class is initialized from a class
instance of SHGravCoeffs using the method geoid(). Geoid heights are
referenced to a flattened ellipsoid of semimajor axis a and flattening f.
Attributes:
geoid : SHGrid class instance of the geoid.
gm : Gravitational constant time the mass of the body.
potref : Potential of the chosen geoid, in m2/s2.
a : Semimajor axis of the reference ellipsoid.
f : Flattening of the reference ellipsoid, f=(a-b)/a.
omega : Angular rotation rate of the body.
r : Reference radius of the Taylor expansion.
order : Order of the Taylor expansion.
lmax : The maximum spherical harmonic degree resolvable by the
geoid grid.
lmax_calc : The maximum spherical harmonic degree of the gravitational
potential used in creating the geoid.
nlat, nlon : The number of latitude and longitude bands in the geoid
grid.
sampling : The longitudinal sampling scheme of the geoid grid: either
1 for nlong=nlat or 2 for nlong=2*nlat.
Methods:
plot() : Plot the geoid.
copy() : Return a copy of the class instance.
info() : Print a summary of the data stored in the SHGrid instance.
"""
def __init__(self, geoid, gm, potref, a, f, omega, r, order, lmax,
lmax_calc):
"""
Initialize the SHGeoid class.
"""
self.geoid = _SHGrid.from_array(geoid, grid='DH')
self.grid = self.geoid.grid
self.sampling = self.geoid.sampling
self.nlat = self.geoid.nlat
self.nlon = self.geoid.nlon
self.potref = potref
self.gm = gm
self.a = a
self.f = f
self.omega = omega
self.order = order
self.r = r
self.lmax = lmax
self.lmax_calc = lmax_calc
def copy(self):
"""
Return a deep copy of the class instance.
Usage
-----
copy = x.copy()
"""
return _copy.deepcopy(self)
def info(self):
"""
Print a summary of the data stored in the SHGeoid class instance.
Usage
-----
x.info()
"""
print(repr(self))
def __repr__(self):
str = ('grid = {:s}\n'.format(repr(self.grid)))
if self.grid == 'DH':
str += 'sampling = {:d}\n'.format(self.sampling)
str += ('nlat = {:d}\n'
'nlon = {:d}\n'
'lmax = {:d}\n'
'lmax_calc = {:d}\n'
'gm (m3 / s2) = {:e}\n'
'reference potential (m2 /s2) = {:e}\n'
'a (m)= {:e}\n'
'f = {:e}\n'
'omega (rad / s) = {:s}\n'
'radius of Taylor expansion (m) = {:e}\n'
'order of expansion = {:d}'
.format(self.nlat, self.nlon, self.lmax, self.lmax_calc,
self.gm, self.potref, self.a, self.f, repr(self.omega),
self.r, self.order))
return str
def plot(self, tick_interval=[30, 30], minor_tick_interval=[None, None],
colorbar=True, cb_orientation='vertical', cb_label='geoid, m',
grid=False, axes_labelsize=None, tick_labelsize=None, show=True,
**kwargs):
"""
Plot the geoid.
Usage
-----
x.plot([tick_interval, minor_tick_interval, xlabel, ylabel, colorbar,
cb_orientation, cb_label, grid, axes_labelsize, tick_labelsize,
ax, show, fname, **kwargs])
Parameters
----------
tick_interval : list or tuple, optional, default = [30, 30]
Intervals to use when plotting the x and y ticks. If set to None,
ticks will not be plotted.
minor_tick_interval : list or tuple, optional, default = [None, None]
Intervals to use when plotting the minor x and y ticks. If set to
None, minor ticks will not be plotted.
xlabel : str, optional, default = 'longitude'
Label for the longitude axis.
ylabel : str, optional, default = 'latitude'
Label for the latitude axis.
colorbar : bool, optional, default = True
If True, plot a colorbar.
cb_orientation : str, optional, default = 'vertical'
Orientation of the colorbar: either 'vertical' or 'horizontal'.
cb_label : str, optional, default = 'geoid, m'
Text label for the colorbar.
grid : bool, optional, default = False
If True, plot major grid lines.
axes_labelsize : int, optional, default = None
The font size for the x and y axes labels.
tick_labelsize : int, optional, default = None
The font size for the x and y tick labels.
ax : matplotlib axes object, optional, default = None
A single matplotlib axes object where the plot will appear.
show : bool, optional, default = True
If True, plot the image to the screen.
fname : str, optional, default = None
If present, and if axes is not specified, save the image to the
specified file.
kwargs : optional
Keyword arguements that will be sent to plt.imshow(), such as cmap,
vmin and vmax.
"""
return self.geoid.plot(tick_interval=tick_interval,
minor_tick_interval=minor_tick_interval,
colorbar=colorbar,
cb_orientation=cb_orientation,
cb_label=cb_label,
grid=grid, axes_labelsize=axes_labelsize,
tick_labelsize=tick_labelsize,
show=show, **kwargs)