Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. import pyart
  2. import cftime
  3. import multiprocessing
  4. import os
  5. import sys
  6.  
  7. def grid_radar(infile):
  8. """
  9. Given the name of a radar file, create a file
  10. ``$PBS_JOBFS/gridded.{time}.nc`` containing a gridded representation of
  11. that data
  12.  
  13. The output files may be concatenated using nco:
  14.  
  15. ncrcat $PBS_JOBFS/gridded.*.nc gridded.nc
  16. """
  17.  
  18. radar_in = pyart.io.read(infile)
  19.  
  20. gatefilter = pyart.filters.GateFilter(radar_in)
  21. gatefilter.exclude_transition()
  22. gatefilter.exclude_masked('reflectivity')
  23.  
  24. gridded_out = pyart.map.grid_from_radars(
  25. radar_in, gatefilters=gatefilter,
  26. grid_shape = (9,117,117),
  27. grid_limits=((0, 4000), (-150000.0, 150000.0), (-150000.0, 150000.0)),
  28. roi_func='constant', constant_roi=2500)
  29.  
  30. # Grab the time from the data so we can add it to the output file name
  31. arttime = gridded_out.time
  32. time = cftime.num2date(arttime['data'][0], arttime['units'], calendar=arttime['calendar'])
  33. gridded_out.write(os.path.join(os.environ.get('PBS_JOBFS','.'), f'gridded.{time.strftime("%Y%m%dT%H%M%S")}.nc'))
  34. return time
  35.  
  36.  
  37. def main():
  38. # Grid the input files in parallel using multiprocessing
  39. # PyART will run out of memory if we open too many files, so we only
  40. # allow a single process to open 10 files, then we make a new one
  41. with multiprocessing.Pool(int(os.environ.get('PBS_NCPUS',4)), maxtasksperchild=10) as p:
  42. for r in p.imap_unordered(grid_radar, sys.argv[1:]):
  43. print(r)
  44.  
  45. if __name__ == '__main__':
  46. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement