On-site fixer script for cmorized EC-Earth3 data.
Python code to fix the incorrect longitude eastward shift of half a grid cell by ece2cmor, see ece2cmor issue 553.
The procedure to use the cmor-fixer is described at the EC-Earth portal wiki page Correct cmorised data with the cmor-fixer. That wiki page referes for some description to this README. A pdf print of this page is uploaded in this repository and can be found here.
Issue 731 at the EC-Earth portal is dedicated to this subject.
- netCDF4
- numpy
With the Mamba package manager all the python packages can be installed within one go. For instance, this is certainly beneficial at HPC systems where permissions to install complementary python packages to the default python distribution are lacking.
First, define a mambapath and two aliases in a .bashrc file for later use:
mambapath=${HOME}/mamba/
alias activatemamba='source ${mambapath}/etc/profile.d/conda.sh'
alias activatecmorfixer='activatemamba; conda activate cmorfixer'Download mamba by using wget and install it via the commandline with bash:
# Check whether mambapath is set:
echo ${mambapath}
# Create a backup of an eventual mamba install (and environments) to prevent an accidental overwrite:
if [ -d ${mambapath} ]; then backup_label=backup-`date +%d-%m-%Y`; mv -f ${mambapath} ${mambapath/mamba/mamba-${backup_label}}; fi
# Download & install mamba:
mkdir -p ${HOME}/Downloads; cd ${HOME}/Downloads/
wget "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-$(uname)-$(uname -m).sh"
bash Miniforge3-$(uname)-$(uname -m).sh -b -u -p ${mambapath}
# Update mamba:
activatemamba
mamba update -y --name base mambaFor example we create the directoy ${HOME}/cmorize/ for the cmor-fixer:
git clone git@github.com:EC-Earth/cmor-fixer.gitactivatemamba # The mamba-activate alias (as defined above)
cd ${HOME}/cmorize/cmor-fixer # Navigate to the cmor-fixer root directory
mamba env create -f environment.yml # Create the python environment (for linux & mac os)
conda activate cmorfixer # Here conda is still used instead of mamba
conda deactivate # Deactivating the active (here cmorfixer) environment # Activate the cmor-fixer conda environment:
activatecmorfixer # The alias as defined above
# Run the help of the cmor-fixer, it lists its argument options:
./cmor-fixer.py -h
# A dry-run example which, due to the --forceid option, will give a new tracking id to any file
# encountered including files with correct lon data:
./cmor-fixer.py --verbose --forceid --olist log-dir --npp 1 --dry CMIP6/
conda deactivate # Deactivating the active (here cmorfixer) environment # Activate the cmor-fixer conda environment:
activatecmorfixer # The mamba-activate alias (as defined above)
cd ${HOME}/cmorize/cmor-fixer # Navigate to the cmor-fixer root directory
conda deactivate # Deactivating the active (here cmorfixer) environment
# An example in which cmor fixer is applying the lon & lon_bnds fix to the data:
./cmor-fixer.py --verbose --forceid --olist log-dir --npp 1 CMIP6/
conda deactivateThe cmor-fixer-safe-mode-wrapper.sh script will only apply changes if at least one file with one error is detected in the entire dataset. In case an error is detected and the script will continue to apply changes, additional checks will be applied to check for interuptions during running the script.
# Activate the cmor-fixer conda environment:
activatecmorfixer # The mamba-activate alias (as defined above)
./cmor-fixer-safe-mode-wrapper.sh 1 CMIP6/
conda deactivate
The submit-cmor-fixer.sh script is an sbatch template for a submit script which needs adjustments of all the paths and possibly adjustent of the cmor-fixer arguments depending on the preferences of the user. The script can be called (it activates the cmor environment itself at the compute node) by:
sbatch submit-cmor-fixer.shIn collaboration with NSC a container environment has been established, see the cmor-fixer wiki for its installation and its use.
# Activate the cmor-fixer conda environment:
activatecmorfixer # The mamba-activate alias (as defined above)
# An example in which cmor fixer is applying the lon & lon_bnds fix to the data:
./cmor-fixer.py --verbose --keepid --olist log-dir --npp 1 CMIP6/
conda deactivateFirst run the version.sh script, for its help use:
./versions.sh -hIn order to see whether there is more than one version in your data:
./versions.sh -l CMIP6/If so (this happens when during running the script the date changed because you crossed midnight), you need to set one version (you can choose what you want, but it should be a different and later date than the one which was previously published). One can set the date for instance to January 20 2020 by:
./versions.sh -v v20200120 -m CMIP6/./files-per-year.sh 1850 2014 CMIP6
conda deactivate # Leaving the cmorfixer environment due to trouble with installing nctime
activatemamba # Only needed when not done before (doesn't harm to do it twice)
cd nctime/
./run-nctime-for-cmip6.sh CMIP6 # This will install nctime directly in the mamba environment en run it
With
ncdump -v lon some-cmorised-file.nc
ncdump -v lon_bnds some-cmorised-file.nc
one can easily see the lon & lon_bnds values.
Incorrect lon values start at 0.3515625 like:
lon = 0.3515625, 1.0546875, 1.7578125, 2.4609375, 3.1640625, 3.8671875,
while correct lon values start at 0 like:
lon = 0, 0.703125, 1.40625, 2.109375, 2.8125, 3.515625, 4.21875, 4.921875,
Incorrect lon_bnds values start at 0, 0.703125 like:
lon_bnds =
0, 0.703125,
0.703125, 1.40625,
1.40625, 2.109375,
2.109375, 2.8125,
2.8125, 3.515625,
3.515625, 4.21875,
4.21875, 4.921875,
4.921875, 5.625,
5.625, 6.328125,
while correct lon_bnds values start at -0.3515625, 0.3515625 like:
lon_bnds =
-0.3515625, 0.3515625,
0.3515625, 1.0546875,
1.0546875, 1.7578125,
1.7578125, 2.4609375,
2.4609375, 3.1640625,
3.1640625, 3.8671875,
3.8671875, 4.5703125,
4.5703125, 5.2734375,
5.2734375, 5.9765625,
5.9765625, 6.6796875,
Because the error and the fix are in the coordinate values itself, diffing the files well is slightly complicated. The best way to inspect the changes in a file after fixing is to make a ncdump of the file before fixing and a ncdump of the file after fixing and thereafter use meld to compare them (it takes a while before meld manages to load). You will then see that the lon and/or lon_bnds values are shifted half a gird cell westwards (lower), that the tracking_idis changed and that a message is added to the netcdf history attribute telling that @cmor-fixer@ has modified the file.