FLEXPART Testing Environment CTBTO WO8
 All Classes Namespaces Files Functions Variables Pages
Public Member Functions | Private Attributes | List of all members
flextest.flexread.FlexpartOutput.FlexpartOutput Class Reference
Inheritance diagram for flextest.flexread.FlexpartOutput.FlexpartOutput:
Inheritance graph
[legend]
Collaboration diagram for flextest.flexread.FlexpartOutput.FlexpartOutput:
Collaboration graph
[legend]

Public Member Functions

def __init__
 
def get_horiz_slice
 
def get_deposition
 
def get_volume
 
def get_horiz_timeseries
 
def get_deposition_timeseries
 
def get_volume_timeseries
 
def get_timestamp_list
 

Private Attributes

 _output_dir
 
 _Header
 

Detailed Description

High level interface to encapsulate and provide access to
the output of a specified FLEXPART simulation

Definition at line 15 of file FlexpartOutput.py.

Constructor & Destructor Documentation

def flextest.flexread.FlexpartOutput.FlexpartOutput.__init__ (   self,
  output_dir = None,
  nest = False 
)
Constructor
    output_dir: full path to directory of FLEXPART output
    nest: Denotes whether this object is for the mother grid or a nest

Definition at line 20 of file FlexpartOutput.py.

20 
21  def __init__(self, output_dir=None, nest=False):
22 
23  """Constructor
24  output_dir: full path to directory of FLEXPART output
25  nest: Denotes whether this object is for the mother grid or a nest
26  """
27 
28 
29 
30  self._output_dir = output_dir
31 
32  if self._output_dir and os.path.isdir(self._output_dir):
33  try:
34  self._Header = rh.Header( self._output_dir, nested=nest )
35  except:
36  raise IOError('Problem getting output data header')
37  else:
38  raise IOError('Bad output data dir: ' + str(self._output_dir))
39 
#print self._Header

Member Function Documentation

def flextest.flexread.FlexpartOutput.FlexpartOutput.get_deposition (   self,
  timestamp = None,
  species = 1,
  release = 1,
  age_class = 1,
  depo_type = 'dry' 
)
Extracts 2D horizontal slice of deposition.  
Note that species and 
release index values for the user start at 1, but they are all
decremented internal to this method so they start at 0.
Returned 2D grid is a NumPy array

Note that if timestamp is not defined, then a timestamp "close to
the middle" will be selected.

If there is any kind of error, we return None

Definition at line 99 of file FlexpartOutput.py.

99 
100  depo_type='dry'):
101 
102  """Extracts 2D horizontal slice of deposition.
103  Note that species and
104  release index values for the user start at 1, but they are all
105  decremented internal to this method so they start at 0.
106  Returned 2D grid is a NumPy array
107 
108  Note that if timestamp is not defined, then a timestamp "close to
109  the middle" will be selected.
110 
111  If there is any kind of error, we return None
112  """
113 
114  # if timestamp is not defined, choose a "mid way" timestamp for default
115  if not timestamp:
116  ntimes = len(self._Header['available_dates'])
117  tstamp_idx = ntimes/2
118  timestamp = self._Header['available_dates'][tstamp_idx]
119 
120  # Get the full grid for specified timestamp and species
121  so_far_so_good = True
122  try:
123  dry_flag=False; wet_flag=False
124  if depo_type=='dry':
125  dry_flag = True
126  if depo_type=='wet':
127  wet_flag = True
128 
129  G = rg.read_grid(self._Header, date=timestamp,
130  nspec_ret=species-1,
131  pspec_ret=release-1,
132  age_ret=age_class-1,
133  getdry=dry_flag,
134  getwet=wet_flag
135  )
136 
137  #print "G"
138  #print G
139  #print G.shape
140  #sys.exit()
141 
142  except:
143  logging.error('Problem getting G from read_grid()')
144  so_far_so_good = False
145 
146  if so_far_so_good:
147  try:
148  # Get the grid (x,y,z,release)
149  the_grid = G[ (species-1, timestamp) ]
150  except:
151  logging.error('Problem getting the_grid from G')
152  so_far_so_good = False
153 
154  if so_far_so_good:
155  try:
156  # Get the 2D slice horizontal slice (x,y)
157 
158  # 2016-03-23 -- DJM modification - apparently John put a
159  # "squeeze()" call on these arrays when they came out in
160  # read_grid(), so they can come out as either 2D or 3D. I
161  # need consistency, so if they're 2D, I'm expanding back out
162  # to 3D
163  #
164  # WARNING - DJM - 2016-03-23 - I'm not sure why I used
165  # "release" as an index in one of the following rather than
166  # species. I "think" it was logical, and I just went by
167  # the dimensions I had available in a test case, but I'm
168  # not 100% positive that this ain't going to get us into
169  # trouble one day.
170  if depo_type=='dry':
171  #print the_grid.dry
172  #print 'dry shape: ', the_grid.dry.shape
173  if the_grid.dry.ndim == 2:
174  dry_grid = np.expand_dims(the_grid.dry, axis=2)
175  else:
176  dry_grid = the_grid.dry
177  the_depo = dry_grid[:, :, release-1]
178  elif depo_type=='wet':
179  #print 'wet shape: ', the_grid.wet.shape
180  if the_grid.wet.ndim == 2:
181  wet_grid = np.expand_dims(the_grid.wet, axis=2)
182  else:
183  wet_grid = the_grid.wet
184  the_depo = wet_grid[:, :, release-1]
185  else:
186  the_depo = None
187  except:
188  logging.error('Problem getting the_depo from the_grid')
189  so_far_so_good = False
190 
191  if so_far_so_good:
192  return the_depo
193  else:
194  return None
195 
196 

