Changeset 6970


Ignore:
Timestamp:
11/13/24 16:42:06 (3 months ago)
Author:
omamce
Message:

O.M : MOSAIX :

  • Add some new cases : ORCA2.4.2, eORCA1.4.0
  • Some code cleaning
Location:
TOOLS/MOSAIX
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • TOOLS/MOSAIX/CalvingWeights.py

    r6899 r6970  
    1 ### =========================================================================== 
    2 ### 
    3 ### Compute calving weights. 
    4 ### 
    5 ### =========================================================================== 
    6 ## 
    7 ##  MOSAIX is under CeCILL_V2 licence. See "Licence_CeCILL_V2-en.txt" 
    8 ##  file for an english version of the licence and 
    9 ##  "Licence_CeCILL_V2-fr.txt" for a french version. 
    10 ## 
    11 ##  Permission is hereby granted, free of charge, to any person or 
    12 ##  organization obtaining a copy of the software and accompanying 
    13 ##  documentation covered by this license (the "Software") to use, 
    14 ##  reproduce, display, distribute, execute, and transmit the 
    15 ##  Software, and to prepare derivative works of the Software, and to 
    16 ##  permit third-parties to whom the Software is furnished to do so, 
    17 ##  all subject to the following: 
    18 ## 
    19 ##  Warning, to install, configure, run, use any of MOSAIX software or 
    20 ##  to read the associated documentation you'll need at least one (1) 
    21 ##  brain in a reasonably working order. Lack of this implement will 
    22 ##  void any warranties (either express or implied).  Authors assumes 
    23 ##  no responsability for errors, omissions, data loss, or any other 
    24 ##  consequences caused directly or indirectly by the usage of his 
    25 ##  software by incorrectly or partially configured 
     1# -*- Mode: python -*- 
     2#!/usr/bin/env python3 
     3### =================================================================== 
     4###                                                                     
     5### Computes calving weights.                                           
     6###                                                                     
     7### =================================================================== 
     8##                                                                      
     9##  MOSAIX is under CeCILL_V2 licence. See "Licence_CeCILL_V2-en.txt"   
     10##  file for an english version of the licence and                      
     11##  "Licence_CeCILL_V2-fr.txt" for a french version.                    
     12##                                                                      
     13##  Permission is hereby granted, free of charge, to any person or      
     14##  organization obtaining a copy of the software and accompanying      
     15##  documentation covered by this license (the "Software") to use,      
     16##  reproduce, display, distribute, execute, and transmit the           
     17##  Software, and to prepare derivative works of the Software, and to   
     18##  permit third-parties to whom the Software is furnished to do so,    
     19##  all subject to the following:                                       
     20##                                                                      
     21##  Warning, to install, configure, run, use any of MOSAIX software or  
     22##  to read the associated documentation you'll need at least one (1)   
     23##  brain in a reasonably working order. Lack of this implement will    
     24##  void any warranties (either express or implied).  Authors assumes   
     25##  no responsability for errors, omissions, data loss, or any other    
     26##  consequences caused directly or indirectly by the usage of his      
     27##  software by incorrectly or partially configured                     
     28##                                                                      
    2629## 
    2730'''Python code to generates weights for calving. Launched by `CreateWeights.bash`. 
     
    4144  for eORCA1 and eORCA025. 
    4245 
    43 ## SVN information 
     46## SVN information                                                              
    4447Author   = "$Author$" 
    4548Date     = "$Date$" 
     
    5962import nemo 
    6063 
    61 ## SVN information 
     64## SVN information                                                              
    6265__SVN__ =  ( { 
    6366    'Author'   : "$Author$", 
     
    6871    'SVN_Date' : '$SVN_Date: $', 
    6972    } ) 
    70 ### 
    71  
    72 ### ===== Handling command line parameters ========================== 
     73 
     74### ===== Handling command line parameters ==================================== 
    7375# Creating a parser 
    7476parser = argparse.ArgumentParser ( 
     
    8082                      choices=['ORCA2.3', 'ORCA2.4', 'ORCA2.4.2',  
    8183                               'ORCA1.0', 'ORCA1.1', 'ORCA1_CNRM', 'eORCA1.2', 
    82                                'eORCA1.4', 'eORCA1.4.2', 'eORCA025', 'eORCA025.1', 'eORCA025.4'] ) 
     84                               'eORCA1.4', 'eORCA1.4.0', 'eORCA1.4.2', 'eORCA025', 'eORCA025.1', 'eORCA025.4'] ) 
    8385parser.add_argument ('--atm'     , type=str, default='ICO40', 
    8486                         help='atm model name (ICO* or LMD*)' ) 
    8587parser.add_argument ('--type'    , help='Type of distribution', type=str, 
    8688                         choices=['iceshelf', 'iceberg', 'nosouth', 'full'], default='full'  ) 
    87 ## parser.add_argument ('--dir'     , help='Directory of input file', type=str, default='./' ) 
     89# parser.add_argument ('--dir'     , help='Directory of input file', type=str, default='./' ) 
    8890parser.add_argument ('--repartition_file', help='Data files with iceberg melting' , type=str, 
    8991                         default='./runoff-icb_DaiTrenberth_Depoorter_eORCA1_JD.nc' ) 
     
    144146if dst_Name.count('ORCA') != 0 : dst_name = 'orc' 
    145147 
    146 CplModel = dst_Name + 'x' + src_Name 
    147  
    148 print ('Atm names : ' + src_name + ' ' + src_Name ) 
    149 print ('Oce names : ' + dst_name + ' ' + dst_Name ) 
     148CplModel = f'{dst_Name}x{src_Name}' 
     149 
     150print (f'Atm names : {src_name} {src_Name}' ) 
     151print (f'Oce names : {dst_name} {dst_Name}' ) 
    150152print (' ') 
    151153 
     
    156158o2a   = myargs.o2a 
    157159 
    158 print ('Opening ' + areas) 
     160print (f'Opening {areas}') 
    159161f_areas = xr.open_dataset ( areas ) 
    160 print ('Opening ' + masks) 
     162print (f'Opening {masks}') 
    161163f_masks = xr.open_dataset ( masks ) 
    162 print ('Opening ' + grids) 
     164print (f'Opening {grids}') 
    163165f_grids = xr.open_dataset ( grids ) 
    164166 
    165 src_lon = f_grids ['t' + src_name + '.lon'] 
    166 src_lat = f_grids ['t' + src_name + '.lat'] 
    167 dst_lon = f_grids ['t' + dst_name + '.lon'] 
    168 dst_lat = f_grids ['t' + dst_name + '.lat'] 
    169  
    170 src_msk = f_masks ['t' + src_name + '.msk'] 
    171 dst_msk = f_masks ['t' + dst_name + '.msk'] 
     167src_lon = f_grids [f't{src_name}.lon'] 
     168src_lat = f_grids [f't{src_name}.lat'] 
     169dst_lon = f_grids [f't{dst_name}.lon'] 
     170dst_lat = f_grids [f't{dst_name}.lat'] 
     171 
     172src_msk = f_masks [f't{src_name}.msk'] 
     173dst_msk = f_masks [f't{dst_name}.msk'] 
    172174dst_mskutil = 1-dst_msk # Reversing the convention : 0 on continent, 1 on ocean 
    173 print ('dst_msk     : ', dst_msk.sum().values ) 
    174 print ('dst_mskutil : ', dst_mskutil.sum().values ) 
     175print (f'dst_msk     : {dst_msk.sum().values}' ) 
     176print (f'dst_mskutil : {dst_mskutil.sum().values}' ) 
    175177 
    176178# Ocean grid periodicity 
     
    188190print ('dst_mskutil : ' + str(np.sum(dst_mskutil))) 
    189191 
    190 ## 
    191 ## Fill Closed seas and other 
    192 ## ================================================== 
     192## Fill Closed seas and other                                                   
     193## ============================================================================ 
    193194 
    194195# Preparation by closing some straits 
     
    243244 
    244245# Surfaces 
    245 src_srf = f_areas.variables ['t' + src_name + '.srf'] 
    246 dst_srf = f_areas.variables ['t' + dst_name + '.srf'] 
     246src_srf = f_areas.variables [f't{src_name}.srf'] 
     247dst_srf = f_areas.variables [f't{dst_name}.srf'] 
    247248dst_srfutil = dst_srf * np.float64 (dst_mskutil) 
    248249 
    249250dst_srfutil_sum = np.sum( dst_srfutil) 
    250251 
    251 src_clo = f_grids ['t' + src_name + '.clo'] 
    252 src_cla = f_grids ['t' + src_name + '.cla'] 
    253 dst_clo = f_grids ['t' + dst_name + '.clo'] 
    254 dst_cla = f_grids ['t' + dst_name + '.cla'] 
     252src_clo = f_grids [f't{src_name}.clo'] 
     253src_cla = f_grids [f't{src_name}.cla'] 
     254dst_clo = f_grids [f't{dst_name}.clo'] 
     255dst_cla = f_grids [f't{dst_name}.cla'] 
    255256 
    256257# Indices 
     
    261262orc_index = np.arange (dst_jpj*dst_jpi, dtype=np.int32) + 1 # Fortran indices (starting at one) 
    262263 
    263 ### ===== Reading needed data ======================================== 
     264### ===== Reading needed data ================================================= 
    264265if myargs.type in ['iceberg', 'iceshelf' ]: 
    265266    # Reading data file for calving or iceberg geometry around Antarctica 
     
    268269    repartition = np.sum ( f_repartition.variables [repartitionVar], axis=0 ) 
    269270 
    270 ## Before loop on basins 
     271## Before loop on basins                                                        
    271272remap_matrix = np.empty ( shape=(0), dtype=np.float64 ) 
    272273src_address  = np.empty ( shape=(0), dtype=np.int32   ) 
     
    275276print (' ') 
    276277 
    277 ### ===== Starting loop on basins===================================== 
     278### ===== Starting loop on basins============================================== 
    278279 
    279280# Initialise some fields 
     
    361362        print ('  ') 
    362363 
    363 ## End of loop 
     364## End of loop                                                                  
    364365print (' ') 
    365366 
     
    378379    dst_field [dst_address [link]-1] +=  remap_matrix[link] * src_field[src_address[link]-1] 
    379380 
    380 ### ===== Writing the weights file, for OASIS MCT ======================= 
     381### ===== Writing the weights file, for OASIS MCT ============================= 
    381382 
    382383# Output file 
     
    480481f_calving =  xr.Dataset ( { 
    481482    'remap_matrix'            : remap_matrix, 
    482         'src_address'             : src_address, 
    483         'dst_address'             : dst_address, 
    484         'src_grid_dims'           : src_grid_dims, 
    485         'src_grid_center_lon'     : src_grid_center_lat, 
    486         'src_grid_center_lat'     : src_grid_center_lat, 
    487         'src_grid_corner_lon'     : src_grid_corner_lon, 
    488         'src_grid_corner_lat'     : src_grid_corner_lat, 
    489         'src_grid_area'           : src_grid_area, 
    490         'src_grid_imask'          : src_grid_imask, 
    491         'dst_grid_dims'           : dst_grid_dims, 
    492         'dst_grid_center_lon'     : dst_grid_center_lon, 
    493         'dst_grid_center_lat'     : dst_grid_center_lat, 
    494         'dst_grid_corner_lon'     : dst_grid_corner_lon, 
    495         'dst_grid_corner_lat'     : dst_grid_corner_lat, 
    496         'dst_grid_area'           : dst_grid_area, 
    497         'dst_grid_imask'          : dst_grid_imask, 
    498         'dst_bassin'              : dst_bassin, 
    499         'dst_repartition'         : dst_repartition, 
    500         'dst_southLimit'          : dst_southLimit, 
    501         'dst_northLimit'          : dst_northLimit, 
    502         'dst_grid_imaskutil'      : dst_grid_imaskutil, 
    503         'dst_grid_imaskclose'     : dst_grid_imaskclose, 
    504         'dst_lon_addressed'       : dst_lon_addressed, 
    505         'dst_lat_addressed'       : dst_lat_addressed, 
    506         'dst_area_addressed'      : dst_area_addressed, 
    507         'dst_imask_addressed'     : dst_imask_addressed, 
    508         'dst_imaskutil_addressed' : dst_imaskutil_addressed, 
    509         'src_field'               : src_field, 
    510         'dst_field'               : dst_field, 
     483    'src_address'             : src_address, 
     484    'dst_address'             : dst_address, 
     485    'src_grid_dims'           : src_grid_dims, 
     486    'src_grid_center_lon'     : src_grid_center_lat, 
     487    'src_grid_center_lat'     : src_grid_center_lat, 
     488    'src_grid_corner_lon'     : src_grid_corner_lon, 
     489    'src_grid_corner_lat'     : src_grid_corner_lat, 
     490    'src_grid_area'           : src_grid_area, 
     491    'src_grid_imask'          : src_grid_imask, 
     492    'dst_grid_dims'           : dst_grid_dims, 
     493    'dst_grid_center_lon'     : dst_grid_center_lon, 
     494    'dst_grid_center_lat'     : dst_grid_center_lat, 
     495    'dst_grid_corner_lon'     : dst_grid_corner_lon, 
     496    'dst_grid_corner_lat'     : dst_grid_corner_lat, 
     497    'dst_grid_area'           : dst_grid_area, 
     498    'dst_grid_imask'          : dst_grid_imask, 
     499    'dst_bassin'              : dst_bassin, 
     500    'dst_repartition'         : dst_repartition, 
     501    'dst_southLimit'          : dst_southLimit, 
     502    'dst_northLimit'          : dst_northLimit, 
     503    'dst_grid_imaskutil'      : dst_grid_imaskutil, 
     504    'dst_grid_imaskclose'     : dst_grid_imaskclose, 
     505    'dst_lon_addressed'       : dst_lon_addressed, 
     506    'dst_lat_addressed'       : dst_lat_addressed, 
     507    'dst_area_addressed'      : dst_area_addressed, 
     508    'dst_imask_addressed'     : dst_imask_addressed, 
     509    'dst_imaskutil_addressed' : dst_imaskutil_addressed, 
     510    'src_field'               : src_field, 
     511    'dst_field'               : dst_field, 
    511512    } ) 
    512513 
     
    551552    } ) 
    552553 
    553 ## 
    554554f_calving.to_netcdf ( calving, mode='w', format=FmtNetcdf ) 
    555555f_calving.close() 
    556556 
    557 print ("That''s all folks !") 
    558 ## ====================================================================================== 
     557### =========================================================================== 
     558###                                                                             
     559###                               That's all folk's !!!                         
     560###                                                                             
     561### =========================================================================== 
  • TOOLS/MOSAIX/CreateWeightsMask.bash

    r6899 r6970  
    44#MSUB -e Out_WeightsMask    # Error output 
    55#MSUB -n 4                  # Number of processors 
    6 #MSUB -T 1800              # Time limit (seconds) 
    7 #MSUB -Q test 
     6#MSUB -T 1800               # Time limit (seconds) 
    87#MSUB -q rome 
    98#MSUB -p devcmip6 
     
    7675# ================================= 
    7776#CplModel=ORCA2.3xLMD9695 
    78 CplModel=ORCA2.4.2xLMD9695 
     77#CplModel=ORCA2.4.2xLMD9695 
    7978#CplModel=ORCA2.3xICO30 
    8079#CplModel=ORCA2.3xICO40 
     
    8685#CplModel=eORCA1.2xICO60 
    8786#CplModel=eORCA1.4.2xICO40 
     87#CplModel=eORCA1.4.2xICO60 
    8888#CplModel=eORCA1.2xICO450 
    8989#CplModel=eORCA025.1xLMD256256 
    9090 
    91 Version="v0" ; Comment="Test ORCA 2.4.2" 
     91Version="v0" ; Comment="Test ORCA 1.4.2" 
    9292#Version="v1" ; Comment="Fully tested in IPSLCM6 eORCA1.2 x LMD 144x142" 
    9393#Version="NoSearchRadius" ; Comment="For testing new routing" 
     
    9595 
    9696# If available, get model name from job name 
    97 if [[ X${SLURM_JOB_NAME} = X*ORC* ||  X${SLURM_JOB_NAME} = X*LMD*  || X${SLURM_JOB_NAME} = X*ICO* ]] ; then 
     97if [[ X${SLURM_JOB_NAME} = X*ORC* || X${SLURM_JOB_NAME} = X*LMD* || X${SLURM_JOB_NAME} = X*ICO* ]] ; then 
    9898    CplModel=${SLURM_JOB_NAME} ;  
    9999fi 
     
    149149#   atmGrid     : up to know, only t grid used in the atmosphere. 
    150150#   useArea     : if true area from the model metrics is used. If false, areas are computed by XIOS from grid corners. 
    151 #   maskSrc     : true to use the source grid mask, false to used all grid points. 
     151#   maskSrc     : true to use the source grid mask, false to use all grid points. 
    152152#   maskDst     : true to use the destination grid mask, false to use all grid points. 
    153153# 
     
    278278if [[ $(hostname) = irene*    ]] ; then arch=irene ; center=tgcc ; fi 
    279279if [[ $(hostname) = lsce*     ]] ; then arch=spip  ; center=spip ; fi 
     280 
     281echo arch=$arch 
    280282 
    281283case ${arch} in 
     
    307309 
    308310set -x ; set -e 
     311mkdir -p ${TMPDIR}/${CplModel} || exit 1 
    309312ls -alt ${TMPDIR} 
    310 mkdir -p ${TMPDIR}/${CplModel} || exit 1 
    311313cd       ${TMPDIR}/${CplModel} || exit 2 
    312314rm -fr * 
     
    406408EOF 
    407409 
    408 python3 update_xml.py -i iodef.xml -c command_file_${OutFileName}.txt 
     410python3 update_xml.py --input iodef.xml --commandfile command_file_${OutFileName}.txt 
    409411cp iodef.xml iodef_${OutFileName}.xml 
    410412 
     
    453455 
    454456if [[ $(ncdump -h ${ATM}_grid_maskFrom_${OCE}.nc | grep domain_dst | wc -l) -gt 0 ]] ; then 
    455     echo "Change dimension names, and some attributes accordingly" 
     457    echo ${Titre}"Change dimension names, and some attributes accordingly"${Norm} 
    456458    ## =========================================================== 
    457459    case ${atm} in 
     
    567569EOF 
    568570 
    569     python3 update_xml.py -i iodef.xml -c command_file_${OutFileName}.txt 
     571    python3 update_xml.py --input iodef.xml --commandfile command_file_${OutFileName}.txt 
    570572    cp iodef.xml iodef_${OutFileName}.xml 
    571573     
     
    635637EOF 
    636638 
    637 for rmpFile in rmp_*.nc ; do 
     639for rmpFile in $(ls rmp_?${atm}_to_[tuv]${oce}_*.nc rmp_[tuv]${oce}_to_t${atm}_*.nc 2> /dev/null ) ; do 
     640    echo ${Titre}"${rmpFile}"${Norm} 
     641     
    638642    mv ${rmpFile} tmp_${rmpFile} 
    639643    ncap2 --history --script-file add_dim.nco tmp_${rmpFile} ${rmpFile} ; rm tmp_${rmpFile} 
     
    643647             --variable  src_idx,src_address  \ 
    644648             --variable  dst_idx,dst_address  \ 
    645              --variable  weight,remap_matrix  ${rmpFile} 
    646    
    647     ncatted --history --attribute conventions,global,o,c,"SCRIP" --attribute normalization,global,o,c,"none" ${rmpFile} 
    648      
    649     case ${rmpFile} in 
    650         ( rmp_*${oce}_to_t${atm}_* ) 
    651         ncatted --history \ 
    652                 --attribute title,global,o,c,"Weights ${OCE} to ${ATM}" \ 
    653                 --attribute source_grid,global,o,c,"${oceDomainType}" \ 
    654                 --attribute dest_grid,global,o,c,"${atmDomainType}"   \ 
    655                 ${rmpFile}       
     649             --variable  weight,remap_matrix  \ 
     650             ${rmpFile} 
     651 
     652     case ${rmpFile} in 
     653        ( rmp_*${oce}_to_*${atm}_* ) 
     654        src=${OCE} ; dst=${ATM} #; ztitre="${OCE} to ${ATM}" 
     655        srcDomainType=${oceDomainType} ; dstDomainType=${atmDomainType} 
    656656        ;; 
    657657        ( rmp_*${atm}_to_*${oce}_* ) 
    658         ncatted --history \ 
    659                 --attribute title,global,o,c,"Weights ${ATM} to ${OCE}" \ 
    660                 --attribute source_grid,global,o,c,"${atmDomainType}" \ 
    661                 --attribute dest_grid,global,o,c,"${oceDomainType}"   \ 
    662                 ${rmpFile} 
     658        src=${ATM} ; dst=${OCE} #; ztitre="${ATM} to ${OCE}" 
     659        srcDomainType=${atmDomainType} ; dstDomainType=${oceDomainType} 
    663660        ;; 
    664     esac 
     661     esac 
     662     
     663     ncatted --history \ 
     664             --attribute conventions,global,o,c,"SCRIP" \ 
     665             --attribute normalization,global,o,c,"none" \ 
     666             --attribute title,global,o,c,"Interpolation weights ${src} to ${dst}" \ 
     667             --attribute source_grid,global,o,c,"${oceDomainType}" \ 
     668             --attribute dest_grid,global,o,c,"${atmDomainType}"   \ 
     669             ${rmpFile} 
     670 
    665671done 
    666672 
     
    803809done 
    804810ls -al ${OCE}_coordinates_mask.nc 
    805 ## 
     811 
     812echo ${Titre}"Update and complete weight files with more comprehensive description"${Norm} 
    806813## ============================================================================ 
     814 
     815for rmpFile in $(ls rmp_?${atm}_to_[tuv]${oce}_*.nc rmp_[tuv]${oce}_to_t${atm}_*.nc 2> /dev/null ) ; do 
     816    echo ${Titre}"${rmpFile}"${Norm} 
     817 
     818     case ${rmpFile} in 
     819         ( rmp_*${oce}_to_*${atm}_* ) 
     820         direction='o2a' 
     821         src=${OCE} ; dst=${ATM} #; ztitre="${OCE} to ${ATM}" 
     822         srcDomainType=${oceDomainType} ; dstDomainType=${atmDomainType} 
     823         ;; 
     824         ( rmp_*${atm}_to_*${oce}_* ) 
     825         direction="a2o" 
     826         src=${ATM} ; dst=${OCE} #; ztitre="${ATM} to ${OCE}" 
     827         srcDomainType=${atmDomainType} ; dstDomainType=${oceDomainType} 
     828         ;; 
     829     esac 
     830      
     831     ncatted --history \ 
     832            --attribute "name",remap_matrix,c,c,"remapping_weights" \ 
     833                --attribute "long_name",remap_matrix,c,c,"remapping_weights" \ 
     834                --attribute "description",remap_matrix,c,c,"remapping weights from ${src} to ${dst}" \ 
     835            --attribute "name",src_address,c,c,"src_grid_index"  \ 
     836              --attribute "long_name",src_address,c,c,"src_grid_index"  \ 
     837              --attribute "IndexingConvention",src_address,c,c,"Fortran"  \ 
     838              --attribute "name",dst_address,c,c,"src_grid_index"  \ 
     839              --attribute "long_name",dst_address,c,c,"src_grid_index"  \ 
     840              --attribute "IndexingConvention",dst_address,c,c,"Fortran" \ 
     841            --attribute "name",src_grid_area,c,c,"src_grid_area" \ 
     842                --attribute "long_name",src_grid_area,c,c,"area of ${src} grid cell" \ 
     843                --attribute "standard_name",src_grid_area,c,c,"cell_area" \ 
     844                --attribute "unit",src_grid_area,c,c,"m2" \ 
     845            --attribute "name",dst_grid_area,c,c,"dst_grid_area" \ 
     846                --attribute "long_name",dst_grid_area,c,c,"area of ${dst}_grid_cell" \ 
     847                --attribute "standard_name",dst_grid_area,c,c,"cell_area" \ 
     848                --attribute "unit",dst_grid_area,c,c,"m2" \ 
     849            --attribute "name",src_grid_center_lat,c,c,"src_enter_lat" \ 
     850                --attribute "long_name",src_grid_center_lat,c,c,"latitude" \ 
     851                --attribute "standard_name",src_grid_center_lat,c,c,"latitude" \ 
     852                --attribute "unit",src_grid_center_lat,c,c,"degrees_north" \ 
     853            --attribute "name",src_grid_center_lon,c,c,"src_grid_center_lon" \ 
     854                --attribute "long_name",src_grid_center_lon,c,c,"longitude" \ 
     855                --attribute "standard_name",src_grid_center_lon,c,c,"longitude" \ 
     856                --attribute "unit",src_grid_center_lon,c,c,"degrees_east" \ 
     857            --attribute "name",dst_grid_center_lat,c,c,"src_grid_center_lat" \ 
     858                --attribute "long_name",dst_grid_center_lat,c,c,"latitude" \ 
     859                --attribute "standard_name",dst_grid_center_lat,c,c,"latitude" \ 
     860                --attribute "unit",dst_grid_center_lat,c,c,"degrees_north" \ 
     861            --attribute "name",dst_grid_center_lon,c,c,"dst_grid_center_lon" \ 
     862                --attribute "long_name",dst_grid_center_lon,c,c,"longitude" \ 
     863                --attribute "standard_name",dst_grid_center_lon,c,c,"longitude" \ 
     864                --attribute "unit",dst_grid_center_lon,c,c,"degrees_east" \ 
     865            --attribute "name",src_grid_imask,c,c,"dst_grid_imask" \ 
     866                --attribute "long_name",src_grid_imask,c,c,"src_grid_imask" \ 
     867                --attribute "unit",src_grid_imask,c,c,"0/1" \ 
     868                --attribute "description",src_grid_imask,c,c,"${src} mask" \ 
     869            --attribute "name",dst_grid_imask,c,c,"dst_grid_imask" \ 
     870                --attribute "long_name",dst_grid_imask,c,c,"dst_grid_imask" \ 
     871                --attribute "unit",dst_grid_imask,c,c,"0/1" \ 
     872                --attribute "description",dst_grid_imask,c,c,"${dst} mask" \ 
     873                ${rmpFile} 
     874      
     875     if [[ "X${direction}" = "Xo2a" ]] ; then 
     876         ncatted --history \ 
     877                 --attribute "name",src_grid_corner_lat,c,c,"src_grid_corner_lat" \ 
     878                 --attribute "long_name",src_grid_corner_lat,c,c,"latitude" \ 
     879                 --attribute "standard_name",src_grid_corner_lat,c,c,"latitude" \ 
     880                 --attribute "unit",src_grid_corner_lat,c,c,"degrees_north" \ 
     881                 --attribute "name",src_grid_corner_lon,c,c,"src_grid_corner_lon" \ 
     882                 --attribute "long_name",src_grid_corner_lon,c,c,"longitude" \ 
     883                 --attribute "standard_name",src_grid_corner_lon,c,c,"longitude" \ 
     884                 --attribute "unit",src_grid_corner_lon,c,c,"degrees_east" \ 
     885                 --attribute "bounds",src_grid_center_lat,c,c,"src_grid_corner_lat" \ 
     886                 --attribute "bounds",src_grid_center_lon,c,c,"src_grid_corner_lon" \ 
     887                 ${rmpFile} 
     888         if [[ ${atm} = ico ]] ; then 
     889             ncatted --history \ 
     890                     --attribute "name",dst_grid_corner_lat,c,c,"dst_grid_corner_lat" \ 
     891                     --attribute "long_name",dst_grid_corner_lat,c,c,"latitude" \ 
     892                     --attribute "standard_name",dst_grid_corner_lat,c,c,"latitude" \ 
     893                     --attribute "unit",dst_grid_corner_lat,c,c,"degrees_north" \ 
     894                     --attribute "name",dst_grid_corner_lon,c,c,"dst_grid_corner_lon" \ 
     895                     --attribute "long_name",dst_grid_corner_lon,c,c,"longitude" \ 
     896                     --attribute "standard_name",dst_grid_corner_lon,c,c,"longitude" \ 
     897                     --attribute "unit",dst_grid_corner_lon,c,c,"degrees_east" \ 
     898                     --attribute "bounds",dst_grid_center_lat,c,c,"dst_grid_corner_lat" \ 
     899                     --attribute "bounds",dst_grid_center_lon,c,c,"dst_grid_corner_lon" \ 
     900                 ${rmpFile} 
     901         fi 
     902     fi 
     903 
     904     if [[ "X${direction}" = "Xa2o" ]] ; then 
     905         ncatted --history \ 
     906                 --attribute "name",dst_grid_corner_lat,c,c,"src_grid_corner_lat" \ 
     907                 --attribute "long_name",dst_grid_corner_lat,c,c,"latitude" \ 
     908                 --attribute "standard_name",dst_grid_corner_lat,c,c,"latitude" \ 
     909                 --attribute "unit",dst_grid_corner_lat,c,c,"degrees_north" \ 
     910                 --attribute "name",dst_grid_corner_lon,c,c,"dst_grid_corner_lon" \ 
     911                 --attribute "long_name",dst_grid_corner_lon,c,c,"longitude" \ 
     912                 --attribute "standard_name",dst_grid_corner_lon,c,c,"longitude" \ 
     913                 --attribute "unit",dst_grid_corner_lon,c,c,"degrees_east" \ 
     914                 --attribute "bounds",dst_grid_center_lat,c,c,"dst_grid_corner_lat" \ 
     915                 --attribute "bounds",dst_grid_center_lon,c,c,"dst_grid_corner_lon" \ 
     916                 ${rmpFile} 
     917         if [[ ${atm} = ico ]] ; then 
     918             ncatted --history \ 
     919                     --attribute "name",src_grid_corner_lat,c,c,"src_grid_corner_lat" \ 
     920                     --attribute "long_name",src_grid_corner_lat,c,c,"latitude" \ 
     921                     --attribute "standard_name",src_grid_corner_lat,c,c,"latitude" \ 
     922                     --attribute "unit",src_grid_corner_lat,c,c,"degrees_north" \ 
     923                     --attribute "name",src_grid_corner_lon,c,c,"src_grid_corner_lon" \ 
     924                     --attribute "long_name",src_grid_corner_lon,c,c,"longitude" \ 
     925                     --attribute "standard_name",src_grid_corner_lon,c,c,"longitude" \ 
     926                     --attribute "unit",src_grid_corner_lon,c,c,"degrees_east" \ 
     927                     --attribute "bounds",src_grid_center_lat,c,c,"src_grid_corner_lat" \ 
     928                     --attribute "bounds",src_grid_center_lon,c,c,"src_grid_corner_lon" \ 
     929                     ${rmpFile} 
     930         fi 
     931     fi 
     932done 
     933      
    807934echo ${Titre}"Creates and save auxiliary files for OASIS : grids.nc, areas.nc and masks.nc"${Norm} 
     935## ============================================================================ 
    808936cp ${SUBMIT_DIR}/CreateOasisGrids.bash . 
    809937bash CreateOasisGrids.bash --oce ${OCE} --atm ${ATM} 
  • TOOLS/MOSAIX/RunoffWeights.py

    r6899 r6970  
    11# -*- Mode: python -*- 
    22#!/usr/bin/env python3 
    3 ### =========================================================================== 
    4 ### 
    5 ### Compute runoff weights. 
    6 ### For LMDZ only. Not suitable for DYNAMICO 
    7 ### 
    8 ### =========================================================================== 
    9 ## 
    10 ##  MOSAIX is under CeCILL_V2 licence. See "Licence_CeCILL_V2-en.txt" 
    11 ##  file for an english version of the licence and 
    12 ##  "Licence_CeCILL_V2-fr.txt" for a french version. 
    13 ## 
    14 ##  Permission is hereby granted, free of charge, to any person or 
    15 ##  organization obtaining a copy of the software and accompanying 
    16 ##  documentation covered by this license (the "Software") to use, 
    17 ##  reproduce, display, distribute, execute, and transmit the 
    18 ##  Software, and to prepare derivative works of the Software, and to 
    19 ##  permit third-parties to whom the Software is furnished to do so, 
    20 ##  all subject to the following: 
    21 ## 
    22 ##  Warning, to install, configure, run, use any of MOSAIX software or 
    23 ##  to read the associated documentation you'll need at least one (1) 
    24 ##  brain in a reasonably working order. Lack of this implement will 
    25 ##  void any warranties (either express or implied).  Authors assumes 
    26 ##  no responsability for errors, omissions, data loss, or any other 
    27 ##  consequences caused directly or indirectly by the usage of his 
    28 ##  software by incorrectly or partially configured 
    29 ## 
     3### =================================================================== 
     4###                                                                     
     5### Compute calving weights.                                            
     6###                                                                     
     7### =================================================================== 
     8##                                                                      
     9##  MOSAIX is under CeCILL_V2 licence. See "Licence_CeCILL_V2-en.txt"   
     10##  file for an english version of the licence and                      
     11##  "Licence_CeCILL_V2-fr.txt" for a french version.                    
     12##                                                                      
     13##  Permission is hereby granted, free of charge, to any person or      
     14##  organization obtaining a copy of the software and accompanying      
     15##  documentation covered by this license (the "Software") to use,      
     16##  reproduce, display, distribute, execute, and transmit the           
     17##  Software, and to prepare derivative works of the Software, and to   
     18##  permit third-parties to whom the Software is furnished to do so,    
     19##  all subject to the following:                                       
     20##                                                                      
     21##  Warning, to install, configure, run, use any of MOSAIX software or  
     22##  to read the associated documentation you'll need at least one (1)   
     23##  brain in a reasonably working order. Lack of this implement will    
     24##  void any warranties (either express or implied).  Authors assumes   
     25##  no responsability for errors, omissions, data loss, or any other    
     26##  consequences caused directly or indirectly by the usage of his      
     27##  software by incorrectly or partially configured                     
     28##                                                                      
    3029## 
    3130'''Python code to generates weights for run-off. Launched by `CreateWeights.bash`. 
     
    4544  than searchRadius. 
    4645 
    47 ## SVN information 
     46## SVN information                                                              
    4847Author   = "$Author$" 
    4948Date     = "$Date$" 
     
    5352''' 
    5453 
    55 ## Modules 
     54## Modules                                                                      
    5655import sys 
    5756import os 
     
    7473    'SVN_Date' : '$SVN_Date: $', 
    7574    }) 
    76 ## 
    77  
    78 ## Useful constants 
     75 
     76## Useful constants                                                             
    7977zero    = np.dtype('float64').type(0.0) 
    8078zone    = np.dtype('float64').type(1.0) 
     
    8482ra      = np.dtype('float64').type(6371229.0) # Earth radius 
    8583 
    86 ## Functions 
     84## Functions                                                                    
    8785def geodist (plon1, plat1, plon2, plat2) : 
    8886    '''Distance between two points (on sphere)''' 
     
    9391    return zgeodist 
    9492 
    95 ### ===== Reading command line parameters ================================================== 
     93### ===== Reading command line parameters ===================================== 
    9694# Creating a parser 
    9795parser = argparse.ArgumentParser ( 
     
    103101                     choices=['ORCA2.3', 'ORCA2.4', 'ORCA2.4.2', 
    104102                              'ORCA1.0', 'ORCA1.1', 'ORCA1_CNRM', 'eORCA1.2', 
    105                               'eORCA1.4', 'eORCA1.4.2', 
     103                              'eORCA1.4', 'eORCA1.4.0', 'eORCA1.4.2', 
    106104                              'eORCA025', 'eORCA025.1', 'eORCA025.4'] ) 
    107105parser.add_argument ('--atm'          , help='atm model name', type=str, default='LMD9695'    ) 
     
    164162if atm_Name.find('ICO') >= 0 : atm_n = 'ico' ; atmDomainType = 'unstructured' 
    165163 
    166 print ('atmQuantity : ' + str (myargs.atmQuantity) ) 
    167 print ('oceQuantity : ' + str (myargs.oceQuantity) ) 
     164print (f'atmQuantity : {str (myargs.atmQuantity)}' ) 
     165print (f'oceQuantity : {str (myargs.oceQuantity)}' ) 
    168166 
    169167# Ocean grid periodicity 
    170168oce_perio = myargs.ocePerio 
    171169 
    172 ### Read coordinates of all models 
    173 ### 
     170### Read coordinates of all models                                              
    174171 
    175172diaFile    = xr.open_dataset ( o2a   ) 
     
    181178o2aFrac = np.where ( np.abs(o2aFrac) < 1E10, o2aFrac, 0.0) 
    182179 
    183 (atm_nvertex, atm_jpj, atm_jpi) = gridFile['t'+atm_n+'.clo'][:].shape 
     180(atm_nvertex, atm_jpj, atm_jpi) = gridFile[f't{atm_n}.clo'][:].shape 
    184181atm_grid_size = atm_jpj*atm_jpi 
    185 atm_grid_rank = len(gridFile['t'+atm_n+'.lat'][:].shape) 
    186  
    187 atm_grid_center_lat = gridFile['t'+atm_n+'.lat'].squeeze() 
    188 atm_grid_center_lon = gridFile['t'+atm_n+'.lon'].squeeze() 
    189 atm_grid_corner_lat = gridFile['t'+atm_n+'.cla'].squeeze() 
    190 atm_grid_corner_lon = gridFile['t'+atm_n+'.clo'].squeeze() 
    191 atm_grid_area       = areaFile['t'+atm_n+'.srf'].squeeze() 
    192 atm_grid_imask      = 1-maskFile['t'+atm_n+'.msk'][:].squeeze() 
    193 atm_grid_dims       = gridFile['t'+atm_n+'.lat'][:].shape 
     182atm_grid_rank = len(gridFile[f't{atm_n}.lat'][:].shape) 
     183 
     184atm_grid_center_lat = gridFile  [f't{atm_n}.lat'].squeeze() 
     185atm_grid_center_lon = gridFile  [f't{atm_n}.lon'].squeeze() 
     186atm_grid_corner_lat = gridFile  [f't{atm_n}.cla'].squeeze() 
     187atm_grid_corner_lon = gridFile  [f't{atm_n}.clo'].squeeze() 
     188atm_grid_area       = areaFile  [f't{atm_n}.srf'].squeeze() 
     189atm_grid_imask      = 1-maskFile[f't{atm_n}.msk'][:].squeeze() 
     190atm_grid_dims       = gridFile  [f't{atm_n}.lat'][:].shape 
    194191 
    195192if atmDomainType == 'unstructured' : 
     
    285282atmOceanFrac = np.where (o2aFrac[:] > epsfrac       , True, False) 
    286283 
    287 ## For LMDZ only !! 
     284## For LMDZ only !!                                                             
    288285if atmDomainType == 'rectilinear' : 
    289286    print ('Extend coastal band ' ) 
     
    318315oce_address  = np.empty ( shape=(0), dtype=np.int32   ) 
    319316 
    320 ## Loop on atmosphere coastal points 
     317## Loop on atmosphere coastal points                                     
    321318if searchRadius > 0. : 
    322319    print ('Loop on atmosphere coastal points') 
     
    469466f_runoff = xr.Dataset ( { 
    470467    'remap_matrix'        : remap_matrix, 
    471         'src_address'         : src_address, 
    472         'dst_address'         : dst_address, 
    473         'src_grid_dims'       : src_grid_dims, 
    474         'src_grid_center_lon' : src_grid_center_lon, 
    475         'src_grid_center_lat' : src_grid_center_lat, 
     468    'src_address'         : src_address, 
     469    'dst_address'         : dst_address, 
     470    'src_grid_dims'       : src_grid_dims, 
     471    'src_grid_center_lon' : src_grid_center_lon, 
     472    'src_grid_center_lat' : src_grid_center_lat, 
    476473    'src_grid_corner_lon' : src_grid_corner_lon, 
    477474    'src_grid_corner_lat' : src_grid_corner_lat, 
    478         'src_grid_area'       : src_grid_area, 
    479         'src_grid_imask'      : src_grid_imask, 
    480         'src_grid_pmask'      : src_grid_pmask, 
    481         'dst_grid_dims'       : dst_grid_dims, 
    482         'dst_grid_center_lon' : dst_grid_center_lon, 
    483         'dst_grid_center_lat' : dst_grid_center_lat, 
    484         'dst_grid_corner_lon' : dst_grid_corner_lon, 
    485         'dst_grid_corner_lat' : dst_grid_corner_lat, 
    486         'dst_grid_area'       : dst_grid_area, 
    487         'dst_grid_imask'      : dst_grid_imask, 
    488         'dst_grid_pmask'      : dst_grid_pmask, 
    489         'src_lon_addressed'   : src_lon_addressed, 
    490         'src_lat_addressed'   : src_lat_addressed, 
    491         'src_area_addressed'  : src_area_addressed, 
    492         'dst_lon_addressed'   : dst_lon_addressed, 
    493         'dst_lat_addressed'   : dst_lat_addressed, 
    494         'dst_area_addressed'  : dst_area_addressed, 
    495         'dst_imask_addressed' : dst_imask_addressed, 
    496         'dst_pmask_addressed' : dst_pmask_addressed, 
    497         'atmCoast'            : atmCoast, 
    498         'oceLand'             : oceLand, 
    499         'oceOcean'            : oceOcean, 
    500         'oceOceanFiltered'    : oceOceanFiltered, 
    501         'oceCoast'            : oceCoast 
     475    'src_grid_area'       : src_grid_area, 
     476    'src_grid_imask'      : src_grid_imask, 
     477    'src_grid_pmask'      : src_grid_pmask, 
     478    'dst_grid_dims'       : dst_grid_dims, 
     479    'dst_grid_center_lon' : dst_grid_center_lon, 
     480    'dst_grid_center_lat' : dst_grid_center_lat, 
     481    'dst_grid_corner_lon' : dst_grid_corner_lon, 
     482    'dst_grid_corner_lat' : dst_grid_corner_lat, 
     483    'dst_grid_area'       : dst_grid_area, 
     484    'dst_grid_imask'      : dst_grid_imask, 
     485    'dst_grid_pmask'      : dst_grid_pmask, 
     486    'src_lon_addressed'   : src_lon_addressed, 
     487    'src_lat_addressed'   : src_lat_addressed, 
     488    'src_area_addressed'  : src_area_addressed, 
     489    'dst_lon_addressed'   : dst_lon_addressed, 
     490    'dst_lat_addressed'   : dst_lat_addressed, 
     491    'dst_area_addressed'  : dst_area_addressed, 
     492    'dst_imask_addressed' : dst_imask_addressed, 
     493    'dst_pmask_addressed' : dst_pmask_addressed, 
     494    'atmCoast'            : atmCoast, 
     495    'oceLand'             : oceLand, 
     496    'oceOcean'            : oceOcean, 
     497    'oceOceanFiltered'    : oceOceanFiltered, 
     498    'oceCoast'            : oceCoast 
    502499    } ) 
    503500 
     
    544541f_runoff.close () 
    545542 
    546 ## 
    547  
    548 print ("That''s all folks !") 
    549 ## ====================================================================================== 
     543### =========================================================================== 
     544###                                                                             
     545###                               That's all folk's !!!                         
     546###                                                                             
     547### =========================================================================== 
Note: See TracChangeset for help on using the changeset viewer.