Changeset 4172 for TOOLS/MOSAIX/CalvingWeights.py
- Timestamp:
- 12/05/18 11:17:10 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TOOLS/MOSAIX/CalvingWeights.py
r4159 r4172 42 42 parser.add_argument ('--repartition_file', help='Data files with iceberg melting' , type=str, default='./runoff-icb_DaiTrenberth_Depoorter_eORCA1_JD.nc' ) 43 43 parser.add_argument ('--repartition_var' , help='Variable name for iceshelf' , type=str, default=None) 44 parser.add_argument ('--output' , help='output rmp file name', default='rmp_tlmd_to_torc_calving_64bit.nc' ) 45 parser.add_argument ('--fmt' , help='NetCDF file format, using nco syntax', default='64bits', choices=['classic', 'netcdf3', '64bit', '64bit_data', '64bit_data', 'netcdf4', 'netcdf4_classsic'] ) 44 46 45 47 # Parse command line … … 63 65 64 66 nb_zone = len(limit_lat) 67 68 if myargs.fmt == 'classic' : FmtNetcdf = 'CLASSIC' 69 if myargs.fmt == 'netcdf3' : FmtNetcdf = 'CLASSIC' 70 if myargs.fmt == '64bit' : FmtNetcdf = 'NETCDF3_64BIT_OFFSET' 71 if myargs.fmt == '64bit_data' : FmtNetcdf = 'NETCDF3_64BIT_DATA' 72 if myargs.fmt == '64bit_offset' : FmtNetcdf = 'NETCDF3_64BIT_OFFSET' 73 if myargs.fmt == 'netcdf4' : FmtNetcdf = 'NETCDF4' 74 if myargs.fmt == 'netcdf4_classic' : FmtNetcdf = 'NETCDF4_CLASSIC' 65 75 ### ========================================================================================== 66 76 … … 258 268 print (' ') 259 269 270 271 260 272 ## End of loop 261 273 print (' ') … … 265 277 print ( 'Total num_links : {:10d}'.format(num_links) ) 266 278 279 # Diag : interpolate uniform field 280 src_field = np.zeros(shape=(src_grid_size)) 281 for n_bas in np.arange ( nb_zone ) : 282 index_src = ((src_grid_size - 1)*n_bas) // (nb_zone-1) + 1 283 src_field[index_src-1] = n_bas 284 285 dst_field = np.zeros(shape=(dst_grid_size,)) 286 for link in np.arange (num_links) : 287 dst_field [dst_address [link]-1] += remap_matrix[link] * src_field[src_address[link]-1] 288 267 289 ### ===== Writing the weights file, for OASIS MCT ========================================== 268 290 269 291 # Output file 270 calving = 'rmp_t' + src_Name + '_to_' + 't' + dst_Name + '_calving_' + myargs.type + '.nc'271 f_calving = netCDF4.Dataset ( calving, 'w', format= 'NETCDF3_64BIT')272 292 calving = myargs.output 293 f_calving = netCDF4.Dataset ( calving, 'w', format=FmtNetcdf ) 294 273 295 print ('Output file: ' + calving ) 274 296 … … 285 307 f_calving.title = calving 286 308 f_calving.Program = "Generated by " + sys.argv[0] + " with flags " + str(sys.argv[1:]) 309 f_calving.repartitionType = myargs.type 310 if myargs.type in ['iceberg', 'iceshelf' ] : 311 f_calving.repartitionFile = myargs.repartition_file 312 f_calving.repartitionVar = repartitionVar 313 f_calving.gridsFile = grids 314 f_calving.areasFile = areas 315 f_calving.masksFile = masks 287 316 f_calving.timeStamp = time.asctime() 288 317 f_calving.uuid = f_areas.uuid … … 293 322 f_calving.release = platform.release() 294 323 f_calving.hardware = platform.machine() 295 f_calving.Comment = "Preliminary attempt - Do not trust !"296 324 f_calving.conventions = "SCRIP" 297 325 if src_name == 'lmd' : f_calving.source_grid = "curvilinear" … … 381 409 v_dst_repartition[:] = key_repartition.reshape( (nb_zone,dst_grid_size) ) 382 410 383 # Addit oonnal fields for debugging411 # Additionnal fields for debugging 384 412 # ================================ 385 413 v_dst_grid_imaskutil = f_calving.createVariable ( 'dst_grid_imaskutil' , 'f8', ('dst_grid_size',) ) … … 407 435 v_dst_imaskutil_addressed[:] = dst_mskutil.ravel()[dst_address-1].ravel() 408 436 437 v_src_field = f_calving.createVariable ( 'src_field', 'f8', ('src_grid_size',) ) 438 v_dst_field = f_calving.createVariable ( 'dst_field', 'f8', ('dst_grid_size',) ) 439 v_src_field[:] = src_field 440 v_dst_field[:] = dst_field 441 409 442 f_calving.close () 410 443
Note: See TracChangeset
for help on using the changeset viewer.