diff --git a/cmpitool/cmpisetup.py b/cmpitool/cmpisetup.py index d7d1ff6..b91d851 100644 --- a/cmpitool/cmpisetup.py +++ b/cmpitool/cmpisetup.py @@ -29,6 +29,7 @@ def cmpisetup(reanalysis='ERA5'): mlotst Variable object for mixed layer depth thetao Variable object for 3D ocean temperature so Variable object for 3D ocean salinity + o2 Variable object for 3D oxygen in ocean ''' @@ -71,6 +72,13 @@ def __init__ (self, name, variables): mlotst = variable(name='mlotst', obs='C-GLORSv7', depths=['surface'], domain='oce') thetao = variable(name='thetao', obs='EN4', depths=['10m','100m','1000m'], domain='oce') so = variable(name='so', obs='EN4', depths=['10m','100m','1000m'], domain='oce') - - return variable, region, climate_model, siconc, tas, clt, pr, rlut, uas, vas, ua, zg, zos, tos, mlotst, thetao, so + alk = variable(name='alk', obs='GLODAP', depths=['50m','400m','800m','2000m'], domain='oce') + co2 = variable(name='co2', obs='GLODAP', depths=['50m','400m','800m','2000m'], domain='oce') + n = variable(name='n', obs='WOA23', depths=['50m','400m','800m'], domain='oce') + o2 = variable(name='o2', obs='WOA23', depths=['50m','400m','1000m'], domain='oce') + p = variable(name='p', obs='WOA23', depths=['50m','400m','800m'], domain='oce') + zoo = variable(name='zoo', obs='MOPS', depths=['50m'], domain='oce') + phy = variable(name='phy', obs='MOPS', depths=['50m'], domain='oce') + + return variable, region, climate_model, siconc, tas, clt, pr, rlut, uas, vas, ua, zg, zos, tos, mlotst, thetao, so, alk, co2, n, o2, p, zoo, phy diff --git a/cmpitool/cmpitool.py b/cmpitool/cmpitool.py index 4e745e3..793205f 100644 --- a/cmpitool/cmpitool.py +++ b/cmpitool/cmpitool.py @@ -1,5 +1,5 @@ def cmpitool(model_path, models, eval_models=None, out_path='output/', obs_path='obs/' , reanalysis='ERA5', - eval_path=None, time='198912-201411', seasons=['MAM', 'JJA', 'SON', 'DJF'], + eval_path=None, time='198912-201411', seasons=['MAM', 'JJA', 'SON', 'DJF', 'year'], # time changes from time='198912-201411' maskfixes=True, use_for_eval=False, complexity='boxes', verbose=False, biasmaps=False): ''' AUTHORS: @@ -12,7 +12,7 @@ def cmpitool(model_path, models, eval_models=None, out_path='output/', obs_path= INPUT: model_path Path pointing towards the output of your model, preprocessed to be read in by cmiptool - models List of climate model objects to be evaluated via cmiptool + models List of climate model objects to be evaluated via cmiptool eval_models List of climate model objects used as reference for evaluation By default this is set to None, which results in a set of 30 CMIP6 being used @@ -35,7 +35,6 @@ def cmpitool(model_path, models, eval_models=None, out_path='output/', obs_path= for simple lat/lon boxes (boxes) or continents & ocean basins (regions) verbose Boolean to activate verbose output - biasmaps Boolean to activate bias map plots RETURN: @@ -53,9 +52,9 @@ def cmpitool(model_path, models, eval_models=None, out_path='output/', obs_path= else: eval_path=eval_path+'/' - variable, region, climate_model, siconc, tas, clt, pr, rlut, uas, vas, ua, zg, zos, tos, mlotst, thetao, so = cmpisetup() + variable, region, climate_model, siconc, tas, clt, pr, rlut, uas, vas, ua, zg, zos, tos, mlotst, thetao, so, alk, co2, n, o2, p, zoo, phy = cmpisetup() - obs = [siconc, tas, clt, pr, rlut, uas, vas, ua, zg, zos, tos, mlotst, thetao, so] + obs = [siconc, tas, clt, pr, rlut, uas, vas, ua, zg, zos, tos, mlotst, thetao, so, alk, co2, n, o2, p, zoo, phy] ''' If you don't add all variables to obs for your analysis, the missing ones will be skipped. @@ -65,7 +64,7 @@ def cmpitool(model_path, models, eval_models=None, out_path='output/', obs_path= - If you add more variables and generate new .csv files, increase the number 14 accordingly! - If you just skip a variable for your analysis, don't change number_of_implemented_variables! ''' - n_implemented_var = 14 + n_implemented_var = 21 #The CMIP6 models are set up by default in their own function cmip6_models = config_cmip6(climate_model, obs) @@ -150,6 +149,6 @@ def cmpitool(model_path, models, eval_models=None, out_path='output/', obs_path= cmpi = write_fractions(error_fraction, models, regions, seasons, out_path, verbose) plotting_heatmaps(models, regions, seasons, obs, error_fraction, cmpi, out_path, verbose) - + if biasmaps == True: plotting_biasmaps(ds_model, ds_obs , models, seasons, obs, out_path, verbose) diff --git a/cmpitool/loading_models.py b/cmpitool/loading_models.py index 0f4f234..6e1a389 100644 --- a/cmpitool/loading_models.py +++ b/cmpitool/loading_models.py @@ -28,7 +28,12 @@ def loading_models(models, model_path, seasons, time, verbose): for model in tqdm(models): for var in model.variables: for depth in var.depths: - for seas in seasons: + if var.name in ('alk', 'co2', 'zoo', 'phy'): + season = ['year'] + else: + season = seasons + + for seas in season: if verbose: print('loading '+model_path+var.name+'_'+model.name+'_'+time+'_'+depth+'_'+seas+'.nc') intermediate = xr.open_mfdataset(model_path+var.name+'_'+model.name+'_'+time+'_'+depth+'_'+seas+'.nc') diff --git a/cmpitool/loading_obs.py b/cmpitool/loading_obs.py index 2385ce1..c67568b 100644 --- a/cmpitool/loading_obs.py +++ b/cmpitool/loading_obs.py @@ -32,7 +32,12 @@ def loading_obs(obs, obs_path, seasons, verbose): for var in tqdm(obs): for depth in var.depths: - for seas in seasons: + if var.name in ('alk', 'co2', 'zoo', 'phy'): + season = ['year'] + else: + season = seasons + + for seas in season: if verbose: print('loading '+obs_path+var.name+'_'+var.obs+'_'+depth+'_'+seas+'.nc') diff --git a/obs/alk_GLODAP_2000m_year.nc b/obs/alk_GLODAP_2000m_year.nc new file mode 100644 index 0000000..580c162 Binary files /dev/null and b/obs/alk_GLODAP_2000m_year.nc differ diff --git a/obs/alk_GLODAP_400m_year.nc b/obs/alk_GLODAP_400m_year.nc new file mode 100644 index 0000000..271f609 Binary files /dev/null and b/obs/alk_GLODAP_400m_year.nc differ diff --git a/obs/alk_GLODAP_50m_year.nc b/obs/alk_GLODAP_50m_year.nc new file mode 100644 index 0000000..8a515f3 Binary files /dev/null and b/obs/alk_GLODAP_50m_year.nc differ diff --git a/obs/alk_GLODAP_800m_year.nc b/obs/alk_GLODAP_800m_year.nc new file mode 100644 index 0000000..15df092 Binary files /dev/null and b/obs/alk_GLODAP_800m_year.nc differ diff --git a/obs/co2_GLODAP_2000m_year.nc b/obs/co2_GLODAP_2000m_year.nc new file mode 100644 index 0000000..f285125 Binary files /dev/null and b/obs/co2_GLODAP_2000m_year.nc differ diff --git a/obs/co2_GLODAP_400m_year.nc b/obs/co2_GLODAP_400m_year.nc new file mode 100644 index 0000000..78bf8d7 Binary files /dev/null and b/obs/co2_GLODAP_400m_year.nc differ diff --git a/obs/co2_GLODAP_50m_year.nc b/obs/co2_GLODAP_50m_year.nc new file mode 100644 index 0000000..fb99cd9 Binary files /dev/null and b/obs/co2_GLODAP_50m_year.nc differ diff --git a/obs/co2_GLODAP_800m_year.nc b/obs/co2_GLODAP_800m_year.nc new file mode 100644 index 0000000..2cd1bca Binary files /dev/null and b/obs/co2_GLODAP_800m_year.nc differ diff --git a/obs/n_WOA23_400m_DJF.nc b/obs/n_WOA23_400m_DJF.nc new file mode 100644 index 0000000..4fd3d03 Binary files /dev/null and b/obs/n_WOA23_400m_DJF.nc differ diff --git a/obs/n_WOA23_400m_JJA.nc b/obs/n_WOA23_400m_JJA.nc new file mode 100644 index 0000000..e75cf7d Binary files /dev/null and b/obs/n_WOA23_400m_JJA.nc differ diff --git a/obs/n_WOA23_400m_MAM.nc b/obs/n_WOA23_400m_MAM.nc new file mode 100644 index 0000000..8744baa Binary files /dev/null and b/obs/n_WOA23_400m_MAM.nc differ diff --git a/obs/n_WOA23_400m_SON.nc b/obs/n_WOA23_400m_SON.nc new file mode 100644 index 0000000..552df57 Binary files /dev/null and b/obs/n_WOA23_400m_SON.nc differ diff --git a/obs/n_WOA23_50m_DJF.nc b/obs/n_WOA23_50m_DJF.nc new file mode 100644 index 0000000..9de6707 Binary files /dev/null and b/obs/n_WOA23_50m_DJF.nc differ diff --git a/obs/n_WOA23_50m_JJA.nc b/obs/n_WOA23_50m_JJA.nc new file mode 100644 index 0000000..774cae4 Binary files /dev/null and b/obs/n_WOA23_50m_JJA.nc differ diff --git a/obs/n_WOA23_50m_MAM.nc b/obs/n_WOA23_50m_MAM.nc new file mode 100644 index 0000000..b138fac Binary files /dev/null and b/obs/n_WOA23_50m_MAM.nc differ diff --git a/obs/n_WOA23_50m_SON.nc b/obs/n_WOA23_50m_SON.nc new file mode 100644 index 0000000..386acea Binary files /dev/null and b/obs/n_WOA23_50m_SON.nc differ diff --git a/obs/n_WOA23_800m_DJF.nc b/obs/n_WOA23_800m_DJF.nc new file mode 100644 index 0000000..ff6da36 Binary files /dev/null and b/obs/n_WOA23_800m_DJF.nc differ diff --git a/obs/n_WOA23_800m_JJA.nc b/obs/n_WOA23_800m_JJA.nc new file mode 100644 index 0000000..1a9221d Binary files /dev/null and b/obs/n_WOA23_800m_JJA.nc differ diff --git a/obs/n_WOA23_800m_MAM.nc b/obs/n_WOA23_800m_MAM.nc new file mode 100644 index 0000000..bd64275 Binary files /dev/null and b/obs/n_WOA23_800m_MAM.nc differ diff --git a/obs/n_WOA23_800m_SON.nc b/obs/n_WOA23_800m_SON.nc new file mode 100644 index 0000000..baada8e Binary files /dev/null and b/obs/n_WOA23_800m_SON.nc differ diff --git a/obs/o2_WOA23_1000m_DJF.nc b/obs/o2_WOA23_1000m_DJF.nc new file mode 100644 index 0000000..36c1116 Binary files /dev/null and b/obs/o2_WOA23_1000m_DJF.nc differ diff --git a/obs/o2_WOA23_1000m_JJA.nc b/obs/o2_WOA23_1000m_JJA.nc new file mode 100644 index 0000000..0a991ed Binary files /dev/null and b/obs/o2_WOA23_1000m_JJA.nc differ diff --git a/obs/o2_WOA23_1000m_MAM.nc b/obs/o2_WOA23_1000m_MAM.nc new file mode 100644 index 0000000..cc5e9c3 Binary files /dev/null and b/obs/o2_WOA23_1000m_MAM.nc differ diff --git a/obs/o2_WOA23_1000m_SON.nc b/obs/o2_WOA23_1000m_SON.nc new file mode 100644 index 0000000..e28ea7c Binary files /dev/null and b/obs/o2_WOA23_1000m_SON.nc differ diff --git a/obs/o2_WOA23_400m_DJF.nc b/obs/o2_WOA23_400m_DJF.nc new file mode 100644 index 0000000..3acd4bc Binary files /dev/null and b/obs/o2_WOA23_400m_DJF.nc differ diff --git a/obs/o2_WOA23_400m_JJA.nc b/obs/o2_WOA23_400m_JJA.nc new file mode 100644 index 0000000..5758f2b Binary files /dev/null and b/obs/o2_WOA23_400m_JJA.nc differ diff --git a/obs/o2_WOA23_400m_MAM.nc b/obs/o2_WOA23_400m_MAM.nc new file mode 100644 index 0000000..49d2955 Binary files /dev/null and b/obs/o2_WOA23_400m_MAM.nc differ diff --git a/obs/o2_WOA23_400m_SON.nc b/obs/o2_WOA23_400m_SON.nc new file mode 100644 index 0000000..bbcdb93 Binary files /dev/null and b/obs/o2_WOA23_400m_SON.nc differ diff --git a/obs/o2_WOA23_50m_DJF.nc b/obs/o2_WOA23_50m_DJF.nc new file mode 100644 index 0000000..0c8d1ec Binary files /dev/null and b/obs/o2_WOA23_50m_DJF.nc differ diff --git a/obs/o2_WOA23_50m_JJA.nc b/obs/o2_WOA23_50m_JJA.nc new file mode 100644 index 0000000..ad2d996 Binary files /dev/null and b/obs/o2_WOA23_50m_JJA.nc differ diff --git a/obs/o2_WOA23_50m_MAM.nc b/obs/o2_WOA23_50m_MAM.nc new file mode 100644 index 0000000..c96370c Binary files /dev/null and b/obs/o2_WOA23_50m_MAM.nc differ diff --git a/obs/o2_WOA23_50m_SON.nc b/obs/o2_WOA23_50m_SON.nc new file mode 100644 index 0000000..9b120db Binary files /dev/null and b/obs/o2_WOA23_50m_SON.nc differ diff --git a/obs/p_WOA23_400m_DJF.nc b/obs/p_WOA23_400m_DJF.nc new file mode 100644 index 0000000..f609433 Binary files /dev/null and b/obs/p_WOA23_400m_DJF.nc differ diff --git a/obs/p_WOA23_400m_JJA.nc b/obs/p_WOA23_400m_JJA.nc new file mode 100644 index 0000000..383595d Binary files /dev/null and b/obs/p_WOA23_400m_JJA.nc differ diff --git a/obs/p_WOA23_400m_MAM.nc b/obs/p_WOA23_400m_MAM.nc new file mode 100644 index 0000000..a1756a5 Binary files /dev/null and b/obs/p_WOA23_400m_MAM.nc differ diff --git a/obs/p_WOA23_400m_SON.nc b/obs/p_WOA23_400m_SON.nc new file mode 100644 index 0000000..7b73a15 Binary files /dev/null and b/obs/p_WOA23_400m_SON.nc differ diff --git a/obs/p_WOA23_50m_DJF.nc b/obs/p_WOA23_50m_DJF.nc new file mode 100644 index 0000000..1d50cba Binary files /dev/null and b/obs/p_WOA23_50m_DJF.nc differ diff --git a/obs/p_WOA23_50m_JJA.nc b/obs/p_WOA23_50m_JJA.nc new file mode 100644 index 0000000..66526b7 Binary files /dev/null and b/obs/p_WOA23_50m_JJA.nc differ diff --git a/obs/p_WOA23_50m_MAM.nc b/obs/p_WOA23_50m_MAM.nc new file mode 100644 index 0000000..8bb56d5 Binary files /dev/null and b/obs/p_WOA23_50m_MAM.nc differ diff --git a/obs/p_WOA23_50m_SON.nc b/obs/p_WOA23_50m_SON.nc new file mode 100644 index 0000000..bd5f7b5 Binary files /dev/null and b/obs/p_WOA23_50m_SON.nc differ diff --git a/obs/p_WOA23_800m_DJF.nc b/obs/p_WOA23_800m_DJF.nc new file mode 100644 index 0000000..160eb61 Binary files /dev/null and b/obs/p_WOA23_800m_DJF.nc differ diff --git a/obs/p_WOA23_800m_JJA.nc b/obs/p_WOA23_800m_JJA.nc new file mode 100644 index 0000000..6678c79 Binary files /dev/null and b/obs/p_WOA23_800m_JJA.nc differ diff --git a/obs/p_WOA23_800m_MAM.nc b/obs/p_WOA23_800m_MAM.nc new file mode 100644 index 0000000..f77d164 Binary files /dev/null and b/obs/p_WOA23_800m_MAM.nc differ diff --git a/obs/p_WOA23_800m_SON.nc b/obs/p_WOA23_800m_SON.nc new file mode 100644 index 0000000..e29b6e3 Binary files /dev/null and b/obs/p_WOA23_800m_SON.nc differ diff --git a/obs/phy_MOPS_50m_year.nc b/obs/phy_MOPS_50m_year.nc new file mode 100644 index 0000000..d77e5c2 Binary files /dev/null and b/obs/phy_MOPS_50m_year.nc differ diff --git a/obs/zoo_MOPS_50m_year.nc b/obs/zoo_MOPS_50m_year.nc new file mode 100644 index 0000000..2366522 Binary files /dev/null and b/obs/zoo_MOPS_50m_year.nc differ diff --git a/preprocessing_examples/Preprocessing_geochemical.sh b/preprocessing_examples/Preprocessing_geochemical.sh new file mode 100755 index 0000000..df9e48a --- /dev/null +++ b/preprocessing_examples/Preprocessing_geochemical.sh @@ -0,0 +1,160 @@ +#!/bin/bash + +Help() +{ + # Display Help + echo "##############################################################################" + echo "# This is an example script preparing climate output without CMOR complient #" + echo "# output from the cmip-tool #" + echo "# Author: Jan Streffing/Lina Lucas 2024-03-10 #" + echo "##############################################################################" + echo "Positional arguments:" + echo "#1 The original path to folder of ocean and atmosphere model data" + echo "#2 Path where the Pre-preprocessed data should be stored" + echo "#3 Path where preprocessed data should be stored" + echo "#4 Name of the climate model (your free choice!)" + echo "#5 Start year of analysed period" + echo "#6 End year of analysed period" + echo "Positional optional argument:" + echo "#7 Set to true when temporary data (tmpstr) should be deleted" + echo "#################################################" + echo "# example: ./Preprocessing_geochemical.sh /home/llucas /home/llucas/CMPI_data/BM /home/llucas/cmpitool/preprocessed_data FOCI1.20.0-CC104_RCP_ESM_spinup2089 2009 2010 true" +} + +# Check if the script was called with the help option +if [[ $1 == "--help" ]]; then + Help + exit 0 # Exit successfully after displaying help +fi + +printf "##########################\n" +printf "# read command line args #\n" +printf "##########################\n" +origdir=$1 # The original path to folder of ocean and atmosphere model data +predata=$2 # Path where the Pre-preprocessed data should be stored +outdir=$3 # Path where preprocessed data should be stored +model_name=$4 # Name of the climate model +starty=$5 # Start year of analysed period +endy=$6 # End year of analysed period +deltmp=${7} # Set to true when temporary data (tmpstr) should be deleted + + +# Create folder of predata and go into the path of the Pre-preprocessed data +mkdir -p $predata +mkdir -p $outdir +cd $predata +tmpstr="analysis_cmpi_period" + + +# Delete files in the predata and out directory so the code can work properly +printf "##############################################\n" +printf "# clean up so we can create new files #\n" +printf "##############################################\n" + +rm -f ${predata}/* +rm -f ${predata}/* +rm -f ${outdir}/*${model_name}_${starty}-${endy}* +wait + + +printf "#################\n" +printf "# Loading files and selecting variables and timeperiod #\n" +printf "#################\n" + +# Atmosphere 1 +for var in ALK DIC DIN O2 PO4 ZOO PHY; +do + cdo -select,startdate=${starty}-01-01T00:00:00,enddate=${endy}-01-01T00:00:00,name=${var} ${origdir}/${model_name}_1m_*_ptrc_T.nc ${var}_${starty}-${endy}.nc +done +wait + + +cd $outdir + + +printf "#################\n" +printf "# ALK and DIC #\n" +printf "#################\n" + +# Interpolating levels +for var in ALK DIC; +do + cdo -L -intlevel,50,400,800,2000 -setctomiss,0 ${predata}/${var}_${starty}-${endy}.nc ${var}_${tmpstr}_int.nc +done +wait + +# Split levels, change names, remap +cdo -L -splitlevel -chname,ALK,alk -remapbil,r180x91 ALK_${tmpstr}_int.nc alk_${tmpstr}_remap_ +cdo -L -splitlevel -chname,DIC,co2 -remapbil,r180x91 DIC_${tmpstr}_int.nc co2_${tmpstr}_remap_ +wait + +# Adjust names +for lvl in 50 400 800 2000; +do + mv -f alk_${tmpstr}_remap_$(printf "%06d" $lvl).nc alk_${model_name}_${starty}-${endy}_${lvl}m_year.nc + mv -f co2_${tmpstr}_remap_$(printf "%06d" $lvl).nc co2_${model_name}_${starty}-${endy}_${lvl}m_year.nc +done + + + +printf "#################\n" +printf "# DIN, O2, PO4 for seasonal means #\n" +printf "#################\n" + +# Interpolating levels +cdo -L -intlevel,50,400,800 -setctomiss,0 ${predata}/DIN_${starty}-${endy}.nc DIN_${tmpstr}_int.nc +cdo -L -intlevel,50,400,800 -setctomiss,0 ${predata}/PO4_${starty}-${endy}.nc PO4_${tmpstr}_int.nc +cdo -L -intlevel,50,400,1000 -setctomiss,0 ${predata}/O2_${starty}-${endy}.nc O2_${tmpstr}_int.nc +wait + +# Split levels, change names, remap +cdo -L -splitlevel -chname,DIN,n -remapbil,r180x91 DIN_${tmpstr}_int.nc n_${tmpstr}_remap_ +cdo -L -splitlevel -chname,PO4,p -remapbil,r180x91 PO4_${tmpstr}_int.nc p_${tmpstr}_remap_ +cdo -L -splitlevel -chname,O2,o2 -remapbil,r180x91 O2_${tmpstr}_int.nc o2_${tmpstr}_remap_ +wait + +# Split seasons +for lvl in 50 400 800; +do + cdo -L splitseas -yseasmean n_${tmpstr}_remap_$(printf "%06d" $lvl).nc n_${model_name}_${starty}-${endy}_${lvl}m_ & + cdo -L splitseas -yseasmean p_${tmpstr}_remap_$(printf "%06d" $lvl).nc p_${model_name}_${starty}-${endy}_${lvl}m_ & +done + +for lvl in 50 400 1000; +do + cdo -L splitseas -yseasmean o2_${tmpstr}_remap_$(printf "%06d" $lvl).nc o2_${model_name}_${starty}-${endy}_${lvl}m_ & +done +wait + + +printf "#################\n" +printf "# ZOO and PHY #\n" +printf "#################\n" + +# Interpolating levels +for var in ZOO PHY; +do + cdo -L -intlevel,50 -setctomiss,0 ${predata}/${var}_${starty}-${endy}.nc ${var}_${tmpstr}_int.nc +done +wait + +# Split levels, change names, remap +cdo -L -splitlevel -chname,ZOO,zoo -remapbil,r180x91 ZOO_${tmpstr}_int.nc zoo_${tmpstr}_remap_ +cdo -L -splitlevel -chname,PHY,phy -remapbil,r180x91 PHY_${tmpstr}_int.nc phy_${tmpstr}_remap_ +wait + +# Adjust names +for lvl in 50; +do + mv -f zoo_${tmpstr}_remap_$(printf "%06d" $lvl).nc zoo_${model_name}_${starty}-${endy}_${lvl}m_year.nc + mv -f phy_${tmpstr}_remap_$(printf "%06d" $lvl).nc phy_${model_name}_${starty}-${endy}_${lvl}m_year.nc +done + + + +# If deltmp set to true, deleting all the temporary files +if $deltmp; then + printf "Deleting tmp data\n" + rm -rf *${tmpstr}* + rm -rf *_int* +fi