Changeset 6093 for TOOLS/MOSAIX
- Timestamp:
- 03/07/22 12:17:05 (2 years ago)
- Location:
- TOOLS/MOSAIX
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
TOOLS/MOSAIX/CreateWeightsMask.bash
r6091 r6093 37 37 # $HeadURL$ 38 38 # 39 ## Tested with : 39 40 # CplModel=eORCA1.2xLMD144142 ; qsub -r ${CplModel} -o Out_${CplModel} -e Out_${CplModel} CreateWeightsMask.bash 40 41 # CplModel=ORCA2.3xLMD9695 … … 49 50 50 51 set +vx 52 # Prefixes for pretty print in color 51 53 export Bold=$(tput bold) 52 54 export Unde=$(tput smul) ; export OffUnde=$(tput rmul) … … 68 70 echo ${Titre}"Defines model"${Norm} 69 71 # ================================= 70 CplModel=ORCA2.3xLMD969572 #CplModel=ORCA2.3xLMD9695 71 73 #CplModel=ORCA2.3xICO30 72 #CplModel=ORCA2.3xICO4074 CplModel=ORCA2.3xICO40 73 75 #CplModel=eORCA1.2xLMD144142 74 76 #CplModel=eORCA1.2xLMD256256 … … 80 82 #Version="v1" ; Comment="Fully tested in IPSLCM6 eORCA1.2 x LMD 144x142" 81 83 #Version="NoSearchRadius" ; Comment="For testing new routing" 82 Version="v2" ; 84 Version="v2" ; Comment="Correction of ORCA masks to have a perfect conservation of run-off" 83 85 84 86 # If available, get model name from job name … … 88 90 OCE=${CplModel//x*} ; ATM=${CplModel##*x} 89 91 90 echo ${Titre}"ATM model : ${ATM}"${Norm} 91 echo ${Titre}"OCE model : ${OCE}"${Norm} 92 echo ${Titre}"Cpl model : ${CplModel}"${Norm} 93 echo ${Titre}"Version : ${Version}"${Norm} 92 ModelName="IPSL CM6" 93 [[ ${ATM} = ICO* ]] && ModelName="IPSL CM7" 94 95 echo ${Titre}"ATM model : ${ATM}" ${Norm} 96 echo ${Titre}"OCE model : ${OCE}" ${Norm} 97 echo ${Titre}"Cpl model : ${CplModel}" ${Norm} 98 echo ${Titre}"Version : ${Version}" ${Norm} 99 echo ${Titre}"Model Name : ${ModelName}"${Norm} 94 100 95 101 # Runoff parameter. atmCoastWidth and oceCoastWidth in grid points, searchRadius in km … … 118 124 # 119 125 # Each item in CommandList describes the properties of interpolation weights to generate. 120 # White spaces separate analysis. No spaces in any analysis. 126 # White spaces separate analysis. 127 # \!/ No spaces in any analysis \!/ 121 128 # 122 129 # Specific commands : 'Runoff', 'Calving' … … 125 132 # Direction : o2a for ocean to atmosphere, a2o for atmosphere to ocean. 126 133 # Order : 1st or 2nd. 127 # Quantity : true if integrated quantity over a grid box , false for flux (quantity / m^2)128 # or intensive value (temperature, salinity, sea-ice fraction, ...).134 # Quantity : true if integrated quantity over a grid box (i.e runoff on atmosphere side), 135 # false for flux (quantity / m^2) or intensive value (temperature, salinity, sea-ice fraction, ...). 129 136 # Renormalize : used when source grid is masked, to use values on non masked points only. 130 137 # oceGrid : t, u or v point for NEMO C grid. … … 185 192 # Functions to handle command parameters 186 193 # ====================================== 187 function read _Command {194 function readCommand { 188 195 # Decipher the command line to set bash variables 189 196 local l_Debug="no" l_Element … … 202 209 203 210 function setValues { 211 ## Read a command line to define shell variables 204 212 # Set default values 205 read _Command "Direction=None,Order=None,Quantity=None,Renormalize=None,atmGrid=None,oceGrid=None,useArea=None,maskSrc=None,maskDst=None"213 readCommand "Direction=None,Order=None,Quantity=None,Renormalize=None,atmGrid=None,oceGrid=None,useArea=None,maskSrc=None,maskDst=None" 206 214 # Read command line 207 read _Command ${1}215 readCommand ${1} 208 216 # 209 217 oceGrid=${oceGrid,,} ; atmGrid=${atmGrid,,} # Model names to lower case … … 329 337 fi 330 338 331 332 339 ## 333 340 echo ${Titre}"NEMO T point towards ATM - 1st order"${Norm} … … 341 348 342 349 cat << EOF > command_file_${OutFileName}.txt 343 -n 'context[@id="interpol_read"]/file_definition/file[@id="file_src"]/field[@id="mask_src"]' -k name -v maskutil_T 344 -n 'context[@id="interpol_read"]/file_definition/file[@id="file_src"]/field[@id="area_src"]' -k name -v area_grid_T 345 -n 'context[@id="interpol_read"]/domain_definition/domain[@id="domain_src"]' -k type -v ${srcDomainType} 346 -n 'context[@id="interpol_read"]/domain_definition/domain[@id="domain_dst"]' -k type -v ${dstDomainType} 347 -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k order -v 1 348 -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k quantity -v false 349 -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k renormalize -v false 350 -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k use_area -v false 351 -n 'context[@id="interpol_run"]/file_definition/file[@id="file_src"]/field[@id="mask_source"]' -k name -v maskutil_T 352 -n 'context[@id="interpol_run"]/file_definition/file[@id="file_src"]/field[@id="area_source"]' -k name -v area_grid_T 353 -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]' -k name -v dia_${OutFileName} 354 -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="title"]' -t "${SRC} mask interpolated to ${DST}" 355 -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="source_grid"]' -t ${srcDomainType} 356 -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="dest_grid"]' -t ${dstDomainType} 357 -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="order"]' -t 1 358 -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_src"]' -k type -v ${srcDomainType} 359 -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]' -k type -v ${dstDomainType} 360 -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k weight_filename -v rmp_${OutFileName}.nc 361 -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k order -v 1 362 -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="normalization"]' -t false 363 -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="quantity"]' -t false 364 -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="use_area"]' -t false 365 -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k renormalize -v false 366 -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k quantity -v false 367 -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k use_area -v false 350 -n 'context[@id="interpol_read"]/file_definition/file[@id="file_src"]/field[@id="mask_src"]' --key name=maskutil_T 351 -n 'context[@id="interpol_read"]/file_definition/file[@id="file_src"]/field[@id="area_src"]' --key name=area_grid_T 352 -n 'context[@id="interpol_read"]/domain_definition/domain[@id="domain_src"]' --key type=${srcDomainType} 353 -n 'context[@id="interpol_read"]/domain_definition/domain[@id="domain_dst"]' --key type=${dstDomainType} 354 -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' --key order=1 355 -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' --key quantity=false 356 -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' --key renormalize=false 357 -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' --key use_area=false 358 -n 'context[@id="interpol_run"]/file_definition/file[@id="file_src"]/field[@id="mask_source"]' --key name=maskutil_T 359 -n 'context[@id="interpol_run"]/file_definition/file[@id="file_src"]/field[@id="area_source"]' --key name=area_grid_T 360 -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]' --key name=dia_${OutFileName} 361 -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="title"]' --text "${SRC} mask interpolated to ${DST}" 362 -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="source_grid"]' --text ${srcDomainType} 363 -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="dest_grid"]' --text ${dstDomainType} 364 -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="order"]' --text 1 365 -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_src"]' --key type=${srcDomainType} 366 -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]' --key type=${dstDomainType} 367 -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' --key weight_filename=rmp_${OutFileName}.nc 368 -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' --key order=1 369 -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="normalization"]' --text false 370 -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="quantity"]' --text false 371 -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="use_area"]' --text false 372 -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' --key renormalize=false 373 -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' --key quantity=false 374 -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' --key use_area=false 375 -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="Model"]' --text "${ModelName}" 368 376 EOF 369 377 … … 376 384 ${MpiRun} ./interpol.exe --mask_src=${maskSrc} --mask_dst=${maskDst} --use_area=${useArea} 377 385 378 ncatted --history --attribute map_method,global,o,c,"Conservative Remapping - 1st order" rmp_${OutFileName}.nc 379 ncatted --history --attribute map_method,global,o,c,"Conservative Remapping - 1st order" dia_${OutFileName}.nc 380 381 ncatted --history --attribute normalization,global,o,c,"false" rmp_${OutFileName}.nc 382 ncatted --history --attribute normalization,global,o,c,"false" dia_${OutFileName}.nc 383 384 ncatted --history --attribute Quantity,global,o,c,"false" rmp_${OutFileName}.nc 385 ncatted --history --attribute Quantity,global,o,c,"false" dia_${OutFileName}.nc 386 387 ncatted --history --attribute UseArea,global,o,c,"false" rmp_${OutFileName}.nc 388 ncatted --history --attribute UseArea,global,o,c,"false" dia_${OutFileName}.nc 389 386 for File in rmp_${OutFileName}.nc dia_${OutFileName}.nc ; do 387 ncatted --history \ 388 --attribute map_method,global,o,c,"Conservative Remapping - 1st order" \ 389 --attribute normalization,global,o,c,"false" \ 390 --attribute Quantity,global,o,c,"false" \ 391 --attribute UseArea,global,o,c,"false" rmp_${OutFileName}.nc 392 done 390 393 ## 391 394 echo ${Titre}"Correct spurious values (extremes)"${Norm} 392 395 ## =========================================================================== 393 396 cat <<EOF > correction_masque.nco 394 where (OceFrac < 0.00001 )OceFrac=OceFrac.get_miss() ;395 where (OceFrac > 0.99999 )OceFrac=1.0 ;397 where (OceFrac < 0.00001) OceFrac=OceFrac.get_miss() ; 398 where (OceFrac > 0.99999) OceFrac=1.0 ; 396 399 OceFrac.delete_miss() ; 397 400 // Fill masked values to land values 398 where (OceFrac > 1.0 )OceFrac=0.0 ;399 where (OceFrac < 0.0 )OceFrac=0.0 ;401 where (OceFrac > 1.0) OceFrac=0.0 ; 402 where (OceFrac < 0.0) OceFrac=0.0 ; 400 403 OceMask = OceFrac ; 401 404 EOF 402 405 ncap2 --history --overwrite --script-file correction_masque.nco dia_t${oce}_to_t${atm}_${FullName}.nc tmp_dia_t${oce}_to_t${atm}_${FullName}.nc ; mv tmp_dia_t${oce}_to_t${atm}_${FullName}.nc dia_t${oce}_to_t${atm}_${FullName}.nc 403 ncatted --history -a missing_value,OceFrac,d,,"" -a _FillValue,OceFrac,d,,"" dia_t${oce}_to_t${atm}_${FullName}.nc 404 ncatted --history -a missing_value,OceMask,d,,"" -a _FillValue,OceMask,d,,"" dia_t${oce}_to_t${atm}_${FullName}.nc 406 ncatted --history -a missing_value,OceFrac,d,,"" -a _FillValue,OceFrac,d,,"" -a missing_value,OceMask,d,,"" -a _FillValue,OceMask,d,,"" dia_t${oce}_to_t${atm}_${FullName}.nc 405 407 406 408 ## … … 413 415 cat <<EOF > creation_masque.nco 414 416 Oce2AtmMask = OceMask ; 415 where (OceMask > 0.0 )Oce2AtmMask=1 ;416 where (OceMask <= 0.0 )Oce2AtmMask=0 ;417 where (OceMask > 0.0) Oce2AtmMask=1 ; 418 where (OceMask <= 0.0) Oce2AtmMask=0 ; 417 419 EOF 418 420 … … 425 427 case ${atm} in 426 428 ( *ico* ) 427 ncrename --history --dimension cell_domain_dst,cell ${ATM}_grid_maskFrom_${OCE}.nc 428 ncrename --history --dimension nvertex_domain_dst,nvertex ${ATM}_grid_maskFrom_${OCE}.nc 429 ncrename --history --variable lat_domain_dst,lat ${ATM}_grid_maskFrom_${OCE}.nc 430 ncrename --history --variable lon_domain_dst,lon ${ATM}_grid_maskFrom_${OCE}.nc 431 ncrename --history --variable bounds_lat_domain_dst,bounds_lat ${ATM}_grid_maskFrom_${OCE}.nc 432 ncrename --history --variable bounds_lon_domain_dst,bounds_lon ${ATM}_grid_maskFrom_${OCE}.nc 433 ncatted --history --attribute bounds,lat,m,c,"bounds_lat" ${ATM}_grid_maskFrom_${OCE}.nc 434 ncatted --history --attribute bounds,lon,m,c,"bounds_lon" ${ATM}_grid_maskFrom_${OCE}.nc 429 ncrename --history \ 430 --dimension cell_domain_dst,cell \ 431 --dimension nvertex_domain_dst,nvertex \ 432 --variable lat_domain_dst,lat --variable lon_domain_dst,lon \ 433 --variable bounds_lat_domain_dst,bounds_lat --variable bounds_lon_domain_dst,bounds_lon ${ATM}_grid_maskFrom_${OCE}.nc 434 ncatted --history --attribute bounds,lat,m,c,"bounds_lat" --attribute bounds,lon,m,c,"bounds_lon" ${ATM}_grid_maskFrom_${OCE}.nc 435 435 ;; 436 436 ( *lmd* ) 437 ncrename --history --variable lon_domain_dst,lon ${ATM}_grid_maskFrom_${OCE}.nc 438 ncrename --history --variable lat_domain_dst,lat ${ATM}_grid_maskFrom_${OCE}.nc 439 ncrename --history --dimension lon_domain_dst,lon ${ATM}_grid_maskFrom_${OCE}.nc 440 ncrename --history --dimension lat_domain_dst,lat ${ATM}_grid_maskFrom_${OCE}.nc 437 ncrename --history \ 438 --variable lon_domain_dst,lon --variable lat_domain_dst,lat \ 439 --dimension lon_domain_dst,lon --dimension lat_domain_dst,lat ${ATM}_grid_maskFrom_${OCE}.nc 441 440 ;; 442 441 esac 443 ncatted --history --attribute coordinates,OceFrac,m,c,"lat lon" ${ATM}_grid_maskFrom_${OCE}.nc444 ncatted --history --attribute coordinates,OceMask,m,c,"lat lon" ${ATM}_grid_maskFrom_${OCE}.nc445 ncatted --history --attribute coordinates,Oce2AtmMask,m,c,"lat lon" ${ATM}_grid_maskFrom_${OCE}.nc 446 447 ncatted --history --attribute long_name,OceFrac,c,c,"fraction of ocean in a grid cell" ${ATM}_grid_maskFrom_${OCE}.nc 448 ncatted --history --attribute units,OceFrac,c,c,"[0,1]" ${ATM}_grid_maskFrom_${OCE}.nc 449 ncatted --history --attribute long_name,OceMask,c,c,"fraction of ocean in a grid cell" ${ATM}_grid_maskFrom_${OCE}.nc 450 ncatted --history --attribute units,OceMask,c,c,"[0,1]" ${ATM}_grid_maskFrom_${OCE}.nc 451 ncatted --history --attribute long_name,Oce2AtmMask,c,c,"land mask" ${ATM}_grid_maskFrom_${OCE}.nc 452 ncatted --history --attribute units,Oce2AtmMask,c,c,"Land:0, Ocean:1" ${ATM}_grid_maskFrom_${OCE}.nc 453 442 443 ncatted --history \ 444 --attribute coordinates,OceFrac,m,c,"lat lon"\ 445 --attribute coordinates,OceMask,m,c,"lat lon" \ 446 --attribute coordinates,Oce2AtmMask,m,c,"lat lon" \ 447 --attribute long_name,OceFrac,c,c,"fraction of ocean in a grid cell" \ 448 --attribute units,OceFrac,c,c,"[0,1]" \ 449 --attribute long_name,OceMask,c,c,"fraction of ocean in a grid cell" \ 450 --attribute units,OceMask,c,c,"[0,1]" \ 451 --attribute long_name,Oce2AtmMask,c,c,"land mask" \ 452 --attribute units,Oce2AtmMask,c,c,"Land:0, Ocean:1" ${ATM}_grid_maskFrom_${OCE}.nc 454 453 fi 455 454 … … 458 457 459 458 [[ ${atm} = *ico* ]] && ncks --alphabetize --history --append --variable bounds_lon,bounds_lat atm_grid.nc ${ATM}_grid_maskFrom_${OCE}.nc 460 461 462 459 463 460 ## … … 489 486 if [[ ${Command} = "Grids" ]] ; then okGrids=yes ; continue ; fi 490 487 491 ln -fs ${OCE}_coordinates_mask.nc oce_grid.nc 492 #ln -fs ${ATM}_grid.nc atm_grid.nc 488 ln -fs ${OCE}_coordinates_mask.nc oce_grid.nc 493 489 ln -fs ${ATM}_grid_maskFrom_${OCE}.nc atm_grid.nc 494 490 … … 499 495 cp iodef_oce_to_atm.xml iodef.xml 500 496 cat << EOF > command_file_${OutFileName}.txt 501 -n 'context[@id="interpol_read"]/file_definition/file[@id="file_src"]/field[@id="mask_src"]' - k name -vmaskutil_${DSTGRID}502 -n 'context[@id="interpol_read"]/file_definition/file[@id="file_dst"]/field[@id="mask_dst"]' - k name -vOce2AtmMask503 -n 'context[@id="interpol_run"]/file_definition/file[@id="file_src"]/field[@id="mask_source"]' - k name -vmaskutil_${SRCGRID}504 -n 'context[@id="interpol_run"]/file_definition/file[@id="file_src"]/field[@id="area_source"]' - k name -varea_grid_${SRCGRID}505 -n 'context[@id="interpol_run"]/file_definition/file[@id="file_dst"]/field[@id="mask_dest"]' - k name -vOce2AtmMask506 -n 'context[@id="interpol_run"]/file_definition/file[@id="file_dst"]/field[@id="area_dest"]' - k name -vaire497 -n 'context[@id="interpol_read"]/file_definition/file[@id="file_src"]/field[@id="mask_src"]' --key name=maskutil_${DSTGRID} 498 -n 'context[@id="interpol_read"]/file_definition/file[@id="file_dst"]/field[@id="mask_dst"]' --key name=Oce2AtmMask 499 -n 'context[@id="interpol_run"]/file_definition/file[@id="file_src"]/field[@id="mask_source"]' --key name=maskutil_${SRCGRID} 500 -n 'context[@id="interpol_run"]/file_definition/file[@id="file_src"]/field[@id="area_source"]' --key name=area_grid_${SRCGRID} 501 -n 'context[@id="interpol_run"]/file_definition/file[@id="file_dst"]/field[@id="mask_dest"]' --key name=Oce2AtmMask 502 -n 'context[@id="interpol_run"]/file_definition/file[@id="file_dst"]/field[@id="area_dest"]' --key name=aire 507 503 EOF 508 504 ;; … … 510 506 cp iodef_atm_to_oce.xml iodef.xml 511 507 cat << EOF > command_file_${OutFileName}.txt 512 -n 'context[@id="interpol_read"]/file_definition/file[@id="file_src"]/field[@id="mask_src"]' - k name -vOce2AtmMask513 -n 'context[@id="interpol_read"]/file_definition/file[@id="file_dst"]/field[@id="mask_dst"]' - k name -vmask_${DSTGRID}514 -n 'context[@id="interpol_run"]/file_definition/file[@id="file_src"]/field[@id="mask_source"]' - k name -vOce2AtmMask515 -n 'context[@id="interpol_run"]/file_definition/file[@id="file_src"]/field[@id="area_source"]' - k name -vaire516 -n 'context[@id="interpol_run"]/file_definition/file[@id="file_dst"]/field[@id="mask_dest"]' - k name -vmask_${DSTGRID}517 -n 'context[@id="interpol_run"]/file_definition/file[@id="file_dst"]/field[@id="area_dest"]' - k name -varea_grid_${DSTGRID}508 -n 'context[@id="interpol_read"]/file_definition/file[@id="file_src"]/field[@id="mask_src"]' --key name=Oce2AtmMask 509 -n 'context[@id="interpol_read"]/file_definition/file[@id="file_dst"]/field[@id="mask_dst"]' --key name=mask_${DSTGRID} 510 -n 'context[@id="interpol_run"]/file_definition/file[@id="file_src"]/field[@id="mask_source"]' --key name=Oce2AtmMask 511 -n 'context[@id="interpol_run"]/file_definition/file[@id="file_src"]/field[@id="area_source"]' --key name=aire 512 -n 'context[@id="interpol_run"]/file_definition/file[@id="file_dst"]/field[@id="mask_dest"]' --key name=mask_${DSTGRID} 513 -n 'context[@id="interpol_run"]/file_definition/file[@id="file_dst"]/field[@id="area_dest"]' --key name=area_grid_${DSTGRID} 518 514 EOF 519 515 ;; … … 521 517 522 518 cat << EOF >> command_file_${OutFileName}.txt 523 -n 'context[@id="interpol_read"]/domain_definition/domain[@id="domain_dst"]' -k type -v ${dstDomainType} 524 -n 'context[@id="interpol_read"]/domain_definition/domain[@id="domain_src"]' -k type -v ${srcDomainType} 525 -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_src"]' -k type -v ${srcDomainType} 526 -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]' -k type -v ${dstDomainType} 527 -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k weight_filename -v rmp_${OutFileName}.nc 528 -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k order -v ${numOrder} 529 -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k quantity -v ${Quantity} 530 -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k renormalize -v ${Renormalize} 531 -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' -k use_area -v ${useArea} 532 -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]' -k name -v dia_${OutFileName} 533 -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="title"]' -t "${SRC} mask interpolated to ${DST}" 534 -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="dest_grid"]' -t ${dstDomainType} 535 -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="source_grid"]' -t ${srcDomainType} 536 -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="normalization"]' -t ${Renormalize} 537 -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="order"]' -t ${numOrder} 538 -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="quantity"]' -t ${Quantity} 539 -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="use_area"]' -t ${useArea} 519 -n 'context[@id="interpol_read"]/domain_definition/domain[@id="domain_dst"]' --key type=${dstDomainType} 520 -n 'context[@id="interpol_read"]/domain_definition/domain[@id="domain_src"]' --key type=${srcDomainType} 521 -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_src"]' --key type=${srcDomainType} 522 -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]' --key type=${dstDomainType} 523 -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' --key weight_filename=rmp_${OutFileName}.nc 524 -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' --key order=${numOrder} 525 -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' --key quantity=${Quantity} 526 -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' --key renormalize=${Renormalize} 527 -n 'context[@id="interpol_run"]/domain_definition/domain[@id="domain_dst"]/interpolate_domain' --key use_area=${useArea} 528 -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]' --key name=dia_${OutFileName} 529 -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="title"]' --text "${SRC} mask interpolated to ${DST}" 530 -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="dest_grid"]' --text ${dstDomainType} 531 -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="source_grid"]' --text ${srcDomainType} 532 -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="normalization"]' --text ${Renormalize} 533 -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="order"]' --text ${numOrder} 534 -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="quantity"]' --text ${Quantity} 535 -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="use_area"]' --text ${useArea} 536 -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="Model"]' --text "${ModelName}" 540 537 EOF 541 538 … … 546 543 547 544 case ${numOrder} in 548 ( 1 ) 549 ncatted --history --attribute map_method,global,o,c,"Conservative Remapping - 1st order" rmp_${OutFileName}.nc 550 ncatted --history --attribute map_method,global,o,c,"Conservative Remapping - 1st order" dia_${OutFileName}.nc 551 ;; 552 ( 2 ) 553 ncatted --history --attribute map_method,global,o,c,"Conservative Remapping - 2nd order" rmp_${OutFileName}.nc 554 ncatted --history --attribute map_method,global,o,c,"Conservative Remapping - 2nd order" dia_${OutFileName}.nc 555 ;; 556 esac 557 558 ncatted --history --attribute normalization,global,o,c,"${Renormalize}" rmp_${OutFileName}.nc 559 ncatted --history --attribute normalization,global,o,c,"${Renormalize}" dia_${OutFileName}.nc 560 561 ncatted --history --attribute Quantity,global,o,c,"${Quantity}" rmp_${OutFileName}.nc 562 ncatted --history --attribute Quantity,global,o,c,"${Quantity}" dia_${OutFileName}.nc 563 564 ncatted --history --attribute UseArea,global,o,c,"${useArea}" rmp_${OutFileName}.nc 565 ncatted --history --attribute UseArea,global,o,c,"${useArea}" dia_${OutFileName}.nc 566 545 ( 1 ) Text="Conservative Remapping - 1st order" ;; 546 ( 2 ) Text="Conservative Remapping - 2nd order" ;; 547 esac 548 for File in rmp_${OutFileName}.nc dia_${OutFileName}.nc ; do 549 ncatted --history \ 550 --attribute map_method,global,o,c,"${Text}" \ 551 --attribute normalization,global,o,c,"${Renormalize}" \ 552 --attribute Quantity,global,o,c,"${Quantity}" \ 553 --attribute UseArea,global,o,c,"${useArea}" ${File} 554 done 567 555 done 568 556 … … 571 559 ## =========================================================================== 572 560 573 NCO="$(ncks --version |& tail -1 |sed 's/ncks //')"561 NCO="$(ncks --version |& tail -1 | sed 's/ncks //')" 574 562 PYTHON_VER=$( python3 -c "import sys ; print (sys.version.split(' ')[0])" ) 575 563 for InFile in $(ls *${oce}_to_*${atm}_*.nc *${atm}_to_*${oce}_*.nc ${ATM}_grid_maskFrom_${OCE}.nc 2> /dev/null) ; do … … 579 567 --attribute Conventions,global,o,c,"CF-1.6" \ 580 568 --attribute source,global,o,c,"IPSL Earth system model" \ 569 --attribute model,global,o,c,"${ModelName}" \ 581 570 --attribute group,global,o,c,"ICMC IPSL Climate Modelling Center" \ 582 571 --attribute Institution,global,o,c,"IPSL https://www.ipsl.fr" \ 583 572 --attribute Ocean,global,o,c,"${OCE} https://www.nemo-ocean.eu" \ 584 573 --attribute Atmosphere,global,o,c,"${ATM} http://lmdz.lmd.jussieu.fr" \ 585 --attribute production,global,o,c,"$(finger ${LOGNAME} | head -1 | awk '{print $4 , $5}')" \574 --attribute production,global,o,c,"$(finger ${LOGNAME} | head -1 | awk '{print $4}')" \ 586 575 --attribute originalFiles,global,o,c,"${OCE}_coordinates_mask.nc ${ATM}_grid_mask.nc" \ 587 576 --attribute associatedFiles,global,o,c,"grids_${CplModel}.nc areas_${CplModel}.nc masks_${CplModel}.nc" \ … … 594 583 --attribute LOGNAME,global,o,c,"$(whoami)" \ 595 584 --attribute NCO,global,o,c,"NCO netCDF Operator ${NCO} http://nco.sourceforge.net" \ 596 --attribute Python,global,o,c,"Python3 version ${PYTHON_VER}" 597 --attribute release,global,o,c,"$(uname -r)" \585 --attribute Python,global,o,c,"Python3 version ${PYTHON_VER}" \ 586 --attribute machine,global,o,c,"$(uname -a)" \ 598 587 --attribute directory,global,o,c,"$(pwd)" \ 599 588 --attribute description,global,o,c,"Generated with XIOS http://forge.ipsl.jussieu.fr/ioserver and MOSAIX https://forge.ipsl.jussieu.fr/igcmg/browser/TOOLS/MOSAIX" \ 600 589 --attribute SVN_Author,global,o,c,'$Author$' \ 601 --attribute SVN_Date,global,o,c,'$Date$' 590 --attribute SVN_Date,global,o,c,'$Date$' \ 602 591 --attribute SVN_Revision,global,o,c,'$Revision$' \ 603 --attribute SVN_Id,global,o,c,'$Id$' 592 --attribute SVN_Id,global,o,c,'$Id$' \ 604 593 ${InFile} 605 594 done … … 607 596 # Duplicate with no global attribute to avoid erasing attributes in other files 608 597 cp ${ATM}_grid_maskFrom_${OCE}.nc ${ATM}_grid_maskFrom_${OCE}_noglobal.nc 609 ncatted --history --attribute 598 ncatted --history --attribute,global,d,c, ${ATM}_grid_maskFrom_${OCE}_noglobal.nc 610 599 611 600 ## … … 621 610 ncap2 --history --script-file add_dim.nco tmp_${rmpFile} ${rmpFile} ; rm tmp_${rmpFile} 622 611 623 ncrename --history --dimension n_weight,num_links ${rmpFile}624 ncrename --history --variable src_idx,src_address ${rmpFile} 625 ncrename --history --variable dst_idx,dst_address ${rmpFile} 626 ncrename --history --variable weight,remap_matrix ${rmpFile} 627 612 ncrename --history \ 613 --dimension n_weight,num_links \ 614 --variable src_idx,src_address \ 615 --variable dst_idx,dst_address \ 616 --variable weight,remap_matrix ${rmpFile} 628 617 629 ncatted --history --attribute conventions,global,o,c,"SCRIP" ${rmpFile} 630 ncatted --history --attribute normalization,global,o,c,"none" ${rmpFile} 618 ncatted --history --attribute conventions,global,o,c,"SCRIP" --attribute normalization,global,o,c,"none" ${rmpFile} 631 619 632 620 case ${rmpFile} in … … 648 636 done 649 637 650 ls651 638 ## 652 639 echo ${Titre}"Add missing variables in rmp files"${Norm} … … 849 836 --o2a=${ATM}_grid_maskFrom_${OCE}.nc 850 837 ;; 851 852 838 esac 853 839 fi … … 911 897 All files have the same uuid in the global attributes 912 898 913 Description : Weigths and auxiliary files for coupling ${OCE} and ${ATM} needed by OASIS-MCT 914 Conventions : CF-1.6 915 source : IPSL Earth system model 916 group : ICMC IPSL Climate Modelling Center 917 Institution : IPSL https://www.ipsl.fr 918 Ocean : ${OCE} https://www.nemo-ocean.eu 919 Atmosphere : ${ATM} http://lmdz.lmd.jussieu.fr 920 production : $(finger ${LOGNAME} | head -1 | awk '{print $4, $5}') 921 originalFiles : ${OCE}_coordinates_mask.nc ${ATM}_grid_mask.nc 922 associatedFiles : grids_${CplModel}.nc areas_${CplModel}.nc masks_${CplModel}.nc 923 directory : $(pwd) 924 timeStamp : $(date) 925 uuid : ${UUID} 926 HOSTNAME : $(hostname) 927 LOGNAME : $(whoami) 928 NCO : NCO netCDF Operator ${NCO} http://nco.sourceforge.net 929 Python version : ${PYTHON_VER} 930 release : $(uname -r) 931 EOF 932 933 echo 'SVN Information : ' >> README.txt 934 echo '$Author$ ' >> README.txt 935 echo '$Date$ ' >> README.txt 936 echo '$Revision$ ' >> README.txt 899 Description : Weigths and auxiliary files for coupling ${OCE} and ${ATM} needed by OASIS-MCT 900 Conventions : CF-1.6 901 Source : IPSL Earth system model 902 Model : ${ModelName} 903 Group : ICMC IPSL Climate Modelling Center 904 Institution : IPSL https://www.ipsl.fr 905 Ocean : ${OCE} https://www.nemo-ocean.eu 906 Atmosphere : ${ATM} http://lmdz.lmd.jussieu.fr 907 Production : $(finger ${LOGNAME} | head -1 | awk '{print $4}') 908 Original files : ${OCE}_coordinates_mask.nc ${ATM}_grid_mask.nc 909 Associated files : grids_${CplModel}.nc areas_${CplModel}.nc masks_${CplModel}.nc 910 Description : Generated with XIOS http://forge.ipsl.jussieu.fr/ioserver and MOSAIX https://forge.ipsl.jussieu.fr/igcmg/browser/TOOLS/MOSAIX" 911 directory : $(pwd) 912 timeStamp : $(date) 913 Machine info : $(uname -a) 914 uuid : ${UUID} 915 HOSTNAME : $(hostname) 916 LOGNAME : $(whoami) 917 NCO : NCO netCDF Operator ${NCO} http://nco.sourceforge.net 918 Python version : ${PYTHON_VER} 919 920 EOF 921 922 echo 'SVN Information : ' >> README.txt 923 echo '$Author$ ' >> README.txt 924 echo '$Date$ ' >> README.txt 925 echo '$Revision$ ' >> README.txt 937 926 echo '$Id$ ' >> README.txt 938 927 echo '$HeadURL$ ' >> README.txt … … 944 933 Files produced, with checksum produced by Unix command shasum (version $(shasum --version)) with default algorithm 945 934 935 Checksum File 936 ======================================================================================================== 946 937 EOF 947 938 -
TOOLS/MOSAIX/update_xml.py
r6091 r6093 22 22 __HeadURL = "$HeadURL$" 23 23 24 # python update_xml.py -i ~/Unix/TOOLS/MOSAIX/iodef_atm_to_oce.xml -o essai.xml -n 'context[@id="interpol_read"]/file_definition/file[@id="file_src"]/field[@id="mask_src"]' -k name -vBidon24 # python update_xml.py -i ~/Unix/TOOLS/MOSAIX/iodef_atm_to_oce.xml -o essai.xml -n 'context[@id="interpol_read"]/file_definition/file[@id="file_src"]/field[@id="mask_src"]' -k name=Bidon 25 25 # python update_xml.py -i ~/Unix/TOOLS/MOSAIX/iodef_atm_to_oce.xml -d -o essai.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="dia"]/variable[@name="title"]' -t "SRC mask interpolated to DST" 26 26 # python update_xml.py -i ~/Unix/TOOLS/MOSAIX/iodef_atm_to_oce.xml -o essai.xml -c InFile.txt … … 29 29 # 30 30 import xml.etree.ElementTree 31 import argparse, sys, textwrap 31 import argparse, sys, textwrap, shlex 32 32 33 33 # Check version of Python … … 55 55 return list_new 56 56 57 def UpdateNode (iodef, Node, Text , Key, Value) :57 def UpdateNode (iodef, Node, Text=None, Key=None) : 58 58 '''Update an xml node''' 59 59 # Remove whitespaces at both ends … … 70 70 71 71 if len (nodeList) > 1 : 72 print ( "Error : " + len (nodeList)+" occurences of node found " )72 print ( "Error : " + len (nodeList)+" occurences of node found in file" ) 73 73 print ( "Node : ", Node ) 74 74 sys.exit (2) … … 77 77 elem = nodeList[0] 78 78 79 if Debug :80 print ( 'Node:', Node, ' -- Key:', Key, ' -- Value:', Value , ' -- Text:', Text )81 82 79 if Text != None : 80 if Verbose : print ( 'Node:', Node, ' -- Text:', Text ) 83 81 if Debug : 84 82 print ( 'Attributes of node: ' + str (elem.attrib) ) … … 87 85 88 86 if Key != None : 89 # To do : check that Key exist (it is added if not : do we want that ?) 90 if Debug : 91 print ( 'Attributes of node: ' + str (elem.attrib) ) 92 elem.attrib.update ( { Key:Value } ) 87 88 # Check the syntax 89 if not '=' in Key : 90 print ( 'Key syntax error. Correct syntax is -k Key=Value' ) 91 sys.exit (-1) 92 else : 93 KeyName, Value = Key.split ('=') 94 if Verbose : print ( 'Node:', Node, ' -- Key:', Key ) 95 # To do : check that KeyName exist (it is added if not : do we want that ?) 96 if Debug : 97 print ( 'Attributes of node: ' + str (elem.attrib) ) 98 elem.attrib.update ( { KeyName:Value } ) 93 99 94 100 return iodef … … 115 121 group1 = parser.add_mutually_exclusive_group (required=False) 116 122 117 parser.add_argument ( '-i', '--input' , help="XML input file" 118 parser.add_argument ( '-o', '--output' , help="XML output file" 123 parser.add_argument ( '-i', '--input' , help="XML input file" , default='iodef.xml', type=str, metavar='<input_file>' ) 124 parser.add_argument ( '-o', '--output' , help="XML output file" , default=None , type=str, metavar='<output_file>' ) 119 125 parser.add_argument ( '-n', '--node' , help="XML node in Xpath syntax", default=None, type=str, metavar='<xml_node>') 120 group1.add_argument ( '-k', '--key' , help="XML key to update " , default=None , type=str, metavar='<xml_key>' )126 group1.add_argument ( '-k', '--key' , help="XML key to update and new value (-k <name>=<value>)", default=None, type=str, metavar='<xml_key>' ) 121 127 group1.add_argument ( '-t', '--text' , help="Will replace the 'text' part of the Xpath by <text>", default=None, type=str, metavar='<text>' ) 122 parser.add_argument ( '-v', '--value' , help="New value for xml key ", default=None, type=str, metavar='<value>' ) 123 parser.add_argument ( '-d', '--debug' , action="store_true", default=False ) 124 parser.add_argument ( '-V', '--verbose', action="store_true", default=False ) 128 parser.add_argument ( '-d', '--debug' , help="Extensive debug prints", action="store_true", default=False ) 129 parser.add_argument ( '-v', '--verbose', help="Some verbosity" , action="store_true", default=False ) 125 130 parser.add_argument ( '-c', '--commandfile', help="file with list of command", default=None, type=str ) 126 131 … … 138 143 Key = myargs.key 139 144 Text = myargs.text 140 Value = myargs.value141 145 142 146 if FileCommand != None : 143 if ( Node != None or Key != None or Text != None or Value != None) :144 print ('Error : when a command file is specified, options -k|--key, -n|--node a nd -v|--value aunused' )147 if ( Node != None or Key != None or Text != None ) : 148 print ('Error : when a command file is specified, options -k|--key, -n|--node are unused' ) 145 149 exit (-2) 146 150 … … 152 156 if FileCommand == None : 153 157 ## Only one node to modify 154 155 # Error handling not dealed by argparse 156 if Key != None and Value == None : 157 print ( "Error. When -k|--key=<key> is specified, you must specify -v|--value=<xml_value>" ) 158 sys.exit (-1) 159 160 iodef = UpdateNode ( iodef, Node, Text, Key, Value) 158 iodef = UpdateNode (iodef, Node, Key, Text) 161 159 162 160 else : … … 166 164 167 165 for nn, ligne in enumerate (lignes) : 166 ligne = ligne.strip ().split ('#')[0] # Remove leading and trailing blanks, and trailing comments 167 if Debug : print (nn+1, ':', type (ligne) , ':', len (ligne) , ':', ligne, ':') 168 if ligne == '' or ligne == None or len(ligne) == 0 or ligne[0] == '#' : 169 if Debug : print ('Skips blank or comment line') 170 else : 171 list_args = shlex.split (ligne) 172 173 if Debug : 174 print ( '{:3d} : '.format(nn+1), end='') 175 print ( list_args ) 176 # Parse args line 177 myargs_ligne = parser.parse_args (list_args) 168 178 169 ligne = ligne.strip()170 if ligne == '' : break # Skips blank lines171 if ligne[0] == '#' : break # Skips comment lines179 Node = myargs_ligne.node 180 Key = myargs_ligne.key 181 Text = myargs_ligne.text 172 182 173 ligne = ligne.split('#')[0] # Remove trailing comments 174 175 list_args = ligne.split() 176 list_args = simplify_string_list ( list_args ) 177 178 if Debug : 179 print ( '{:3d} : '.format(nn+1), end='') 180 print ( list_args ) 181 myargs_ligne = parser.parse_args ( list_args ) 182 183 Node = myargs_ligne.node 184 Key = myargs_ligne.key 185 Text = myargs_ligne.text 186 Value = myargs_ligne.value 187 188 if Key != None and Value == None : 189 print ( "Error. When -k|--key=<key> is specified, you must specify -v|--value=<xml_value>" ) 190 sys.exit (-1) 191 UpdateNode ( iodef, Node, Text, Key, Value) 183 UpdateNode (iodef, Node, Text, Key) 192 184 193 185 ## Writes XML tree to file … … 195 187 196 188 ## This is the end 197 sys.exit (0) 189 if Debug : print ('This is the end') 190 #sys.exit (0) 198 191 199 192 ### ===========================================================================
Note: See TracChangeset
for help on using the changeset viewer.