Changeset 6066 for TOOLS/MOSAIX/CalvingWeights.py
- Timestamp:
- 02/24/22 15:17:45 (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TOOLS/MOSAIX/CalvingWeights.py
r6064 r6066 14 14 ## personal. 15 15 ## 16 import n etCDF4, numpy as np16 import numpy as np, xarray as xr 17 17 import sys, os, platform, argparse, textwrap, time 18 18 from scipy import ndimage … … 36 36 37 37 # Adding arguments 38 parser.add_argument ('--oce' , help='oce model name', type=str, default='eORCA1.2', choices=['ORCA2.3', 'eORCA1.2', 'eORCA025', 'eORCA025.1'] ) 38 parser.add_argument ('--oce' , help='oce model name', type=str, default='eORCA1.2', 39 choices=['ORCA2.3', 'eORCA1.2', 'eORCA1.4', 'eORCA1.4.2', 'eORCA025', 'eORCA025.1', 'eORCA025.4'] ) 39 40 parser.add_argument ('--atm' , help='atm model name (ICO* or LMD*)', type=str, default='ICO40' ) 40 41 parser.add_argument ('--type' , help='Type of distribution', type=str, choices=['iceshelf', 'iceberg', 'nosouth', 'full'], default='full' ) 41 parser.add_argument ('--dir' , help='Directory of input file', type=str, default='./' )42 ## parser.add_argument ('--dir' , help='Directory of input file', type=str, default='./' ) 42 43 parser.add_argument ('--repartition_file', help='Data files with iceberg melting' , type=str, default='./runoff-icb_DaiTrenberth_Depoorter_eORCA1_JD.nc' ) 43 44 parser.add_argument ('--repartition_var' , help='Variable name for iceshelf' , type=str, default=None) 45 parser.add_argument ('--grids' , help='grids file name', default='grids.nc' ) 46 parser.add_argument ('--areas' , help='masks file name', default='areas.nc' ) 47 parser.add_argument ('--masks' , help='areas file name', default='masks.nc' ) 48 parser.add_argument ('--o2a' , help='o2a file name' , default='o2a.nc' ) 44 49 parser.add_argument ('--output' , help='output rmp file name', default='rmp_tlmd_to_torc_calving.nc' ) 45 parser.add_argument ('--fmt' , help='NetCDF file format, using nco syntax', default='netcdf4', choices=['classic', 'netcdf3', '64bit', '64bit_data', '64bit_data', 'netcdf4', 'netcdf4_classsic'] ) 46 parser.add_argument ('--ocePerio' , help='periodicity of ocean grid', type=int, default=0 ) 50 parser.add_argument ('--fmt' , help='NetCDF file format, using nco syntax', default='netcdf4', 51 choices=['classic', 'netcdf3', '64bit', '64bit_data', '64bit_data', 'netcdf4', 'netcdf4_classsic'] ) 52 parser.add_argument ('--ocePerio', help='periodicity of ocean grid', type=int, default=0 ) 47 53 48 54 # Parse command line … … 89 95 90 96 # Reading domains characteristics 91 areas = myargs.dir + '/areas_' + dst_Name + 'x' + src_Name + '.nc' 92 masks = myargs.dir + '/masks_' + dst_Name + 'x' + src_Name + '.nc' 93 grids = myargs.dir + '/grids_' + dst_Name + 'x' + src_Name + '.nc' 97 grids = myargs.grids 98 areas = myargs.areas 99 masks = myargs.masks 100 o2a = myargs.o2a 94 101 95 102 print ('Opening ' + areas) 96 f_areas = netCDF4.Dataset ( areas, "r")103 f_areas = xr.open_dataset ( areas ) 97 104 print ('Opening ' + masks) 98 f_masks = netCDF4.Dataset ( masks, "r")105 f_masks = xr.open_dataset ( masks ) 99 106 print ('Opening ' + grids) 100 f_grids = netCDF4.Dataset ( grids, "r")101 102 src_lon = f_grids .variables ['t' + src_name + '.lon'][:]103 src_lat = f_grids .variables ['t' + src_name + '.lat'][:]104 dst_lon = f_grids .variables ['t' + dst_name + '.lon'][:]105 dst_lat = f_grids .variables ['t' + dst_name + '.lat'][:]106 107 src_msk = f_masks .variables ['t' + src_name + '.msk'][:]108 dst_msk = f_masks .variables ['t' + dst_name + '.msk'][:]107 f_grids = xr.open_dataset ( grids ) 108 109 src_lon = f_grids ['t' + src_name + '.lon'] 110 src_lat = f_grids ['t' + src_name + '.lat'] 111 dst_lon = f_grids ['t' + dst_name + '.lon'] 112 dst_lat = f_grids ['t' + dst_name + '.lat'] 113 114 src_msk = f_masks ['t' + src_name + '.msk'] 115 dst_msk = f_masks ['t' + dst_name + '.msk'] 109 116 dst_mskutil = 1-dst_msk # Reversing the convention : 0 on continent, 1 on ocean 110 print ('dst_msk : ' + str(np.sum(dst_msk)))111 print ('dst_mskutil : ' + str(np.sum(dst_mskutil)))117 print ('dst_msk : ', dst_msk.sum().values ) 118 print ('dst_mskutil : ', dst_mskutil.sum().values ) 112 119 113 120 # Ocean grid periodicity … … 116 123 # Periodicity masking for NEMO 117 124 if nperio_dst == 0 : 118 if dst_Name == 'ORCA2.3' : nperio_dst = 4 119 if dst_Name == 'eORCA1.2' : nperio_dst = 6 120 if dst_Name == 'ORCA025' : nperio_dst = 6 121 if dst_Name == 'eORCA025' : nperio_dst = 6 122 if dst_Name == 'eORCA025.1' : nperio_dst = 6 125 if dst_Name in ['ORCA2.3', 'ORCA2.4'] : nperio_dst = 4 126 if dst_Name in ['eORCA1.2', 'eORCA1.3'] : nperio_dst = 6 127 if dst_Name in ['ORCA025', 'eORCA025', 'eORCA025.1', 'eORCA025.4'] : nperio_dst = 6 128 123 129 print ('nperio_dst: ' + str(nperio_dst) ) 124 130 dst_mskutil = nemo.lbc_mask (dst_mskutil, nperio=nperio_dst, cd_type='T', sval=0 ) … … 144 150 dst_mskutil[997:1012,907] = 0 145 151 146 if dst_Name in [ 'eORCA1.2', 'eORCA1.3', 'eORCA1.4' ] :152 if dst_Name in [ 'eORCA1.2', 'eORCA1.3', 'eORCA1.4', 'eORCA1.4.2' ] : 147 153 print ('Filling some seas for ' + dst_Name) 148 154 # Set Gibraltar strait to 0 to fill Mediterrean sea … … 184 190 dst_srfutil_sum = np.sum( dst_srfutil) 185 191 186 src_clo = f_grids .variables ['t' + src_name + '.clo'][:]187 src_cla = f_grids .variables ['t' + src_name + '.cla'][:]188 dst_clo = f_grids .variables ['t' + dst_name + '.clo'][:]189 dst_cla = f_grids .variables ['t' + dst_name + '.cla'][:]192 src_clo = f_grids ['t' + src_name + '.clo'] 193 src_cla = f_grids ['t' + src_name + '.cla'] 194 dst_clo = f_grids ['t' + dst_name + '.clo'] 195 dst_cla = f_grids ['t' + dst_name + '.cla'] 190 196 191 197 # Indices … … 198 204 # Reading data file for calving or iceberg geometry around Antarctica 199 205 print ( 'Opening ' + myargs.repartition_file) 200 f_repartition = netCDF4.Dataset ( myargs.repartition_file, "r")201 repartition = np.sum ( f_repartition.variables [repartitionVar] [:], axis=0 )206 f_repartition = xr.open_dataset ( myargs.repartition_file ) 207 repartition = np.sum ( f_repartition.variables [repartitionVar], axis=0 ) 202 208 203 209 ## Before loop on basins … … 246 252 247 253 # Integral and normalisation 248 sum_repartition = np.sum ( key_repartition[n_bas] * dst_srfutil ) 254 sum_repartition = np.sum ( key_repartition[n_bas] * dst_srfutil ).values 249 255 key_repartition = key_repartition / sum_repartition 250 256 251 257 print ( 'Sum of repartition key : {:12.3e}'.format (np.sum (key_repartition[n_bas] )) ) 252 print ( 'Integral (area weighted) of repartition key : {:12.3e}'.format (np.sum (key_repartition[n_bas] * dst_srfutil ) ) )258 print ( 'Integral (area weighted) of repartition key : {:12.3e}'.format (np.sum (key_repartition[n_bas] * dst_srfutil ).values) ) 253 259 254 260 # Basin surface (modulated by repartition key) … … 257 263 # Weights and links 258 264 poids = 1.0 / basin_srfutil 259 matrix_local = np.where ( basin_msk[n_bas].ravel() > 0.5, key_repartition[n_bas].ravel()*poids , 0. )265 matrix_local = np.where ( basin_msk[n_bas].ravel() > 0.5, key_repartition[n_bas].ravel()*poids.values, 0. ) 260 266 matrix_local = matrix_local[matrix_local > 0.0] # Keep only non zero values 261 267 num_links = np.count_nonzero (matrix_local) … … 297 303 # Output file 298 304 calving = myargs.output 299 f_calving = netCDF4.Dataset ( calving, 'w', format=FmtNetcdf )300 305 301 306 print ('Output file: ' + calving ) 302 307 303 f_calving.Conventions = "CF-1.6" 304 f_calving.source = "IPSL Earth system model" 305 f_calving.group = "ICMC IPSL Climate Modelling Center" 306 f_calving.Institution = "IPSL https.//www.ipsl.fr" 307 f_calving.Ocean = dst_Name + " https://www.nemo-ocean.eu" 308 f_calving.Atmosphere = src_Name + " http://lmdz.lmd.jussieu.fr" 309 if myargs.type in ['iceberg', 'iceshelf' ]: f_calving.originalFiles = myargs.repartition_file 310 f_calving.associatedFiles = grids + " " + areas + " " + masks 311 f_calving.directory = os.getcwd () 312 f_calving.description = "Generated with XIOS http://forge.ipsl.jussieu.fr/ioserver and MOSAIX https://forge.ipsl.jussieu.fr/igcmg/browser/TOOLS/MOSAIX" 313 f_calving.title = calving 314 f_calving.Program = "Generated by " + sys.argv[0] + " with flags " + str(sys.argv[1:]) 315 f_calving.repartitionType = myargs.type 316 if myargs.type in [ 'iceberg', 'iceshelf' ] : 317 f_calving.repartitionFile = myargs.repartition_file 318 f_calving.repartitionVar = repartitionVar 319 f_calving.gridsFile = grids 320 f_calving.areasFile = areas 321 f_calving.masksFile = masks 322 f_calving.timeStamp = time.asctime() 323 f_calving.HOSTNAME = platform.node() 324 #f_calving.LOGNAME = os.getlogin() 325 f_calving.Python = "Python version " + platform.python_version() 326 f_calving.OS = platform.system() 327 f_calving.release = platform.release() 328 f_calving.hardware = platform.machine() 329 f_calving.conventions = "SCRIP" 330 if src_name == 'lmd' : f_calving.source_grid = "curvilinear" 331 if src_name == 'ico' : f_calving.source_grid = "unstructured" 332 f_calving.dest_grid = "curvilinear" 333 f_calving.Model = "IPSL CM6" 334 f_calving.SVN_Author = "$Author$" 335 f_calving.SVN_Date = "$Date$" 336 f_calving.SVN_Revision = "$Revision$" 337 f_calving.SVN_Id = "$Id$" 338 f_calving.SVN_HeadURL = "$HeadURL$" 339 340 d_nb_zone = f_calving.createDimension ('nb_zone' , nb_zone ) 341 d_num_links = f_calving.createDimension ('num_links' , num_links ) 342 d_num_wgts = f_calving.createDimension ('num_wgts' , 1 ) 343 344 d_src_grid_size = f_calving.createDimension ('src_grid_size' , src_grid_size ) 345 d_src_grid_corners = f_calving.createDimension ('src_grid_corners', src_clo.shape[0] ) 346 d_src_grid_rank = f_calving.createDimension ('src_grid_rank' , 2 ) 347 348 d_dst_grid_size = f_calving.createDimension ('dst_grid_size' , dst_grid_size ) 349 d_dst_grid_corners = f_calving.createDimension ('dst_grid_corners', dst_clo.shape[0] ) 350 d_dst_grid_rank = f_calving.createDimension ('dst_grid_rank' , 2 ) 351 352 v_remap_matrix = f_calving.createVariable ( 'remap_matrix', 'f8', ('num_links', 'num_wgts') ) 353 v_src_address = f_calving.createVariable ( 'src_address' , 'i4', ('num_links',) ) 354 v_src_address.convention = "Fortran style addressing, starting at 1" 355 v_dst_address = f_calving.createVariable ( 'dst_address' , 'i4', ('num_links',) ) 356 v_dst_address.convention = "Fortran style addressing, starting at 1" 357 358 v_remap_matrix[:] = remap_matrix 359 v_src_address [:] = src_address 360 v_dst_address [:] = dst_address 361 362 v_src_grid_dims = f_calving.createVariable ( 'src_grid_dims' , 'i4', ('src_grid_rank',) ) 363 v_src_grid_center_lon = f_calving.createVariable ( 'src_grid_center_lon', 'i4', ('src_grid_size',) ) 364 v_src_grid_center_lat = f_calving.createVariable ( 'src_grid_center_lat', 'i4', ('src_grid_size',) ) 365 v_src_grid_center_lon.units='degrees_east' ; v_src_grid_center_lon.long_name='Longitude' 366 v_src_grid_center_lon.long_name='longitude' ; v_src_grid_center_lon.bounds="src_grid_corner_lon" 367 v_src_grid_center_lat.units='degrees_north' ; v_src_grid_center_lat.long_name='Latitude' 368 v_src_grid_center_lat.long_name='latitude ' ; v_src_grid_center_lat.bounds="src_grid_corner_lat" 369 v_src_grid_corner_lon = f_calving.createVariable ( 'src_grid_corner_lon', 'f8', ('src_grid_size', 'src_grid_corners') ) 370 v_src_grid_corner_lat = f_calving.createVariable ( 'src_grid_corner_lat', 'f8', ('src_grid_size', 'src_grid_corners') ) 371 v_src_grid_corner_lon.units="degrees_east" 372 v_src_grid_corner_lat.units="degrees_north" 373 v_src_grid_area = f_calving.createVariable ( 'src_grid_area' , 'f8', ('src_grid_size',) ) 374 v_src_grid_area.long_name="Grid area" ; v_src_grid_area.standard_name="cell_area" ; v_src_grid_area.units="m2" 375 v_src_grid_imask = f_calving.createVariable ( 'src_grid_imask' , 'f8', ('src_grid_size',) ) 376 v_src_grid_imask.long_name="Land-sea mask" ; v_src_grid_imask.units="Land:1, Ocean:0" 377 378 v_src_grid_dims [:] = ( src_jpi, src_jpi ) 379 v_src_grid_center_lon[:] = src_lon[:].ravel() 380 v_src_grid_center_lat[:] = src_lat[:].ravel() 381 v_src_grid_corner_lon[:] = src_clo.reshape( (src_jpi*src_jpj, d_src_grid_corners.__len__()) ) 382 v_src_grid_corner_lat[:] = src_cla.reshape( (src_jpi*src_jpj, d_src_grid_corners.__len__()) ) 383 v_src_grid_area [:] = src_srf[:].ravel() 384 v_src_grid_imask [:] = src_msk[:].ravel() 308 remap_matrix = xr.DataArray (np.reshape(remap_matrix, (num_links, 1)), dims = ['num_links', 'num_wgts'] ) 309 src_address = xr.DataArray (src_address.astype(np.int32) , dims = ['num_links',] ) 310 src_address.attrs['convention'] = "Fortran style addressing, starting at 1" 311 dst_address = xr.DataArray (dst_address.astype(np.int32) , dims = ['num_links',] ) 312 dst_address.attrs['convention'] = "Fortran style addressing, starting at 1" 313 314 src_grid_dims = xr.DataArray ( np.array (( src_jpi, src_jpi ), dtype=np.int32), dims = ['src_grid_rank',] ) 315 src_grid_center_lon = xr.DataArray ( src_lon.values.ravel(), dims = ['src_grid_size',] ) 316 src_grid_center_lat = xr.DataArray ( src_lat.values.ravel(), dims = ['src_grid_size',] ) 317 src_grid_center_lon.attrs['units']='degrees_east' ; src_grid_center_lon.attrs['long_name']='Longitude' 318 src_grid_center_lon.attrs['long_name']='longitude' ; src_grid_center_lon.attrs['bounds']="src_grid_corner_lon" 319 src_grid_center_lat.attrs['units']='degrees_north' ; src_grid_center_lat.attrs['long_name']='Latitude' 320 src_grid_center_lat.attrs['long_name']='latitude ' ; src_grid_center_lat.attrs['bounds']="src_grid_corner_lat" 321 src_grid_corner_lon = xr.DataArray ( src_clo.values.reshape( (src_jpi*src_jpj, src_clo.shape[0]) ), dims = ['src_grid_size', 'src_grid_corners'] ) 322 src_grid_corner_lat = xr.DataArray ( src_cla.values.reshape( (src_jpi*src_jpj, src_clo.shape[0]) ), dims = ['src_grid_size', 'src_grid_corners' ] ) 323 src_grid_corner_lon.attrs['units']="degrees_east" 324 src_grid_corner_lat.attrs['units']="degrees_north" 325 src_grid_area = xr.DataArray ( src_srf.values.ravel(), dims = ['src_grid_size',] ) 326 src_grid_area.attrs['long_name']="Grid area" ; src_grid_area.attrs['standard_name']="cell_area" ; src_grid_area.attrs['units']="m2" 327 src_grid_imask = xr.DataArray ( src_msk.values.ravel().astype(np.int32) , dims = ['src_grid_size',] ) 328 src_grid_imask.attrs['long_name']="Land-sea mask" ; src_grid_imask.attrs['units']="Land:1, Ocean:0" 385 329 386 330 # -- 387 388 v_dst_grid_dims = f_calving.createVariable ( 'dst_grid_dims' , 'i4', ('dst_grid_rank',) ) 389 v_dst_grid_center_lon = f_calving.createVariable ( 'dst_grid_center_lon', 'i4', ('dst_grid_size',) ) 390 v_dst_grid_center_lat = f_calving.createVariable ( 'dst_grid_center_lat', 'i4', ('dst_grid_size',) ) 391 v_dst_grid_center_lon.units='degrees_east' ; v_dst_grid_center_lon.long_name='Longitude' 392 v_dst_grid_center_lon.long_name='longitude' ; v_dst_grid_center_lon.bounds="dst_grid_corner_lon" 393 v_dst_grid_center_lat.units='degrees_north' ; v_dst_grid_center_lat.long_name='Latitude' 394 v_dst_grid_center_lat.long_name='latitude' ; v_dst_grid_center_lat.bounds="dst_grid_corner_lat" 395 v_dst_grid_corner_lon = f_calving.createVariable ( 'dst_grid_corner_lon', 'f8', ('dst_grid_size', 'dst_grid_corners') ) 396 v_dst_grid_corner_lat = f_calving.createVariable ( 'dst_grid_corner_lat', 'f8', ('dst_grid_size', 'dst_grid_corners') ) 397 v_dst_grid_corner_lon.units="degrees_east" 398 v_dst_grid_corner_lat.units="degrees_north" 399 v_dst_grid_area = f_calving.createVariable ( 'dst_grid_area' , 'f8', ('dst_grid_size',) ) 400 v_dst_grid_area.long_name="Grid area" ; v_dst_grid_area.standard_name="cell_area" ; v_dst_grid_area.units="m2" 401 v_dst_grid_imask = f_calving.createVariable ( 'dst_grid_imask' , 'f8', ('dst_grid_size',) ) 402 v_dst_grid_imask.long_name="Land-sea mask" ; v_dst_grid_imask.units="Land:1, Ocean:0" 403 404 v_dst_bassin = f_calving.createVariable ( 'dst_bassin' , 'f8', ('nb_zone', 'dst_grid_size',) ) 405 v_dst_repartition = f_calving.createVariable ( 'dst_repartition' , 'f8', ('nb_zone', 'dst_grid_size',) ) 406 407 v_dst_southLimit = f_calving.createVariable ('dst_southLimit', 'f4', ('nb_zone',) ) 408 v_dst_northLimit = f_calving.createVariable ('dst_northLimit', 'f4', ('nb_zone',) ) 409 v_dst_southLimit[:] = np.min(limit_lat, axis=(1,) ) 410 v_dst_northLimit[:] = np.max(limit_lat, axis=(1,) ) 411 412 v_dst_grid_dims [:] = ( dst_jpi, dst_jpi ) 413 v_dst_grid_center_lon[:] = dst_lon[:].ravel() 414 v_dst_grid_center_lat[:] = dst_lat[:].ravel() 415 v_dst_grid_corner_lon[:] = dst_clo.reshape( (dst_jpi*dst_jpj, d_dst_grid_corners.__len__()) ) 416 v_dst_grid_corner_lat[:] = dst_cla.reshape( (dst_jpi*dst_jpj, d_dst_grid_corners.__len__()) ) 417 v_dst_grid_area [:] = dst_srf[:].ravel() 418 v_dst_grid_imask [:] = dst_msk[:].ravel() 419 420 v_dst_bassin[:] = basin_msk.reshape ( (nb_zone,dst_grid_size) ) 421 v_dst_repartition[:] = key_repartition.reshape( (nb_zone,dst_grid_size) ) 331 dst_grid_dims = xr.DataArray ( np.array(( dst_jpi, dst_jpi), dtype=np.int32) , dims = ['dst_grid_rank', ]) 332 dst_grid_center_lon = xr.DataArray ( dst_lon.values.ravel(), dims = ['dst_grid_size', ]) 333 dst_grid_center_lat = xr.DataArray ( dst_lat.values.ravel(), dims = ['dst_grid_size', ]) 334 dst_grid_center_lon.attrs['units']='degrees_east' ; dst_grid_center_lon.attrs['long_name']='Longitude' 335 dst_grid_center_lon.attrs['long_name']='longitude' ; dst_grid_center_lon.attrs['bounds']="dst_grid_corner_lon" 336 dst_grid_center_lat.attrs['units']='degrees_north' ; dst_grid_center_lat.attrs['long_name']='Latitude' 337 dst_grid_center_lat.attrs['long_name']='latitude' ; dst_grid_center_lat.attrs['bounds']="dst_grid_corner_lat" 338 dst_grid_corner_lon = xr.DataArray ( dst_clo.values.reshape(dst_jpi*dst_jpj, dst_clo.shape[0] ), dims = ['dst_grid_size', 'dst_grid_corners'] ) 339 dst_grid_corner_lat = xr.DataArray ( dst_cla.values.reshape(dst_jpi*dst_jpj, dst_clo.shape[0] ), dims = ['dst_grid_size', 'dst_grid_corners'] ) 340 dst_grid_corner_lon.attrs['units']="degrees_east" 341 dst_grid_corner_lat.attrs['units']="degrees_north" 342 dst_grid_area = xr.DataArray ( dst_srf.values.ravel(), dims = ['dst_grid_size', ] ) 343 dst_grid_area.attrs['long_name']="Grid area" ; dst_grid_area.attrs['standard_name']="cell_area" ; dst_grid_area.attrs['units']="m2" 344 dst_grid_imask = xr.DataArray ( dst_msk.values.ravel(), dims = ['dst_grid_size',] ) 345 dst_grid_imask.attrs['long_name']="Land-sea mask" ; dst_grid_imask.attrs['units']="Land:1, Ocean:0" 346 347 dst_bassin = xr.DataArray ( basin_msk.reshape ( (nb_zone,dst_grid_size) ) , dims = ['nb_zone', 'dst_grid_size', ] ) 348 dst_repartition = xr.DataArray ( key_repartition.reshape( (nb_zone,dst_grid_size) ) , dims = ['nb_zone', 'dst_grid_size', ] ) 349 350 dst_southLimit = xr.DataArray ( np.min(limit_lat, axis=(1,)).astype(np.float32) , dims = ['nb_zone', ] ) 351 dst_northLimit = xr.DataArray ( np.min(limit_lat, axis=(1,)).astype(np.float32) , dims = ['nb_zone', ] ) 422 352 423 353 # Additionnal fields for debugging 424 354 # ================================ 425 v_dst_grid_imaskutil = f_calving.createVariable ( 'dst_grid_imaskutil' , 'f8', ('dst_grid_size',) ) 426 v_dst_grid_imaskutil.long_name="Land-sea mask" ; v_dst_grid_imaskutil.units="Land:1, Ocean:0" 427 v_dst_grid_imaskclose = f_calving.createVariable ( 'dst_grid_imaskclose' , 'f8', ('dst_grid_size',) ) 428 v_dst_grid_imaskclose.long_name="Land-sea mask" ; v_dst_grid_imaskclose.units="Land:1, Ocean:0" 429 v_dst_grid_imaskutil [:] = dst_mskutil[:].ravel() 430 v_dst_grid_imaskclose[:] = dst_closed[:].ravel() 431 432 v_dst_lon_addressed = f_calving.createVariable ( 'dst_lon_addressed', 'f8', ('num_links',) ) 433 v_dst_lat_addressed = f_calving.createVariable ( 'dst_lat_addressed', 'f8', ('num_links',) ) 434 v_dst_lon_addressed.long_name="Longitude" ; v_dst_lon_addressed.standard_name="longitude" ; v_dst_lon_addressed.units="degrees_east" 435 v_dst_lat_addressed.long_name="Latitude" ; v_dst_lat_addressed.standard_name="latitude" ; v_dst_lat_addressed.units="degrees_north" 436 v_dst_area_addressed = f_calving.createVariable ( 'dst_area_addressed', 'f8', ('num_links',) ) 437 v_dst_area_addressed.long_name="Grid area" ; v_dst_area_addressed.standard_name="cell_area" ; v_dst_grid_area.units="m2" 438 v_dst_imask_addressed = f_calving.createVariable ( 'dst_imask_addressed', 'i4', ('num_links',) ) 439 v_dst_imask_addressed.long_name="Land-sea mask" ; v_dst_imask_addressed.units="Land:1, Ocean:0" 440 v_dst_imaskutil_addressed = f_calving.createVariable ( 'dst_imaskutil_addressed', 'i4', ('num_links',) ) 441 v_dst_imaskutil_addressed.long_name="Land-sea mask" ; v_dst_imaskutil_addressed.units="Land:1, Ocean:0" 442 443 v_dst_lon_addressed [:] = dst_lon.ravel()[dst_address-1].ravel() 444 v_dst_lat_addressed [:] = dst_lat.ravel()[dst_address-1].ravel() 445 v_dst_area_addressed [:] = dst_srf[:].ravel()[dst_address-1].ravel() 446 v_dst_imask_addressed[:] = dst_msk[:].ravel()[dst_address-1].ravel() 447 v_dst_imaskutil_addressed[:] = dst_mskutil.ravel()[dst_address-1].ravel() 448 449 v_src_field = f_calving.createVariable ( 'src_field', 'f8', ('src_grid_size',) ) 450 v_dst_field = f_calving.createVariable ( 'dst_field', 'f8', ('dst_grid_size',) ) 451 v_src_field[:] = src_field 452 v_dst_field[:] = dst_field 453 454 f_calving.close () 455 456 457 ### ===== That's all Folk's !! ============================================== 355 dst_grid_imaskutil = xr.DataArray ( dst_mskutil.ravel().astype(np.float32), dims = ['dst_grid_size',] ) 356 dst_grid_imaskutil.attrs['long_name']="Land-sea mask" ; dst_grid_imaskutil.attrs['units']="Land:1, Ocean:0" 357 dst_grid_imaskclose = xr.DataArray ( dst_closed.values.ravel(), dims = ['dst_grid_size',] ) 358 dst_grid_imaskclose.attrs['long_name']="Land-sea mask" ; dst_grid_imaskclose.attrs['units']="Land:1, Ocean:0" 359 360 dst_lon_addressed = xr.DataArray ( dst_lon.values.ravel()[dst_address-1].ravel(), dims = ['num_links',] ) 361 dst_lat_addressed = xr.DataArray ( dst_lat.values.ravel()[dst_address-1].ravel(), dims = ['num_links',] ) 362 dst_lon_addressed.attrs['long_name']="Longitude" ; dst_lon_addressed.attrs['standard_name']="longitude" ; dst_lon_addressed.attrs['units']="degrees_east" 363 dst_lat_addressed.attrs['long_name']="Latitude" ; dst_lat_addressed.attrs['standard_name']="latitude" ; dst_lat_addressed.attrs['units']="degrees_north" 364 dst_area_addressed = xr.DataArray ( dst_srf.values.ravel()[dst_address-1].ravel(), dims = ['num_links',] ) 365 dst_area_addressed.attrs['long_name']="Grid area" ; dst_area_addressed.attrs['standard_name']="cell_area" ; dst_grid_area.attrs['units']="m2" 366 dst_imask_addressed = xr.DataArray ( dst_msk.values.ravel()[dst_address-1].ravel(), dims = ['num_links', ] ) 367 dst_imask_addressed.attrs['long_name']="Land-sea mask" ; dst_imask_addressed.attrs['units']="Land:1, Ocean:0" 368 dst_imaskutil_addressed = xr.DataArray ( dst_mskutil.ravel()[dst_address-1].astype(np.float32), dims = ['num_links'] ) 369 dst_imaskutil_addressed.attrs['long_name']="Land-sea mask" ; dst_imaskutil_addressed.attrs['units']="Land:1, Ocean:0" 370 371 src_field = xr.DataArray ( src_field, dims = ['src_grid_size',] ) 372 dst_field = xr.DataArray ( dst_field, dims = ['dst_grid_size',] ) 373 374 f_calving = xr.Dataset ( { 375 'remap_matrix' : remap_matrix, 376 'src_address' : src_address, 377 'dst_address' : dst_address, 378 'src_grid_dims' : src_grid_dims, 379 'src_grid_center_lon' : src_grid_center_lat, 380 'src_grid_center_lat' : src_grid_center_lat, 381 'src_grid_corner_lon' : src_grid_corner_lon, 382 'src_grid_corner_lat' : src_grid_corner_lat, 383 'src_grid_area' : src_grid_area, 384 'src_grid_imask' : src_grid_imask, 385 'dst_grid_dims' : dst_grid_dims, 386 'dst_grid_center_lon' : dst_grid_center_lon, 387 'dst_grid_center_lat' : dst_grid_center_lat, 388 'dst_grid_corner_lon' : dst_grid_corner_lon, 389 'dst_grid_corner_lat' : dst_grid_corner_lat, 390 'dst_grid_area' : dst_grid_area, 391 'dst_grid_imask' : dst_grid_imask, 392 'dst_bassin' : dst_bassin, 393 'dst_repartition' : dst_repartition, 394 'dst_southLimit' : dst_southLimit, 395 'dst_northLimit' : dst_northLimit, 396 'dst_grid_imaskutil' : dst_grid_imaskutil, 397 'dst_grid_imaskclose' : dst_grid_imaskclose, 398 'dst_lon_addressed' : dst_lon_addressed, 399 'dst_lat_addressed' : dst_lat_addressed, 400 'dst_area_addressed' : dst_area_addressed, 401 'dst_imask_addressed' : dst_imask_addressed, 402 'dst_imaskutil_addressed' : dst_imaskutil_addressed, 403 'src_field' : src_field, 404 'dst_field' : dst_field, 405 } ) 406 407 f_calving.attrs['Conventions'] = "CF-1.6" 408 f_calving.attrs['source'] = "IPSL Earth system model" 409 f_calving.attrs['group'] = "ICMC IPSL Climate Modelling Center" 410 f_calving.attrs['Institution'] = "IPSL https.//www.ipsl.fr" 411 f_calving.attrs['Ocean'] = dst_Name + " https://www.nemo-ocean.eu" 412 f_calving.attrs['Atmosphere'] = src_Name + " http://lmdz.lmd.jussieu.fr" 413 if myargs.type in ['iceberg', 'iceshelf' ]: f_calving.attrs['originalFiles'] = myargs.repartition_file 414 f_calving.attrs['associatedFiles'] = grids + " " + areas + " " + masks 415 f_calving.attrs['directory'] = os.getcwd () 416 f_calving.attrs['description'] = "Generated with XIOS http://forge.ipsl.jussieu.fr/ioserver and MOSAIX https://forge.ipsl.jussieu.fr/igcmg/browser/TOOLS/MOSAIX" 417 f_calving.attrs['title'] = calving 418 f_calving.attrs['Program'] = "Generated by " + sys.argv[0] + " with flags " + str(sys.argv[1:]) 419 f_calving.attrs['repartitionType'] = myargs.type 420 if myargs.type in [ 'iceberg', 'iceshelf' ] : 421 f_calving.attrs['repartitionFile'] = myargs.repartition_file 422 f_calving.attrs['repartitionVar'] = repartitionVar 423 f_calving.attrs['gridsFile'] = grids 424 f_calving.attrs['areasFile'] = areas 425 f_calving.attrs['masksFile'] = masks 426 f_calving.attrs['timeStamp'] = time.asctime() 427 f_calving.attrs['HOSTNAME'] = platform.node() 428 f_calving.attrs['LOGNAME'] = os.getlogin() 429 f_calving.attrs['Python'] = "Python version " + platform.python_version() 430 f_calving.attrs['OS'] = platform.system() 431 f_calving.attrs['release'] = platform.release() 432 f_calving.attrs['hardware'] = platform.machine() 433 f_calving.attrs['conventions'] = "SCRIP" 434 if src_name == 'lmd' : f_calving.attrs['source_grid'] = "curvilinear" 435 if src_name == 'ico' : f_calving.attrs['source_grid'] = "unstructured" 436 f_calving.attrs['dest_grid'] = "curvilinear" 437 f_calving.attrs['Model'] = "IPSL CM6" 438 f_calving.attrs['SVN_Author'] = "$Author$" 439 f_calving.attrs['SVN_Date'] = "$Date$" 440 f_calving.attrs['SVN_Revision'] = "$Revision$" 441 f_calving.attrs['SVN_Id'] = "$Id$" 442 f_calving.attrs['SVN_HeadURL'] = "$HeadURL$" 443 444 ## 445 f_calving.to_netcdf ( calving, mode='w', format=FmtNetcdf ) 446 f_calving.close() 447 448 print ('That''s all folks !') 449 ## ======================================================================================
Note: See TracChangeset
for help on using the changeset viewer.