Source code for pycaps.diagnostic.arps_gridinfo

#!/usr/bin/env python2.7

#Code: arps_info.py
#Author: Nate Snook (CAPS)
#Written: Feb. 2014
#Last modified: 28 Feb. 2014

#Purpose:  Give information about an ARPS run.

import sys
from PyNIO import Nio
from pycaps.io.io_modules import grdbas_read

[docs]def arps_gridinfo(arpsfile, format='hdf', **kwargs): """ Args: arpsfile: the file for which you want grid information format: OPTIONAL -- The format of your history file (valid choices are 'hdf' and 'netcdf') grdbas: OPTIONAL -- A separate file (.netgrdbas or .hdfgrdbas) containing gridbase data, if needed. Returns: <<nothing>> (Prints grid information to terminal) """ #----------------------------------------------------# #Obtain data on ARPS grid from grdbas file: try: ctrlat, ctrlon, trulat1, trulat2, trulon, nx, ny, nz, dx, dy, width_x, width_y = grdbas_read(arpsfile, format=format) except: if 'grdbas' in kwargs: ctrlat, ctrlon, trulat1, trulat2, trulon, nx, ny, nz, dx, dy, width_x, width_y = grdbas_read(kwargs['grdbas'], format=format) else: sys.exit('ERROR: No valid history file found!') #----------------------------------------------------# #Open the history dump file(s) for reading dumpfile = Nio.open_file(arpsfile, mode='r', options=None, history='', format=format) #Obtain data about the ARPS run in question start_year = int(dumpfile.attributes['year']) start_month = int(dumpfile.attributes['month']) start_day = int(dumpfile.attributes['day']) start_hour = int(dumpfile.attributes['hour']) start_minute = int(dumpfile.attributes['minute']) start_second = int(dumpfile.attributes['second']) n_mphy_var = int(dumpfile.attributes['nscalar']) nzsoil = int(dumpfile.attributes['nzsoil']) modeltime = float(dumpfile.attributes['time']) #----------------------------------------------------# #Report results to user: print '' print '###=============================================================================###' print '### ARPS Grid Information ###' print '###=============================================================================###' print '' print ' History Dump Filename: ' + str(arpsfile) if 'grdbas' in kwargs: print ' Gridbase Filename: ' + str(kwargs['grdbas']) print '' print ' Dimensions:' print ' (nx, ny, nz) = (' + str(nx) + ',' + str(ny) + ',' + str(nz) + ')' print ' dx = ' + str(dx) + ' m' print ' dy = ' + str(dy) + ' m' print '' print ' Domain width (east-west): ' + str(width_x / 1000.) + ' km' print ' Domain width (north-south): ' + str(width_y / 1000.) + ' km' print '' print ' Map projection values:' print ' Domain center: (lat, lon) = (' + str(ctrlat) + ',' + str(ctrlon) + ')' print ' trulat1 = ' + str(trulat1) print ' trulat2 = ' + str(trulat2) print ' trulon = ' + str(trulon) print '' print ' Number of Microphysical Variables: ' + str(n_mphy_var) print ' Number of Soil Layers: ' + str(nzsoil) print '' print ' Model Start time: ' + str(start_year) + '/' + str(start_month) + '/' + str(start_day) + ' -- ' + str(start_hour) + ':' + str(start_minute) + ':' + str(start_second) + ' UTC' print '' print ' Model time (seconds since start) of this file: ' + str(modeltime) print '' print '###=============================================================================###' print ''