Here is the call graph for this function:

Here is the caller graph for this function:

def flextest.flexread.FlexpartOutput.FlexpartOutput.get_deposition_timeseries (   self,
  timestamp_list = None,
  species = 1,
  release = 1,
  age_class = 1,
  depo_type = 'dry' 
)
Extracts timeseries of 2D deposition.  If timestamp_list is
defined correctly, it extracts just the timestamps (in YYYYMMDDHHMMss
format) listed.  Otherwise, it extracts all timestamps. The timeseries
is returned in a 3D NumPy array, indexed by (t, x, y)

Definition at line 309 of file FlexpartOutput.py.

310  depo_type='dry'):
311 
312  """Extracts timeseries of 2D deposition. If timestamp_list is
313  defined correctly, it extracts just the timestamps (in YYYYMMDDHHMMss
314  format) listed. Otherwise, it extracts all timestamps. The timeseries
315  is returned in a 3D NumPy array, indexed by (t, x, y)"""
316 
317  # Get the dimensions to create a 3D (t, x, y) array
318  if not timestamp_list:
319  timestamp_list = self._Header['available_dates']
320  Nx = self._Header.nx
321  Ny = self._Header.ny
322 
323  depo_timeseries = np.ndarray( (len(timestamp_list), Nx, Ny),
324  dtype=np.float64 )
325 
326 
327  #print Nx, Ny
328 
329  time_idx = 0
330  for ts in timestamp_list:
331  next_depo = self.get_deposition(timestamp=ts,
332  species=species,
333  release=release,
334  age_class=age_class,
335  depo_type=depo_type
336  )
337 
338 
339  #print 'next_depo: ', next_depo
340  #print next_depo.shape
341 
342  #print next_slice
343  depo_timeseries[time_idx, :, :] = next_depo
344  time_idx += 1
345 
346 
347  return depo_timeseries
348 

Here is the call graph for this function:

Here is the caller graph for this function:

def flextest.flexread.FlexpartOutput.FlexpartOutput.get_horiz_slice (   self,
  timestamp = None,
  level = 1,
  species = 1,
  release = 1,
  age_class = 1 
)
Extracts 2D horizontal slice.  Note that level, species and 
release index values for the user start at 1, but they are all
decremented internal to this method so they start at 0.
Returned 2D grid is a NumPy array

Note that if timestamp is not defined, then a timestamp "close to
the middle" will be selected.

If there is any kind of error, we return None

Definition at line 41 of file FlexpartOutput.py.

41 
42  release=1, age_class=1):
43 
44  """Extracts 2D horizontal slice. Note that level, species and
45  release index values for the user start at 1, but they are all
46  decremented internal to this method so they start at 0.
47  Returned 2D grid is a NumPy array
48 
49  Note that if timestamp is not defined, then a timestamp "close to
50  the middle" will be selected.
51 
52  If there is any kind of error, we return None
53  """
54 
55  # if timestamp is not defined, choose a "mid way" timestamp for default
56  if not timestamp:
57  ntimes = len(self._Header['available_dates'])
58  tstamp_idx = ntimes/2
59  timestamp = self._Header['available_dates'][tstamp_idx]
60 
61  # Get the full grid for specified timestamp and species
62  so_far_so_good = True
63  try:
64 
65  G = rg.read_grid(self._Header, date=timestamp,
66  nspec_ret=species-1,
67  pspec_ret=release-1,
68  age_ret=age_class-1,
69  )
70 
71  except:
72  logging.error('Problem getting G from read_grid()')
73  so_far_so_good = False
74 
75  if so_far_so_good:
76  try:
77  # Get the grid (x,y,z,release)
78  the_grid = G[ (species-1, timestamp) ]
79  except:
80  logging.error('Problem getting the_grid from G')
81  so_far_so_good = False
82 
83  if so_far_so_good:
84  try:
85  # Get the 2D slice horizontal slice (x,y)
86  the_slice = the_grid.grid[:, :, level-1, release-1]
87 
88  except:
89  logging.error('Problem getting the_slice from the_grid')
90  so_far_so_good = False
91 
92  if so_far_so_good:
93  return the_slice
94  else:
95  return None
96 

Here is the call graph for this function:

Here is the caller graph for this function:

def flextest.flexread.FlexpartOutput.FlexpartOutput.get_horiz_timeseries (   self,
  timestamp_list = None,
  level = 1,
  species = 1,
  release = 1,
  age_class = 1 
)
Extracts timeseries of 2D horizontal slices.  If timestamp_list is
defined correctly, it extracts just the timestamps (in YYYYMMDDHHMMss
format) listed.  Otherwise, it extracts all timestamps. The timeseries
is returned in a 3D NumPy array, indexed by (t, x, y)

Definition at line 269 of file FlexpartOutput.py.

270  release=1, age_class=1):
271 
272  """Extracts timeseries of 2D horizontal slices. If timestamp_list is
273  defined correctly, it extracts just the timestamps (in YYYYMMDDHHMMss
274  format) listed. Otherwise, it extracts all timestamps. The timeseries
275  is returned in a 3D NumPy array, indexed by (t, x, y)"""
276 
277  # Get the dimensions to create a 3D (t, x, y) array
278  if not timestamp_list:
279  timestamp_list = self._Header['available_dates']
280  Nx = self._Header.nx
281  Ny = self._Header.ny
282 
283  slice_timeseries = np.ndarray( (len(timestamp_list), Nx, Ny),
284  dtype=np.float64 )
285 
286 
287  #print Nx, Ny
288 
289  time_idx = 0
290  for ts in timestamp_list:
291  next_slice = self.get_horiz_slice(timestamp=ts,
292  level=level,
293  species=species,
294  release=release,
295  age_class=age_class)
296 
297 
298 
299  #print next_slice
300  slice_timeseries[time_idx, :, :] = next_slice
301  time_idx += 1
302 
303 
304  return slice_timeseries
305 

Here is the call graph for this function:

Here is the caller graph for this function:

def flextest.flexread.FlexpartOutput.FlexpartOutput.get_timestamp_list (   self)
Returns the list of timestamps as Python list

Definition at line 394 of file FlexpartOutput.py.

395  def get_timestamp_list(self):
396 
397  """
398  Returns the list of timestamps as Python list
399  """
400  timestamp_list = self._Header['available_dates']
401 
402  return timestamp_list
403 
404 
405 
def flextest.flexread.FlexpartOutput.FlexpartOutput.get_volume (   self,
  timestamp = None,
  level_list = None,
  species = 1,
  release = 1,
  age_class = 1 
)
Extracts 3D volume.  if level_list is not defined, we return the full
volume for the timestamp.  If level_list is defined,then we extract the
specified levels and create a volume from them

Note that level, species and 
release index values for the user start at 1, but they are all
decremented internal to this method so they start at 0.
Returned 2D grid is a NumPy array

If there is any kind of error, we return None

Definition at line 198 of file FlexpartOutput.py.

