Changeset 6970
- Timestamp:
- 11/13/24 16:42:06 (3 months ago)
- 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 ## 26 29 ## 27 30 '''Python code to generates weights for calving. Launched by `CreateWeights.bash`. … … 41 44 for eORCA1 and eORCA025. 42 45 43 ## SVN information 46 ## SVN information 44 47 Author = "$Author$" 45 48 Date = "$Date$" … … 59 62 import nemo 60 63 61 ## SVN information 64 ## SVN information 62 65 __SVN__ = ( { 63 66 'Author' : "$Author$", … … 68 71 'SVN_Date' : '$SVN_Date: $', 69 72 } ) 70 ### 71 72 ### ===== Handling command line parameters ========================== 73 74 ### ===== Handling command line parameters ==================================== 73 75 # Creating a parser 74 76 parser = argparse.ArgumentParser ( … … 80 82 choices=['ORCA2.3', 'ORCA2.4', 'ORCA2.4.2', 81 83 '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'] ) 83 85 parser.add_argument ('--atm' , type=str, default='ICO40', 84 86 help='atm model name (ICO* or LMD*)' ) 85 87 parser.add_argument ('--type' , help='Type of distribution', type=str, 86 88 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='./' ) 88 90 parser.add_argument ('--repartition_file', help='Data files with iceberg melting' , type=str, 89 91 default='./runoff-icb_DaiTrenberth_Depoorter_eORCA1_JD.nc' ) … … 144 146 if dst_Name.count('ORCA') != 0 : dst_name = 'orc' 145 147 146 CplModel = dst_Name + 'x' + src_Name147 148 print ( 'Atm names : ' + src_name + ' ' + src_Name)149 print ( 'Oce names : ' + dst_name + ' ' + dst_Name)148 CplModel = f'{dst_Name}x{src_Name}' 149 150 print (f'Atm names : {src_name} {src_Name}' ) 151 print (f'Oce names : {dst_name} {dst_Name}' ) 150 152 print (' ') 151 153 … … 156 158 o2a = myargs.o2a 157 159 158 print ( 'Opening ' + areas)160 print (f'Opening {areas}') 159 161 f_areas = xr.open_dataset ( areas ) 160 print ( 'Opening ' + masks)162 print (f'Opening {masks}') 161 163 f_masks = xr.open_dataset ( masks ) 162 print ( 'Opening ' + grids)164 print (f'Opening {grids}') 163 165 f_grids = xr.open_dataset ( grids ) 164 166 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']167 src_lon = f_grids [f't{src_name}.lon'] 168 src_lat = f_grids [f't{src_name}.lat'] 169 dst_lon = f_grids [f't{dst_name}.lon'] 170 dst_lat = f_grids [f't{dst_name}.lat'] 171 172 src_msk = f_masks [f't{src_name}.msk'] 173 dst_msk = f_masks [f't{dst_name}.msk'] 172 174 dst_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)175 print (f'dst_msk : {dst_msk.sum().values}' ) 176 print (f'dst_mskutil : {dst_mskutil.sum().values}' ) 175 177 176 178 # Ocean grid periodicity … … 188 190 print ('dst_mskutil : ' + str(np.sum(dst_mskutil))) 189 191 190 ## 191 ## Fill Closed seas and other 192 ## ================================================== 192 ## Fill Closed seas and other 193 ## ============================================================================ 193 194 194 195 # Preparation by closing some straits … … 243 244 244 245 # Surfaces 245 src_srf = f_areas.variables [ 't' + src_name + '.srf']246 dst_srf = f_areas.variables [ 't' + dst_name + '.srf']246 src_srf = f_areas.variables [f't{src_name}.srf'] 247 dst_srf = f_areas.variables [f't{dst_name}.srf'] 247 248 dst_srfutil = dst_srf * np.float64 (dst_mskutil) 248 249 249 250 dst_srfutil_sum = np.sum( dst_srfutil) 250 251 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']252 src_clo = f_grids [f't{src_name}.clo'] 253 src_cla = f_grids [f't{src_name}.cla'] 254 dst_clo = f_grids [f't{dst_name}.clo'] 255 dst_cla = f_grids [f't{dst_name}.cla'] 255 256 256 257 # Indices … … 261 262 orc_index = np.arange (dst_jpj*dst_jpi, dtype=np.int32) + 1 # Fortran indices (starting at one) 262 263 263 ### ===== Reading needed data ======================================== 264 ### ===== Reading needed data ================================================= 264 265 if myargs.type in ['iceberg', 'iceshelf' ]: 265 266 # Reading data file for calving or iceberg geometry around Antarctica … … 268 269 repartition = np.sum ( f_repartition.variables [repartitionVar], axis=0 ) 269 270 270 ## Before loop on basins 271 ## Before loop on basins 271 272 remap_matrix = np.empty ( shape=(0), dtype=np.float64 ) 272 273 src_address = np.empty ( shape=(0), dtype=np.int32 ) … … 275 276 print (' ') 276 277 277 ### ===== Starting loop on basins===================================== 278 ### ===== Starting loop on basins============================================== 278 279 279 280 # Initialise some fields … … 361 362 print (' ') 362 363 363 ## End of loop 364 ## End of loop 364 365 print (' ') 365 366 … … 378 379 dst_field [dst_address [link]-1] += remap_matrix[link] * src_field[src_address[link]-1] 379 380 380 ### ===== Writing the weights file, for OASIS MCT ======================= 381 ### ===== Writing the weights file, for OASIS MCT ============================= 381 382 382 383 # Output file … … 480 481 f_calving = xr.Dataset ( { 481 482 'remap_matrix' : remap_matrix, 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 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, 511 512 } ) 512 513 … … 551 552 } ) 552 553 553 ##554 554 f_calving.to_netcdf ( calving, mode='w', format=FmtNetcdf ) 555 555 f_calving.close() 556 556 557 print ("That''s all folks !") 558 ## ====================================================================================== 557 ### =========================================================================== 558 ### 559 ### That's all folk's !!! 560 ### 561 ### =========================================================================== -
TOOLS/MOSAIX/CreateWeightsMask.bash
r6899 r6970 4 4 #MSUB -e Out_WeightsMask # Error output 5 5 #MSUB -n 4 # Number of processors 6 #MSUB -T 1800 # Time limit (seconds) 7 #MSUB -Q test 6 #MSUB -T 1800 # Time limit (seconds) 8 7 #MSUB -q rome 9 8 #MSUB -p devcmip6 … … 76 75 # ================================= 77 76 #CplModel=ORCA2.3xLMD9695 78 CplModel=ORCA2.4.2xLMD969577 #CplModel=ORCA2.4.2xLMD9695 79 78 #CplModel=ORCA2.3xICO30 80 79 #CplModel=ORCA2.3xICO40 … … 86 85 #CplModel=eORCA1.2xICO60 87 86 #CplModel=eORCA1.4.2xICO40 87 #CplModel=eORCA1.4.2xICO60 88 88 #CplModel=eORCA1.2xICO450 89 89 #CplModel=eORCA025.1xLMD256256 90 90 91 Version="v0" ; Comment="Test ORCA 2.4.2"91 Version="v0" ; Comment="Test ORCA 1.4.2" 92 92 #Version="v1" ; Comment="Fully tested in IPSLCM6 eORCA1.2 x LMD 144x142" 93 93 #Version="NoSearchRadius" ; Comment="For testing new routing" … … 95 95 96 96 # 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* ]] ; then97 if [[ X${SLURM_JOB_NAME} = X*ORC* || X${SLURM_JOB_NAME} = X*LMD* || X${SLURM_JOB_NAME} = X*ICO* ]] ; then 98 98 CplModel=${SLURM_JOB_NAME} ; 99 99 fi … … 149 149 # atmGrid : up to know, only t grid used in the atmosphere. 150 150 # 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 use dall grid points.151 # maskSrc : true to use the source grid mask, false to use all grid points. 152 152 # maskDst : true to use the destination grid mask, false to use all grid points. 153 153 # … … 278 278 if [[ $(hostname) = irene* ]] ; then arch=irene ; center=tgcc ; fi 279 279 if [[ $(hostname) = lsce* ]] ; then arch=spip ; center=spip ; fi 280 281 echo arch=$arch 280 282 281 283 case ${arch} in … … 307 309 308 310 set -x ; set -e 311 mkdir -p ${TMPDIR}/${CplModel} || exit 1 309 312 ls -alt ${TMPDIR} 310 mkdir -p ${TMPDIR}/${CplModel} || exit 1311 313 cd ${TMPDIR}/${CplModel} || exit 2 312 314 rm -fr * … … 406 408 EOF 407 409 408 python3 update_xml.py - i iodef.xml -ccommand_file_${OutFileName}.txt410 python3 update_xml.py --input iodef.xml --commandfile command_file_${OutFileName}.txt 409 411 cp iodef.xml iodef_${OutFileName}.xml 410 412 … … 453 455 454 456 if [[ $(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} 456 458 ## =========================================================== 457 459 case ${atm} in … … 567 569 EOF 568 570 569 python3 update_xml.py - i iodef.xml -ccommand_file_${OutFileName}.txt571 python3 update_xml.py --input iodef.xml --commandfile command_file_${OutFileName}.txt 570 572 cp iodef.xml iodef_${OutFileName}.xml 571 573 … … 635 637 EOF 636 638 637 for rmpFile in rmp_*.nc ; do 639 for 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 638 642 mv ${rmpFile} tmp_${rmpFile} 639 643 ncap2 --history --script-file add_dim.nco tmp_${rmpFile} ${rmpFile} ; rm tmp_${rmpFile} … … 643 647 --variable src_idx,src_address \ 644 648 --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} 656 656 ;; 657 657 ( 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} 663 660 ;; 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 665 671 done 666 672 … … 803 809 done 804 810 ls -al ${OCE}_coordinates_mask.nc 805 ## 811 812 echo ${Titre}"Update and complete weight files with more comprehensive description"${Norm} 806 813 ## ============================================================================ 814 815 for 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 932 done 933 807 934 echo ${Titre}"Creates and save auxiliary files for OASIS : grids.nc, areas.nc and masks.nc"${Norm} 935 ## ============================================================================ 808 936 cp ${SUBMIT_DIR}/CreateOasisGrids.bash . 809 937 bash CreateOasisGrids.bash --oce ${OCE} --atm ${ATM} -
TOOLS/MOSAIX/RunoffWeights.py
r6899 r6970 1 1 # -*- Mode: python -*- 2 2 #!/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 ## 30 29 ## 31 30 '''Python code to generates weights for run-off. Launched by `CreateWeights.bash`. … … 45 44 than searchRadius. 46 45 47 ## SVN information 46 ## SVN information 48 47 Author = "$Author$" 49 48 Date = "$Date$" … … 53 52 ''' 54 53 55 ## Modules 54 ## Modules 56 55 import sys 57 56 import os … … 74 73 'SVN_Date' : '$SVN_Date: $', 75 74 }) 76 ## 77 78 ## Useful constants 75 76 ## Useful constants 79 77 zero = np.dtype('float64').type(0.0) 80 78 zone = np.dtype('float64').type(1.0) … … 84 82 ra = np.dtype('float64').type(6371229.0) # Earth radius 85 83 86 ## Functions 84 ## Functions 87 85 def geodist (plon1, plat1, plon2, plat2) : 88 86 '''Distance between two points (on sphere)''' … … 93 91 return zgeodist 94 92 95 ### ===== Reading command line parameters ===================================== =============93 ### ===== Reading command line parameters ===================================== 96 94 # Creating a parser 97 95 parser = argparse.ArgumentParser ( … … 103 101 choices=['ORCA2.3', 'ORCA2.4', 'ORCA2.4.2', 104 102 'ORCA1.0', 'ORCA1.1', 'ORCA1_CNRM', 'eORCA1.2', 105 'eORCA1.4', 'eORCA1.4. 2',103 'eORCA1.4', 'eORCA1.4.0', 'eORCA1.4.2', 106 104 'eORCA025', 'eORCA025.1', 'eORCA025.4'] ) 107 105 parser.add_argument ('--atm' , help='atm model name', type=str, default='LMD9695' ) … … 164 162 if atm_Name.find('ICO') >= 0 : atm_n = 'ico' ; atmDomainType = 'unstructured' 165 163 166 print ( 'atmQuantity : ' + str (myargs.atmQuantity))167 print ( 'oceQuantity : ' + str (myargs.oceQuantity))164 print (f'atmQuantity : {str (myargs.atmQuantity)}' ) 165 print (f'oceQuantity : {str (myargs.oceQuantity)}' ) 168 166 169 167 # Ocean grid periodicity 170 168 oce_perio = myargs.ocePerio 171 169 172 ### Read coordinates of all models 173 ### 170 ### Read coordinates of all models 174 171 175 172 diaFile = xr.open_dataset ( o2a ) … … 181 178 o2aFrac = np.where ( np.abs(o2aFrac) < 1E10, o2aFrac, 0.0) 182 179 183 (atm_nvertex, atm_jpj, atm_jpi) = gridFile[ 't'+atm_n+'.clo'][:].shape180 (atm_nvertex, atm_jpj, atm_jpi) = gridFile[f't{atm_n}.clo'][:].shape 184 181 atm_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'][:].shape182 atm_grid_rank = len(gridFile[f't{atm_n}.lat'][:].shape) 183 184 atm_grid_center_lat = gridFile [f't{atm_n}.lat'].squeeze() 185 atm_grid_center_lon = gridFile [f't{atm_n}.lon'].squeeze() 186 atm_grid_corner_lat = gridFile [f't{atm_n}.cla'].squeeze() 187 atm_grid_corner_lon = gridFile [f't{atm_n}.clo'].squeeze() 188 atm_grid_area = areaFile [f't{atm_n}.srf'].squeeze() 189 atm_grid_imask = 1-maskFile[f't{atm_n}.msk'][:].squeeze() 190 atm_grid_dims = gridFile [f't{atm_n}.lat'][:].shape 194 191 195 192 if atmDomainType == 'unstructured' : … … 285 282 atmOceanFrac = np.where (o2aFrac[:] > epsfrac , True, False) 286 283 287 ## For LMDZ only !! 284 ## For LMDZ only !! 288 285 if atmDomainType == 'rectilinear' : 289 286 print ('Extend coastal band ' ) … … 318 315 oce_address = np.empty ( shape=(0), dtype=np.int32 ) 319 316 320 ## Loop on atmosphere coastal points 317 ## Loop on atmosphere coastal points 321 318 if searchRadius > 0. : 322 319 print ('Loop on atmosphere coastal points') … … 469 466 f_runoff = xr.Dataset ( { 470 467 'remap_matrix' : remap_matrix, 471 472 473 474 475 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, 476 473 'src_grid_corner_lon' : src_grid_corner_lon, 477 474 'src_grid_corner_lat' : src_grid_corner_lat, 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 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 502 499 } ) 503 500 … … 544 541 f_runoff.close () 545 542 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.