Ignore:
Timestamp:
12/05/18 11:17:10 (6 years ago)
Author:
omamce
Message:

O.M. :

  • More documentation
  • Update run-off weights computation
  • Update calving weights computation
File:
1 edited

Legend:

Unmodified
Added
Removed
  • TOOLS/MOSAIX/CalvingWeights.py

    r4159 r4172  
    4242parser.add_argument ('--repartition_file', help='Data files with iceberg melting' , type=str, default='./runoff-icb_DaiTrenberth_Depoorter_eORCA1_JD.nc' ) 
    4343parser.add_argument ('--repartition_var' , help='Variable name for iceshelf'      , type=str, default=None) 
     44parser.add_argument ('--output'  , help='output rmp file name', default='rmp_tlmd_to_torc_calving_64bit.nc' ) 
     45parser.add_argument ('--fmt'     , help='NetCDF file format, using nco syntax', default='64bits', choices=['classic', 'netcdf3', '64bit', '64bit_data', '64bit_data', 'netcdf4', 'netcdf4_classsic'] ) 
    4446 
    4547# Parse command line 
     
    6365 
    6466nb_zone = len(limit_lat) 
     67 
     68if myargs.fmt == 'classic'         : FmtNetcdf = 'CLASSIC' 
     69if myargs.fmt == 'netcdf3'         : FmtNetcdf = 'CLASSIC' 
     70if myargs.fmt == '64bit'           : FmtNetcdf = 'NETCDF3_64BIT_OFFSET' 
     71if myargs.fmt == '64bit_data'      : FmtNetcdf = 'NETCDF3_64BIT_DATA' 
     72if myargs.fmt == '64bit_offset'    : FmtNetcdf = 'NETCDF3_64BIT_OFFSET' 
     73if myargs.fmt == 'netcdf4'         : FmtNetcdf = 'NETCDF4' 
     74if myargs.fmt == 'netcdf4_classic' : FmtNetcdf = 'NETCDF4_CLASSIC' 
    6575### ========================================================================================== 
    6676 
     
    258268        print ('  ') 
    259269 
     270 
     271 
    260272## End of loop 
    261273print (' ') 
     
    265277print ( 'Total num_links : {:10d}'.format(num_links) ) 
    266278 
     279# Diag : interpolate uniform field 
     280src_field = np.zeros(shape=(src_grid_size)) 
     281for 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 
     285dst_field = np.zeros(shape=(dst_grid_size,)) 
     286for link in np.arange (num_links) : 
     287    dst_field [dst_address [link]-1] +=  remap_matrix[link] * src_field[src_address[link]-1] 
     288 
    267289### ===== Writing the weights file, for OASIS MCT ========================================== 
    268290 
    269291# 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  
     292calving = myargs.output 
     293f_calving = netCDF4.Dataset ( calving, 'w', format=FmtNetcdf ) 
     294     
    273295print ('Output file: ' + calving ) 
    274296 
     
    285307f_calving.title           = calving 
    286308f_calving.Program         = "Generated by " + sys.argv[0] + " with flags " + str(sys.argv[1:]) 
     309f_calving.repartitionType = myargs.type 
     310if myargs.type in ['iceberg', 'iceshelf' ] : 
     311    f_calving.repartitionFile = myargs.repartition_file 
     312    f_calving.repartitionVar  = repartitionVar 
     313f_calving.gridsFile       = grids 
     314f_calving.areasFile       = areas 
     315f_calving.masksFile       = masks 
    287316f_calving.timeStamp       = time.asctime() 
    288317f_calving.uuid            = f_areas.uuid 
     
    293322f_calving.release         = platform.release() 
    294323f_calving.hardware        = platform.machine() 
    295 f_calving.Comment         = "Preliminary attempt - Do not trust !" 
    296324f_calving.conventions     = "SCRIP" 
    297325if src_name == 'lmd' : f_calving.source_grid = "curvilinear" 
     
    381409v_dst_repartition[:] = key_repartition.reshape( (nb_zone,dst_grid_size) ) 
    382410 
    383 # Additoonnal fields for debugging 
     411# Additionnal fields for debugging 
    384412# ================================ 
    385413v_dst_grid_imaskutil      = f_calving.createVariable ( 'dst_grid_imaskutil'     , 'f8', ('dst_grid_size',)  ) 
     
    407435v_dst_imaskutil_addressed[:] = dst_mskutil.ravel()[dst_address-1].ravel() 
    408436 
     437v_src_field = f_calving.createVariable ( 'src_field', 'f8', ('src_grid_size',) ) 
     438v_dst_field = f_calving.createVariable ( 'dst_field', 'f8', ('dst_grid_size',) ) 
     439v_src_field[:] = src_field 
     440v_dst_field[:] = dst_field 
     441 
    409442f_calving.close () 
    410443 
Note: See TracChangeset for help on using the changeset viewer.