Skip to content

Commit

Permalink
for opendap files, we should close nc files/links, particularly the o…
Browse files Browse the repository at this point in the history
…nes without time step
  • Loading branch information
U-SOLISCOM\Sutan101 authored and U-SOLISCOM\Sutan101 committed May 6, 2020
1 parent d01c707 commit 77ee06b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
2 changes: 1 addition & 1 deletion conda_env/pcrglobwb_py3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ dependencies:
- nco
- ncview

# Note: You may want to exclude cdsapi, cdo, nco and ncview.
# Note: You may want to exclude cdsapi, cdo, and ncview.
5 changes: 4 additions & 1 deletion model/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,10 @@ def initialize_logging(self, log_file_location = "Default", system_arguments = N
else:
logger.info('PYTHONPATH=%s', "N/A")
# - hostname
logger.info('HOSTNAME: %s', os.environ["HOSTNAME"])
if "PYTHONPATH" in os.environ.keys():
logger.info('HOSTNAME: %s', os.environ["HOSTNAME"])
else:
logger.info('HOSTNAME: %s', "N/A")
# - PCRaster NUMBER_OF_WORKING_THREADS
if "PCRASTER_NR_WORKER_THREADS" in os.environ.keys():
logger.info('PCRASTER_NR_WORKER_THREADS (set by export, only for PCRaster version >= 4.2): %s', os.environ["PCRASTER_NR_WORKER_THREADS"])
Expand Down
26 changes: 16 additions & 10 deletions model/virtualOS.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,19 @@ def singleTryNetcdf2PCRobjCloneWithoutTime(ncFile, varName,\
# Only works if cells are 'square'.
# Only works if cellsizeClone <= cellsizeInput
# Get netCDF file and variable name:
if ncFile in list(filecache.keys()):
f = filecache[ncFile]
#~ print "Cached: ", ncFile
else:
f = nc.Dataset(ncFile)
filecache[ncFile] = f
#~ print "New: ", ncFile

# - for file without time steps, we should close it (as most likely, it will be used once only).
#~ if ncFile in list(filecache.keys()):
#~ f = filecache[ncFile]
#~ # print "Cached: ", ncFile
#~ else:
#~ f = nc.Dataset(ncFile)
#~ filecache[ncFile] = f
#~ # print "New: ", ncFile

# print ncFile

#print ncFile
#f = nc.Dataset(ncFile)
f = nc.Dataset(ncFile)
varName = str(varName)

if varName == "automatic":
Expand Down Expand Up @@ -205,8 +208,11 @@ def singleTryNetcdf2PCRobjCloneWithoutTime(ncFile, varName,\
#~ print(varName)
#~ os.system('aguila tmp.map')

#f.close();
# we should close the file
f.close();

f = None ; cropData = None

# PCRaster object
return (outPCR)

Expand Down

0 comments on commit 77ee06b

Please sign in to comment.