source: TOOLS/MOSAIX/RunoffWeights.py @ 4188

Last change on this file since 4188 was 4188, checked in by omamce, 3 years ago

O.M. : add keywords

  • Property svn:keywords set to Date Revision HeadURL Author Id
File size: 21.4 KB
Line 
1# -*- Mode: python -*-
2### ===========================================================================
3###
4### Compute runoff weights.
5### For LMDZ only. Not suitable for DYNAMICO
6###
7### ===========================================================================
8##
9##  Warning, to install, configure, run, use any of Olivier Marti's
10##  software or to read the associated documentation you'll need at least
11##  one (1) brain in a reasonably working order. Lack of this implement
12##  will void any warranties (either express or implied).
13##  O. Marti assumes no responsability for errors, omissions,
14##  data loss, or any other consequences caused directly or indirectly by
15##  the usage of his software by incorrectly or partially configured
16##  personal.
17##
18# SVN information
19__Author__   = "$Author$"
20__Date__     = "$Date$"
21__Revision__ = "$Revision$"
22__Id__       = "$Id$"
23__HeadURL__  = "$HeadURL$"
24__SVN_Date__ = "$SVN_Date: $"
25##
26
27## Modules
28import netCDF4
29import numpy as np
30import nemo
31from scipy import ndimage
32import sys, os, platform, argparse, textwrap, time
33
34## Userful constants
35zero    = np.dtype('float64').type(0.0)
36zone    = np.dtype('float64').type(1.0)
37epsfrac = np.dtype('float64').type(1.0E-10)
38pi      = np.pi
39rad     = pi/np.dtype('float64').type(180.0)  # Conversion from degrees to radian
40ra      = np.dtype('float64').type(6371229.0) # Earth radius
41
42## Functions
43def geodist (plon1, plat1, plon2, plat2) :
44      """Distance between two points (on sphere)"""
45      zs = np.sin (rad*plat1) * np.sin (rad*plat2) +  np.cos (rad*plat1) * np.cos (rad*plat2) * np.cos(rad*(plon2-plon1))
46      zs = np.maximum (-zone, np.minimum (zone, zs))
47      geodist =  np.arccos (zs)
48      return geodist
49
50### ===== Reading command line parameters ==================================================
51# Creating a parser
52parser = argparse.ArgumentParser (
53    description = """Compute calving weights""",
54    epilog='-------- End of the help message --------')
55
56# Adding arguments
57parser.add_argument ('--oce'          , help='oce model name', type=str, default='eORCA1.2', choices=['ORCA2.3', 'eORCA1.2', 'eORCA025'] )
58parser.add_argument ('--atm'          , help='atm model name', type=str, default='LMD9695'    )
59parser.add_argument ('--atmCoastWidth', help='width of the coastal band in atmosphere (in grid points)', type=int, default=1 )
60parser.add_argument ('--oceCoastWidth', help='width of the coastal band in ocean (in grid points)'     , type=int, default=2 )
61parser.add_argument ('--atmQuantity'  , help='Quantity if atm provides quantities (m/s), Surfacic if atm provided flux (m/s/m2)'  , type=str, default='Quantity', choices=['Quantity', 'Surfacic'] )
62parser.add_argument ('--oceQuantity'  , help='Quantity if oce requires quantities (ks/s), Surfacic if oce requires flux (m/s/m2)' , type=str, default='Surfacic', choices=['Quantity', 'Surfacic'] )
63parser.add_argument ('--searchRadius' , help='max distance to connect a land point to an ocean point (in km)', type=float, default=600.0 )
64parser.add_argument ('--grids' , help='grids file name', default='grids.nc' )
65parser.add_argument ('--areas' , help='masks file name', default='areas.nc' )
66parser.add_argument ('--masks' , help='areas file name', default='masks.nc' )
67parser.add_argument ('--o2a'   , help='o2a file name'  , default='o2a.nc' )
68parser.add_argument ('--output', help='output rmp file name', default='rmp_tlmd_to_torc_runoff_64bit.nc' )
69parser.add_argument ('--fmt'   , help='NetCDF file format, using nco syntax', default='64bit', choices=['classic', 'netcdf3', '64bit', '64bit_data', '64bit_data', 'netcdf4', 'netcdf4_classsic'] )
70
71# Parse command line
72myargs = parser.parse_args()
73
74#
75grids = myargs.grids
76areas = myargs.areas
77masks = myargs.masks
78o2a   = myargs.o2a
79
80# Model Names
81atm_Name = myargs.atm
82oce_Name = myargs.oce
83# Width of the coastal band (land points) in the atmopshere
84atmCoastWidth = myargs.atmCoastWidth
85# Width of the coastal band (ocean points) in the ocean
86oceCoastWidth = myargs.oceCoastWidth
87searchRadius  = myargs.searchRadius * 1000.0 # From km to meters
88# Netcdf format
89if myargs.fmt == 'classic'         : FmtNetcdf = 'CLASSIC'
90if myargs.fmt == 'netcdf3'         : FmtNetcdf = 'CLASSIC'
91if myargs.fmt == '64bit'           : FmtNetcdf = 'NETCDF3_64BIT_OFFSET'
92if myargs.fmt == '64bit_data'      : FmtNetcdf = 'NETCDF3_64BIT_DATA'
93if myargs.fmt == '64bit_offset'    : FmtNetcdf = 'NETCDF3_64BIT_OFFSET'
94if myargs.fmt == 'netcdf4'         : FmtNetcdf = 'NETCDF4'
95if myargs.fmt == 'netcdf4_classic' : FmtNetcdf = 'NETCDF4_CLASSIC'
96
97#
98if atm_Name.find('LMD') >= 0 : atm_n = 'lmd' ; atmDomainType = 'rectilinear'
99if atm_Name.find('ICO') >= 0 : atm_n = 'ico' ; atmDomainType = 'unstructured'
100
101print ('atmQuantity : ' + str (myargs.atmQuantity) )
102print ('oceQuantity : ' + str (myargs.oceQuantity) )
103   
104### Read coordinates of all models
105###
106
107diaFile    = netCDF4.Dataset ( o2a   )
108gridFile   = netCDF4.Dataset ( grids )
109areaFile   = netCDF4.Dataset ( areas )
110maskFile   = netCDF4.Dataset ( masks )
111
112o2aFrac             = diaFile ['OceFrac'][:].squeeze()
113o2aFrac = np.where ( np.abs(o2aFrac) < 1E10, o2aFrac, 0.0)
114
115(atm_nvertex, atm_jpj, atm_jpi) = gridFile['t'+atm_n+'.clo'][:].shape
116atm_grid_size = atm_jpj*atm_jpi
117atm_grid_rank = len(gridFile['t'+atm_n+'.lat'][:].shape)
118
119atm_grid_center_lat = gridFile['t'+atm_n+'.lat'][:].ravel()
120atm_grid_center_lon = gridFile['t'+atm_n+'.lon'][:].ravel()
121atm_grid_corner_lat = np.reshape ( gridFile['t'+atm_n+'.cla'][:], (atm_nvertex, atm_grid_size) )
122atm_grid_corner_lon = np.reshape ( gridFile['t'+atm_n+'.clo'][:], (atm_nvertex, atm_grid_size) )
123atm_grid_area       = areaFile['t'+atm_n+'.srf'][:].ravel()
124atm_grid_imask      = 1-maskFile['t'+atm_n+'.msk'][:].squeeze().ravel()
125atm_grid_dims       = gridFile['t'+atm_n+'.lat'][:].shape
126
127atm_perio = 0
128atm_grid_pmask = atm_grid_imask
129atm_address = np.arange(atm_jpj*atm_jpi)
130
131
132(oce_nvertex, oce_jpj, oce_jpi) = gridFile['torc.cla'][:].shape ; jpon=oce_jpj*oce_jpj
133oce_grid_size = oce_jpj*oce_jpi
134oce_grid_rank = len(gridFile['torc.lat'][:].shape)
135
136oce_grid_center_lat = gridFile['torc.lat'][:].ravel()
137oce_grid_center_lon = gridFile['torc.lon'][:].ravel()
138oce_grid_corner_lat = np.reshape( gridFile['torc.cla'][:], (oce_nvertex, oce_grid_size) )
139oce_grid_corner_lon = np.reshape( gridFile['torc.clo'][:], (oce_nvertex, oce_grid_size) )
140oce_grid_area       = areaFile['torc.srf'][:].ravel()
141oce_grid_imask      = 1-maskFile['torc.msk'][:].ravel()
142oce_grid_dims       = gridFile['torc.lat'][:].shape
143if oce_jpi ==  182 : oce_perio = 4 # ORCA 2
144if oce_jpi ==  362 : oce_perio = 6 # ORCA 1
145if oce_jpi == 1442 : oce_perio = 6 # ORCA 025
146oce_grid_pmask = nemo.lbc_mask (np.reshape(oce_grid_imask, (oce_jpj,oce_jpi)), 'T', oce_perio).ravel()
147oce_address = np.arange(oce_jpj*oce_jpi)
148
149## Fill closed sea with image processing library
150oce_grid_imask2D = np.reshape(oce_grid_pmask,(oce_jpj,oce_jpi))
151oce_grid_imask2D = nemo.lbc_mask ( 1-ndimage.binary_fill_holes (1-nemo.lbc(oce_grid_imask2D, nperio=oce_perio, cd_type='T')), nperio=oce_perio, cd_type='T' )
152oce_grid_imask = oce_grid_imask2D.ravel()
153##
154print ("Determination d'une bande cotiere ocean")
155
156oceLand2D  = np.reshape ( np.where (oce_grid_pmask[:] < 0.5, True, False), (oce_jpj, oce_jpi) )
157oceOcean2D = np.reshape ( np.where (oce_grid_pmask[:] > 0.5, True, False), (oce_jpj, oce_jpi) )
158
159NNocean = 1+2*oceCoastWidth
160oceOceanFiltered2D = ndimage.uniform_filter(oceOcean2D.astype(float), size=NNocean)
161oceCoast2D = np.where (oceOceanFiltered2D<(1.0-0.5/(NNocean**2)),True,False) & oceOcean2D
162oceCoast2D = nemo.lbc_mask (np.reshape(oceCoast2D,(oce_jpj,oce_jpi)), oce_perio, 'T').ravel()
163
164oceOceanFiltered = oceOceanFiltered2D.ravel()
165oceLand  = oceLand2D.ravel()
166oceOcean = oceOcean2D.ravel()
167oceCoast = oceCoast2D.ravel()
168
169print ('Number of points in oceLand  : ' + str(oceLand.sum()) )
170print ('Number of points in oceOcean : ' + str(oceOcean.sum()) )
171print ('Number of points in oceCoast : ' + str(oceCoast.sum()) )
172
173# Arrays with coastal points only
174oceCoast_grid_center_lon = oce_grid_center_lon[oceCoast]
175oceCoast_grid_center_lat = oce_grid_center_lat[oceCoast]
176oceCoast_grid_area       = oce_grid_area      [oceCoast]
177oceCoast_grid_imask      = oce_grid_imask     [oceCoast]
178oceCoast_grid_pmask      = oce_grid_pmask     [oceCoast]
179oceCoast_address         = oce_address        [oceCoast]
180
181print ("Determination d'une bande cotiere atmosphere " )
182atmLand      = np.where (o2aFrac[:] < epsfrac       , True, False)
183atmLandFrac  = np.where (o2aFrac[:] < zone-epsfrac  , True, False)
184atmFrac      = np.where (o2aFrac[:] > epsfrac       , True, False) & np.where (o2aFrac[:] < (zone-epsfrac), True, False)
185atmOcean     = np.where (o2aFrac[:] < (zone-epsfrac), True, False)
186atmOceanFrac = np.where (o2aFrac[:] > epsfrac       , True, False)
187
188## La suite marche avec LMDZ seulement !!
189if atmDomainType == 'rectilinear' :
190    NNatm = 1+2*atmCoastWidth
191    atmLand2D = np.reshape ( atmLand, ( atm_jpj, atm_jpi) )
192
193    atmLandFiltered2D = ndimage.uniform_filter(atmLand2D.astype(float), size=NNatm)
194    atmCoast2D = np.where (atmLandFiltered2D<(1.0-0.5/(NNatm**2)),True,False) & atmLandFrac
195   
196    atmLandFiltered = atmLandFiltered2D.ravel()
197    atmCoast = atmCoast2D.ravel()
198
199    print ('Number of points in atmLand  : ' + str(atmLand.sum())  )
200    print ('Number of points in atmOcean : ' + str(atmOcean.sum()) )
201    print ('Number of points in atmCoast : ' + str(atmCoast.sum()) )
202
203else :
204    atmCoast = atmFrac
205   
206   
207# Arrays with coastal points only
208atmCoast_grid_center_lon = atm_grid_center_lon[atmCoast]
209atmCoast_grid_center_lat = atm_grid_center_lat[atmCoast]
210atmCoast_grid_area       = atm_grid_area      [atmCoast]
211atmCoast_grid_imask      = atm_grid_imask     [atmCoast]
212atmCoast_grid_pmask      = atm_grid_pmask     [atmCoast]
213atmCoast_address         = atm_address        [atmCoast]
214
215# Initialisations before the loop
216remap_matrix = np.empty ( shape=(0), dtype=np.float64 )
217atm_address  = np.empty ( shape=(0), dtype=np.int32   )
218oce_address  = np.empty ( shape=(0), dtype=np.int32   )
219
220## Loop on atmosphere coastal points
221for ja in np.arange(len(atmCoast_grid_pmask)) :
222    z_dist = geodist ( atmCoast_grid_center_lon[ja], atmCoast_grid_center_lat[ja], oceCoast_grid_center_lon, oceCoast_grid_center_lat)
223    z_mask = np.where ( z_dist*ra < searchRadius, True, False)
224    num_links = np.int(z_mask.sum())
225    if num_links == 0 : continue
226    z_area = oceCoast_grid_area[z_mask].sum()
227    poids = np.ones ((num_links),dtype=np.float64) / z_area
228    if myargs.atmQuantity == 'Surfacic' : poids = poids * atm_grid_area[ja]
229    if myargs.oceQuantity == 'Quantity' : poids = poids * oceCoast_grid_area[z_mask]
230    if  ja % (len(atmCoast_grid_pmask)//50) == 0 : # Control print
231        print ( 'ja:{:8d}, num_links:{:8d},  z_area:{:8.4e},  atm area:{:8.4e},  weights sum:{:8.4e}  '.format(ja, num_links, z_area, atm_grid_area[ja], poids.sum() ) )
232    #
233    matrix_local = poids
234    atm_address_local = np.ones(num_links, dtype=np.int32 ) * atmCoast_address[ja]
235    # Address on destination grid
236    oce_address_local = oceCoast_address[z_mask]
237    # Append to global tabs
238    remap_matrix = np.append ( remap_matrix, matrix_local      )
239    atm_address  = np.append ( atm_address , atm_address_local )
240    oce_address  = np.append ( oce_address , oce_address_local )
241
242print ('End of loop')
243
244num_links = remap_matrix.shape[0]
245
246### Output file
247runoff = myargs.output
248f_runoff = netCDF4.Dataset ( runoff, 'w', format=FmtNetcdf )
249print ('Output file: ' + runoff )
250
251f_runoff.Conventions     = "CF-1.6"
252f_runoff.source          = "IPSL Earth system model"
253f_runoff.group           = "ICMC IPSL Climate Modelling Center"
254f_runoff.Institution     = "IPSL https.//www.ipsl.fr"
255f_runoff.Ocean           = oce_Name + " https://www.nemo-ocean.eu"
256f_runoff.Atmosphere      = atm_Name + " http://lmdz.lmd.jussieu.fr"
257f_runoff.associatedFiles = grids + " " + areas + " " + masks
258f_runoff.directory       = os.getcwd ()
259f_runoff.description     = "Generated with cotes_etal.py"
260f_runoff.title           = runoff
261f_runoff.Program         = "Generated by " + sys.argv[0] + " with flags " + str(sys.argv[1:])
262f_runoff.atmCoastWidth   = str(atmCoastWidth) + " grid points"
263f_runoff.oceCoastWidth   = str(oceCoastWidth) + " grid points"
264f_runoff.searchRadius    = str(searchRadius/1000.) + " km"
265f_runoff.gridsFile       = grids
266f_runoff.areasFile       = areas
267f_runoff.masksFile       = masks
268f_runoff.o2aFile         = o2a
269f_runoff.timeStamp       = time.asctime()
270f_runoff.uuid            = areaFile.uuid
271f_runoff.HOSTNAME        = platform.node()
272#f_runoff.LOGNAME         = os.getlogin()
273f_runoff.Python          = "Python version " +  platform.python_version()
274f_runoff.OS              = platform.system()
275f_runoff.release         = platform.release()
276f_runoff.hardware        = platform.machine()
277f_runoff.conventions     = "SCRIP"
278f_runoff.source_grid     = "curvilinear"
279f_runoff.dest_grid       = "curvilinear"
280f_runoff.Model           = "IPSL CM6"
281f_runoff.SVN_Author      = "$Author$"
282f_runoff.SVN_Date        = "$Date$"
283f_runoff.SVN_Revision    = "$Revision$"
284f_runoff.SVN_Id          = "$Id$"
285f_runoff.SVN_HeadURL     = "$HeadURL$"
286
287d_num_links = f_runoff.createDimension ('num_links'       , num_links )
288d_num_wgts  = f_runoff.createDimension ('num_wgts'        ,         1 )
289
290d_atm_grid_size    = f_runoff.createDimension ('src_grid_size'   , atm_grid_size )
291d_atm_grid_corners = f_runoff.createDimension ('src_grid_corners', atm_grid_corner_lon.shape[0]  )
292d_atm_grid_rank    = f_runoff.createDimension ('src_grid_rank'   , atm_grid_rank  )
293
294d_oce_grid_size    = f_runoff.createDimension ('dst_grid_size'   , oce_grid_size )
295d_oce_grid_corners = f_runoff.createDimension ('dst_grid_corners', oce_grid_corner_lon.shape[0] )
296d_oce_grid_rank    = f_runoff.createDimension ('dst_grid_rank'   , oce_grid_rank  )
297
298v_remap_matrix = f_runoff.createVariable ( 'remap_matrix', 'f8', ('num_links', 'num_wgts') )
299
300v_atm_address  = f_runoff.createVariable ( 'src_address' , 'i4', ('num_links',) )
301v_oce_address  = f_runoff.createVariable ( 'dst_address' , 'i4', ('num_links',) )
302
303v_remap_matrix[:] = remap_matrix
304v_atm_address [:] = atm_address + 1 # OASIS uses Fortran style indexing
305v_oce_address [:] = oce_address + 1
306
307v_atm_grid_dims       = f_runoff.createVariable ( 'src_grid_dims'      , 'i4', ('src_grid_rank',) )
308v_atm_grid_center_lon = f_runoff.createVariable ( 'src_grid_center_lon', 'i4', ('src_grid_size',) )
309v_atm_grid_center_lat = f_runoff.createVariable ( 'src_grid_center_lat', 'i4', ('src_grid_size',) )
310v_atm_grid_center_lon.units='degrees_east'  ; v_atm_grid_center_lon.long_name='Longitude' ; v_atm_grid_center_lon.long_name='longitude' ; v_atm_grid_center_lon.bounds="src_grid_corner_lon"
311v_atm_grid_center_lat.units='degrees_north' ; v_atm_grid_center_lat.long_name='Latitude'  ; v_atm_grid_center_lat.long_name='latitude ' ; v_atm_grid_center_lat.bounds="src_grid_corner_lat"
312v_atm_grid_corner_lon = f_runoff.createVariable ( 'src_grid_corner_lon', 'f8', ('src_grid_size', 'src_grid_corners')  )
313v_atm_grid_corner_lat = f_runoff.createVariable ( 'src_grid_corner_lat', 'f8', ('src_grid_size', 'src_grid_corners')  )
314v_atm_grid_corner_lon.units="degrees_east"
315v_atm_grid_corner_lat.units="degrees_north"
316v_atm_grid_area       = f_runoff.createVariable ( 'src_grid_area'      , 'f8', ('src_grid_size',)  )
317v_atm_grid_area.long_name="Grid area" ; v_atm_grid_area.standard_name="cell_area" ; v_atm_grid_area.units="m2"
318v_atm_grid_imask      = f_runoff.createVariable ( 'src_grid_imask'     , 'i4', ('src_grid_size',)  )
319v_atm_grid_imask.long_name="Land-sea mask" ; v_atm_grid_imask.units="Land:1, Ocean:0"
320v_atm_grid_pmask      = f_runoff.createVariable ( 'src_grid_pmask'     , 'i4', ('src_grid_size',)  )
321v_atm_grid_pmask.long_name="Land-sea mask (periodicity removed)" ; v_atm_grid_pmask.units="Land:1, Ocean:0"
322
323v_atm_grid_dims      [:] = atm_grid_dims
324v_atm_grid_center_lon[:] = atm_grid_center_lon[:]
325v_atm_grid_center_lat[:] = atm_grid_center_lat[:]
326v_atm_grid_corner_lon[:] = atm_grid_corner_lon
327v_atm_grid_corner_lat[:] = atm_grid_corner_lat
328v_atm_grid_area      [:] = atm_grid_area[:]
329v_atm_grid_imask     [:] = atm_grid_imask[:]
330v_atm_grid_pmask     [:] = atm_grid_pmask[:]
331
332# --
333
334v_oce_grid_dims       = f_runoff.createVariable ( 'dst_grid_dims'      , 'i4', ('dst_grid_rank',) )
335v_oce_grid_center_lon = f_runoff.createVariable ( 'dst_grid_center_lon', 'i4', ('dst_grid_size',) )
336v_oce_grid_center_lat = f_runoff.createVariable ( 'dst_grid_center_lat', 'i4', ('dst_grid_size',) )
337v_oce_grid_center_lon.units='degrees_east'  ; v_oce_grid_center_lon.long_name='Longitude' ; v_oce_grid_center_lon.long_name='longitude' ; v_oce_grid_center_lon.bounds="dst_grid_corner_lon"
338v_oce_grid_center_lat.units='degrees_north' ; v_oce_grid_center_lat.long_name='Latitude'  ; v_oce_grid_center_lat.long_name='latitude'  ; v_oce_grid_center_lat.bounds="dst_grid_corner_lat"
339v_oce_grid_corner_lon = f_runoff.createVariable ( 'dst_grid_corner_lon', 'f8', ('dst_grid_size', 'dst_grid_corners')  )
340v_oce_grid_corner_lat = f_runoff.createVariable ( 'dst_grid_corner_lat', 'f8', ('dst_grid_size', 'dst_grid_corners')  )
341v_oce_grid_corner_lon.units="degrees_east"
342v_oce_grid_corner_lat.units="degrees_north"
343v_oce_grid_area       = f_runoff.createVariable ( 'dst_grid_area'  , 'f8', ('dst_grid_size',) )
344v_oce_grid_area.long_name="Grid area" ; v_oce_grid_area.standard_name="cell_area" ; v_oce_grid_area.units="m2"
345v_oce_grid_imask      = f_runoff.createVariable ( 'dst_grid_imask'     , 'i4', ('dst_grid_size',)  )
346v_oce_grid_imask.long_name="Land-sea mask" ; v_oce_grid_imask.units="Land:1, Ocean:0"
347v_oce_grid_pmask      = f_runoff.createVariable ( 'dst_grid_pmask'     , 'i4', ('dst_grid_size',)  )
348v_oce_grid_pmask.long_name="Land-sea mask (periodicity removed)" ; v_oce_grid_pmask.units="Land:1, Ocean:0"
349
350v_oce_grid_dims      [:] = oce_grid_dims
351v_oce_grid_center_lon[:] = oce_grid_center_lon[:]
352v_oce_grid_center_lat[:] = oce_grid_center_lat[:]
353v_oce_grid_corner_lon[:] = oce_grid_corner_lon
354v_oce_grid_corner_lat[:] = oce_grid_corner_lon
355v_oce_grid_area      [:] = oce_grid_area[:]
356v_oce_grid_imask     [:] = oce_grid_imask[:]
357v_oce_grid_pmask     [:] = oce_grid_pmask[:]
358
359v_atm_lon_addressed   = f_runoff.createVariable ( 'src_lon_addressed'  , 'f8', ('num_links',) )
360v_atm_lat_addressed   = f_runoff.createVariable ( 'src_lat_addressed'  , 'f8', ('num_links',) )
361v_atm_area_addressed  = f_runoff.createVariable ( 'src_area_addressed' , 'f8', ('num_links',) )
362v_atm_imask_addressed = f_runoff.createVariable ( 'src_imask_addressed', 'i4', ('num_links',) )
363v_atm_pmask_addressed = f_runoff.createVariable ( 'src_pmask_addressed', 'i4', ('num_links',) )
364
365v_oce_lon_addressed   = f_runoff.createVariable ( 'dst_lon_addressed'  , 'f8', ('num_links',) )
366v_oce_lat_addressed   = f_runoff.createVariable ( 'dst_lat_addressed'  , 'f8', ('num_links',) )
367v_oce_area_addressed  = f_runoff.createVariable ( 'dst_area_addressed' , 'f8', ('num_links',) )
368v_oce_imask_addressed = f_runoff.createVariable ( 'dst_imask_addressed', 'i4', ('num_links',) )
369v_oce_pmask_addressed = f_runoff.createVariable ( 'dst_pmask_addressed', 'i4', ('num_links',) )
370
371v_atm_lon_addressed.long_name="Longitude" ; v_atm_lon_addressed.standard_name="longitude" ; v_atm_lon_addressed.units="degrees_east"
372v_atm_lat_addressed.long_name="Latitude"  ; v_atm_lat_addressed.standard_name="latitude"  ; v_atm_lat_addressed.units="degrees_north"
373v_atm_lon_addressed  [:] = atm_grid_center_lon[atm_address]
374v_atm_lat_addressed  [:] = atm_grid_center_lat[atm_address]
375v_atm_area_addressed [:] = atm_grid_area[atm_address]
376v_atm_imask_addressed[:] = 1-atm_grid_imask[atm_address]
377v_atm_pmask_addressed[:] = 1-atm_grid_pmask[atm_address]
378
379v_oce_lon_addressed.long_name="Longitude" ; v_oce_lon_addressed.standard_name="longitude" ; v_oce_lon_addressed.units="degrees_east"
380v_oce_lat_addressed.long_name="Latitude"  ; v_oce_lat_addressed.standard_name="latitude"  ; v_oce_lat_addressed.units="degrees_north"
381v_oce_lon_addressed  [:] = oce_grid_center_lon[oce_address]
382v_oce_lat_addressed  [:] = oce_grid_center_lat[oce_address]#.ravel()
383v_oce_area_addressed [:] = oce_grid_area[oce_address]
384v_oce_imask_addressed[:] = 1-oce_grid_imask[oce_address]
385v_oce_pmask_addressed[:] = 1-oce_grid_pmask[oce_address]
386
387if atmDomainType == 'rectilinear' :
388    v_atmLand         = f_runoff.createVariable ( 'atmLand'        , 'i4', ('src_grid_size',) )
389    v_atmLandFiltered = f_runoff.createVariable ( 'atmLandFiltered', 'f4', ('src_grid_size',) )
390    v_atmLandFrac     = f_runoff.createVariable ( 'atmLandFrac'    , 'i4', ('src_grid_size',) )
391    v_atmFrac         = f_runoff.createVariable ( 'atmFrac'        , 'i4', ('src_grid_size',) )
392    v_atmOcean        = f_runoff.createVariable ( 'atmOcean'       , 'i4', ('src_grid_size',) )
393    v_atmOceanFrac    = f_runoff.createVariable ( 'atmOceanFrac'   , 'i4', ('src_grid_size',) )
394   
395    v_atmLand[:]         = atmLand
396    v_atmLandFrac[:]     = atmLandFrac
397    v_atmLandFiltered[:] = atmLandFiltered
398    v_atmFrac[:]         = atmFrac
399    v_atmOcean[:]        = atmOcean
400    v_atmOceanFrac[:]    = atmOceanFrac
401
402v_atmCoast         = f_runoff.createVariable ( 'atmCoast'       , 'i4', ('src_grid_size',) ) 
403v_atmCoast[:]      = atmCoast
404
405v_oceLand          = f_runoff.createVariable ( 'oceLand'         , 'i4', ('dst_grid_size',) )
406v_oceOcean         = f_runoff.createVariable ( 'oceOcean'        , 'i4', ('dst_grid_size',) )
407v_oceOceanFiltered = f_runoff.createVariable ( 'oceOceanFiltered', 'f4', ('dst_grid_size',) )
408v_oceCoast         = f_runoff.createVariable ( 'oceCoast'        , 'i4', ('dst_grid_size',) )
409
410v_oceLand[:]      = oceLand
411v_oceOcean[:]     = oceOcean
412v_oceOceanFiltered[:]     = oceOceanFiltered
413v_oceCoast[:]     = oceCoast
414
415f_runoff.sync ()
416
417##
418f_runoff.close()
419
420print ('The end')
421
422## ======================================================================================
Note: See TracBrowser for help on using the repository browser.