Ignore:
Timestamp:
06/07/18 15:59:11 (6 years ago)
Author:
omamce
Message:

O.M. : add weight for coastal points only, to prepare computation

of weights for river run-off

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TOOLS/MOSAIX/CreateWeightsMask.bash

    r3734 r3901  
    3636#  $Id$ 
    3737#  $HeadURL$ 
     38export Bold=$(tput bold)   
     39export Unde=$(tput smul) ; export OffUnde=$(tput rmul) 
     40export Stou=$(tput smso) ; export OffStou=$(tput rmso) 
     41export Reve=$(tput rev )  
     42couleurs=( "Black" "Blue" "Green" "Cyan" "Red" "Magenta" "Yellow" "White" ) 
     43for i in $(seq 0 7 ) ; do eval "export ${couleurs[$i]}=$(tput setf $i)" ; done 
     44export Norm=$(tput sgr0 ) 
    3845 
    3946## 
     
    5865# =========================== 
    5966ListOCEGRID="T U V" 
    60 ListOrder="1st" # " 2nd 
     67ListOrder="1st" # 2nd" 
    6168ListNormalize="false true" 
    6269 
     
    7178# Defines computer 
    7279# ================ 
    73 if [[ $(hostname) = curie* ]]    ; then arch=curie ; center=tgcc ; fi 
    74 if [[ $(hostname) = irene* ]]    ; then arch=irene ; center=tgcc ; fi 
     80if [[ $(hostname) = curie*    ]] ; then arch=curie ; center=tgcc ; fi 
     81if [[ $(hostname) = irene*    ]] ; then arch=irene ; center=tgcc ; fi 
    7582if [[ $(hostname) = lsce3005* ]] ; then arch=spip  ; center=spip ; fi 
    7683 
     
    95102    MPIRUN=/opt/local/bin/mpirun-openmpi-gcc49 -n 2 
    96103    ;;  
    97     ( * ) 
    98     exit -1 
    99     ;; 
     104    ( * ) exit -1 ;; 
    100105esac 
    101106 
     
    127132# Format for OASIS files : should be NetCDF3 classic or NetCDF3 64 bits 
    128133# --------------------------------------------------------------------------- 
    129 FL_FMT=64bit 
     134FMT_OASIS=64bit 
     135FMT_XIOS=netcdf4 
    130136 
    131137 
     
    133139cp ${SUBMIT_DIR}/*.py                . 
    134140 
    135 ## 
    136 ## NEMO T point towards ATM - 1st order 
    137 ## =========================================================================== 
     141 
    138142cp ${R_IN}/OCE/NEMO/${OCE}/${OCE}_coordinates_mask.nc  . 
    139143cp ${R_IN}/ATM/GRID/${ATM}_grid.nc . 
    140144 
    141 ln -s ${OCE}_coordinates_mask.nc  oce_grid.nc 
    142 ln -s ${ATM}_grid.nc              atm_grid.nc 
    143  
     145ncks --overwrite --fl_fmt=${FMT_OASIS} --history ${OCE}_coordinates_mask.nc ${OCE}_coordinates_mask_${FMT_OASIS}.nc 
     146ncks --overwrite --fl_fmt=${FMT_OASIS} --history ${ATM}_grid.nc                    ${ATM}_grid_${FMT_OASIS}.nc 
     147# 
     148# Creates OCEAN C grid : redundant point removed to compute proper integrals # A passer dans CreateWeights 
     149# ---------------------------------------------------------------------------- 
     150cat <<EOF >add_c_grid.nco 
     151nav_lon_grid_C    = nav_lon_grid_T    ; 
     152nav_lat_grid_C    = nav_lat_grid_T    ; 
     153bounds_lon_grid_C = bounds_lon_grid_T ; 
     154bounds_lat_grid_C = bounds_lat_grid_T ; 
     155area_grid_C       = area_grid_T       ; 
     156mask_C            = maskutil_T        ;  
     157EOF 
     158 
     159ncap2 --overwrite --history --script-file add_c_grid.nco ${OCE}_coordinates_mask.nc tmp_${OCE}_coordinates_mask.nc 
     160ncks --overwrite --variable nav_lon_grid_C,nav_lat_grid_C,bounds_lon_grid_C,bounds_lat_grid_C,area_grid_C,mask_C tmp_${OCE}_coordinates_mask.nc C_${OCE}_coordinates_mask.nc 
     161rm tmp_${OCE}_coordinates_mask_${FMT_OASIS}.nc 
     162ncrename --dimension x_grid_T,x_grid_C                C_${OCE}_coordinates_mask.nc 
     163ncrename --dimension y_grid_T,y_grid_C                C_${OCE}_coordinates_mask.nc 
     164ncrename --dimension nvertex_grid_T,nvertex_grid_C    C_${OCE}_coordinates_mask.nc 
     165ncks --append C_${OCE}_coordinates_mask.nc            ${OCE}_coordinates_mask.nc 
     166rm C_${OCE}_coordinates_mask.nc 
     167 
     168ncks --overwrite --fl_fmt=${FMT_OASIS} --history {OCE}_coordinates_mask.nc ${OCE}_coordinates_mask_${FMT_OASIS}.nc 
     169 
     170ls -al 
     171 
     172## 
     173## NEMO T point towards ATM - 1st order 
     174## =========================================================================== 
    144175echo ${Green}"${OCE} T toward ${ATM} - 1storder"${Norm} 
    145176cp ${SUBMIT_DIR}/iodef_oce_to_atm.xml   iodef.xml 
     
    162193 
    163194cp iodef.xml iodef_t${oce}_to_t${atm}_1storder_false.xml 
     195ln -fs ${OCE}_coordinates_mask.nc  oce_grid.nc 
     196ln -fs ${ATM}_grid.nc              atm_grid.nc 
    164197 
    165198time /usr/bin/time ${MPIRUN} ./interpol.exe --mask_src=yes --mask_dst=no 
     
    197230rm dia_t${oce}_to_t${atm}_1storder_false_mask.nc 
    198231 
    199 ## 
    200 ## Creates mask of coastal OCE points 
    201 ## =========================================================================== 
    202 python ComputeNemoCoast.py  -n ${OcePerio} -i oce_grid.nc 
    203  
    204 ## 
    205 ## Creates mask of coastal ATM points 
    206 ## =========================================================================== 
    207 cat <<EOF > coastal.nco 
    208 AtmCoastal = OceFrac * 0.0 ; 
    209 where (OceFrac > 0.0 && OceFrac < 1.0 )  AtmCoastal = 1.0 ; 
    210 EOF 
    211 ncap2 --history --overwrite --script-file coastal.nco ${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_coastal_maskFrom_${OCE}.nc 
    212 ncks --history --append --variable AtmCoastal ${ATM}_coastal_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}.nc 
    213 rm ${ATM}_coastal_maskFrom_${OCE}.nc 
     232 
    214233 
    215234## 
     
    247266                cp iodef.xml iodef_${ocegrid}${oce}_t${atm}_${order}order_${normalize}.xml 
    248267                 
     268                ln -fs ${OCE}_coordinates_mask.nc  oce_grid.nc 
     269                ln -fs ${ATM}_grid.nc              atm_grid.nc 
    249270                time /usr/bin/time ${MPIRUN} ./interpol.exe --mask_src=yes --mask_dst=yes 
    250271            fi 
     
    288309            cp iodef.xml iodef_t${atm}_to_${ocegrid}${oce}_${order}order_${normalize}.xml 
    289310             
     311            ln -fs ${OCE}_coordinates_mask.nc  oce_grid.nc 
     312            ln -fs ${ATM}_grid.nc              atm_grid.nc 
    290313            time /usr/bin/time ${MPIRUN} ./interpol.exe --mask_src=yes --mask_dst=yes 
    291314             
     
    294317done 
    295318 
     319## 
     320## Creates mask of coastal OCE points 
     321## =========================================================================== 
     322python ComputeNemoCoast.py -n ${OcePerio} -i ${OCE}_coordinates_mask.nc # Creates OceCoastal 
     323## 
     324## Creates mask of coastal ATM points 
     325## =========================================================================== 
     326cat <<EOF > coastal.nco 
     327AtmCoastal = OceFrac * 0.0 ; 
     328where (OceFrac > 0.0 && OceFrac < 1.0 )  AtmCoastal = 1.0 ; 
     329EOF 
     330ncap2 --history --overwrite --script-file coastal.nco ${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_coastal_maskFrom_${OCE}.nc 
     331ncks --history --append --variable AtmCoastal ${ATM}_coastal_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}.nc 
     332rm ${ATM}_coastal_maskFrom_${OCE}.nc 
     333ncks --alphabetize --history --overwrite --fl_fmt=${FMT_OASIS} ${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}_${FMT_OASIS}.nc 
    296334## 
    297335## ATM towards NEMO points - runoff 
     
    312350    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 AtmCoastal 
    313351    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 OceCoastal 
    314     python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]'                               -k name  -v dia_c${atm}_to_t${oce}_1storder_${normalize} 
    315     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_c${atm}_to_t${oce}_1storder_${normalize}.nc 
     352    python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]'                               -k name  -v dia_o${atm}_to_c${oce}_1storder_${normalize} 
     353    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_o${atm}_to_c${oce}_1storder_${normalize}.nc 
    316354    python update_xml.py -i iodef.xml -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k renormalize     -v ${normalize} 
    317355     
    318     cp iodef.xml iodef_c${atm}_to_t${oce}_1storder_${normalize}.xml 
     356    cp iodef.xml iodef_o${atm}_to_c${oce}_1storder_${normalize}.xml 
    319357     
     358    ln -fs ${OCE}_coordinates_mask.nc  oce_grid.nc 
     359    ln -fs ${ATM}_grid.nc              atm_grid.nc 
    320360    time /usr/bin/time ${MPIRUN} ./interpol.exe --mask_src=yes --mask_dst=yes 
    321 done 
    322 ## 
    323 ## Change all NetCDF files to NetCDF 3 format (needed for OASIS) 
     361 
     362    # Now we should divide weight par source (atm) grid area : run-off is a quantity/s integrated on the grid mox, not a flux  
     363done 
     364## 
     365## Copy all NetCDF files to NetCDF 3 format (needed for OASIS) 
    324366## =========================================================================== 
    325367for InFile in *.nc ; do 
    326     mv ${InFile} tmp_${InFile} 
    327     ncks --alphabetize --fl_fmt=${FL_FMT} --history  tmp_${InFile}  ${InFile} 
     368    OuFile=$(basename ${InFile} .nc)_${FMT_OASIS}.nc 
     369    if [[ ! -f ${OuFile} ]] ; then 
     370        ncks --alphabetize --history --fl_fmt=${FMT_OASIS} ${InFile} ${OuFile} 
     371    fi 
    328372done 
    329373 
     
    334378#ncatted --history -a coordinates,aire,m,c,"lat lon" ${ATM}_grid_maskFrom_${OCE}.nc 
    335379ncap2 --overwrite --history --script 'defdim("time_counter",1) ;' ${ATM}_grid_maskFrom_${OCE}.nc tmp_${ATM}_grid_maskFrom_${OCE}.nc ; mv tmp_${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}.nc 
     380ncks --alphabetize --history --overwrite --fl_fmt=${FMT_OASIS} ${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}_${FMT_OASIS}.nc 
    336381 
    337382if [[ ${atm} = ico ]] ; then 
     
    349394            ${ATM}_grid_maskFrom_${OCE}.nc 
    350395fi 
     396ncks --alphabetize --history --overwrite --fl_fmt=${FMT_OASIS} ${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}_${FMT_OASIS}.nc 
     397 
    351398if [[ ${atm} = lmd ]] ; then 
    352399    cat <<EOF > add_time.nco 
     
    364411fi 
    365412ncks --alphabetize --overwrite --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 
    366  
     413ncks --alphabetize --history --overwrite --fl_fmt=${FMT_OASIS} ${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}_${FMT_OASIS}.nc 
    367414 
    368415## 
     
    373420NCO="$(ncks --version |& tail -1|sed 's/ncks //')" 
    374421PYTHON_VER=$( python -i -c "import sys ; print (sys.version.split(' ')[0])" ) 
    375 for InFile in *${oce}_to_*${atm}_*.nc *${atm}_to_*${oce}_*.nc ${ATM}_grid_maskFrom_${OCE}.nc ; do 
     422for InFile in *${oce}_to_*${atm}_*.nc *${atm}_to_*${oce}_*.nc ${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}_${FMT_OASIS}.nc; do 
    376423    ncatted --history \ 
    377424            --attribute uuid,global,d,,                                           \ 
     
    421468for rmpFile in rmp_*.nc ; do 
    422469    mv ${rmpFile} xios_${rmpFile} 
    423     ncap2 --fl_fmt=${FL_FMT} --history --script-file add_dim.nco xios_${rmpFile} ${rmpFile} 
     470    ncap2 --fl_fmt=${FMT_OASIS} --history --script-file add_dim.nco xios_${rmpFile} ${rmpFile} 
    424471     
    425472    ncrename --history --dimension n_weight,num_links   ${rmpFile} 
     
    460507## =========================================================================== 
    461508for rmpFile in rmp_* ; do 
     509    echo ${rmpFile} 
    462510    a_to_o=false ; o_to_a=false 
    463511    case ${rmpFile} in 
     
    466514    esac 
    467515 
    468     for Grid in t u v c ; do # Identify grids 
    469         case ${rmpFile} in 
    470             (  rmp_${Grid}${oce}_to_?${atm}_*.nc ) ogrid=${Grid} ;; 
    471             (  rmp_?${oce}_to_${Grid}${atm}_*.nc ) agrid=${Grid} ;; 
    472             (  rmp_${Grid}${atm}_to_?${oce}_*.nc ) agrid=${Grid} ;; 
    473             (  rmp_?${atm}_to_${Grid}${oce}_*.nc ) ogrid=${Grid} ;; 
    474         esac 
     516    for Grid in t u v o c ; do # Identify grids 
     517        [[ ${rmpFile} = rmp_${Grid}${oce}_to_?${atm}_*.nc ]] && ogrid=${Grid} 
     518        [[ ${rmpFile} = rmp_?${oce}_to_${Grid}${atm}_*.nc ]] && agrid=${Grid} 
     519        [[ ${rmpFile} = rmp_${Grid}${atm}_to_?${oce}_*.nc ]] && agrid=${Grid} 
     520        [[ ${rmpFile} = rmp_?${atm}_to_${Grid}${oce}_*.nc ]] && ogrid=${Grid} 
    475521    done 
    476522    OGRID=${ogrid^} 
     
    502548EOF 
    503549 
    504     [[ ${o_to_a} = true ]] && ncap2 --history --append --script-file add_varoce.nco oce_grid.nc ${rmpFile} 
     550    [[ ${o_to_a} = true ]] && ncap2 --history --append --script-file add_varoce.nco ${OCE}_coordinates_mask_${FMT_OASIS}.nc ${rmpFile} 
    505551    sed --in-place "s/src_/dst_/g" add_varoce.nco 
    506     [[ ${a_to_o} = true ]] && ncap2 --history --append --script-file add_varoce.nco oce_grid.nc ${rmpFile} 
     552    [[ ${a_to_o} = true ]] && ncap2 --history --append --script-file add_varoce.nco ${OCE}_coordinates_mask_${FMT_OASIS}.nc ${rmpFile} 
    507553                 
    508554    if [[ ${atm} = ico ]] ; then 
     
    532578EOF 
    533579        if [[ ${o_to_a} = true ]] ; then 
    534             ncap2 --history --append --script-file add_varatm.nco ${ATM}_grid_maskFrom_${OCE}.nc ${rmpFile} 
     580            ncap2 --history --append --script-file add_varatm.nco ${ATM}_grid_maskFrom_${OCE}_${FMT_OASIS}.nc ${rmpFile} 
    535581            ncks --alphabetize --history --overwrite --variable src_address,dst_address,remap_matrix,src_grid_dims,src_grid_center_lat,src_grid_center_lon,src_grid_corner_lon,src_grid_corner_lat,src_grid_area,src_grid_imask,dst_grid_dims,dst_grid_center_lat,dst_grid_center_lon,dst_grid_corner_lon,dst_grid_corner_lat,dst_grid_area,dst_grid_imask ${rmpFile} rmp_tmp.nc 
    536582            mv rmp_tmp.nc ${rmpFile} 
     
    539585        sed --in-place "s/dst_/src_/g" add_varatm.nco 
    540586        if [[ ${a_to_o} = true ]] ; then 
    541             ncap2 --history --append --script-file add_varatm.nco ${ATM}_grid_maskFrom_${OCE}.nc ${rmpFile} 
     587            ncap2 --history --append --script-file add_varatm.nco ${ATM}_grid_maskFrom_${OCE}_${FMT_OASIS}.nc ${rmpFile} 
    542588            ncks --alphabetize --history --overwrite --variable src_address,dst_address,remap_matrix,src_grid_dims,src_grid_center_lat,src_grid_center_lon,src_grid_corner_lon,src_grid_corner_lat,src_grid_area,src_grid_imask,dst_grid_dims,dst_grid_center_lat,dst_grid_center_lon,dst_grid_corner_lon,dst_grid_corner_lat,dst_grid_area,dst_grid_imask ${rmpFile} rmp_tmp.nc 
    543589            mv rmp_tmp.nc ${rmpFile} 
     
    573619EOF 
    574620        if [[ ${o_to_a} = true ]] ; then 
    575             ncap2 --history --append --script-file add_varatm.nco ${ATM}_grid_maskFrom_${OCE}.nc ${rmpFile} 
     621            ncap2 --history --append --script-file add_varatm.nco ${ATM}_grid_maskFrom_${OCE}_${FMT_OASIS}.nc ${rmpFile} 
    576622            ncks --alphabetize --history --overwrite --variable src_address,dst_address,remap_matrix,src_grid_dims,src_grid_center_lat,src_grid_center_lon,src_grid_corner_lon,src_grid_corner_lat,src_grid_area,src_grid_imask,dst_grid_dims,dst_grid_center_lat,dst_grid_center_lon,dst_grid_area,dst_grid_imask ${rmpFile} rmp_tmp.nc 
    577623            mv rmp_tmp.nc ${rmpFile} 
     
    580626        sed --in-place "s/dst/src/g" add_varatm.nco 
    581627        if [[ ${a_to_o} = true ]] ; then 
    582             ncap2 --history --append --script-file add_varatm.nco ${ATM}_grid_maskFrom_${OCE}.nc ${rmpFile} 
     628            ncap2 --history --append --script-file add_varatm.nco ${ATM}_grid_maskFrom_${OCE}_${FMT_OASIS}.nc ${rmpFile} 
    583629            ncks --alphabetize --history --overwrite --variable src_address,dst_address,remap_matrix,src_grid_dims,src_grid_center_lat,src_grid_center_lon,src_grid_area,src_grid_imask,dst_grid_dims,dst_grid_center_lat,dst_grid_center_lon,dst_grid_corner_lon,dst_grid_corner_lat,dst_grid_area,dst_grid_imask ${rmpFile} rmp_tmp.nc 
    584630            mv rmp_tmp.nc ${rmpFile} 
     
    586632    fi 
    587633done 
    588  
     634ls -al ${OCE}_coordinates_mask.nc 
    589635## 
    590636## Save results 
Note: See TracChangeset for help on using the changeset viewer.