Skip to content

Commit

Permalink
Add cupid_temp directory for writing file
Browse files Browse the repository at this point in the history
The coupling index was being written to Meg's scratch space on derecho; now we
look for $SCRATCH and write in a subdirectory ($SCRATCH/CUPiD_scratch)
otherwise we write in $PWD
  • Loading branch information
mnlevy1981 committed Dec 20, 2024
1 parent e73d76a commit fd1f66c
Showing 1 changed file with 28 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,16 @@
"# obsDir = '/glade/campaign/cgd/tss/people/mdfowler/FLUXNET2015/' ## Need to copy into CUPiD Data\n",
"\n",
"## Where CESM timeseries data is stored\n",
"CESM_output_dir = \"/glade/campaign/cesm/development/cross-wg/diagnostic_framework/CESM_output_for_testing/\"\n",
"CESM_output_dir = os.path.join(\n",
" os.path.sep,\n",
" \"glade\",\n",
" \"campaign\",\n",
" \"cesm\",\n",
" \"development\",\n",
" \"cross-wg\",\n",
" \"diagnostic_framework\",\n",
" \"CESM_output_for_testing\",\n",
")\n",
"\n",
"\n",
"## Full casenames that are present in CESM_output_dir and in individual filenames\n",
Expand Down Expand Up @@ -123,6 +132,14 @@
"## - - - - - - - - - - - - - - - - - - - - - -\n",
"## Settings for computing coupling index\n",
"## - - - - - - - - - - - - - - - - - - - - - -\n",
"\n",
"# Set up directory for aux output like coupling index file\n",
"if \"SCRATCH\" in os.environ:\n",
" cupid_temp = os.path.join(os.path.sep, os.environ[\"SCRATCH\"], \"CUPiD_scratch\")\n",
" os.makedirs(cupid_temp, exist_ok=True)\n",
"else:\n",
" cupid_temp = \".\"\n",
"\n",
"startYrs = [start_date.split(\"-\")[0]]\n",
"endYrs = [f\"{int(end_date.split('-')[0])-1:04d}\"]\n",
"\n",
Expand Down Expand Up @@ -200,10 +217,8 @@
"source": [
"for iCase in range(len(caseNames)):\n",
" ## Check first if coupling index has already been created:\n",
" TCI_filePath = (\n",
" \"/glade/derecho/scratch/mdfowler/\"\n",
" + caseNames[0]\n",
" + \"_TerrestrialCouplingIndex_SHvsSM.nc\"\n",
" TCI_filePath = os.path.join(\n",
" cupid_temp, f\"{caseNames[iCase]}_TerrestrialCouplingIndex_SHvsSM.nc\"\n",
" )\n",
"\n",
" if os.path.exists(TCI_filePath): # Use previously computed TCI\n",
Expand Down Expand Up @@ -280,22 +295,16 @@
" yDS = shflx_DS\n",
"\n",
" couplingInd = compute_couplingIndex_cesm(xname, yname, xDS, yDS)\n",
"\n",
" filePath = (\n",
" \"/glade/derecho/scratch/mdfowler/\"\n",
" + caseNames[0]\n",
" + \"_TerrestrialCouplingIndex_SHvsSM.nc\"\n",
" )\n",
" couplingInd.to_netcdf(filePath)\n",
" print(\"File created: \", filePath)"
" couplingInd.to_netcdf(TCI_filePath)\n",
" print(\"File created: \", TCI_filePath)"
]
},
{
"cell_type": "markdown",
"id": "5f8fba2a-98d2-4e94-9d71-3b2625e16032",
"metadata": {},
"source": [
"### 1.1 Read in FLUXNET data if requested"
"### 2.1 Read in FLUXNET data if requested"
]
},
{
Expand Down Expand Up @@ -659,7 +668,7 @@
"id": "bc387253-cdd7-4a36-956b-8ce548e963bd",
"metadata": {},
"source": [
"## 2. Make plots"
"## 3. Make plots"
]
},
{
Expand Down Expand Up @@ -701,12 +710,11 @@
"outputs": [],
"source": [
"for iCase in range(len(caseNames)):\n",
" filePath = (\n",
" \"/glade/derecho/scratch/mdfowler/\"\n",
" + caseNames[iCase]\n",
" + \"_TerrestrialCouplingIndex_SHvsSM.nc\"\n",
" TCI_filePath = os.path.join(\n",
" cupid_temp, f\"{caseNames[iCase]}_TerrestrialCouplingIndex_SHvsSM.nc\"\n",
" )\n",
" couplingIndex_case = uxr.open_dataset(gridFile, filePath)\n",
"\n",
" couplingIndex_case = uxr.open_dataset(gridFile, TCI_filePath)\n",
" # Rename the variable:\n",
" couplingIndex_case = couplingIndex_case.rename(\n",
" {\"__xarray_dataarray_variable__\": \"CouplingIndex\"}\n",
Expand Down

0 comments on commit fd1f66c

Please sign in to comment.