#!/bin/bash #MSUB -r WeightsMask # nom de la requete #MSUB -o Out_WeightsMask # nom du fichier de sortie #MSUB -e Out_WeightsMask # nom du fichier de sortie #MSUB -eo #MSUB -n 4 # Reservation des processeurs pour le job #MSUB -T 1800 # Limite temps (en secondes) #MSUB -q standard #MSUB -Q test #MSUB -p devcmip6 ### =========================================================================== ### ### Creates interpolation weights between ORCA and atmospher grids. ### Interpolates ORCA mask to atmosphere grid. ### Weight files are at OASIS-MCT format. ### ### Atmosphere grid may be lon/lat LMDZ or DYNAMICO icosahedron ### ### Documentation : https://forge.ipsl.jussieu.fr/igcmg/wiki/IPSLCM6/MOSAIX ### =========================================================================== ## ## Warning, to install, configure, run, use any of Olivier Marti's ## software or to read the associated documentation you'll need at least ## one (1) brain in a reasonably working order. Lack of this implement ## will void any warranties (either express or implied). ## O. Marti assumes no responsability for errors, omissions, ## data loss, or any other consequences caused directly or indirectly by ## the usage of his software by incorrectly or partially configured ## personal. ## ## SVN information # $Author: omamce $ # $Date: 2018-03-12 11:17:59 +0100 (Mon, 12 Mar 2018) $ # $Revision: 3625 $ # $Id: CreateWeightsMask.bash 3625 2018-03-12 10:17:59Z omamce $ # $Log: $ ## ## Configuration ## =========================================================================== # # Defines models # ============== OCE=ORCA2.3 #OCE=eORCA1.2 #OCE=ORCA025 ATM=ICO30 #ATM=ICO40 #ATM=ICO450 #ATM=LMD9695 #ATM=LMD144X142 # # Defines OCE grids to handle # =========================== ListOCEGRID="T U V" Listorder="1st" # " 2nd ## =========================================================================== ## ## You should not change anything below this line .... ## ## =========================================================================== SUBMIT_DIR=$(pwd) # # Defines computer # ================ if [[ $(hostname) = curie* ]] ; then arch=curie ; center=tgcc ; fi if [[ $(hostname) = irene* ]] ; then arch=irene ; center=tgcc ; fi PROGRAM=$(basename ${0}) case ${arch} in ( curie | irene ) set +vx module unload cdo nco ferret module unload netcdf hdf5 module load python # /2.7.12 module load netcdf/4.3.3.1_hdf5_parallel # Version for XIOS module load nco R_IN=$(ccc_home -u igcmg --cccwork)/IGCM TMPDIR=${SCRATCHDIR}/TMP SUBMIT_DIR=${BRIDGE_MSUB_PWD:-${SUBMIT_DIR}} PROGRAM=${BRIDGE_MSUB_REQNAME} ;; ( * ) exit -1 ;; esac set -x ; set -e mkdir -p ${TMPDIR}/${OCE}x${ATM} || exit 1 cd ${TMPDIR}/${OCE}x${ATM} || exit 1 rm -f * # # Suffixes # --------------------------------------------------------------------------- Listocegrid=${ListOCEGRID~} case ${OCE} in ( *ORC* ) oce=orc ; oce_domain_type=curvilinear ;; esac case ${ATM} in ( *dynamico* ) atm=ico ; atm_domain_type=unstructured ;; ( *ICO* ) atm=ico ; atm_domain_type=unstructured ;; ( *lmd* | *LMD* ) atm=lmd ; atm_domain_type=rectilinear ;; esac # # Format for OASIS files : should be NetCDF3 classic or NetCDF3 64 bits # --------------------------------------------------------------------------- FL_FMT=64bit cp ${SUBMIT_DIR}/bin/interpol.exe . cp ${SUBMIT_DIR}/update_xml.py . ## ## NEMO T point towards ATM - 1st order ## =========================================================================== cp ${R_IN}/OCE/NEMO/${OCE}/${OCE}_coordinates_mask.nc . cp ${R_IN}/ATM/${ATM}/${ATM}_grid.nc . ln -s ${OCE}_coordinates_mask.nc oce_grid.nc ln -s ${ATM}_grid.nc atm_grid.nc echo ${Green}"${OCE} T toward ${ATM} - 1storder"${Norm} cp ${SUBMIT_DIR}/iodef_oce_to_atm.xml iodef.xml python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/file_definition/file[@id="file_src"]/field[@id="mask_src"]' -k name -v maskutil_T python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/domain_definition/domain[@id="domain_src"]' -k type -v ${oce_domain_type} python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/domain_definition/domain[@id="domain_dst"]' -k type -v ${atm_domain_type} python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="file_src"]/field[@id="mask_source"]' -k name -v maskutil_T python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]' -k name -v dia_t${oce}_to_t${atm}_1storder python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="title"]' -t "${OCE} mask interpolated to ${ATM}" python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="source_grid"]' -t ${oce_domain_type} python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="dest_grid"]' -t ${atm_domain_type} python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="order"]' -t 1 python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_src"]' -k type -v ${oce_domain_type} python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]' -k type -v ${atm_domain_type} python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k weight_filename -v rmp_t${oce}_to_t${atm}_1storder.nc python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k order -v 1 cp iodef.xml iodef_t${oce}_to_t${atm}_1storder.xml time /usr/bin/time ccc_mprun ./interpol.exe --mask_src=yes --mask_dst=no ## ## Correct spurious values (extremes) ## =========================================================================== cat < correction_masque.nco where (OceFrac < 0.00001 ) OceFrac=OceFrac.get_miss() ; where (OceFrac > 0.99999 ) OceFrac=1.0 ; OceFrac.delete_miss() ; // Fill masked values to land values where (OceFrac > 1.0 ) OceFrac=0.0 ; where (OceFrac < 0.0 ) OceFrac=0.0 ; EOF ncap2 -h --overwrite --script-file correction_masque.nco dia_t${oce}_to_t${atm}_1storder.nc tmp_dia_t${oce}_to_t${atm}_1storder.nc ; mv tmp_dia_t${oce}_to_t${atm}_1storder.nc dia_t${oce}_to_t${atm}_1storder.nc ncatted -h -a missing_value,OceFrac,d,,"" -a _FillValue,OceFrac,d,,"" dia_t${oce}_to_t${atm}_1storder.nc ## ## Creates mask on ATM grid ## =========================================================================== cp dia_t${oce}_to_t${atm}_1storder.nc dia_t${oce}_to_t${atm}_1storder_mask.nc ncks -h --overwrite -v OceFrac dia_t${oce}_to_t${atm}_1storder_mask.nc ${ATM}_grid_maskFrom_${OCE}.nc ncks -h --append -v aire atm_grid.nc ${ATM}_grid_maskFrom_${OCE}.nc [[ ${atm} = *ico* ]] && ncks -h --append -v bounds_lon,bounds_lat atm_grid.nc ${ATM}_grid_maskFrom_${OCE}.nc cat < creation_masque.nco where (OceFrac > 0.0 ) OceFrac=1 ; where (OceFrac <= 0.0 ) OceFrac=0 ; EOF ncap2 -h --overwrite --script-file creation_masque.nco dia_t${oce}_to_t${atm}_1storder_mask.nc tmp_dia_t${oce}_to_t${atm}_1storder_mask.nc ; mv tmp_dia_t${oce}_to_t${atm}_1storder_mask.nc dia_t${oce}_to_t${atm}_1storder_mask.nc ncrename -h -v OceFrac,OceMask dia_t${oce}_to_t${atm}_1storder_mask.nc ncks -h --append -v OceMask dia_t${oce}_to_t${atm}_1storder_mask.nc ${ATM}_grid_maskFrom_${OCE}.nc ## ## NEMO, other case, towards ATM ## =========================================================================== for order in ${Listorder} ; do case ${order} in ( 1st ) num_order=1 ;; ( 2nd ) num_order=2 ;; esac for OCEGRID in ${ListOCEGRID} ; do ocegrid=${OCEGRID~} if [[ !( ${order} = 1st && ${OCEGRID} = T ) ]] ; then echo ${Green}"${OCE} ${OCEGRID} toward ${ATM} - ${order}order"${Norm} python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/file_definition/file[@id="file_src"]/field[@id="mask_src"]' -k name -v maskutil_${OCEGRID} python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/domain_definition/domain[@id="domain_src"]' -k type -v ${oce_domain_type} python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/domain_definition/domain[@id="domain_dst"]' -k type -v ${atm_domain_type} python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="file_src"]/field[@id="mask_source"]' -k name -v maskutil_${OCEGRID} python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]' -k name -v dia_${ocegrid}${oce}_to_t${atm}_${order}order python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="title"]' -t "${OCE} mask interpolated to ${ATM}" python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="source_grid"]' -t ${oce_domain_type} python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="dest_grid"]' -t ${atm_domain_type} python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="order"]' -t ${num_order} python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_src"]' -k type -v ${oce_domain_type} python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]' -k type -v ${atm_domain_type} python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k order -v ${num_order} python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k weight_filename -v rmp_${ocegrid}${oce}_to_t${atm}_${order}order.nc cp iodef.xml iodef_${ocegrid}${oce}_t${atm}_${order}order.xml time /usr/bin/time ccc_mprun ./interpol.exe --mask_src=yes --mask_dst=yes fi done done ## ## ATM towards NEMO points ## =========================================================================== cp ${SUBMIT_DIR}/iodef_atm_to_oce.xml iodef.xml python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/domain_definition/domain[@id="domain_src"]' -k type -v ${atm_domain_type} python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/domain_definition/domain[@id="domain_dst"]' -k type -v ${oce_domain_type} python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="title"]' -t "${ATM} mask interpolated to ${OCE}" python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="source_grid"]' -t ${atm_domain_type} python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="dest_grid"]' -t ${oce_domain_type} python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_src"]' -k type -v ${atm_domain_type} python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]' -k type -v ${oce_domain_type} for order in ${Listorder} ; do case ${order} in ( 1st ) num_order=1 ;; ( 2nd ) num_order=2 ;; esac python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k order -v ${num_order} python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="order"]' -t ${num_order} for OCEGRID in ${ListOCEGRID} ; do ocegrid=${OCEGRID~} echo ${Green}"${ATM} toward ${OCE} ${OCEGRID} - ${order}order"${Norm} python update_xml.py -i iodef.xml -n 'context[@id="interpol_read"]/file_definition/file[@id="file_dst"]/field[@id="mask_dst"]' -k name -v mask_${OCEGRID} python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="file_dst"]/field[@id="mask_dest"]' -k name -v mask_${OCEGRID} python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]' -k name -v dia_t${atm}_to_${ocegrid}${oce}_${order}order python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k weight_filename -v rmp_t${atm}_to_${ocegrid}${oce}_${order}order.nc cp iodef.xml iodef_t${atm}_to_${ocegrid}${oce}_${order}order.xml time /usr/bin/time ccc_mprun ./interpol.exe --mask_src=yes --mask_dst=yes done done ## ## Change all NetCDF files to NetCDF 3 format (needed for OASIS) ## =========================================================================== for InFile in *.nc ; do if [[ $(ncdump -k ${InFile}) = *netCDF-4* ]] ; then mv ${InFile} tmp_${InFile} ncks --fl_fmt=${FL_FMT} -h tmp_${InFile} ${InFile} fi done ## ## Add time axis and coordinates information ## (needed if files need to be read by XIOS) ## =========================================================================== if [[ ${atm} = ico ]] ; then cat < add_time.nco defdim("time_counter",1) ; OceFrac [time_counter,cell] = OceFrac (:) ; OceMask [time_counter,cell] = OceMask (:) ; EOF ncap2 -O -h -S add_time.nco ${ATM}_grid_maskFrom_${OCE}.nc tmp_${ATM}_grid_maskFrom_${OCE}.nc ; mv tmp_${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}.nc ncks -O --mk_rec time_counter ${ATM}_grid_maskFrom_${OCE}.nc tmp_${ATM}_grid_maskFrom_${OCE}.nc ; mv tmp_${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}.nc ncatted -h \ -a coordinates,OceFrac,c,c,"time_counter cell" \ -a coordinates,OceMask,c,c,"time_counter cell" \ -a coordinates,aire,c,c,"time_counter cell" ${ATM}_grid_maskFrom_${OCE}.nc fi if [[ ${atm} = lmd ]] ; then cat < add_time.nco defdim("time_counter",1) ; OceFrac [time_counter,lat,lon] = OceFrac (:,:) ; OceMask [time_counter,lat,lon] = OceMask (:,:) ; EOF ncap2 -O -h -S add_time.nco ${ATM}_grid_maskFrom_${OCE}.nc tmp_${ATM}_grid_maskFrom_${OCE}.nc ; mv tmp_${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}.nc ncks -O --mk_rec time_counter ${ATM}_grid_maskFrom_${OCE}.nc tmp_${ATM}_grid_maskFrom_${OCE}.nc ; mv tmp_${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}.nc ncatted -h \ -a coordinates,OceFrac,c,c,"time_counter lat lon" \ -a coordinates,OceMask,c,c,"time_counter lat lon" \ -a coordinates,aire,c,c,"time_counter lat lon" ${ATM}_grid_maskFrom_${OCE}.nc fi ## ## Add some information in file headers ## =========================================================================== UUID=$(uuid) NCO="$(ncks --version |& tail -1|sed 's/ncks //')" PYTHON_VER=$( python -i -c "import sys ; print (sys.version.split(' ')[0])" ) for InFile in *${oce}_to_*${atm}_*.nc *${atm}_to_*${oce}_*.nc ${ATM}_grid_maskFrom_${OCE}.nc ; do ncatted -h \ --attribute uuid,global,d,, \ --attribute LongName,global,d,, \ --attribute nco_openmp_thread_number,global,d,, \ --attribute Conventions,global,o,c,"CF-1.6" \ --attribute source,global,o,c,"IPSL Earth system model" \ --attribute group,global,o,c,"ICMC IPSL Climate Modelling Center" \ --attribute Institution,global,o,c,"IPSL https://www.ipsl.fr" \ --attribute Ocean,global,o,c,"${OCE} https://www.nemo-ocean.eu" \ --attribute Atmosphere,global,o,c,"${ATM} http://lmdz.lmd.jussieu.fr" \ --attribute production,global,o,c,"$(finger ${LOGNAME} | head -1 | awk '{print $4, $5}') " \ --attribute originalFiles,global,o,c,"${OCE}_coordinates_mask.nc ${ATM}_grid_mask.nc" \ --attribute associatedFiles,global,o,c,"grids_${OCE}x${ATM}.nc areas_${OCE}x${ATM}.nc masks_${OCE}x${ATM}.nc" \ --attribute directory,global,o,c,"$(pwd)" \ --attribute description,global,o,c,"Fields needed by OASIS-MCT" \ --attribute title,global,o,c,"${InFile}.nc" \ --attribute Program,global,o,c,"Generated by ${PROGRAM}" \ --attribute timeStamp,global,o,c,"$(date)" \ --attribute uuid,global,o,c,"${UUID}" \ --attribute HOSTNAME,global,o,c,"$(hostname)" \ --attribute LOGNAME,global,o,c,"$(whoami)" \ --attribute NCO,global,o,c,"NCO netCDF Operator ${NCO} http://nco.sourceforge.net" \ --attribute Python,global,o,c,"Python version ${PYTHON_VER}" \ --attribute OS,global,o,c,"$(uname -o)" \ --attribute release,global,o,c,"$(uname -r)" \ --attribute hardware,global,o,c,"$(uname -i)" \ --attribute directory,global,o,c,"$(pwd)" \ --attribute description,global,o,c,"Generated with XIOS http://forge.ipsl.jussieu.fr/ioserver and MOSAIX https://forge.ipsl.jussieu.fr/igcmg/browser/TOOLS/MOSAIX" \ --attribute Comment,global,o,c,"Preliminary attempt - Do not trust !" \ --attribute SVN_Author,global,o,c,"$Author: omamce $" \ --attribute SVN_Date,global,o,c,"$Date: 2018-03-12 11:17:59 +0100 (Mon, 12 Mar 2018) $" \ --attribute SVN_Revision,global,o,c,"$Revision: 3625 $" \ --attribute SVN_Id,global,o,c,"$Id: CreateWeightsMask.bash 3625 2018-03-12 10:17:59Z omamce $" \ --attribute SVN_Log,global,o,c,"$Log: $" \ ${InFile} done ## ## Update and complete weights file to fit OASIS requested format ## =========================================================================== cat < add_dim.nco defdim("num_wgts",1) ; weight[n_weight, num_wgts] = weight ; EOF for file in rmp_*${oce}_to_*${atm}_*.nc rmp_*${atm}_to_*${oce}_*.nc ; do mv ${file} xios_${file} ncap2 --fl_fmt=${FL_FMT} -h --script-file add_dim.nco xios_${file} ${file} ncrename -h --dimension n_weight,num_links ${file} ncrename -h --variable src_idx,src_address ${file} ncrename -h --variable dst_idx,dst_address ${file} ncrename -h --variable weight,remap_matrix ${file} case ${file} in ( *1storder.nc ) ncatted -h --attribute map_method,global,o,c,"Conservative Remapping - 1st order" ${file} ;; ( *2ndorder.nc ) ncatted -h --attribute map_method,global,o,c,"Conservative Remapping - 2nd order" ${file} ;; esac ncatted -h --attribute conventions,global,o,c,"SCRIP" ${file} ncatted -h --attribute normalization,global,o,c,"none" ${file} case ${file} in ( rmp_*${oce}_to_t${atm}_* ) ncatted -h \ --attribute title,global,o,c,"Weights ${OCE} to ${ATM}" \ --attribute source_grid,global,o,c,"${oce_domain_type}" \ --attribute dest_grid,global,o,c,"${atm_domain_type}" \ ${file} ;; ( rmp_*${atm}_to_*${oce}_* ) ncatted -h \ --attribute title,global,o,c,"Weights ${ATM} to ${OCE}" \ --attribute source_grid,global,o,c,"${atm_domain_type}" \ --attribute dest_grid,global,o,c,"${oce_domain_type}" \ ${file} ;; esac done ## ## Save results ## =========================================================================== cp ${ATM}_grid_maskFrom_${OCE}.nc ${SUBMIT_DIR} for order in ${Listorder} do cp dia_t${oce}_to_t${atm}_${order}order.nc ${SUBMIT_DIR}/dia_t${OCE}_to_t${ATM}_${order}order.nc cp rmp_t${oce}_to_t${atm}_${order}order.nc ${SUBMIT_DIR}/rmp_t${OCE}_to_t${ATM}_${order}order.nc for grid in ${Listocegrid} ; do cp rmp_t${atm}_to_${grid}${oce}_${order}order.nc ${SUBMIT_DIR}/rmp_t${ATM}_to_${grid}${OCE}_${order}order.nc cp dia_t${atm}_to_${grid}${oce}_${order}order.nc ${SUBMIT_DIR}/dia_t${ATM}_to_${grid}${OCE}_${order}order.nc done done ## ## Creates and save auxiliary files for OASIS ## =========================================================================== bash ${SUBMIT_DIR}/CreateOasisGrids.bash --oce ${OCE} --atm ${ATM} cp areas_${OCE}x${ATM}.nc ${SUBMIT_DIR} cp grids_${OCE}x${ATM}.nc ${SUBMIT_DIR} cp masks_${OCE}x${ATM}.nc ${SUBMIT_DIR} ## =========================================================================== ## ## That's all folk's !!! ## ## ===========================================================================