Skip to content

Commit

Permalink
Explicitly close xr.Dataset in VarHandler.cmorize() (#244)
Browse files Browse the repository at this point in the history
- This is to avoid any possibility of resource locking with `.nc` files
  • Loading branch information
tomvothecoder authored Feb 22, 2024
1 parent fd821e1 commit 21ecaef
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
2 changes: 2 additions & 0 deletions e3sm_to_cmip/cmor_handlers/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ def cmorize(
else:
self._cmor_write_with_time(ds, cmor_var_id, time_dim, cmor_ips_id)

ds.close()

# NOTE: It is important to close the CMOR module AFTER CMORizing all of
# the variables. Otherwise, the IDs of cmor objects gets wiped after
# every loop.
Expand Down
35 changes: 35 additions & 0 deletions scripts/debug/549_zppy_debug/549_zppy_ts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from e3sm_to_cmip.__main__ import E3SMtoCMIP

# e3sm_to_cmip --output-path ~/test -v 'lai' --realm lnd --input-path /lcrc/group/e3sm/ac.zhang40/zppy_test_complete_run_output/test-main2-20240216/v2.LR.historical_0201_try7/post/lnd/180x360_aave/ts/monthly/2yr --user-metadata ~/zppy/zppy/templates/e3sm_to_cmip/default_metadata.json --tables-path /lcrc/group/e3sm/diagnostics/cmip6-cmor-tables/Tables --num-proc 12

# This version of CMOR_TABLES_DIR is outdated and fails with `default_metadata.json`
# CMOR_TABLES_DIR = "/lcrc/group/e3sm/diagnostics/cmip6-cmor-tables/Tables"
CMOR_TABLES_DIR = "/home/ac.tvo/E3SM-Project/cmip6-cmor-tables/Tables"
INPUT_DIR = "/lcrc/group/e3sm/ac.zhang40/zppy_test_complete_run_output/test-main2-20240216/v2.LR.historical_0201_try7/post/lnd/180x360_aave/ts/monthly/2yr"
OUTPUT_PATH = "/home/ac.tvo/E3SM-Project/e3sm_to_cmip/scripts/debug/549_zppy_ts"

# e3sm_to_cmip version
METADATA_PATH = "/home/ac.tvo/E3SM-Project/e3sm_to_cmip/e3sm_to_cmip/resources/default_metadata.json"


args = [
"--output-path",
OUTPUT_PATH,
"--var-list",
"lai",
"--realm",
"lnd",
"--input-path",
INPUT_DIR,
"--user-metadata",
METADATA_PATH,
"--num-proc",
"12",
"--tables-path",
CMOR_TABLES_DIR,
# "--serial",
]

run = E3SMtoCMIP(args)

run.run()

0 comments on commit 21ecaef

Please sign in to comment.