199  release=1, age_class=1):
200 
201  """Extracts 3D volume. if level_list is not defined, we return the full
202  volume for the timestamp. If level_list is defined,then we extract the
203  specified levels and create a volume from them
204 
205  Note that level, species and
206  release index values for the user start at 1, but they are all
207  decremented internal to this method so they start at 0.
208  Returned 2D grid is a NumPy array
209 
210  If there is any kind of error, we return None
211  """
212 
213  # if timestamp is not defined, choose a "mid way" timestamp for default
214  if not timestamp:
215  ntimes = len(self._Header['available_dates'])
216  tstamp_idx = ntimes/2
217  timestamp = self._Header['available_dates'][tstamp_idx]
218 
219  # Get the full grid for specified timestamp and species
220  so_far_so_good = True
221  try:
222  G = rg.read_grid(self._Header, date=timestamp,
223  nspec_ret=species-1,
224  pspec_ret=release-1,
225  age_ret=age_class-1,
226  )
227 
228  except:
229  logging.error('Problem getting G from read_grid()')
230  so_far_so_good = False
231 
232  if so_far_so_good:
233  try:
234  # Get the grid (x,y,z,release)
235  the_grid = G[ (species-1, timestamp) ]
236  except:
237  logging.error('Problem getting the_grid from G')
238  so_far_so_good = False
239 
240  if so_far_so_good:
241  if level_list:
242  # Decrement indices to 0 start
243  level_indices = list(map(lambda x: x-1, level_list))
244  try:
245  # Get the volume (x,y,z)
246  the_volume = the_grid.grid[:, :, level_indices, release-1]
247  except:
248  logging.error('Problem getting the_volume from the_grid')
249  so_far_so_good = False
250  else:
251  # Extract the full volume
252  # Make sure all level numbers are less than levels dimension
253  # of grid
254 
255  try:
256  # Get the volume (x,y,z)
257  the_volume = the_grid.grid[:, :, :, release-1]
258  except:
259  logging.error('Problem getting the_volume from the_grid')
260  so_far_so_good = False
261 
262  if so_far_so_good:
263  return the_volume
264  else:
265  return None
266 

Here is the call graph for this function:

Here is the caller graph for this function:

def flextest.flexread.FlexpartOutput.FlexpartOutput.get_volume_timeseries (   self,
  timestamp_list = None,
  level_list = None,
  species = 1,
  release = 1,
  age_class = 1 
)
Extracts timeseries of 2D horizontal slices.  If timestamp_list is
defined correctly, it extracts just the timestamps (in YYYYMMDDHHMMss
format) listed.  Otherwise, it extracts all timestamps. The timeseries
is returned in a 3D NumPy array, indexed by (t, x, y)

Definition at line 351 of file FlexpartOutput.py.

352  release=1, age_class=1):
353 
354  """Extracts timeseries of 2D horizontal slices. If timestamp_list is
355  defined correctly, it extracts just the timestamps (in YYYYMMDDHHMMss
356  format) listed. Otherwise, it extracts all timestamps. The timeseries
357  is returned in a 3D NumPy array, indexed by (t, x, y)"""
358 
359  # Get the dimensions to create a 3D (t, x, y) array
360  if not timestamp_list:
361  timestamp_list = self._Header['available_dates']
362  Nx = self._Header.nx
363  Ny = self._Header.ny
364 
365  if not level_list:
366  Nz = self._Header.nz
367  else:
368  Nz = len( level_list )
369 
370  volume_timeseries = np.ndarray( (len(timestamp_list), Nx, Ny, Nz),
371  dtype=np.float64 )
372 
373 
374  #print Nx, Ny, Nz
375 
376  time_idx = 0
377  for ts in timestamp_list:
378  next_volume = self.get_volume(timestamp=ts,
379  level_list=level_list,
380  species=species,
381  release=release,
382  age_class=age_class)
383 
384 
385 
386  #print next_volume
387  volume_timeseries[time_idx, :, :] = next_volume
388  time_idx += 1
389 
390 
391  return volume_timeseries
392 
393 

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

flextest.flexread.FlexpartOutput.FlexpartOutput._Header
private

Definition at line 33 of file FlexpartOutput.py.

flextest.flexread.FlexpartOutput.FlexpartOutput._output_dir
private

Definition at line 29 of file FlexpartOutput.py.


The documentation for this class was generated from the following file: