7
7
8
8
def run (dates , lons , lats , alts , f107s , f107as , aps ,
9
9
options = None , version = 2 ):
10
- """Call MSIS looping over all possible inputs.
10
+ """
11
+ Call MSIS looping over all possible inputs. If ndates is
12
+ the same as nlons, nlats, and nalts, then a flattened
13
+ multi-point input array is assumed. Otherwise, the data
14
+ will be expanded in a grid-like fashion. The possible
15
+ return shapes are therefore (ndates, 11) and
16
+ (ndates, nlons, nlats, nalts, 11).
11
17
12
18
Parameters
13
19
----------
@@ -32,7 +38,7 @@ def run(dates, lons, lats, alts, f107s, f107as, aps,
32
38
33
39
Returns
34
40
-------
35
- ndarray (ndates, nlons, nlats, nalts, 11)
41
+ ndarray (ndates, nlons, nlats, nalts, 11) or (ndates, 11)
36
42
| The data calculated at each grid point:
37
43
| [Total mass density (kg/m3)
38
44
| N2 # density (m-3),
@@ -168,7 +174,8 @@ def create_input(dates, lons, lats, alts, f107s, f107as, aps):
168
174
(shape, flattened_input)
169
175
The shape of the data as a tuple (ndates, nlons, nlats, nalts) and
170
176
the flattened version of the input data
171
- (ndates*nlons*nlats*nalts, 14).
177
+ (ndates*nlons*nlats*nalts, 14). If the input array was preflattened
178
+ (ndates == nlons == nlats == nalts), then the shape is (ndates,).
172
179
"""
173
180
# Turn everything into arrays
174
181
dates = np .atleast_1d (np .array (dates , dtype = 'datetime64' ))
@@ -194,18 +201,30 @@ def create_input(dates, lons, lats, alts, f107s, f107as, aps):
194
201
nlons = len (lons )
195
202
nlats = len (lats )
196
203
nalts = len (alts )
197
- shape = (ndates , nlons , nlats , nalts )
198
204
199
205
if not (ndates == len (f107s ) == len (f107as ) == len (aps )):
200
206
raise ValueError (f"The length of dates ({ ndates } ), f107s "
201
207
f"({ len (f107s )} ), f107as ({ len (f107as )} ), "
202
208
f"and aps ({ len (aps )} ) must all be equal" )
203
209
210
+ if ndates == nlons == nlats == nalts :
211
+ # This means the data came in preflattened, from a satellite
212
+ # trajectory for example, where we don't want to make a grid
213
+ # out of the input data, we just want to stack it together.
214
+ arr = np .stack ([dyear , dseconds , lons , lats , alts , f107s , f107as ], - 1 )
215
+
216
+ # ap has 7 components, so we need to concatenate it onto the
217
+ # arrays rather than stack
218
+ flattened_input = np .concatenate ([arr , aps ], axis = 1 ,
219
+ dtype = np .float32 )
220
+ shape = (ndates ,)
221
+ return shape , flattened_input
222
+
204
223
# Make a grid of indices
205
224
indices = np .stack (np .meshgrid (np .arange (ndates ),
206
- np .arange (nlons ),
207
- np .arange (nlats ),
208
- np .arange (nalts ), indexing = 'ij' ),
225
+ np .arange (nlons ),
226
+ np .arange (nlats ),
227
+ np .arange (nalts ), indexing = 'ij' ),
209
228
- 1 ).reshape (- 1 , 4 )
210
229
211
230
# Now stack all of the arrays, indexing by the proper indices
@@ -215,5 +234,7 @@ def create_input(dates, lons, lats, alts, f107s, f107as, aps):
215
234
f107s [indices [:, 0 ]], f107as [indices [:, 0 ]]], - 1 )
216
235
# ap has 7 components, so we need to concatenate it onto the
217
236
# arrays rather than stack
218
- return shape , np .concatenate ([arr , aps [indices [:, 0 ], :]], axis = 1 ,
219
- dtype = np .float32 )
237
+ flattened_input = np .concatenate ([arr , aps [indices [:, 0 ], :]], axis = 1 ,
238
+ dtype = np .float32 )
239
+ shape = (ndates , nlons , nlats , nalts )
240
+ return shape , flattened_input
0 commit comments