Source code for pycaps.diagnostic.patchinfo

#!/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.

from pycaps.io.io_modules import grdbas_read

[docs]def patchinfo(format='hdf', **kwargs): """ Given an ARPS history file or a specified domain size (nx by ny), returns information on valid patch configurations for MPI runs. Args: format: OPTIONAL -- The format of your history file (valid choices are 'hdf' and 'netcdf') file: OPTIONAL -- If you want to run patchinfo on an existing ARPS history dump file, the path to that file. nx: OPTIONAL -- If you want to specify dimensions manually, # of x-gridpoints (remember ARPS adds 3 points to the edges!) ny: OPTIONAL -- If you want to specify dimensions manually, # of y-gridpoints (remember ARPS adds 3 points to the edges!) target: OPTIONAL -- A target number of processors; show detailed information on patch configurations near this target. tolerance: OPTIONAL -- Given with a target, how close a configuration must be (in terms of # of procs) to be shown. Returns: <<nothing>> (Prints grid information to terminal) """ #-----------------------------------------------------# # READ DATA FROM FILE (IF NEEDED) # #-----------------------------------------------------# #Obtain data on ARPS grid from grdbas file: if 'nx' in kwargs: nx = kwargs['nx'] ny = kwargs['ny'] #for manual specification, insert null values for other printed variables nz = -999 dx = -999 dy = -999 else: if format in ['netcdf', 'NetCDF', 'NETCDF']: ctrlat, ctrlon, trulat1, trulat2, trulon, nx, ny, nz, dx, dy, width_x, width_y = grdbas_read(kwargs['file'], format='netcdf') else: ctrlat, ctrlon, trulat1, trulat2, trulon, nx, ny, nz, dx, dy, width_x, width_y = grdbas_read(kwargs['file'], format='hdf') #----------------------------------------------------# #Calculate valid choices for nproc_x, nproc_y: valid_nproc_x = [] valid_nproc_y = [] for i in range(1, int(nx-3), 1): if int(nx-3)%i == 0: valid_nproc_x.append(i) for j in range(1, int(ny-3), 1): if int(ny-3)%j == 0: valid_nproc_y.append(j) #----------------------------------------------------# #If user has requested a target number of patches, give this information: if kwargs['target']: #Define tolerance range (if not given, make it 10% of the target value) if kwargs['tolerance']: tol = int(kwargs['tolerance']) else: tol = int(kwargs['target'] * 0.1) #Find combinations close to the target suggested_x = [] suggested_y = [] for xpatches in valid_nproc_x: for ypatches in valid_nproc_y: if ((int(xpatches)*int(ypatches) > kwargs['target'] - tol) and (int(xpatches)*int(ypatches) < kwargs['target'] + tol)): suggested_x.append(xpatches) suggested_y.append(ypatches) #Print results for user: print '' print '###=============================================================================###' print '### ARPS Patch Information ###' print '###=============================================================================###' print '' print ' ARPS Filename: ' + str(kwargs['file']) print '' print ' Grid Dimensions:' print ' (nx, ny, nz) = (' + str(nx) + ',' + str(ny) + ',' + str(nz) + ')' print ' dx = ' + str(dx) + ' m' print ' dy = ' + str(dy) + ' m' print '' print ' Valid nproc_x choices: ' + str(valid_nproc_x) print ' Valid nproc_y choices: ' + str(valid_nproc_y) print '' if kwargs['target']: print ' -----------------------------------------------------------------------------' print ' Patch layouts within ' + str(tol) + ' of the target patch number (' + str(kwargs['target']) + ')' print ' -----------------------------------------------------------------------------' for i in range(1, len(suggested_x), 1): print ' nproc_x = ' + str(suggested_x[i]) + '; nproc_y = ' + str(suggested_y[i]) + ': ' + str(suggested_x[i]*suggested_y[i]) + ' patches (patch dimensions: ' + str(int(nx) / suggested_x[i]) + ' by ' + str(int(ny) / suggested_y[i]) + ')' if len(suggested_x) < 1: print ' No valid patch layouts found. Try specifying a larger --tolerance' print '' print '###=============================================================================###' print ''