Bias-correct NorESM climate data: create ROMS forcing for downscaled projections
The scripts used for this toolbox uses the Climate Data Operator toolbox heavily. Its a fantastic set of functions that enables working with large climate data much easier.
Notes: When working here with smaller values of e.g. nitrate and silicate weneeded to ensure we used full precision of the dataset which is neabled with the options:
cdo -b F64 .....
The new version of model2roms now produces BCG + PHYSICS into the same BRY file. But prior to that we had two separate BRY files. This script combines those two files into one, based on the new output file used as template. This makes it easy to compare the historical hindcast with the projections and to caclulate climatology and deltas for downscaling: (combineSODAAndBGCFileIntoOne.py)
./createDeltas-NorESM-ocean.sh
Script that uses the CDO toolbox to calculate statistics and trends from the NorESM files. The script calculates the detrended climatology and removes this climatology from the timeseries. The result is a file containig the residuals and trends inherent in the timeseries. These residuals are later added to teh hindcast climatology to create a biascorrected timeseries.
Load the module using
module load CDO/1.9.3-intel-2018a
The starting point is a collection of global NorESM files for longer time-periods (2006-2050). As the script performs the following calculations are created:
- Extract data for period 2006-2015
- Calculate the monthly climatology and remove from the time-series to calculate non-seasonal trends
- Remove the trend from the original 2006-2015 dataset
- Calculate the climatology for the de-trended dataset (2006-2015)
- Remove the monthly climatology from the entire dataset (2006-2050)
- The result is the deltas from the climatology which will later be added to the higher resolution ERA climatology to create downscaled projections of climate change
./createDeltas-SODA-ocean.sh
Creates the climatology of the hindcast timeseries. This timeseries is assumed to be reaalistic and in phase with observations. Here, we use the SODA (Simple Ocean Data Assimilation) dataset to create the hindcast using the model2roms toolbox. This toolbox handles SODA3 as input files to create the required hindcast BRY file.
This script reads the output from step 1 and 2 and combined the two BRY files. The deltas/residuals from step 1 is added to the climatology created in step 2. A new file, the bias-corrected BRY file, is created.
Use this script to interpolate from NorESM grid to local ROMS grid. This script uses the fast and efficient interpolation of ESMF and requires the module to be installed to run. Install using Anaconda with command:
conda install -c conda-forge esmpy
If you dont have Anaconda install follow these suggestions:
Create a new environment called OpenDrift:
conda config --add channels conda-forge
conda create --name OpenDrift python=3.7 basemap matplotlib gdal libnetcdf netCDF4 numpy scipy seaborn xarray
conda activate OpenDrift
conda install -c conda-forge basemap-data-hires
conda install -c conda-forge esmpy
conda install -c conda-forge seawater
conda install -c conda-forge geos proj4
conda install -c conda-forge cartopy
The interpolateNORESM_using_ESMF.py
script should be run on a queue as it requires large memory (bigmem):
#!/bin/bash
##########################
# A20 particle tracking SLURM MPI job #
##########################
#SBATCH --job-name=A20interpolation
#SBATCH --ntasks-per-node=1
#SBATCH --nodes=4
#SBATCH -A nn9297k
#SBATCH --mem=32G
# run for minutes
# d-hh:mm:ss
#SBATCH --time=0-06:00:00
# short partition should do it
#SBATCH --partition=bigmem
# turn on all mail notification
#SBATCH --mail-type=ALL
SCRATCH_DIRECTORY=/cluster/projects/nn9412k/A20/DELTA/${SLURM_JOBID}
mkdir -p ${SCRATCH_DIRECTORY}
cd ${SCRATCH_DIRECTORY}
# Activate Anaconda work environment for OpenDrift
source /cluster/home/${USER}/.bashrc
conda activate OpenDrift
# we copy everything we need to the scratch directory
# ${SLURM_SUBMIT_DIR} points to the path where this script was submitted from
scp ${SLURM_SUBMIT_DIR}/interpolateNORESM_using_ESMF.py ${SCRATCH_DIRECTORY}
# we execute the job and time it
python interpolateNORESM_using_ESMF.py &> a20.output
# after the job is done we copy our output back to $SLURM_SUBMIT_DIR
cp ${SCRATCH_DIRECTORY}/a20.output ${SLURM_SUBMIT_DIR}
cp ${SCRATCH_DIRECTORY}/*.nc ${SLURM_SUBMIT_DIR}
# happy end
exit 0
- Create one file containing all of the atmospheric variables from the NorESM model. Duplicate timesteps are ignored.
export SKIP_SAME_TIME=1
cdo mergetime CO2.cam2.hmlvl.2* CO2.cam2.hmlvl.2006-2100.nc
- In our case, CLDTOT came in a separate file which then had to be merged with the other atmospheric variables:
cdo merge CLDTOT.cam2.hmlvl.2006-2100.nc atm.cam2.hmlvl.2006-2100.nc NORESM_ATM.cam2.hmlvl.2006-2100.nc
- Create the detrended climatology from hindcast timeseries ERA dataset:
createClimatologyERA.sh
- Create the detrended climatology and remove from teh timeseries to create residuals/deltas:
createDeltasNorESM-atm.sh
This script creates de-trended climatology for 2006-2015 of the ROMS grid interpolated forcing files created using the global AN ERA-INTERIM files. The atmospheric forcing files for the hindcast has already been created for the grid using the toolbox for atmosphere found in my romstools. This script then reads each individual file for each atmospheric variable and calulates the deltas and climatology. The variables used are :
declare -a ERAvars=( cloud lwrad swrad_daymean Pair Qair rain Tair Uwind Vwind )
The CO2 variable was provided in a separate file so a duplicate script for this variable was used: createClimatologyERA-xCO2.sh
This script creates the detrended climatology (2006-2015) and removes it from the timeseries (2006-2100) to create residuals/deltas. These deltas will be added to the climatology created in step 1.
createDeltasNorESM-atm.sh
The script is run twice changing the input file to cover both standard atmospheric variables and CO2:
export pattern="NORESM_ATM.cam2.hmlvl.2006-2100.nc"
export pattern="CO2.cam2.hmlvl.2006-2100.nc"
Finally, we run the script:
interpolateNORESM_using_ESMF.py
This interpolates the ERA climatology and the NorESM deltas to the ROMS grid (A20 in this case). The interpolated deltas are added to the interpolated climatology for each grid point for each timestep. The result is written to a new NetCDF4 file. This result file is the bias-corrected atmospheric forcing file required to run ROMS.