source: TOOLS/MOSAIX/CalvingWeights.py @ 4411

Last change on this file since 4411 was 4298, checked in by omamce, 5 years ago

O.M. : corection on MOSAIX

  • add ORCA025.1 to known resolutions
  • Correct mask used to generate weigths
  • Suppress the second computation of uuid
  • OceMask? is now ocean fraction like it was in MOZAIC. OceFrac? still exists (and equals OceFrac?)
  • Add Oce2AtmMask as a 1/0 mask
  • Property svn:keywords set to Date Revision HeadURL Author Id
File size: 22.3 KB
Line 
1### ===========================================================================
2###
3### Compute calving weights.
4###
5### ===========================================================================
6##
7##  Warning, to install, configure, run, use any of Olivier Marti's
8##  software or to read the associated documentation you'll need at least
9##  one (1) brain in a reasonably working order. Lack of this implement
10##  will void any warranties (either express or implied).
11##  O. Marti assumes no responsability for errors, omissions,
12##  data loss, or any other consequences caused directly or indirectly by
13##  the usage of his software by incorrectly or partially configured
14##  personal.
15##
16import netCDF4, numpy as np
17import sys, os, platform, argparse, textwrap, time
18from scipy import ndimage
19import nemo
20
21## SVN information
22__Author__   = "$Author$"
23__Date__     = "$Date$"
24__Revision__ = "$Revision$"
25__Id__       = "$Id$"
26__HeadURL__  = "$HeadURL$"
27__SVN_Date__ = "$SVN_Date: $"
28
29###
30
31### ===== Handling command line parameters ==================================================
32# Creating a parser
33parser = argparse.ArgumentParser (
34    description = """Compute calving weights""",
35    epilog='-------- End of the help message --------')
36
37# Adding arguments
38parser.add_argument ('--oce'     , help='oce model name', type=str, default='eORCA1.2', choices=['ORCA2.3', 'eORCA1.2', 'eORCA025', 'eORCA025.1'] )
39parser.add_argument ('--atm'     , help='atm model name (ICO* or LMD*)', type=str, default='ICO40'    )
40parser.add_argument ('--type'    , help='Type of distribution', type=str, choices=['iceshelf', 'iceberg', 'nosouth', 'full'], default='full'  )
41parser.add_argument ('--dir'     , help='Directory of input file', type=str, default='./' )
42parser.add_argument ('--repartition_file', help='Data files with iceberg melting' , type=str, default='./runoff-icb_DaiTrenberth_Depoorter_eORCA1_JD.nc' )
43parser.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.nc' )
45parser.add_argument ('--fmt'     , help='NetCDF file format, using nco syntax', default='netcdf4', choices=['classic', 'netcdf3', '64bit', '64bit_data', '64bit_data', 'netcdf4', 'netcdf4_classsic'] )
46
47# Parse command line
48myargs = parser.parse_args()
49
50# Model Names
51src_Name = myargs.atm ; dst_Name = myargs.oce
52   
53# Default vars
54if myargs.repartition_var == None :
55    # Runoff from Antarctica iceshelves (Depoorter, 2013)
56    if myargs.type == 'iceshelf' : repartitionVar = 'sornfisf'
57       
58    # Runoff from Antarctica iceberg (Depoorter, 2013)
59    if myargs.type == 'iceberg' :  repartitionVar = 'Icb_Flux'
60       
61else :                             repartitionVar = myargs.repartition_var
62
63# Latitude limits of each calving zone
64limit_lat = ( (40.0, 90.0), (-50.0, 40.0), ( -90.0, -50.0) )
65
66nb_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'
75### ==========================================================================================
76
77# Model short names
78src_name = None ; dst_name = None
79if src_Name.count('ICO')  != 0 : src_name = 'ico'
80if src_Name.count('LMD')  != 0 : src_name = 'lmd'
81if dst_Name.count('ORCA') != 0 : dst_name = 'orc'
82
83CplModel = dst_Name + 'x' + src_Name
84
85print ('Atm names : ' + src_name + ' ' + src_Name )
86print ('Oce names : ' + dst_name + ' ' + dst_Name )
87print (' ')
88
89# Reading domains characteristics
90areas = myargs.dir + '/areas_' + dst_Name + 'x' + src_Name + '.nc' 
91masks = myargs.dir + '/masks_' + dst_Name + 'x' + src_Name + '.nc'
92grids = myargs.dir + '/grids_' + dst_Name + 'x' + src_Name + '.nc'
93
94print ('Opening ' + areas)
95f_areas = netCDF4.Dataset ( areas, "r" )
96print ('Opening ' + masks)
97f_masks = netCDF4.Dataset ( masks, "r" )
98print ('Opening ' + grids)
99f_grids = netCDF4.Dataset ( grids, "r" )
100
101src_lon = f_grids.variables ['t' + src_name + '.lon'][:]
102src_lat = f_grids.variables ['t' + src_name + '.lat'][:]
103dst_lon = f_grids.variables ['t' + dst_name + '.lon'][:]
104dst_lat = f_grids.variables ['t' + dst_name + '.lat'][:]
105
106src_msk = f_masks.variables ['t' + src_name + '.msk'][:]
107dst_msk = f_masks.variables ['t' + dst_name + '.msk'][:]
108dst_mskutil = 1-dst_msk # Reversing the convention : 0 on continent, 1 on ocean
109print ('dst_msk     : ' + str(np.sum(dst_msk)))
110print ('dst_mskutil : ' + str(np.sum(dst_mskutil)))
111
112# Periodicity masking for NEMO
113if dst_Name == 'ORCA2.3'    : nperio_dst = 4
114if dst_Name == 'eORCA1.2'   : nperio_dst = 6
115if dst_Name == 'ORCA025'    : nperio_dst = 6
116if dst_Name == 'eORCA025'   : nperio_dst = 6
117if dst_Name == 'eORCA025.1' : nperio_dst = 6
118print ('nperio_dst: ' + str(nperio_dst) )
119dst_mskutil = nemo.lbc_mask (dst_mskutil, nperio=nperio_dst, cd_type='T' )
120print ('dst_mskutil : ' + str(np.sum(dst_mskutil)))
121
122##
123## Fill Closed seas and other
124## ==================================================
125
126# Preparation by closing some straits
127# -----------------------------------
128if dst_Name in [ 'eORCA025', 'eORCA025.1' ] :
129    print ('Filling some seas for ' + dst_Name )
130    # Set Gibraltar strait to 0 to fill Mediterranean sea
131    dst_mskutil[838:841,1125] = 0
132    # Set Bal-El-Mandeb to 0 to fill Red Sea
133    dst_mskutil[736,1321:1324] = 0
134    # Set Stagerak to 0 to fill Baltic Sea
135    dst_mskutil[961,1179:1182] = 0
136    # Set Ormuz Strait to 0 to fill Arabo-Persian Gulf
137    dst_mskutil[794:798,1374] = 0
138    # Set Hudson Strait to 0 to fill Hudson Bay
139    dst_mskutil[997:1012,907] = 0
140   
141if dst_Name == 'eORCA1.2' :
142    print ('Filling some seas for eORCA1.2')
143    # Set Gibraltar strait to 0 to fill Mediterrean sea
144    dst_mskutil[240, 283] = 0
145    # Set Bal-El-Mandeb to 0 to fill Red Sea
146    dst_mskutil[211:214, 332] = 0
147    # Set Stagerak to 0 to fill Baltic Sea
148    dst_mskutil[272:276, 293] = 0
149    # Set Ormuz Strait to 0 to fill Arabo-Persian Gulf
150    dst_mskutil[227:230, 345] = 0
151    # Set Hudson Strait to 0 to fill Hudson Bay
152    dst_mskutil[284,222:225] = 0
153   
154if dst_Name == 'ORCA2.3' :
155    print ('Filling some seas for ORCA2.3')
156    # Set Gibraltar strait to 0 to fill Mediterrean sea
157    dst_mskutil[101,139] = 0
158    # Set Black Sea to zero. At the edge of the domain : binary_fill_holes fails
159    dst_mskutil[ 99:111,   0:  5] = 0
160    dst_mskutil[106:111, 173:182] = 0
161    # Set Stagerak to 0 to fill Baltic Sea
162    dst_mskutil[115,144] = 0
163    # Set Hudson Strait to 0 to fill Hudson Bay
164    dst_mskutil[120:123,110] = 0
165    # Set Bal-El-Mandeb to 0 to fill Red Sea
166    dst_mskutil[87:89,166] = 0
167
168dst_closed = dst_mskutil
169
170# Fill closed seas with image processing library
171# ----------------------------------------------
172dst_mskutil = nemo.lbc_mask ( 1-ndimage.binary_fill_holes (1-nemo.lbc(dst_mskutil, nperio=nperio_dst, cd_type='T')), nperio=nperio_dst, cd_type='T' )
173
174# Surfaces
175src_srf = f_areas.variables ['t' + src_name + '.srf']
176dst_srf = f_areas.variables ['t' + dst_name + '.srf']
177dst_srfutil = dst_srf * np.float64 (dst_mskutil)
178
179dst_srfutil_sum = np.sum( dst_srfutil)
180
181src_clo = f_grids.variables ['t' + src_name + '.clo'][:]
182src_cla = f_grids.variables ['t' + src_name + '.cla'][:]
183dst_clo = f_grids.variables ['t' + dst_name + '.clo'][:]
184dst_cla = f_grids.variables ['t' + dst_name + '.cla'][:]
185
186# Indices
187( src_jpj, src_jpi) = src_lat.shape ; src_grid_size = src_jpj*src_jpi
188( dst_jpj, dst_jpi) = dst_lat.shape ; dst_grid_size = dst_jpj*dst_jpi
189orc_index = np.arange (dst_jpj*dst_jpi, dtype=np.int32) + 1 # Fortran indices (starting at one)
190
191### ===== Reading needed data ==================================================
192if myargs.type in ['iceberg', 'iceshelf' ]: 
193    # Reading data file for calving or iceberg geometry around Antarctica
194    print ( 'Opening ' + myargs.repartition_file)
195    f_repartition = netCDF4.Dataset ( myargs.repartition_file, "r" )
196    repartition = np.sum ( f_repartition.variables [repartitionVar][:], axis=0 )
197
198## Before loop on basins
199remap_matrix = np.empty ( shape=(0), dtype=np.float64 )
200src_address  = np.empty ( shape=(0), dtype=np.int32   )
201dst_address  = np.empty ( shape=(0), dtype=np.int32   )
202
203print (' ')
204
205### ===== Starting loop on basins==============================================
206
207# Initialise some fields
208remap_matrix = np.empty ( shape=(0), dtype=np.float64 )
209src_address  = np.empty ( shape=(0), dtype=np.int32   )
210dst_address  = np.empty ( shape=(0), dtype=np.int32   )
211
212basin_msk       = np.zeros( shape=(nb_zone, dst_jpj, dst_jpi), dtype=np.float32)
213key_repartition = np.zeros( shape=(nb_zone, dst_jpj, dst_jpi), dtype=np.float64)
214
215## Loop
216for n_bas in np.arange ( nb_zone ) :
217    south = False ; ok_run = False
218    lat_south = np.min(limit_lat[n_bas]) ; lat_north = np.max(limit_lat[n_bas])
219    if lat_south <= -60.0 : south = True
220   
221    print ( 'basin: {:2d} -- Latitudes: {:+.1f} {:+.1f} --'.format(n_bas, lat_south, lat_north) )
222    ##
223    if myargs.type == 'iceberg'  and     south : ok_run = True  ; print ('Applying iceberg to south' )
224    if myargs.type == 'iceshelf' and     south : ok_run = True  ; print ('Applying iceshelf to south' )
225    if myargs.type == 'iceberg'  and not south : ok_run = False ; print ('Skipping iceberg: not south ')
226    if myargs.type == 'iceshelf' and not south : ok_run = False ; print ('Skipping iceshelf: not south ')
227    if myargs.type == 'nosouth'  and     south : ok_run = False ; print ('Skipping south: nosouth case' )
228    if myargs.type == 'nosouth'  and not south : ok_run = True  ; print ('Running: not in south, uniform repartition')
229    if myargs.type == 'full'                   : ok_run = True  ; print ('Running general trivial case, uniform repartition' )
230
231    if ok_run :
232        # Calving integral send to one point per latitude bands
233        index_src = ((src_grid_size - 1)*n_bas) // (nb_zone-1) + 1
234   
235        # Basin mask
236        basin_msk[n_bas] = np.where ( (dst_lat > lat_south ) & (dst_lat <= lat_north ), dst_mskutil, 0 )
237
238        # Repartition pattern
239        if myargs.type in ['iceberg', 'iceshelf' ] : key_repartition[n_bas] = repartition * basin_msk[n_bas]
240        else :                                       key_repartition[n_bas] =               basin_msk[n_bas]
241
242        # Integral and normalisation
243        sum_repartition = np.sum ( key_repartition[n_bas] * dst_srfutil )
244        key_repartition = key_repartition / sum_repartition
245   
246        print ( 'Sum of repartition key                      : {:12.3e}'.format (np.sum (key_repartition[n_bas]               )) )
247        print ( 'Integral (area weighted) of repartition key : {:12.3e}'.format (np.sum (key_repartition[n_bas] * dst_srfutil )) )
248   
249        # Basin surface (modulated by repartition key)
250        basin_srfutil = np.sum ( key_repartition[n_bas] * dst_srfutil )
251           
252        # Weights and links
253        poids = 1.0 / basin_srfutil
254        matrix_local   = np.where ( basin_msk[n_bas].ravel() > 0.5, key_repartition[n_bas].ravel()*poids, 0. )
255        matrix_local   = matrix_local[matrix_local > 0.0] # Keep only non zero values
256        num_links      = np.count_nonzero (matrix_local)
257        # Address on source grid : all links points to the same LMDZ point.
258        src_address_local = np.ones(num_links, dtype=np.int32 )*index_src
259        # Address on destination grid : each NEMO point with non zero link
260        dst_address_local = np.where ( key_repartition[n_bas].ravel() > 0.0, orc_index, 0)
261        dst_address_local = dst_address_local[dst_address_local > 0]
262        # Append to global tabs
263        remap_matrix = np.append ( remap_matrix, matrix_local      )
264        src_address  = np.append ( src_address , src_address_local )
265        dst_address  = np.append ( dst_address , dst_address_local )
266        #
267        #print ( 'Sum of remap_matrix : {:12.3e}'.format(np.sum(matrix_local)) )
268        print ( 'Point in atmospheric grid : {:4d} -- num_links: {:6d}'.format(index_src, num_links) ) 
269        print ('  ')
270
271
272
273## End of loop
274print (' ')
275
276#
277num_links = np.count_nonzero (remap_matrix)
278print ( 'Total num_links : {:10d}'.format(num_links) )
279
280# Diag : interpolate uniform field
281src_field = np.zeros(shape=(src_grid_size))
282for n_bas in np.arange ( nb_zone ) :
283    index_src = ((src_grid_size - 1)*n_bas) // (nb_zone-1) + 1
284    src_field[index_src-1] = n_bas
285
286dst_field = np.zeros(shape=(dst_grid_size,))
287for link in np.arange (num_links) :
288    dst_field [dst_address [link]-1] +=  remap_matrix[link] * src_field[src_address[link]-1]
289
290### ===== Writing the weights file, for OASIS MCT ==========================================
291
292# Output file
293calving = myargs.output
294f_calving = netCDF4.Dataset ( calving, 'w', format=FmtNetcdf )
295   
296print ('Output file: ' + calving )
297
298f_calving.Conventions     = "CF-1.6"
299f_calving.source          = "IPSL Earth system model"
300f_calving.group           = "ICMC IPSL Climate Modelling Center"
301f_calving.Institution     = "IPSL https.//www.ipsl.fr"
302f_calving.Ocean           = dst_Name + " https://www.nemo-ocean.eu"
303f_calving.Atmosphere      = src_Name + " http://lmdz.lmd.jussieu.fr"
304if myargs.type in ['iceberg', 'iceshelf' ]: f_calving.originalFiles = myargs.repartition_file
305f_calving.associatedFiles = grids + " " + areas + " " + masks
306f_calving.directory       = os.getcwd ()
307f_calving.description     = "Generated with XIOS http://forge.ipsl.jussieu.fr/ioserver and MOSAIX https://forge.ipsl.jussieu.fr/igcmg/browser/TOOLS/MOSAIX"
308f_calving.title           = calving
309f_calving.Program         = "Generated by " + sys.argv[0] + " with flags " + str(sys.argv[1:])
310f_calving.repartitionType = myargs.type
311if myargs.type in [ 'iceberg', 'iceshelf' ] :
312    f_calving.repartitionFile = myargs.repartition_file
313    f_calving.repartitionVar  = repartitionVar
314f_calving.gridsFile       = grids
315f_calving.areasFile       = areas
316f_calving.masksFile       = masks
317f_calving.timeStamp       = time.asctime()
318f_calving.HOSTNAME        = platform.node()
319#f_calving.LOGNAME         = os.getlogin()
320f_calving.Python          = "Python version " +  platform.python_version()
321f_calving.OS              = platform.system()
322f_calving.release         = platform.release()
323f_calving.hardware        = platform.machine()
324f_calving.conventions     = "SCRIP"
325if src_name == 'lmd' : f_calving.source_grid = "curvilinear"
326if src_name == 'ico' : f_calving.source_grid = "unstructured"
327f_calving.dest_grid       = "curvilinear"
328f_calving.Model           = "IPSL CM6"
329f_calving.SVN_Author      = "$Author$"
330f_calving.SVN_Date        = "$Date$"
331f_calving.SVN_Revision    = "$Revision$"
332f_calving.SVN_Id          = "$Id$"
333f_calving.SVN_HeadURL     = "$HeadURL$"
334
335d_nb_zone   = f_calving.createDimension ('nb_zone'         ,   nb_zone )
336d_num_links = f_calving.createDimension ('num_links'       , num_links )
337d_num_wgts  = f_calving.createDimension ('num_wgts'        ,         1 )
338
339d_src_grid_size    = f_calving.createDimension ('src_grid_size'   , src_grid_size )
340d_src_grid_corners = f_calving.createDimension ('src_grid_corners', src_clo.shape[0]  )
341d_src_grid_rank    = f_calving.createDimension ('src_grid_rank'   ,        2  )
342
343d_dst_grid_size    = f_calving.createDimension ('dst_grid_size'   , dst_grid_size )
344d_dst_grid_corners = f_calving.createDimension ('dst_grid_corners', dst_clo.shape[0] )
345d_dst_grid_rank    = f_calving.createDimension ('dst_grid_rank'   ,        2  )
346
347v_remap_matrix = f_calving.createVariable ( 'remap_matrix', 'f8', ('num_links', 'num_wgts') )
348v_src_address  = f_calving.createVariable ( 'src_address' , 'i4', ('num_links',) )
349v_src_address.convention = "Fortran style addressing, starting at 1"
350v_dst_address  = f_calving.createVariable ( 'dst_address' , 'i4', ('num_links',) )
351v_dst_address.convention = "Fortran style addressing, starting at 1"
352
353v_remap_matrix[:] = remap_matrix
354v_src_address [:] = src_address
355v_dst_address [:] = dst_address
356
357v_src_grid_dims       = f_calving.createVariable ( 'src_grid_dims'      , 'i4', ('src_grid_rank',) )
358v_src_grid_center_lon = f_calving.createVariable ( 'src_grid_center_lon', 'i4', ('src_grid_size',) )
359v_src_grid_center_lat = f_calving.createVariable ( 'src_grid_center_lat', 'i4', ('src_grid_size',) )
360v_src_grid_center_lon.units='degrees_east'  ; v_src_grid_center_lon.long_name='Longitude'
361v_src_grid_center_lon.long_name='longitude' ; v_src_grid_center_lon.bounds="src_grid_corner_lon" 
362v_src_grid_center_lat.units='degrees_north' ; v_src_grid_center_lat.long_name='Latitude'
363v_src_grid_center_lat.long_name='latitude ' ; v_src_grid_center_lat.bounds="src_grid_corner_lat" 
364v_src_grid_corner_lon = f_calving.createVariable ( 'src_grid_corner_lon', 'f8', ('src_grid_size', 'src_grid_corners')  )
365v_src_grid_corner_lat = f_calving.createVariable ( 'src_grid_corner_lat', 'f8', ('src_grid_size', 'src_grid_corners')  )
366v_src_grid_corner_lon.units="degrees_east"
367v_src_grid_corner_lat.units="degrees_north"
368v_src_grid_area       = f_calving.createVariable ( 'src_grid_area'      , 'f8', ('src_grid_size',)  )
369v_src_grid_area.long_name="Grid area" ; v_src_grid_area.standard_name="cell_area" ; v_src_grid_area.units="m2"
370v_src_grid_imask      = f_calving.createVariable ( 'src_grid_imask'     , 'f8', ('src_grid_size',)  )
371v_src_grid_imask.long_name="Land-sea mask" ; v_src_grid_imask.units="Land:1, Ocean:0"
372
373v_src_grid_dims      [:] = ( src_jpi, src_jpi ) 
374v_src_grid_center_lon[:] = src_lon[:].ravel()
375v_src_grid_center_lat[:] = src_lat[:].ravel()
376v_src_grid_corner_lon[:] = src_clo.reshape( (src_jpi*src_jpj, d_src_grid_corners.__len__()) )
377v_src_grid_corner_lat[:] = src_cla.reshape( (src_jpi*src_jpj, d_src_grid_corners.__len__()) )
378v_src_grid_area      [:] = src_srf[:].ravel()
379v_src_grid_imask     [:] = src_msk[:].ravel()
380
381# --
382
383v_dst_grid_dims       = f_calving.createVariable ( 'dst_grid_dims'      , 'i4', ('dst_grid_rank',) )
384v_dst_grid_center_lon = f_calving.createVariable ( 'dst_grid_center_lon', 'i4', ('dst_grid_size',) )
385v_dst_grid_center_lat = f_calving.createVariable ( 'dst_grid_center_lat', 'i4', ('dst_grid_size',) )
386v_dst_grid_center_lon.units='degrees_east'  ; v_dst_grid_center_lon.long_name='Longitude'
387v_dst_grid_center_lon.long_name='longitude' ; v_dst_grid_center_lon.bounds="dst_grid_corner_lon" 
388v_dst_grid_center_lat.units='degrees_north' ; v_dst_grid_center_lat.long_name='Latitude'
389v_dst_grid_center_lat.long_name='latitude'  ; v_dst_grid_center_lat.bounds="dst_grid_corner_lat" 
390v_dst_grid_corner_lon = f_calving.createVariable ( 'dst_grid_corner_lon', 'f8', ('dst_grid_size', 'dst_grid_corners')  )
391v_dst_grid_corner_lat = f_calving.createVariable ( 'dst_grid_corner_lat', 'f8', ('dst_grid_size', 'dst_grid_corners')  )
392v_dst_grid_corner_lon.units="degrees_east"
393v_dst_grid_corner_lat.units="degrees_north"
394v_dst_grid_area       = f_calving.createVariable ( 'dst_grid_area'      , 'f8', ('dst_grid_size',)  )
395v_dst_grid_area.long_name="Grid area" ; v_dst_grid_area.standard_name="cell_area" ; v_dst_grid_area.units="m2"
396v_dst_grid_imask      = f_calving.createVariable ( 'dst_grid_imask'     , 'f8', ('dst_grid_size',)  )
397v_dst_grid_imask.long_name="Land-sea mask" ; v_dst_grid_imask.units="Land:1, Ocean:0"
398
399v_dst_bassin      = f_calving.createVariable ( 'dst_bassin'      , 'f8', ('nb_zone', 'dst_grid_size',)  )
400v_dst_repartition = f_calving.createVariable ( 'dst_repartition' , 'f8', ('nb_zone', 'dst_grid_size',)  )
401
402v_dst_southLimit = f_calving.createVariable ('dst_southLimit', 'f4', ('nb_zone',) )
403v_dst_northLimit = f_calving.createVariable ('dst_northLimit', 'f4', ('nb_zone',) )
404v_dst_southLimit[:] = np.min(limit_lat, axis=(1,) ) 
405v_dst_northLimit[:] = np.max(limit_lat, axis=(1,) ) 
406
407v_dst_grid_dims      [:] = ( dst_jpi, dst_jpi ) 
408v_dst_grid_center_lon[:] = dst_lon[:].ravel()
409v_dst_grid_center_lat[:] = dst_lat[:].ravel()
410v_dst_grid_corner_lon[:] = dst_clo.reshape( (dst_jpi*dst_jpj, d_dst_grid_corners.__len__()) )
411v_dst_grid_corner_lat[:] = dst_cla.reshape( (dst_jpi*dst_jpj, d_dst_grid_corners.__len__()) )
412v_dst_grid_area      [:] = dst_srf[:].ravel()
413v_dst_grid_imask     [:] = dst_msk[:].ravel()
414
415v_dst_bassin[:]      = basin_msk.reshape      ( (nb_zone,dst_grid_size) )
416v_dst_repartition[:] = key_repartition.reshape( (nb_zone,dst_grid_size) )
417
418# Additionnal fields for debugging
419# ================================
420v_dst_grid_imaskutil      = f_calving.createVariable ( 'dst_grid_imaskutil'     , 'f8', ('dst_grid_size',)  )
421v_dst_grid_imaskutil.long_name="Land-sea mask" ; v_dst_grid_imaskutil.units="Land:1, Ocean:0"
422v_dst_grid_imaskclose      = f_calving.createVariable ( 'dst_grid_imaskclose'     , 'f8', ('dst_grid_size',)  )
423v_dst_grid_imaskclose.long_name="Land-sea mask" ; v_dst_grid_imaskclose.units="Land:1, Ocean:0"
424v_dst_grid_imaskutil [:] = dst_mskutil[:].ravel()
425v_dst_grid_imaskclose[:] = dst_closed[:].ravel()
426
427v_dst_lon_addressed = f_calving.createVariable ( 'dst_lon_addressed', 'f8', ('num_links',) )
428v_dst_lat_addressed = f_calving.createVariable ( 'dst_lat_addressed', 'f8', ('num_links',) )
429v_dst_lon_addressed.long_name="Longitude" ; v_dst_lon_addressed.standard_name="longitude" ; v_dst_lon_addressed.units="degrees_east"
430v_dst_lat_addressed.long_name="Latitude"  ; v_dst_lat_addressed.standard_name="latitude"  ; v_dst_lat_addressed.units="degrees_north"
431v_dst_area_addressed  = f_calving.createVariable ( 'dst_area_addressed', 'f8', ('num_links',) )
432v_dst_area_addressed.long_name="Grid area" ; v_dst_area_addressed.standard_name="cell_area" ; v_dst_grid_area.units="m2"
433v_dst_imask_addressed = f_calving.createVariable ( 'dst_imask_addressed', 'i4', ('num_links',) )
434v_dst_imask_addressed.long_name="Land-sea mask" ; v_dst_imask_addressed.units="Land:1, Ocean:0"
435v_dst_imaskutil_addressed = f_calving.createVariable ( 'dst_imaskutil_addressed', 'i4', ('num_links',) )
436v_dst_imaskutil_addressed.long_name="Land-sea mask" ; v_dst_imaskutil_addressed.units="Land:1, Ocean:0"
437
438v_dst_lon_addressed  [:] = dst_lon.ravel()[dst_address-1].ravel()
439v_dst_lat_addressed  [:] = dst_lat.ravel()[dst_address-1].ravel()
440v_dst_area_addressed [:] = dst_srf[:].ravel()[dst_address-1].ravel()
441v_dst_imask_addressed[:] = dst_msk[:].ravel()[dst_address-1].ravel()
442v_dst_imaskutil_addressed[:] = dst_mskutil.ravel()[dst_address-1].ravel()
443
444v_src_field = f_calving.createVariable ( 'src_field', 'f8', ('src_grid_size',) )
445v_dst_field = f_calving.createVariable ( 'dst_field', 'f8', ('dst_grid_size',) )
446v_src_field[:] = src_field
447v_dst_field[:] = dst_field
448
449f_calving.close ()
450
451
452### ===== That's all Folk's !! ==============================================
Note: See TracBrowser for help on using the repository browser.