Created
October 10, 2014 16:41
-
-
Save cbcunc/a3dc8da8f5e550177749 to your computer and use it in GitHub Desktop.
Sanity check for ugrid2shp. Convert all the NAM output to shapefiles. Wait for something to blow up.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
import multiprocessing | |
import ugrid2shp | |
urlformat = "http://opendap.renci.org:1935/thredds/dodsC/daily/nam/%s/nc6b/hatteras.renci.org/rencidaily/namforecast/%s.63.nc" | |
outformat = "%s_%s" | |
errformat = "%s_%s.err" | |
variables = (("swan_HS", "swan_HS",), | |
("swan_HS_max", "swan_HS_max",), | |
("swan_DIR", "swan_DIR",), | |
("swan_DIR_max", "swan_DIR_max",), | |
("swan_TPS", "swan_TPS",), | |
("swan_TPS_max", "swan_TPS_max",), | |
("swan_TMM10", "swan_TMM10",), | |
("swan_TMM10_max", "swan_TMM10_max",), | |
("minpr", "pressure_min"), | |
("maxwvel", "wind_max"), | |
("maxrs", "radstress_max"), | |
("maxele", "zeta_max"), | |
) | |
def worker(argv, date, varid): | |
try: | |
ugrid2shp.main(argv) | |
except Exception as e: | |
with open(os.path.join("shapefiles", errformat % (date, varid)), "w") as error: | |
error_msg = "Process for date %s and variable name %s: Exception = %s, message = %s." % (date, variable, type(e), e.message) | |
error.write(error_msg + "\n") | |
with open("datelist.txt") as handle: | |
datelist = handle.readlines() | |
datelist = [date.strip() for date in datelist] | |
for date in datelist: | |
processes = [] | |
for varid, varname in variables: | |
argv = ["-n", | |
urlformat % (date, varid), | |
"-o", | |
os.path.join("shapefiles", outformat % (date, varid)), | |
"-v", | |
varname, | |
] | |
process = multiprocessing.Process(target=worker, args=(argv, date, varid,)) | |
process.start() | |
processes.append((process, varid,)) | |
for process, varid in processes: | |
process.join() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment