Changeset 4259


Ignore:
Timestamp:
02/07/19 10:04:07 (2 years ago)
Author:
omamce
Message:

O.M. : MOSAIX

  • Two versions of fraction on atmosphere grid to be compatible with both DYNAMICO and LMDZ
  • Various improvments
Location:
TOOLS/MOSAIX
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • TOOLS/MOSAIX/CalvingWeights.py

    r4199 r4259  
    347347v_remap_matrix = f_calving.createVariable ( 'remap_matrix', 'f8', ('num_links', 'num_wgts') ) 
    348348v_src_address  = f_calving.createVariable ( 'src_address' , 'i4', ('num_links',) ) 
    349 v_src_address  = f_calving.createVariable ( 'dst_address' , 'i4', ('num_links',) ) 
     349v_src_address.convention = "Fortran style addressing, starting at 1" 
     350v_dst_address  = f_calving.createVariable ( 'dst_address' , 'i4', ('num_links',) ) 
     351v_dst_address.convention = "Fortran style addressing, starting at 1" 
    350352 
    351353v_remap_matrix[:] = remap_matrix 
    352354v_src_address [:] = src_address 
    353 v_src_address [:] = src_address 
     355v_dst_address [:] = dst_address 
    354356 
    355357v_src_grid_dims       = f_calving.createVariable ( 'src_grid_dims'      , 'i4', ('src_grid_rank',) ) 
  • TOOLS/MOSAIX/CreateOasisGrids.bash

    r4199 r4259  
    178178 
    179179ncks --history -C --variable OceMask         ${ATM}_grid_maskFrom_${OCE}.nc OceMask_tmp.nc 
    180 ncwa --history --overwrite --average time_counter OceMask_tmp.nc OceMask_tmp2.nc # Suppress time dimension 
     180#ncwa --history --overwrite --average time_counter OceMask_tmp.nc OceMask_tmp2.nc # Suppress time dimension 
    181181ncatted --history \ 
    182182        --attribute cell_methods,OceMask,d,c,       \ 
     
    186186        --attribute missing_value,OceMask,d,,       \ 
    187187        OceMask_tmp.nc 
    188 ncap2 --history --append --script "OceMask=int(1-OceMask)" OceMask_tmp2.nc masks_${CplModel}.nc # For OASIS, ocean=0, land=1 
     188ncap2 --history --append --script "OceMask=int(1-OceMask)" OceMask_tmp.nc masks_${CplModel}.nc # For OASIS, ocean=0, land=1 
    189189rm OceMask_tmp.nc 
    190190ncatted --history \ 
     
    398398done 
    399399 
     400 
     401echo ${Titre}"Add time axis and coordinates information"${Norm} 
     402# (needed if files need to be read by XIOS) ??? 
     403## =========================================================================== 
     404ncap2 --overwrite --history --script 'defdim("time_counter",1) ;' ${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}_time.nc 
     405 
     406if [[ ${atm} = ico ]] ; then 
     407    cat <<EOF > add_time.nco 
     408OceFrac    [time_counter,cell] = OceFrac    [cell] ; 
     409OceMask    [time_counter,cell] = OceMask    [cell] ; 
     410EOF 
     411    ncap2 --overwrite --history --script-file add_time.nco ${ATM}_grid_maskFrom_${OCE}_time.nc tmp_${ATM}_grid_maskFrom_${OCE}_time.nc ; mv tmp_${ATM}_grid_maskFrom_${OCE}_time.nc ${ATM}_grid_maskFrom_${OCE}_time.nc 
     412    ncatted --history \ 
     413            -a coordinates,OceFrac,m,c,"time_counter lat lon"    \ 
     414            -a coordinates,OceMask,m,c,"time_counter lat lon"    \ 
     415            -a coordinates,aire,c,c,"lat lon" \ 
     416            ${ATM}_grid_maskFrom_${OCE}.nc 
     417fi 
     418 
     419if [[ ${atm} = lmd ]] ; then 
     420    cat <<EOF > add_time.nco 
     421OceFrac    [time_counter,lat,lon] = OceFrac    [lat,lon] ; 
     422OceMask    [time_counter,lat,lon] = OceMask    [lat,lon]  ; 
     423EOF 
     424    ncap2 --overwrite --history --script-file add_time.nco ${ATM}_grid_maskFrom_${OCE}_time.nc tmp_${ATM}_grid_maskFrom_${OCE}_time.nc 
     425    ncdump -h tmp_${ATM}_grid_maskFrom_${OCE}_time.nc 
     426    mv tmp_${ATM}_grid_maskFrom_${OCE}_time.nc ${ATM}_grid_maskFrom_${OCE}_time.nc 
     427     
     428    ncatted --history \ 
     429            -a coordinates,OceFrac,m,c,"time_counter lat lon"    \ 
     430            -a coordinates,OceMask,m,c,"time_counter lat lon"    \ 
     431            -a coordinates,aire,m,c,"lat lon" \ 
     432            ${ATM}_grid_maskFrom_${OCE}.nc 
     433fi 
     434ncks --alphabetize --history --overwrite --mk_rec time_counter ${ATM}_grid_maskFrom_${OCE}_time.nc tmp_${ATM}_grid_maskFrom_${OCE}_time.nc 
     435mv tmp_${ATM}_grid_maskFrom_${OCE}_time.nc ${ATM}_grid_maskFrom_${OCE}_time.nc 
    400436## 
    401437echo ${Titre}"Add some useful information in NetCDF headers"${Norm} 
  • TOOLS/MOSAIX/CreateWeightsMask.bash

    r4199 r4259  
    4646export Reve=$(tput rev )  
    4747couleurs=( "Black" "Blue" "Green" "Cyan" "Red" "Magenta" "Yellow" "White" ) 
    48 for i in $(seq 0 7 ) ; do eval "export ${couleurs[$i]}=$(tput setf $i)" ; done 
     48for i in $(seq 0 7) ; do eval "export ${couleurs[$i]}=$(tput setf ${i})" ; done 
    4949export Norm=$(tput sgr0) 
    5050export Titre=${Bold}${Blue} 
     
    5858echo ${Titre}"Defines models"${Norm} 
    5959# ================================== 
    60 OCE=ORCA2.3 
    61 #OCE=eORCA1.2 
     60#OCE=ORCA2.3 
     61OCE=eORCA1.2 
    6262#OCE=eORCA025 
    6363 
    64 ATM=ICO30 
     64#ATM=ICO30 
    6565#ATM=ICO40 
    6666#ATM=ICO450 
    6767#ATM=LMD9695 
    68 #ATM=LMD144142 
     68ATM=LMD144142 
    6969#ATM=LMD256256 
    7070 
     
    116116#   maskDst     : true to use the destination grid mask, false to use all grid points 
    117117# 
    118 # Classic cases for IPSLCM6 
    119 AtmOceFluxes="  Direction=a2o,Order=1st,Quantity=false,Renormalize=false,atmGrid=t,oceGrid=t,useArea=true,maskSrc=true,maskDst=true,Name=HeatWaterFluxes" # Heat and water fluxes 
    120 OceAtmTemp="    Direction=o2a,Order=1st,Quantity=false,Renormalize=true,oceGrid=t,atmGrid=t,useArea=false,maskSrc=true,maskDst=true,Name=TempIceAlb" # Temperature, sea-ice fraction, albedo 
    121 AtmOceStressU=" Direction=a2o,Order=2nd,Quantity=false,Renormalize=false,atmGrid=t,oceGrid=u,useArea=true,maskSrc=true,maskDst=true,Name=WindStress" # Wind stress to NEMO U point 
    122 AtmOceStressV=" Direction=a2o,Order=2nd,Quantity=false,Renormalize=false,atmGrid=t,oceGrid=v,useArea=true,maskSrc=true,maskDst=true,Name=WindStress" # Wind stress to NEMO V point 
    123 AtmOceQuantity="Direction=a2o,Order=1st,Quantity=true,Renormalize=false,atmGrid=t,oceGrid=t,useArea=false,maskSrc=true,maskDst=true,Name=Quantity"   # e.g. runoff 
     118## Classic cases for IPSLCM6 
     119AtmOceFluxes="   Direction=a2o,Order=1st,Quantity=false,Renormalize=false,atmGrid=t,oceGrid=t,useArea=true,maskSrc=true,maskDst=true,Name=HeatWaterFluxes" # Heat and water fluxes 
     120AtmOceFluxes2nd="Direction=a2o,Order=2nd,Quantity=false,Renormalize=false,atmGrid=t,oceGrid=t,useArea=true,maskSrc=true,maskDst=true,Name=HeatWaterFluxes" # Heat and water fluxes 
     121OceAtmTemp="     Direction=o2a,Order=1st,Quantity=false,Renormalize=true,oceGrid=t,atmGrid=t,useArea=false,maskSrc=true,maskDst=true,Name=TempIceAlb" # Temperature, sea-ice fraction, albedo 
     122OceAtmTemp2nd="  Direction=o2a,Order=2nd,Quantity=false,Renormalize=true,oceGrid=t,atmGrid=t,useArea=false,maskSrc=true,maskDst=true,Name=TempIceAlb" # Temperature, sea-ice fraction, albedo 
     123AtmOceStressU="  Direction=a2o,Order=2nd,Quantity=false,Renormalize=false,atmGrid=t,oceGrid=u,useArea=true,maskSrc=true,maskDst=true,Name=WindStress" # Wind stress to NEMO U point 
     124AtmOceStressV="  Direction=a2o,Order=2nd,Quantity=false,Renormalize=false,atmGrid=t,oceGrid=v,useArea=true,maskSrc=true,maskDst=true,Name=WindStress" # Wind stress to NEMO V point 
     125AtmOceQuantity=" Direction=a2o,Order=1st,Quantity=true,Renormalize=false,atmGrid=t,oceGrid=t,useArea=false,maskSrc=true,maskDst=true,Name=Quantity"   # e.g. runoff 
    124126# Other cases 
    125 OceAtmFluxes=" Direction=o2a,Order=1st,Quantity=false,Renormalize=false,atmGrid=t,oceGrid=t,useArea=true,maskSrc=true,maskDst=true,Name=OceAtmFluxes" # e.g. CO2 fluxes 
    126 AtmOceTemp="   Direction=o2a,Order=1st,Quantity=false,Renormalize=true,oceGrid=t,atmGrid=t,useArea=false,maskSrc=true,maskDst=true,Name=OceTemp" # e.g. T and S correction from DWL parametrization 
     127OceAtmFluxes="   Direction=o2a,Order=1st,Quantity=false,Renormalize=false,atmGrid=t,oceGrid=t,useArea=true,maskSrc=true,maskDst=true,Name=OceAtmFluxes" # e.g. CO2 fluxes 
     128OceAtmFluxes2nd="Direction=o2a,Order=2nd,Quantity=false,Renormalize=false,atmGrid=t,oceGrid=t,useArea=true,maskSrc=true,maskDst=true,Name=OceAtmFluxes" # e.g. CO2 fluxes 
     129AtmOceTemp="     Direction=o2a,Order=1st,Quantity=false,Renormalize=true,oceGrid=t,atmGrid=t,useArea=false,maskSrc=true,maskDst=true,Name=OceTemp" # e.g. T and S correction from DWL parametrization 
     130AtmOceTemps2nd=" Direction=o2a,Order=2nd,Quantity=false,Renormalize=true,oceGrid=t,atmGrid=t,useArea=false,maskSrc=true,maskDst=true,Name=OceTemp" # e.g. T and S correction from DWL parametrization 
     131 
     132## Creates the list 
    127133 
    128134# Standard list for IPSLCM6 
    129135#CommandList=( ${AtmOceFluxes} ${OceAtmTemp} ${AtmOceStressU} ${AtmOceStressV} ${OceAtmFluxes} Runoff Calving Grids ) 
    130136 
    131 # More comprehesive list for IPSLCM6 with new features 
    132 CommandList=( ${AtmOceFluxes} ${OceAtmTemp} ${AtmOceStressU} ${AtmOceStressV} ${OceAtmFluxes} ${AtmOceTemp} Runoff Calving Grids ) 
     137# More comprehensive list for IPSLCM6 with new features 
     138#CommandList=( ${AtmOceFluxes} ${OceAtmTemp} ${AtmOceStressU} ${AtmOceStressV} ${OceAtmFluxes} ${AtmOceTemp} Runoff Calving Grids ) 
     139 
     140# With 2nd order 
     141CommandList=( ${AtmOceFluxes} ${AtmOceFluxes2nd} ${OceAtmTemp} ${OceAtmTemp2nd} ${AtmOceStressU} ${AtmOceStressV} ${OceAtmFluxes} ${OceAtmFluxes2nd} ${AtmOceTemp} ${AtmOceTemp2nd} Runoff Calving Grids ) 
    133142 
    134143# Debugs 
    135 #CommandList=( Runoff ) 
    136144#CommandList=( ${AtmOceFluxes} ${OceAtmTemp} Runoff Calving Grids ) 
    137145#CommandList=( ${AtmOceFluxes} Runoff Calving Grids ) 
    138 CommandList=( ${AtmOceFluxes}  ) 
     146#CommandList=( ${AtmOceFluxes}  ) 
     147#CommandList=( Runoff ) 
     148#CommandList=( Runoff Calving Grids ) 
    139149#CommandList=( Calving ) 
    140150#CommandList=( Grids ) 
    141151 
    142  
    143  
    144152## =========================================================================== 
    145153## 
     
    149157Tag="MOSAIX" 
    150158SUBMIT_DIR=$(pwd) 
     159FMT_XIOS=netcdf4 
    151160 
    152161# Functions to handle command parameters 
     
    194203 
    195204    if [[ "${Name}" != "None" ]] ; then 
    196         FullName=${Name} 
     205        FullName=${Name}_${Order}Order 
    197206    else 
    198207        FullName=${Order}Order_${NormName}_${QuantName}_${AreaName} 
     
    224233    ( irene ) 
    225234    set +vx 
     235    set +e 
    226236    R_IN=$(ccc_home -u igcmg --cccwork)/IGCM 
    227237    TMPDIR=${CCCWORKDIR}/TMP 
     
    230240    MpiRun="time ccc_mprun" 
    231241    PyRun="time ccc_mprun -n 1" # Needed to force python to run on one process only 
     242    #module purge 
     243    source $(ccc_home -u igcmg)/MachineEnvironment/irene/env_irene 
    232244    source ${SUBMIT_DIR}/arch.env 
    233     module load nco 
    234     #source $(ccc_home -u igcmg)/MachineEnvironment/irene/env_irene 
     245    #module load nco 
    235246    module load python3  
    236247    module load datadir/igcmg 
    237248    module list 
     249    set -e 
    238250    ;; 
    239251    ( spip ) 
     
    273285esac 
    274286# 
    275 echo ${Titre}"Format for OASIS files : should be NetCDF3 classic or NetCDF3 64 bits"${Norm} 
    276 # --------------------------------------------------------------------------- 
    277 FMT_OASIS=64bit 
    278 FMT_XIOS=netcdf4 
    279287 
    280288cp ${SUBMIT_DIR}/bin/interpol.exe       . 
     
    491499    ${MpiRun} ./interpol.exe --mask_src=${maskSrc} --mask_dst=${maskDst} --use_area=${useArea} 
    492500done 
    493  
    494 echo ${Titre}"Add time axis and coordinates information"${Norm} 
    495 ## (needed if files need to be read by XIOS) 
    496 ## =========================================================================== 
    497 ncap2 --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 
    498  
    499 if [[ ${atm} = ico ]] ; then 
    500     cat <<EOF > add_time.nco 
    501 OceFrac    [time_counter,cell] = OceFrac    [cell] ; 
    502 OceMask    [time_counter,cell] = OceMask    [cell] ; 
    503 EOF 
    504     ncap2 --overwrite --history --script-file 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 
    505     ncatted --history \ 
    506             -a coordinates,OceFrac,m,c,"time_counter lat lon"    \ 
    507             -a coordinates,OceMask,m,c,"time_counter lat lon"    \ 
    508             -a coordinates,aire,c,c,"lat lon" \ 
    509             ${ATM}_grid_maskFrom_${OCE}.nc 
    510 fi 
    511  
    512 if [[ ${atm} = lmd ]] ; then 
    513     cat <<EOF > add_time.nco 
    514 OceFrac    [time_counter,lat,lon] = OceFrac    [lat,lon] ; 
    515 OceMask    [time_counter,lat,lon] = OceMask    [lat,lon]  ; 
    516 EOF 
    517     ncap2 --overwrite --history --script-file add_time.nco ${ATM}_grid_maskFrom_${OCE}.nc tmp_${ATM}_grid_maskFrom_${OCE}.nc 
    518     ncdump -h tmp_${ATM}_grid_maskFrom_${OCE}.nc 
    519     mv tmp_${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}.nc 
    520      
    521     ncatted --history \ 
    522             -a coordinates,OceFrac,m,c,"time_counter lat lon"    \ 
    523             -a coordinates,OceMask,m,c,"time_counter lat lon"    \ 
    524             -a coordinates,aire,m,c,"lat lon" \ 
    525             ${ATM}_grid_maskFrom_${OCE}.nc 
    526 fi 
    527 ncks --alphabetize --history --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 
    528501 
    529502## 
     
    621594echo ${Titre}"Add missing variables in rmp files"${Norm} 
    622595## =========================================================================== 
    623 for rmpFile in $(ls rmp_?${atm}_to_[tuv]${oce}_*.nc rmp_[tuv]${oce}_to_t${atm}_*.nc 2>& /dev/null ) ; do 
     596for rmpFile in $(ls rmp_?${atm}_to_[tuv]${oce}_*.nc rmp_[tuv]${oce}_to_t${atm}_*.nc 2> /dev/null ) ; do 
    624597    echo ${rmpFile} 
    625598    a_to_o=false ; o_to_a=false 
     
    690663dst_grid_area  [dst_grid_size] = 0.0d ; 
    691664dst_grid_frac  [dst_grid_size] = 1.0d ; 
    692 dst_grid_imask (:) = 1 - OceMask(0,:) ; 
     665dst_grid_imask (:) = 1 - OceMask(:) ; 
    693666dst_grid_imask.int() ; 
    694667dst_grid_area  (:) = aire(:) ; 
    695 dst_grid_frac  (:) = OceFrac(0,:) ; 
     668dst_grid_frac  (:) = OceFrac(:) ; 
    696669EOF 
    697670        cp add_varatm.nco add_varatm_$(basename ${rmpFile} .nc)_o_to_a.nco 
     
    734707dst_grid_area  [dst_grid_size] = 0.0d ; 
    735708dst_grid_frac  [dst_grid_size] = 1.0d ; 
    736 dst_grid_imask (:) = 1 - OceMask(0,:,:) ; 
     709dst_grid_imask (:) = 1 - OceMask(:,:) ; 
    737710dst_grid_imask.int() ; 
    738711dst_grid_area  (:) = aire(:,:) ; 
    739 dst_grid_frac (:)  = OceFrac(0,:,:) ; 
     712dst_grid_frac (:)  = OceFrac(:,:) ; 
    740713EOF 
    741714        cp add_varatm.nco add_varatm_$(basename ${rmpFile} .nc)_o_to_a.nco 
     
    767740echo ${Titre}"Runoff weights"${Norm} 
    768741## =========================================================================== 
    769 #if [[ "X${okRunoff}" = "Xyes" && "${atm}" = "lmd" ]] ; then 
    770742if [[ "X${okRunoff}" = "Xyes" ]] ; then 
    771743    ${PyRun} python3 -u RunoffWeights.py --oce=${OCE} --atm=${ATM} \ 
     
    824796echo ${Titre}"Rename rmp and dia files"${Norm} 
    825797## =========================================================================== 
    826 for File in $(ls dia_*.nc rmp_*.nc  2>& /dev/null ); do 
     798for File in $(ls *${oce}*${atm}* *${atm}*${oce}*  2> /dev/null ); do 
    827799    NewFile=$(echo ${File} | sed -e "s/${atm}/${ATM}/" -e "s/${oce}/${OCE}/" ) 
    828     mv ${File} ${SUBMIT_DIR}/${NewFile} 
     800    mv ${File} ${NewFile} 
    829801done 
    830802 
     
    914886EOF 
    915887 
    916 cp README.txt ${SUBMIT_DIR}/README_${CplModel}_MOSAIX.txt 
    917  
     888if [[ "X${Version}" != "X" ]] ; then 
     889    cp README.txt ${SUBMIT_DIR}/README_${CplModel}_MOSAIX_${Version}.txt 
     890else 
     891    cp README.txt ${SUBMIT_DIR}/README_${CplModel}_MOSAIX.txt 
     892fi 
    918893## =========================================================================== 
    919894## 
  • TOOLS/MOSAIX/RunoffWeights.py

    r4199 r4259  
    3232import sys, os, platform, argparse, textwrap, time 
    3333 
    34 ## Userful constants 
     34## Useful constants 
    3535zero    = np.dtype('float64').type(0.0) 
    3636zone    = np.dtype('float64').type(1.0) 
     
    235235    # Address on destination grid 
    236236    oce_address_local = oceCoast_address[z_mask] 
    237     # Append to global tabs 
     237    # Append to global arrays 
    238238    remap_matrix = np.append ( remap_matrix, matrix_local      ) 
    239239    atm_address  = np.append ( atm_address , atm_address_local ) 
     
    257257f_runoff.associatedFiles = grids + " " + areas + " " + masks 
    258258f_runoff.directory       = os.getcwd () 
    259 f_runoff.description     = "Generated with cotes_etal.py" 
     259f_runoff.description     = "Generated with RunoffWeights.py" 
    260260f_runoff.title           = runoff 
    261261f_runoff.Program         = "Generated by " + sys.argv[0] + " with flags " + str(sys.argv[1:]) 
     
    263263f_runoff.oceCoastWidth   = str(oceCoastWidth) + " grid points" 
    264264f_runoff.searchRadius    = str(searchRadius/1000.) + " km" 
     265f_runoff.atmQuantity     = myargs.atmQuantity 
     266f_runoff.oceQuantity     = myargs.oceQuantity 
    265267f_runoff.gridsFile       = grids 
    266268f_runoff.areasFile       = areas 
     
    299301 
    300302v_atm_address  = f_runoff.createVariable ( 'src_address' , 'i4', ('num_links',) ) 
     303v_atm_address.convention = "Fortran style addressing, starting at 1" 
    301304v_oce_address  = f_runoff.createVariable ( 'dst_address' , 'i4', ('num_links',) ) 
     305v_oce_address.convention = "Fortran style addressing, starting at 1" 
    302306 
    303307v_remap_matrix[:] = remap_matrix 
    304 v_atm_address [:] = atm_address + 1 # OASIS uses Fortran style indexing 
     308v_atm_address [:] = atm_address + 1 # OASIS uses Fortran style indexing, starting at one 
    305309v_oce_address [:] = oce_address + 1 
    306310 
  • TOOLS/MOSAIX/make_mosaix

    r4102 r4259  
    2121            echo "make_xios [options]" 
    2222            echo "options :" 
    23             echo "       [--xios path] : path to XIOS. Default is ../XIOS" 
     23            echo "       [--xios path] : path to XIOS. Default is ${xios_dir}" 
    2424            echo "       [--full]      : to generate dependencies and recompile from scratch" 
    2525            echo "Example : ./make_mosaix --xios ../XIOS" 
     
    5858# Use config.fcm from XIOS 
    5959rm -f ${install_dir}/config.fcm 
    60 #cp ${xios_dir}/config.fcm ${install_dir} 
     60 
    6161echo "%XIOS_DIR      ${xios_dir} "    > ${install_dir}/config.fcm 
    6262cat ${xios_dir}/config.fcm >> ${install_dir}/config.fcm 
  • TOOLS/MOSAIX/nemo.py

    r4083 r4259  
    2121__HeadURL    = "$HeadURL$" 
    2222 
    23 def lbc (ptab, nperio=6, cd_type='T', psgn=1.0) : 
    24     # Set periodicity on input fields 
     23import sys, numpy as np 
     24 
     25def __guessNperio__ (jpi, nperio) : 
    2526    """ 
     27    Tries to guess the value of nperio 
     28    """ 
     29    if nperio == None : 
     30        if jpi ==  182 : nperio = 4 #   ORCA2. We choose legacy orca2 
     31        if jpi ==  362 : nperio = 6 #   ORCA1. 
     32        if jpi == 1442 : nperio = 6 # ORCA025. 
     33        # 
     34        if nperio == None : 
     35            sys.exit ('in nemo.lbc : nperio not found, and cannot by guessed' ) 
     36        else : 
     37            print ('nperio set as {:d} (deduced from jpi={:d}'.format(nperio, jpi)) 
     38 
     39    return nperio     
     40             
     41def lbc (ptab, nperio=None, cd_type='T', psgn=1.0) : 
     42    """ 
     43    Set periodicity on input fields 
    2644    ptab      : Input array 
    27       rank 2 at least : patb[...., lat, lon] 
     45      rank 2 at least : ptab[...., lat, lon] 
    2846    nperio    : Type of periodicity 
    2947      1, 4, 6 : Cyclic on i dimension (generaly longitudes) 
     
    3250      5, 6    : North fold F-point pivot (ORCA1, ORCA025, ORCA2 with new grid for paleo) 
    3351    cd_type   : Grid specification : T, U, V or F 
    34     psgn      : For change of sign for vector components 
     52    psgn      : For change of sign for vector components (1 for scalars, -1 for vector components) 
    3553     
    3654    See NEMO documentation for further details 
    3755    """ 
    3856         
    39     jpi = ptab.shape[-1] 
     57    jpi    = ptab.shape[-1] 
     58    nperio = __guessNperio__ ( jpi, nperio ) 
     59    psgn   = ptab.dtype.type(psgn) 
    4060     
    4161    # 
    4262    #> East-West boundary conditions 
    43     # -------------------------------- 
     63    # ------------------------------ 
    4464 
    4565    if nperio in [1, 4, 6] : 
     
    5070    # 
    5171    #> North-South boundary conditions 
    52     # ---------------------------------- 
    53     if nperio in [3, 4] :  # North fold T-point pivot      
     72    # -------------------------------- 
     73    if nperio in [3, 4] :  # North fold T-point pivot 
    5474        if cd_type in [ 'T', 'W' ] : # T-, W-point 
    5575            ptab[..., -1, 1:       ] = psgn * ptab[..., -3, -1:0:-1      ]       
     
    84104        if cd_type == 'V' : 
    85105            ptab[..., -1, 0:       ] = psgn * ptab[..., -3, -1::-1       ] 
    86             ptab[..., -2, jpi/2:   ] = psgn * ptab[..., -2, jpi/2-1::-1 ] 
     106            ptab[..., -2, jpi//2:  ] = psgn * ptab[..., -2, jpi//2-1::-1 ] 
    87107                              
    88108        if cd_type == 'F' : 
     
    94114 
    95115 
    96 def lbc_mask (ptab, nperio=6, cd_type='T', psgn=1.0) : 
    97     # Mask fields on duplicate points 
     116def lbc_mask (ptab, nperio=None, cd_type='T') : 
     117    # 
    98118    """ 
     119    Mask fields on duplicated points 
    99120    ptab      : Input array 
    100       rank 2 at least : patb[...., lat, lon] 
     121      rank 2 at least : ptab[...., lat, lon] 
    101122    nperio    : Type of periodicity 
    102123      1, 4, 6 : Cyclic on i dimension (generaly longitudes) 
     
    105126      5, 6    : North fold F-point pivot (ORCA1, ORCA025, ORCA2 with new grid for paleo) 
    106127    cd_type   : Grid specification : T, U, V or F 
    107     psgn      : For change of sign for vector components 
    108128     
    109129    See NEMO documentation for further details 
    110130    """ 
    111          
    112     jpi = ptab.shape[-1] 
    113     # 
    114     zero = 0 
     131 
     132    jpi    = ptab.shape[-1] 
     133    nperio = __guessNperio__ ( jpi, nperio ) 
     134    zero   = ptab.dtype.type(0) 
    115135     
    116136    # 
    117137    #> East-West boundary conditions 
    118     # -------------------------------- 
    119  
     138    # ------------------------------ 
    120139    if nperio in [1, 4, 6] : 
    121140        # ... cyclic 
    122141        ptab [...,:,  0] = zero 
    123142        ptab [...,:, -1] = zero 
    124     
     143 
     144    # 
     145    #> South (in which nperio cases ?) 
     146    # -------------------------------- 
     147    if nperio in [1, 3, 4, 5, 6] : 
     148        ptab[...,0,:] = zero 
     149         
    125150    # 
    126151    #> North-South boundary conditions 
    127     # ---------------------------------- 
     152    # -------------------------------- 
    128153    if nperio in [3, 4] :  # North fold T-point pivot      
    129154        if cd_type in [ 'T', 'W' ] : # T-, W-point 
     
    146171            ptab[..., -2, 0:-1     ] = zero 
    147172            ptab[..., -1, 0:-1     ] = zero 
    148             ptab[..., -1,  0       ] =zero 
     173            ptab[..., -1,  0       ] = zero 
    149174            ptab[..., -1, -1       ] = zero 
    150175       
     
    159184        if cd_type == 'V' : 
    160185            ptab[..., -1, 0:       ] = zero 
    161             ptab[..., -2, jpi/2:   ] = zero 
     186            ptab[..., -2, jpi//2:  ] = zero 
    162187                              
    163188        if cd_type == 'F' : 
Note: See TracChangeset for help on using the changeset viewer.