Skip to content

Commit

Permalink
monthlyAggregateBFMData.py, script to postprocess the raw BFM output …
Browse files Browse the repository at this point in the history
…for the paper on biogeochemistry
  • Loading branch information
Lorenzo Mentaschi committed Apr 21, 2023
1 parent 719eadd commit 60b9dea
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 7 deletions.
11 changes: 11 additions & 0 deletions acIndUtils/acIndUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,17 @@ def generateDifferencDataset(projNcFileSpec,



def addNavlonNavlatFields(ncFileSpec):
ds = netCDF4.Dataset(ncFileSpec.ncFileName, "r+")
x = ds.variables[ncFileSpec.xVarName][:]
y = ds.variables[ncFileSpec.yVarName][:]
lonmtx, latmtx = np.meshgrid(x, y)
nav_lon = ds.createVariable("nav_lon", 'f4', (ncFileSpec.yVarName, ncFileSpec.xVarName))
nav_lon[:] = lonmtx
nav_lat = ds.createVariable("nav_lat", 'f4', (ncFileSpec.yVarName, ncFileSpec.xVarName))
nav_lat[:] = latmtx
ds.close()




Expand Down
92 changes: 85 additions & 7 deletions notebooksOther/monthlyAggregateBFMData.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@

import acIndUtils, acIndAggregator

cdo = "/g100/home/userexternal/lmentasc/usr/Miniconda3/bin/cdo"
nccopy = "/g100/home/userexternal/lmentasc/usr/Miniconda3/bin/nccopy"

bfmDataFlPattern = "/gss/gss_work/DRES_uBOC2/adriaClim/bfm/output/historical/test1997-1999/BFM_5d_*.nc"
outFl = "/gss/gss_work/DRES_uBOC2/adriaClim/bfm/output/historical/test1997-1999/BFM_monthly.nc"
outdir = "/gss/gss_work/DRES_uBOC2/adriaClim/bfm/output/historical/test1997-1999/"

bfmDataFlPattern = os.path.join(outdir, "BFM_5d_*.nc")
maskFilePath = "/g100/home/userexternal/lmentasc/src/git/projects/AdriaClim/configurationProjCineca/scenarios/mask_NEMO_AdriaClim_compressed.nc"

os.system(f"cd {outdir}; rm BFM_1monclim*.nc BFM_monthly*.nc")

inputNcFileSpec = acIndUtils.acNcFileSpec(
ncFileName = bfmDataFlPattern,
varName = "Chla",
Expand All @@ -20,10 +25,10 @@
)

outputNcFileSpec = acIndUtils.acNcFileSpec(
ncFileName = outFl,
varName = "Chla",
xVarName = "lon",
yVarName = "lat",
ncFileName = "",
varName = "",
xVarName = "x",
yVarName = "y",
zVarName = "deptht",
tVarName = "time_counter"
)
Expand All @@ -37,9 +42,82 @@
tVarName = "time_counter"
)

import pdb; pdb.set_trace()

varName = "Chla"
print("")
print(f"elaborating {varName}")
outFl = os.path.join(outdir, f"BFM_monthly_{varName}.nc")
inputNcFileSpec.varName = varName
outputNcFileSpec.varName = varName
outputNcFileSpec.ncFileName = outFl
acIndAggregator.collectMonthlyData(inputNcFileSpec,
outputNcFileSpec,
coordsNcFileSpec = coordsNcFileSpec,
fill_value = 0)


varName = "O2o"
print("")
print(f"elaborating {varName}")
outFl = os.path.join(outdir, f"BFM_monthly_{varName}.nc")
inputNcFileSpec.varName = varName
outputNcFileSpec.varName = varName
outputNcFileSpec.ncFileName = outFl
acIndAggregator.collectMonthlyData(inputNcFileSpec,
outputNcFileSpec,
coordsNcFileSpec = coordsNcFileSpec,
fill_value = 0)


varName = "N1p"
print("")
print(f"elaborating {varName}")
outFl = os.path.join(outdir, f"BFM_monthly_{varName}.nc")
inputNcFileSpec.varName = varName
outputNcFileSpec.varName = varName
outputNcFileSpec.ncFileName = outFl
acIndAggregator.collectMonthlyData(inputNcFileSpec,
outputNcFileSpec,
coordsNcFileSpec = coordsNcFileSpec,
fill_value = 0)


varName = "N3n"
print("")
print(f"elaborating {varName}")
outFl = os.path.join(outdir, f"BFM_monthly_{varName}.nc")
inputNcFileSpec.varName = varName
outputNcFileSpec.varName = varName
outputNcFileSpec.ncFileName = outFl
acIndAggregator.collectMonthlyData(inputNcFileSpec,
outputNcFileSpec,
coordsNcFileSpec = coordsNcFileSpec,
fill_value = 0)


varName = "N5s"
print("")
print(f"elaborating {varName}")
outFl = os.path.join(outdir, f"BFM_monthly_{varName}.nc")
inputNcFileSpec.varName = varName
outputNcFileSpec.varName = varName
outputNcFileSpec.ncFileName = outFl
acIndAggregator.collectMonthlyData(inputNcFileSpec,
outputNcFileSpec,
coordsNcFileSpec = coordsNcFileSpec,
fill_value = 0)


curdir = os.getcwd()
os.chdir(outdir)
print("merging ...")
os.system(f"{cdo} merge BFM_monthly_*.nc BFM_monthly.nc")
outputNcFileSpec.ncFileName = "BFM_monthly.nc"
acIndUtils.addNavlonNavlatFields(outputNcFileSpec)
print("creating monthly climatology ...")
os.system(f"{cdo} ymonmean BFM_monthly.nc BFM_1monclim_uncompressed.nc")
print("compressing ...")
os.system(f"{nccopy} -d9 BFM_1monclim_uncompressed.nc BFM_1monclim.nc")
os.chdir(curdir)


18 changes: 18 additions & 0 deletions notebooksOther/monthlyAggregateBFMData.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
#SBATCH --account=uBOC2_mentasc
#SBATCH --partition=g100_all_serial
##SBATCH --partition=g100_usr_prod
##SBATCH --qos=noQOS
#SBATCH --mem=30G
#SBATCH --nodes 1
#SBATCH --ntasks-per-node=1
#SBATCH --time=4:00:00
#SBATCH --job-name=monthlyAggregateBFMData
#SBATCH --output=monthlyAggregateBFMData_%j.out
#SBATCH --error=monthlyAggregateBFMData_%j.err
#SBATCH --mail-user=lorenzo.mentaschi@unibo.it

py=/g100/home/userexternal/lmentasc/usr/Miniconda3/bin/python3.9

rm BFM_1monclim* BFM_monthly*
$py monthlyAggregateBFMData.py

0 comments on commit 60b9dea

Please sign in to comment.