55# Research Applications Laboratory
66
77import sys , os
8+ from mpi4py import MPI
89
910# Set path to include internal library
1011cwd = os .getcwd ()
1415import sys , os
1516import argparse
1617from regridUtilities .argUtil import checkArgs
17- from regridUtilities .logMod import initLog
18- # from regridUtilities.preProc import shpConvert
18+ from regridUtilities .logMod import initLog , logErr , logMaster , logInfo
19+ from regridUtilities .preProcMod import shpConvert
1920import datetime
20- import logging
21+
22+ MPI_COMM = MPI .COMM_WORLD
23+ MPI_RANK = MPI_COMM .Get_rank ()
2124
2225def main (argv ):
2326 # Parse arguments passed in.
@@ -43,22 +46,52 @@ def main(argv):
4346 # Specify output path to store NetCDF file.
4447 parser .add_argument ('--shpPath' , nargs = '?' , help = 'Input polygon shapefile' )
4548 parser .add_argument ('--geoPath' , nargs = '?' , help = 'Input LSM geoGrid file.' )
49+ parser .add_argument ('--shpUid' , nargs = '?' , help = 'Unique Identifier for Shapefile.' )
50+ parser .add_argument ('--nodeThresh' , nargs = '?' , help = 'Number of nodes to cutoff.' )
4651
4752 args = parser .parse_args ()
4853
4954 # Ensure arguments provided by user are sane
50- try :
51- checkArgs (args )
52- except :
53- print "ERROR: Improper arguments passed."
54- sys .exit (1 )
55+ if MPI_RANK == 0 :
56+ try :
57+ checkArgs (args )
58+ except :
59+ print "ERROR: Improper arguments passed."
60+ sys .exit (1 )
61+
62+ # Set default node threshold. For any unstructured polygons with a number
63+ # of vertices above this number, they will be broken up to reduce
64+ # large ragged arrays.
65+ if not parser .nodeThresh :
66+ nodeThresh = 10000
5567
5668 # Initiate log file to store log messages on
5769 pId = os .getpid ()
5870 cDate = datetime .datetime .now ()
5971 cDate = cDate .strftime ('%Y_%m_%d_%H_%M_%S' )
6072 logDir = cwd + "/log"
61- initLog (pId ,cDate ,logDir )
73+ initLog (pId ,cDate ,logDir )
74+
75+ # Establish temporary directory, which will hold temporary
76+ # files during pre-processing, weight generation, and regridding
77+ tmpDir = cwd + "/tmp"
78+
79+ # First check to see if weight file already exists. If it does,
80+ # forego pre-processing and go straight to pre-processing source
81+ # data for regridding.
82+ if os .path .isfile (parser .weightPath ):
83+ try :
84+ shpConvert (shpPath ,shpUid ,nodeThresh ,tmpDir ,MPI_RANK )
85+ except :
86+ logErr ('Pre-Processing of shapefile failed. Program exiting.' )
87+ sys .exit (1 )
88+ else :
89+ if parser .shpPath :
90+
91+ # Call routine to pre-process shp file
92+ elif parser .geoPath :
93+ # Call routine to pre-process geoGrid file
94+
6295
6396if __name__ == "__main__" :
6497 main (sys .argv [1 :])
0 commit comments