Changeset 99

User picture

Author: Trond Kristiansen

(2010/02/08 14:02) Over 2 years ago

Important commit that solves a number of issues. First of all, all result files are now completely CF compliant. Second, a subset of the  input data can now be chosen using max and min of longitude and latitude coordinates. This makes it much faster to read input data that may be global such as SODA. The solution required me to write a new module called IOsubset.py. The module contains some handy functions for getting the indices of an input grid and to combine a grid that runs from 0-360 degrees longitude into a grid that runs from -180 to 180 instead in order of making the extraction of data for the North Atlantic continuos.

Affected files

Updated grd.py Download diff

9899
40
        
40
        
41
        if grdfilename=="/Users/trond/Projects/arcwarm/nordic/AA_10km_grid.nc":
41
        if grdfilename=="/Users/trond/Projects/arcwarm/nordic/AA_10km_grid.nc":
42
            self.grdName='NA'
42
            self.grdName='NA'
43
        elif grdfilename=="/Users/trond/Projects/arcwarm/nordic/imr_nordic_4km.nc":
43
        elif grdfilename=="/Users/trond/Projects/Roms/Nordic/Inputs/imr_nordic_4km.nc":
44
            self.grdName='Nordic'
44
            self.grdName='Nordic'
45
        elif grdfilename=='/Users/trond/Projects/Nathan/NoMed47_GRID_Global.nc':
45
        elif grdfilename=='/Users/trond/Projects/Nathan/NoMed47_GRID_Global.nc':
46
            self.grdName='NA_Nathan'
46
            self.grdName='NA_Nathan'
...
...
48
            self.grdName='GOM_Nathan'
48
            self.grdName='GOM_Nathan'
49
        elif grdfilename=='/Users/trond/Projects/arcwarm/SODA/soda2roms/imr_nordic_8km.nc':
49
        elif grdfilename=='/Users/trond/Projects/arcwarm/SODA/soda2roms/imr_nordic_8km.nc':
50
            self.grdName='Nordic2'
50
            self.grdName='Nordic2'
51
        elif grdfilename=='/Users/trond/Projects/Roms/GOMsmall/Inputs/ns8_grd.nc':
52
            self.grdName='NorthSea'
53
        elif grdfilename=='/Users/trond/Projects/Roms/Julia/NATLC/Data/natl_40km.nc':
54
            self.grdName='NATL'
55
            
51
        else:
56
        else:
52
            self.grdName='GOM'
57
            self.grdName='GOM'
53
            
58
            
...
...
179
            self.lon_rho  = self.cdf.variables["lon_rho"][:,:]
184
            self.lon_rho  = self.cdf.variables["lon_rho"][:,:]
180
            self.lat_rho  = self.cdf.variables["lat_rho"][:,:]
185
            self.lat_rho  = self.cdf.variables["lat_rho"][:,:]
181
            self.depth    = self.cdf.variables["h"][:,:]
186
            self.depth    = self.cdf.variables["h"][:,:]
187
          
182
            self.mask_rho = self.cdf.variables["mask_rho"][:,:]
188
            self.mask_rho = self.cdf.variables["mask_rho"][:,:]
183
            # Nathan fixes
189
            # Nathan fixes
184
            # Need to convert all longitude values in grid that are less than 360 and larger than 180 to negative values.
190
            # Need to convert all longitude values in grid that are less than 360 and larger than 180 to negative values.

Updated interp2D.py Download diff

9899
70
        elif var=='vvel':
70
        elif var=='vvel':
71
            grdROMS.v[k,:,:]=Zg
71
            grdROMS.v[k,:,:]=Zg
72
           
72
           
73
        plotData.contourMap(grdROMS,grdMODEL,Zg,k,var)
73
      #  plotData.contourMap(grdROMS,grdMODEL,Zg,k,var)
74
                  
74
                  
75
                      
75
                      
76
def doHorInterpolationRegularGrid(var,grdROMS,grdMODEL,data,show_progress):
76
def doHorInterpolationRegularGrid(var,grdROMS,grdMODEL,data,show_progress):
...
...
127
            p=int( ((k+1*1.0)/(1.0*grdMODEL.Nlevels))*100.)
127
            p=int( ((k+1*1.0)/(1.0*grdMODEL.Nlevels))*100.)
128
        
128
        
129
            progress.render(p)
129
            progress.render(p)
130
        
130
    
131
        
132
      
133
   
134
    return array1
131
    return array1
135
    
132
    
136
    
133
    
...
...
172
        
169
        
173
   
170
   
174
    array1[0,:,:]=Zin*grdROMS.mask_rho
171
    array1[0,:,:]=Zin*grdROMS.mask_rho
175
    plotData.contourMap(grdROMS,grdMODEL,np.squeeze(array1[0,:,:]),1,var)
172
    #plotData.contourMap(grdROMS,grdMODEL,np.squeeze(array1[0,:,:]),1,var)
176
    
173
    
177
    return array1
174
    return array1
178
175

Updated interpolation.f90 Download diff

9899
66
            do jc=1,JJ
66
            do jc=1,JJ
67
              do ic=1,II
67
              do ic=1,II
68
                  do kc=1,Nroms
68
                  do kc=1,Nroms
69
                      
70
                      ! CASE 1: ROMS deeper than SODA. This part searches for deepest good value if ROMS depth is deeper
69
                      ! CASE 1: ROMS deeper than SODA. This part searches for deepest good value if ROMS depth is deeper
71
                      ! than SODA. This means that if no value, or only fill_value, is available from SODA where ROMS is
70
                      ! than SODA. This means that if no value, or only fill_value, is available from SODA where ROMS is
72
                      ! deepest, the closest value from SODA is found by looping upward in the water column.
71
                      ! deepest, the closest value from SODA is found by looping upward in the water column.

Updated IOinitial.py Download diff

9899
19
     salt, temp, u, v, ubar, vbar, zeta, and time. Time dimension for each variable is ocean_time which is days
19
     salt, temp, u, v, ubar, vbar, zeta, and time. Time dimension for each variable is ocean_time which is days
20
     since 1948/1/1.
20
     since 1948/1/1.
21
     
21
     
22
     This file is netcdf CF compliant and to check the CLIM file for CF compliancy:
23
     http://titania.badc.rl.ac.uk/cgi-bin/cf-checker.pl?cfversion=1.0
24
     
22
     Edited by Trond Kristiansen, 16.3.2009, 11.11.2009, 20.11.2009
25
     Edited by Trond Kristiansen, 16.3.2009, 11.11.2009, 20.11.2009
23
     """
26
     """
24
27
...
...
40
          f1.history     ="Created " + time.ctime(time.time())
43
          f1.history     ="Created " + time.ctime(time.time())
41
          f1.source      ="Trond Kristiansen (trond.kristiansen@imr.no)"
44
          f1.source      ="Trond Kristiansen (trond.kristiansen@imr.no)"
42
          f1.type        ="File in NetCDF4 format created using SODA2ROMS"
45
          f1.type        ="File in NetCDF4 format created using SODA2ROMS"
43
        
46
          f1.Conventions = "CF-1.0"
47
          
44
          """Define dimensions"""
48
          """Define dimensions"""
45
          f1.createDimension('xi_rho',  grdROMS.xi_rho)
49
          f1.createDimension('xi_rho',  grdROMS.xi_rho)
46
          f1.createDimension('eta_rho', grdROMS.eta_rho)
50
          f1.createDimension('eta_rho', grdROMS.eta_rho)
...
...
54
          f1.createDimension('s_rho', len(grdROMS.s_rho))
58
          f1.createDimension('s_rho', len(grdROMS.s_rho))
55
          f1.createDimension('s_w', len(grdROMS.s_w))
59
          f1.createDimension('s_w', len(grdROMS.s_w))
56
     
60
     
57
          vnc = f1.createVariable('lon_rho', 'd', ('eta_rho','xi_rho',))
61
          vnc = f1.createVariable('lon_rho', 'd', ('eta_rho','xi_rho',),zlib=False)
58
          vnc.long_name = 'Longitude at RHO points'
62
          vnc.long_name = 'Longitude of RHO-points'
59
          vnc.units = 'degrees east'
63
          vnc.units = 'degree_east'
64
          vnc.standard_name = 'longitude'
60
          vnc[:,:] = grdROMS.lon_rho
65
          vnc[:,:] = grdROMS.lon_rho
61
          
66
          
62
          vnc = f1.createVariable('lat_rho', 'd', ('eta_rho','xi_rho',))
67
          vnc = f1.createVariable('lat_rho', 'd', ('eta_rho','xi_rho',),zlib=False)
63
          vnc.long_name = 'Latitude at RHO points'
68
          vnc.long_name = 'Latitude of RHO-points'
64
          vnc.units = 'degrees north'
69
          vnc.units = 'degree_north'
70
          vnc.standard_name = 'latitude'
65
          vnc[:,:] = grdROMS.lat_rho
71
          vnc[:,:] = grdROMS.lat_rho
66
          
72
          
67
          vnc = f1.createVariable('lon_u', 'd', ('eta_u','xi_u',))
73
          vnc = f1.createVariable('lon_u', 'd', ('eta_u','xi_u',),zlib=False)
68
          vnc.long_name = 'Longitude at U points'
74
          vnc.long_name = 'Longitude of U-points'
69
          vnc.units = 'degrees east'
75
          vnc.units = 'degree_east'
76
          vnc.standard_name = 'longitude'
70
          vnc[:,:] = grdROMS.lon_u
77
          vnc[:,:] = grdROMS.lon_u
71
          
78
          
72
          vnc = f1.createVariable('lat_u', 'd', ('eta_u','xi_u',))
79
          vnc = f1.createVariable('lat_u', 'd', ('eta_u','xi_u',),zlib=False)
73
          vnc.long_name = 'Latitude at U points'
80
          vnc.long_name = 'Latitude of U-points'
74
          vnc.units = 'degrees north'
81
          vnc.units = 'degree_north'
82
          vnc.standard_name = 'latitude'
75
          vnc[:,:] = grdROMS.lat_u
83
          vnc[:,:] = grdROMS.lat_u
76
          
84
          
77
          vnc = f1.createVariable('lon_v', 'd', ('eta_v','xi_v',))
85
          vnc = f1.createVariable('lon_v', 'd', ('eta_v','xi_v',),zlib=False)
78
          vnc.long_name = 'Longitude at V points'
86
          vnc.long_name = 'Longitude of V-points'
79
          vnc.units = 'degrees east'
87
          vnc.units = 'degree_east'
88
          vnc.standard_name = 'longitude'
80
          vnc[:,:] = grdROMS.lon_v
89
          vnc[:,:] = grdROMS.lon_v
81
          
90
          
82
          vnc = f1.createVariable('lat_v', 'd', ('eta_v','xi_v',))
91
          vnc = f1.createVariable('lat_v', 'd', ('eta_v','xi_v',),zlib=False)
83
          vnc.long_name = 'Latitude at V points'
92
          vnc.long_name = 'Latitude of V-points'
84
          vnc.units = 'degrees north'
93
          vnc.units = 'degree_north'
94
          vnc.standard_name = 'latitude'
85
          vnc[:,:] = grdROMS.lat_v
95
          vnc[:,:] = grdROMS.lat_v
86
          
96
          
87
          vnc = f1.createVariable('h', 'd', ('eta_rho','xi_rho',))
97
          vnc = f1.createVariable('lat_psi', 'd', ('eta_psi','xi_psi',),zlib=False)
98
          vnc.long_name = 'Latitude of PSI-points'
99
          vnc.units = 'degree_north'
100
          vnc.standard_name = 'latitude'
101
          vnc[:,:] = grdROMS.lat_psi
102
          
103
          vnc = f1.createVariable('lon_psi', 'd', ('eta_psi','xi_psi',),zlib=False)
104
          vnc.long_name = 'Longitude of PSI-points'
105
          vnc.units = 'degree_east'
106
          vnc.standard_name = 'longitude'
107
          vnc[:,:] = grdROMS.lon_psi
108
          
109
          vnc = f1.createVariable('h', 'd', ('eta_rho','xi_rho',),zlib=False)
88
          vnc.long_name = 'Final bathymetry at RHO points'
110
          vnc.long_name = 'Final bathymetry at RHO points'
89
          vnc.units = 'meter'
111
          vnc.units = 'meter'
90
          vnc.field = "bath, scalar"
112
          vnc.field = "bath, scalar"
91
          vnc[:,:] = grdROMS.depth
113
          vnc[:,:] = grdROMS.depth
92
          
114
          
93
          vnc = f1.createVariable('s_rho', 'd', ('s_rho',)) 
115
          vnc = f1.createVariable('s_rho', 'd', ('s_rho',),zlib=False) 
94
          vnc.long_name = "S-coordinate at RHO-points"
116
          vnc.long_name = "S-coordinate at RHO-points"
95
          vnc.valid_min = -1.
117
          vnc.valid_min = -1.
96
          vnc.valid_max = 0.
118
          vnc.valid_max = 0.
119
          vnc.positive = "up" 
97
          if grdROMS.vstretching==2:
120
          if grdROMS.vstretching==2:
98
            vnc.standard_name = "ocean_s_coordinate_g2" 
121
            vnc.standard_name = "ocean_s_coordinate_g2" 
99
            vnc.formula_terms = "s: s_rho C: Cs_r eta: zeta depth: h depth_c: hc"
122
            vnc.formula_terms = "s: s_rho C: Cs_r eta: zeta depth: h depth_c: hc"
...
...
103
          vnc.field = "s_rho, scalar"
126
          vnc.field = "s_rho, scalar"
104
          vnc[:] = np.flipud(grdROMS.s_rho)
127
          vnc[:] = np.flipud(grdROMS.s_rho)
105
          
128
          
106
          vnc = f1.createVariable('s_w', 'd', ('s_w',))
129
          vnc = f1.createVariable('s_w', 'd', ('s_w',),zlib=False)
107
          vnc.long_name = "S-coordinate at W-points"
130
          vnc.long_name = "S-coordinate at W-points"
108
          vnc.valid_min = -1.
131
          vnc.valid_min = -1.
109
          vnc.valid_max = 0.
132
          vnc.valid_max = 0.
133
          vnc.positive = "up" 
110
          if grdROMS.vstretching==2:
134
          if grdROMS.vstretching==2:
111
            vnc.standard_name = "ocean_s_coordinate_g2" 
135
            vnc.standard_name = "ocean_s_coordinate_g2" 
112
            vnc.formula_terms = "s: s_w C: Cs_w eta: zeta depth: h depth_c: hc"
136
            vnc.formula_terms = "s: s_w C: Cs_w eta: zeta depth: h depth_c: hc"
...
...
116
          vnc.field = "s_w, scalar"
140
          vnc.field = "s_w, scalar"
117
          vnc[:] = np.flipud(grdROMS.s_w)
141
          vnc[:] = np.flipud(grdROMS.s_w)
118
        
142
        
119
          vnc= f1.createVariable('Cs_rho', 'd', ('s_rho',))
143
          vnc= f1.createVariable('Cs_rho', 'd', ('s_rho',),zlib=False)
120
          vnc.long_name = "S-coordinate stretching curves at RHO-points"
144
          vnc.long_name = "S-coordinate stretching curves at RHO-points"
121
          vnc.valid_min = -1.
145
          vnc.valid_min = -1.
122
          vnc.valid_max = 0.
146
          vnc.valid_max = 0.
...
...
128
          vnc.units = "meter"
152
          vnc.units = "meter"
129
          vnc[:]=grdROMS.hc
153
          vnc[:]=grdROMS.hc
130
          
154
          
131
          vnc=f1.createVariable('z_r','d',('s_rho','eta_rho','xi_rho',))
155
          vnc=f1.createVariable('z_r','d',('s_rho','eta_rho','xi_rho',),zlib=False)
132
          vnc.long_name = "Sigma layer to depth matrix" ;
156
          vnc.long_name = "Sigma layer to depth matrix" ;
133
          vnc.units = "meter"
157
          vnc.units = "meter"
134
          vnc[:,:,:]=grdROMS.z_r
158
          vnc[:,:,:]=grdROMS.z_r
...
...
146
          vnc.long_name = "S-coordinate bottom control parameter"
170
          vnc.long_name = "S-coordinate bottom control parameter"
147
          vnc[:]=grdROMS.theta_b
171
          vnc[:]=grdROMS.theta_b
148
          
172
          
149
          vnc=f1.createVariable('angle','d',('eta_rho','xi_rho',))
173
          vnc=f1.createVariable('angle','d',('eta_rho','xi_rho',),zlib=False)
150
          vnc.long_name = "angle between xi axis and east"
174
          vnc.long_name = "angle between xi axis and east"
151
          vnc.units = "radian" 
175
          vnc.units = "radian" 
152
        
153
          vnc=f1.createVariable('mask_rho','d',('eta_rho', 'xi_rho',))
154
          vnc.long_name = "mask on RHO-points"
155
          vnc.option_0 = "land" 
156
          vnc.option_1 = "water"
157
          vnc.FillValue = 1.0
158
          vnc[:,:]=grdROMS.mask_rho
159
          
176
          
160
          vnc=f1.createVariable('mask_u','d',('eta_u', 'xi_u',))
177
          v_time = f1.createVariable('ocean_time', 'd', ('ocean_time',),zlib=False)
161
          vnc.long_name = "mask on U-points"
162
          vnc.option_0 = "land" 
163
          vnc.option_1 = "water"
164
          vnc.FillValue = 1.0
165
          vnc[:,:]=grdROMS.mask_u
166
       
167
          vnc=f1.createVariable('mask_v','d',('eta_v', 'xi_v',))
168
          vnc.long_name = "mask on V-points"
169
          vnc.option_0 = "land" 
170
          vnc.option_1 = "water"
171
          vnc.FillValue = 1.0
172
          vnc[:,:]=grdROMS.mask_v
173
          
174
          v_time = f1.createVariable('ocean_time', 'd', ('ocean_time',))
175
          v_time.long_name = 'seconds since 1948-01-01 00:00:00'
178
          v_time.long_name = 'seconds since 1948-01-01 00:00:00'
176
          v_time.units = 'seconds since 1948-01-01 00:00:00'
179
          v_time.units = 'seconds since 1948-01-01 00:00:00'
177
          v_time.field = 'time, scalar, series'
180
          v_time.field = 'time, scalar, series'
178
          v_time.calendar='standard'
181
          v_time.calendar='standard'
179
          
182
          
180
          v_temp=f1.createVariable('temp', 'f', ('ocean_time', 's_rho', 'eta_rho', 'xi_rho',))
183
          v_temp=f1.createVariable('temp', 'f', ('ocean_time', 's_rho', 'eta_rho', 'xi_rho',),zlib=False)
181
          v_temp.long_name = "potential temperature"
184
          v_temp.long_name = "potential temperature"
182
          v_temp.units = "Celsius"
185
          v_temp.units = "Celsius"
183
          v_temp.time = "ocean_time"
186
          v_temp.time = "ocean_time"
184
          v_temp.FillValue = grdROMS.fill_value
187
          v_temp._FillValue = grdROMS.fill_value
185
          
188
          
186
          v_salt=f1.createVariable('salt', 'f', ('ocean_time', 's_rho', 'eta_rho', 'xi_rho',))
189
          v_salt=f1.createVariable('salt', 'f', ('ocean_time', 's_rho', 'eta_rho', 'xi_rho',),zlib=False)
187
          v_salt.long_name = "salinity"
190
          v_salt.long_name = "salinity"
188
          v_salt.units = "nondimensional"
189
          v_salt.time = "ocean_time"
191
          v_salt.time = "ocean_time"
190
          v_salt.FillValue = grdROMS.fill_value
192
          v_salt.field = "salinity, scalar, series" 
193
          v_salt._FillValue = grdROMS.fill_value
191
          
194
          
192
          v_ssh=f1.createVariable('zeta','f',('ocean_time','eta_rho', 'xi_rho',))
195
          v_ssh=f1.createVariable('zeta','f',('ocean_time','eta_rho', 'xi_rho',),zlib=False)
193
          v_ssh.long_name = "sea level"
196
          v_ssh.long_name = "sea level"
194
          v_ssh.units = "meter"
197
          v_ssh.units = "meter"
195
          v_ssh.time = "ocean_time"
198
          v_ssh.time = "ocean_time"
196
          v_ssh.FillValue = grdROMS.fill_value
199
          v_ssh._FillValue = grdROMS.fill_value
197
          
200
          
198
          v_u=f1.createVariable('u', 'f', ('ocean_time', 's_rho', 'eta_u', 'xi_u',))
201
          v_u=f1.createVariable('u', 'f', ('ocean_time', 's_rho', 'eta_u', 'xi_u',),zlib=False)
199
          v_u.long_name = "U-velocity, scalar, series"
202
          v_u.long_name = "U-velocity, scalar, series"
200
          v_u.units = "meter second-1"
203
          v_u.units = "meter second-1"
201
          v_u.time = "ocean_time"
204
          v_u.time = "ocean_time"
202
          v_u.FillValue = grdROMS.fill_value
205
          v_u._FillValue = grdROMS.fill_value
203
          
206
          
204
          v_v=f1.createVariable('v', 'f', ('ocean_time', 's_rho', 'eta_v', 'xi_v',))
207
          v_v=f1.createVariable('v', 'f', ('ocean_time', 's_rho', 'eta_v', 'xi_v',),zlib=False)
205
          v_v.long_name = "V-velocity, scalar, series"
208
          v_v.long_name = "V-velocity, scalar, series"
206
          v_v.units = "meter second-1"
209
          v_v.units = "meter second-1"
207
          v_v.time = "ocean_time"
210
          v_v.time = "ocean_time"
208
          v_v.FillValue = grdROMS.fill_value
211
          v_v._FillValue = grdROMS.fill_value
209
          
212
          
210
          v_vbar=f1.createVariable('vbar', 'f', ('ocean_time', 'eta_v','xi_v',))
213
          v_vbar=f1.createVariable('vbar', 'f', ('ocean_time', 'eta_v','xi_v',),zlib=False)
211
          v_vbar.long_name = "Barotropic V-velocity, scalar, series"
214
          v_vbar.long_name = "Barotropic V-velocity, scalar, series"
212
          v_vbar.units = "meter second-1"
215
          v_vbar.units = "meter second-1"
213
          v_vbar.time = "ocean_time"
216
          v_vbar.time = "ocean_time"
214
          v_vbar.FillValue = grdROMS.fill_value
217
          v_vbar._FillValue = grdROMS.fill_value
215
        
218
        
216
          v_ubar=f1.createVariable('ubar', 'f', ('ocean_time', 'eta_u', 'xi_u',))
219
          v_ubar=f1.createVariable('ubar', 'f', ('ocean_time', 'eta_u', 'xi_u',),zlib=False)
217
          v_ubar.long_name = "Barotropic U-velocity, scalar, series"
220
          v_ubar.long_name = "Barotropic U-velocity, scalar, series"
218
          v_ubar.units = "meter second-1"
221
          v_ubar.units = "meter second-1"
219
          v_ubar.time = "ocean_time"
222
          v_ubar.time = "ocean_time"
220
          v_ubar.FillValue = grdROMS.fill_value
223
          v_ubar._FillValue = grdROMS.fill_value
221
              
224
              
222
          d= num2date(grdROMS.time * 86400.0,units=v_time.long_name,calendar=v_time.calendar)
225
          d= num2date(grdROMS.time * 86400.0,units=v_time.long_name,calendar=v_time.calendar)
223
          print '\n'
226
          print '\n'
...
...
236
     ntime=0
239
     ntime=0
237
     f1.variables['ocean_time'][ntime]   = grdROMS.time * 86400.0
240
     f1.variables['ocean_time'][ntime]   = grdROMS.time * 86400.0
238
       
241
       
239
     if var=='temperature':
242
     if var.lower()=='temperature':
243
        print data1
240
        f1.variables['temp'][ntime,:,:,:]  = data1
244
        f1.variables['temp'][ntime,:,:,:]  = data1
241
     if var=='salinity':
245
     if var.lower()=='salinity':
242
        f1.variables['salt'][ntime,:,:,:]  = data1
246
        f1.variables['salt'][ntime,:,:,:]  = data1
243
     if var=='ssh':
247
     if var.lower()=='ssh':
244
        f1.variables['zeta'][ntime,:,:]    = data1
248
        f1.variables['zeta'][ntime,:,:]    = data1
245
     if var in ['uvel','vvel','ubar','vbar']:
249
     if var in ['uvel','vvel','ubar','vbar']:
246
        f1.variables['u'][ntime,:,:,:]     = data1
250
        f1.variables['u'][ntime,:,:,:]     = data1

Updated IOwrite.py Download diff

9899
1
1
from datetime import datetime, timedelta
2
from netCDF4 import Dataset
2
from netCDF4 import Dataset
3
from netCDF4 import num2date
3
from netCDF4 import num2date
4
import numpy as np
4
import numpy as np
5
import time
5
import time
6
import os
6
import os
7
7
8
__author__   = 'Trond Kristiansen'
9
__email__    = 'trond.kristiansen@imr.no'
10
__created__  = datetime(2009, 3,2)
11
__modified__ = datetime(2009, 11,18)
12
__version__  = "0.9.1"
13
__status__   = "Development"
14
15
16
def help ():
17
     """
18
     This function generates a CLIM file from scratch. The variables created include:
19
     salt, temp, u, v, ubar, vbar, zeta, and time. Time dimension for each variable is ocean_time which is days
20
     since 1948/1/1.
21
     
22
     This file is netcdf CF compliant and to check the CLIM file for CF compliancy:
23
     http://titania.badc.rl.ac.uk/cgi-bin/cf-checker.pl?cfversion=1.0
24
     
25
     (also see: https://www.myroms.org/forum/viewtopic.php?f=30&t=1450&p=5209&hilit=cf+compliant#p5209)
26
27
     This function is called from soda2roms.py.
28
     """
29
8
def writeClimFile(grdROMS,ntime,outfilename,var,data1=None,data2=None,data3=None,data4=None):
30
def writeClimFile(grdROMS,ntime,outfilename,var,data1=None,data2=None,data3=None,data4=None):
9
        
31
        
10
     if grdROMS.ioClimInitialized is False:
32
     if grdROMS.ioClimInitialized is False:
...
...
19
        f1.history     ="Created " + time.ctime(time.time())
41
        f1.history     ="Created " + time.ctime(time.time())
20
        f1.source      = "Trond Kristiansen (trond.kristiansen@imr.no)"
42
        f1.source      = "Trond Kristiansen (trond.kristiansen@imr.no)"
21
        f1.type        ="File in NetCDF4 format created using SODA2ROMS"
43
        f1.type        ="File in NetCDF4 format created using SODA2ROMS"
44
        f1.Conventions = "CF-1.0"
22
        
45
        
23
        """Define dimensions"""   
46
        """Define dimensions"""   
24
        f1.createDimension('xi_rho',  grdROMS.xi_rho)
47
        f1.createDimension('xi_rho',  grdROMS.xi_rho)
...
...
33
        f1.createDimension('s_rho', len(grdROMS.s_rho))
56
        f1.createDimension('s_rho', len(grdROMS.s_rho))
34
        f1.createDimension('s_w', len(grdROMS.s_w))
57
        f1.createDimension('s_w', len(grdROMS.s_w))
35
58
36
        vnc = f1.createVariable('lon_rho', 'd', ('eta_rho','xi_rho',))
59
        vnc = f1.createVariable('lon_rho', 'd', ('eta_rho','xi_rho',),zlib=False)
37
        vnc.long_name = 'Longitude of RHO-points'
60
        vnc.long_name = 'Longitude of RHO-points'
38
        vnc.units = 'degrees east'
61
        vnc.units = 'degree_east'
62
        vnc.standard_name = 'longitude'
39
        vnc[:,:] = grdROMS.lon_rho
63
        vnc[:,:] = grdROMS.lon_rho
40
        
64
        
41
        vnc = f1.createVariable('lat_rho', 'd', ('eta_rho','xi_rho',))
65
        vnc = f1.createVariable('lat_rho', 'd', ('eta_rho','xi_rho',),zlib=False)
42
        vnc.long_name = 'Latitude of RHO-points'
66
        vnc.long_name = 'Latitude of RHO-points'
43
        vnc.units = 'degrees north'
67
        vnc.units = 'degree_north'
68
        vnc.standard_name = 'latitude'
44
        vnc[:,:] = grdROMS.lat_rho
69
        vnc[:,:] = grdROMS.lat_rho
45
        
70
        
46
        vnc = f1.createVariable('lon_u', 'd', ('eta_u','xi_u',))
71
        vnc = f1.createVariable('lon_u', 'd', ('eta_u','xi_u',),zlib=False)
47
        vnc.long_name = 'Longitude of U-points'
72
        vnc.long_name = 'Longitude of U-points'
48
        vnc.units = 'degrees east'
73
        vnc.units = 'degree_east'
74
        vnc.standard_name = 'longitude'
49
        vnc[:,:] = grdROMS.lon_u
75
        vnc[:,:] = grdROMS.lon_u
50
        
76
        
51
        vnc = f1.createVariable('lat_u', 'd', ('eta_u','xi_u',))
77
        vnc = f1.createVariable('lat_u', 'd', ('eta_u','xi_u',),zlib=False)
52
        vnc.long_name = 'Latitude of U-points'
78
        vnc.long_name = 'Latitude of U-points'
53
        vnc.units = 'degrees north'
79
        vnc.units = 'degree_north'
80
        vnc.standard_name = 'latitude'
54
        vnc[:,:] = grdROMS.lat_u
81
        vnc[:,:] = grdROMS.lat_u
55
        
82
        
56
        vnc = f1.createVariable('lon_v', 'd', ('eta_v','xi_v',))
83
        vnc = f1.createVariable('lon_v', 'd', ('eta_v','xi_v',),zlib=False)
57
        vnc.long_name = 'Longitude of V-points'
84
        vnc.long_name = 'Longitude of V-points'
58
        vnc.units = 'degrees east'
85
        vnc.units = 'degree_east'
86
        vnc.standard_name = 'longitude'
59
        vnc[:,:] = grdROMS.lon_v
87
        vnc[:,:] = grdROMS.lon_v
60
        
88
        
61
        vnc = f1.createVariable('lat_v', 'd', ('eta_v','xi_v',))
89
        vnc = f1.createVariable('lat_v', 'd', ('eta_v','xi_v',),zlib=False)
62
        vnc.long_name = 'Latitude of V-points'
90
        vnc.long_name = 'Latitude of V-points'
63
        vnc.units = 'degrees north'
91
        vnc.units = 'degree_north'
92
        vnc.standard_name = 'latitude'
64
        vnc[:,:] = grdROMS.lat_v
93
        vnc[:,:] = grdROMS.lat_v
65
        
94
        
66
        vnc = f1.createVariable('lat_psi', 'd', ('eta_psi','xi_psi',))
95
        vnc = f1.createVariable('lat_psi', 'd', ('eta_psi','xi_psi',),zlib=False)
67
        vnc.long_name = 'Latitude of PSI-points'
96
        vnc.long_name = 'Latitude of PSI-points'
68
        vnc.units = 'degrees north'
97
        vnc.units = 'degree_north'
98
        vnc.standard_name = 'latitude'
69
        vnc[:,:] = grdROMS.lat_psi
99
        vnc[:,:] = grdROMS.lat_psi
70
        
100
        
71
        vnc = f1.createVariable('lon_psi', 'd', ('eta_psi','xi_psi',))
101
        vnc = f1.createVariable('lon_psi', 'd', ('eta_psi','xi_psi',),zlib=False)
72
        vnc.long_name = 'Longitude of PSI-points'
102
        vnc.long_name = 'Longitude of PSI-points'
73
        vnc.units = 'degrees east'
103
        vnc.units = 'degree_east'
104
        vnc.standard_name = 'longitude'
74
        vnc[:,:] = grdROMS.lon_psi
105
        vnc[:,:] = grdROMS.lon_psi
75
        
106
        
76
        vnc = f1.createVariable('h', 'd', ('eta_rho','xi_rho',))
107
        vnc = f1.createVariable('h', 'd', ('eta_rho','xi_rho',),zlib=False)
77
        vnc.long_name = 'Bathymetry at RHO-points'
108
        vnc.long_name = 'Bathymetry at RHO-points'
78
        vnc.units = 'meter'
109
        vnc.units = 'meter'
79
        vnc.field = "bath, scalar"
110
        vnc.field = "bath, scalar"
80
        vnc[:,:] = grdROMS.depth
111
        vnc[:,:] = grdROMS.depth
81
        
112
        
82
        vnc = f1.createVariable('f', 'd', ('eta_rho','xi_rho',))
113
        vnc = f1.createVariable('f', 'd', ('eta_rho','xi_rho',),zlib=False)
83
        vnc.long_name = 'Coriolis parameter at RHO-points'
114
        vnc.long_name = 'Coriolis parameter at RHO-points'
84
        vnc.units = 'second-1'
115
        vnc.units = 'second-1'
85
        vnc.field = "Coriolis, scalar"
116
        vnc.field = "Coriolis, scalar"
86
        vnc[:,:] = grdROMS.f
117
        vnc[:,:] = grdROMS.f
87
        
118
        
88
        vnc = f1.createVariable('pm', 'd', ('eta_rho','xi_rho',))
119
        vnc = f1.createVariable('pm', 'd', ('eta_rho','xi_rho',),zlib=False)
89
        vnc.long_name = 'curvilinear coordinate metric in XI'
120
        vnc.long_name = 'curvilinear coordinate metric in XI'
90
        vnc.units = 'meter-1'
121
        vnc.units = 'meter-1'
91
        vnc.field = "pm, scalar"
122
        vnc.field = "pm, scalar"
92
        vnc[:,:] = grdROMS.pm
123
        vnc[:,:] = grdROMS.pm
93
        
124
        
94
        vnc = f1.createVariable('pn', 'd', ('eta_rho','xi_rho',))
125
        vnc = f1.createVariable('pn', 'd', ('eta_rho','xi_rho',),zlib=False)
95
        vnc.long_name = 'curvilinear coordinate metric in ETA'
126
        vnc.long_name = 'curvilinear coordinate metric in ETA'
96
        vnc.units = 'meter-1'
127
        vnc.units = 'meter-1'
97
        vnc.field = "pn, scalar"
128
        vnc.field = "pn, scalar"
98
        vnc[:,:] = grdROMS.pn
129
        vnc[:,:] = grdROMS.pn
99
        
130
        
100
        vnc = f1.createVariable('s_rho', 'd', ('s_rho',))
131
        vnc = f1.createVariable('s_rho', 'd', ('s_rho',),zlib=False)
101
        vnc.long_name = "S-coordinate at RHO-points"
132
        vnc.long_name = "S-coordinate at RHO-points"
102
        vnc.valid_min = -1.
133
        vnc.valid_min = -1.
103
        vnc.valid_max = 0.
134
        vnc.valid_max = 0.
...
...
110
        vnc.field = "s_rho, scalar"
141
        vnc.field = "s_rho, scalar"
111
        vnc[:] = np.flipud(grdROMS.s_rho)
142
        vnc[:] = np.flipud(grdROMS.s_rho)
112
        
143
        
113
        vnc = f1.createVariable('s_w', 'd', ('s_w',))
144
        vnc = f1.createVariable('s_w', 'd', ('s_w',),zlib=False)
114
        vnc.long_name = "S-coordinate at W-points"
145
        vnc.long_name = "S-coordinate at W-points"
115
        vnc.valid_min = -1.
146
        vnc.valid_min = -1.
116
        vnc.valid_max = 0.
147
        vnc.valid_max = 0.
...
...
123
        vnc.field = "s_w, scalar"
154
        vnc.field = "s_w, scalar"
124
        vnc[:] = np.flipud(grdROMS.s_w)
155
        vnc[:] = np.flipud(grdROMS.s_w)
125
        
156
        
126
        vnc= f1.createVariable('Cs_r', 'd', ('s_rho',))
157
        vnc= f1.createVariable('Cs_r', 'd', ('s_rho',),zlib=False)
127
        vnc.long_name = "S-coordinate stretching curves at RHO-points"
158
        vnc.long_name = "S-coordinate stretching curves at RHO-points"
128
        vnc.valid_min = -1.
159
        vnc.valid_min = -1.
129
        vnc.valid_max = 0.
160
        vnc.valid_max = 0.
130
        vnc.field = "s_rho, scalar"
161
        vnc.field = "s_rho, scalar"
131
        vnc[:] = np.flipud(grdROMS.Cs_rho)
162
        vnc[:] = np.flipud(grdROMS.Cs_rho)
132
        
163
        
133
        vnc= f1.createVariable('Cs_w', 'd', ('s_w',))
164
        vnc= f1.createVariable('Cs_w', 'd', ('s_w',),zlib=False)
134
        vnc.long_name = "S-coordinate stretching curves at W-points"
165
        vnc.long_name = "S-coordinate stretching curves at W-points"
135
        vnc.valid_min = -1.
166
        vnc.valid_min = -1.
136
        vnc.valid_max = 0.
167
        vnc.valid_max = 0.
...
...
142
        vnc.units = "meter"
173
        vnc.units = "meter"
143
        vnc[:]=grdROMS.hc
174
        vnc[:]=grdROMS.hc
144
        
175
        
145
        vnc=f1.createVariable('z_r','d',('s_rho','eta_rho','xi_rho',))
176
        vnc=f1.createVariable('z_r','d',('s_rho','eta_rho','xi_rho',),zlib=False)
146
        vnc.long_name = "Sigma layer to depth matrix" ;
177
        vnc.long_name = "Sigma layer to depth matrix" ;
147
        vnc.units = "meter"
178
        vnc.units = "meter"
148
        vnc[:,:,:]=grdROMS.z_r
179
        vnc[:,:,:]=grdROMS.z_r
149
        
180
        
150
        vnc=f1.createVariable('z_w','d',('s_w','eta_rho','xi_rho',))
181
        vnc=f1.createVariable('z_w','d',('s_w','eta_rho','xi_rho',),zlib=False)
151
        vnc.long_name = "Sigma layer to depth matrix" ;
182
        vnc.long_name = "Sigma layer to depth matrix" ;
152
        vnc.units = "meter"
183
        vnc.units = "meter"
153
        vnc[:,:,:]=grdROMS.z_w
184
        vnc[:,:,:]=grdROMS.z_w
...
...
165
        vnc.long_name = "S-coordinate bottom control parameter"
196
        vnc.long_name = "S-coordinate bottom control parameter"
166
        vnc[:]=grdROMS.theta_b
197
        vnc[:]=grdROMS.theta_b
167
        
198
        
168
        vnc=f1.createVariable('angle','d',('eta_rho','xi_rho',))
199
        vnc=f1.createVariable('angle','d',('eta_rho','xi_rho',),zlib=False)
169
        vnc.long_name = "angle between xi axis and east"
200
        vnc.long_name = "angle between xi axis and east"
170
        vnc.units = "radian" 
201
        vnc.units = "radian" 
171
        vnc[:,:]=grdROMS.angle
202
        vnc[:,:]=grdROMS.angle
172
   
203
173
        vnc=f1.createVariable('mask_rho','d',('eta_rho', 'xi_rho',))
174
        vnc.long_name = "mask on RHO-points"
175
        vnc.option_0 = "land" 
176
        vnc.option_1 = "water"
177
        vnc.FillValue = 1.0
178
        vnc[:,:]=grdROMS.mask_rho
179
        
204
        
180
        vnc=f1.createVariable('mask_u','d',('eta_u', 'xi_u',))
205
        v_time = f1.createVariable('ocean_time', 'd', ('ocean_time',),zlib=False)
181
        vnc.long_name = "mask at U-points"
182
        vnc.option_0 = "land" 
183
        vnc.option_1 = "water"
184
        vnc.FillValue = 1.0
185
        vnc[:,:]=grdROMS.mask_u
186
        
187
        vnc=f1.createVariable('mask_v','d',('eta_v', 'xi_v',))
188
        vnc.long_name = "mask at V-points"
189
        vnc.option_0 = "land" 
190
        vnc.option_1 = "water"
191
        vnc.FillValue = 1.0
192
        vnc[:,:]=grdROMS.mask_v
193
        
194
        vnc=f1.createVariable('mask_psi','d',('eta_psi', 'xi_psi',))
195
        vnc.long_name = "mask at PSI-points"
196
        vnc.option_0 = "land" 
197
        vnc.option_1 = "water"
198
        vnc.FillValue = 1.0
199
        vnc[:,:]=grdROMS.mask_psi
200
        
201
        v_time = f1.createVariable('ocean_time', 'd', ('ocean_time',))
202
        v_time.long_name = 'seconds since 1948-01-01 00:00:00'
206
        v_time.long_name = 'seconds since 1948-01-01 00:00:00'
203
        v_time.units = 'seconds since 1948-01-01 00:00:00'
207
        v_time.units = 'seconds since 1948-01-01 00:00:00'
204
        v_time.field = 'time, scalar, series'
208
        v_time.field = 'time, scalar, series'
205
        v_time.calendar='standard'
209
        v_time.calendar='standard'
206
        
210
        
207
        v_u=f1.createVariable('u', 'f', ('ocean_time', 's_rho', 'eta_u', 'xi_u',))
211
        v_u=f1.createVariable('u', 'f', ('ocean_time', 's_rho', 'eta_u', 'xi_u',),zlib=False)
208
        v_u.long_name = "u-momentum component"
212
        v_u.long_name = "u-momentum component"
209
        v_u.units = "meter second-1"
213
        v_u.units = "meter second-1"
210
        v_u.time = "ocean_time"
214
        v_u.time = "ocean_time"
211
        v_u.field= "u-velocity, scalar, series"
215
        v_u.field= "u-velocity, scalar, series"
212
        v_u.FillValue = grdROMS.fill_value
216
        v_u._FillValue = grdROMS.fill_value
213
        
217
        
214
        v_v=f1.createVariable('v', 'f', ('ocean_time', 's_rho', 'eta_v', 'xi_v',))
218
        v_v=f1.createVariable('v', 'f', ('ocean_time', 's_rho', 'eta_v', 'xi_v',),zlib=False)
215
        v_v.long_name = "v-momentum component"
219
        v_v.long_name = "v-momentum component"
216
        v_v.units = "meter second-1"
220
        v_v.units = "meter second-1"
217
        v_v.time = "ocean_time"
221
        v_v.time = "ocean_time"
218
        v_v.field= "v-velocity, scalar, series"
222
        v_v.field= "v-velocity, scalar, series"
219
        v_v.FillValue = grdROMS.fill_value
223
        v_v._FillValue = grdROMS.fill_value
220
        
224
        
221
        v_salt=f1.createVariable('salt', 'f', ('ocean_time', 's_rho', 'eta_rho', 'xi_rho',))
225
        v_salt=f1.createVariable('salt', 'f', ('ocean_time', 's_rho', 'eta_rho', 'xi_rho',),zlib=False)
222
        v_salt.long_name = "salinity"
226
        v_salt.long_name = "salinity"
223
        v_salt.units = "nondimensional"
224
        v_salt.time = "ocean_time"
227
        v_salt.time = "ocean_time"
225
        v_salt.field="salinity, scalar, series"
228
        v_salt.field="salinity, scalar, series"
226
        v_salt.FillValue = grdROMS.fill_value
229
        v_salt._FillValue = grdROMS.fill_value
227
        
230
        
228
        v_temp=f1.createVariable('temp', 'f', ('ocean_time', 's_rho', 'eta_rho', 'xi_rho',))
231
        v_temp=f1.createVariable('temp', 'f', ('ocean_time', 's_rho', 'eta_rho', 'xi_rho',),zlib=False)
229
        v_temp.long_name = "potential temperature"
232
        v_temp.long_name = "potential temperature"
230
        v_temp.units = "Celsius"
233
        v_temp.units = "Celsius"
231
        v_temp.time = "ocean_time"
234
        v_temp.time = "ocean_time"
232
        v_temp.field="temperature, scalar, series"
235
        v_temp.field="temperature, scalar, series"
233
        v_temp.FillValue = grdROMS.fill_value
236
        v_temp._FillValue = grdROMS.fill_value
234
        
237
        
235
        v_ssh=f1.createVariable('zeta','f',('ocean_time','eta_rho', 'xi_rho',))
238
        v_ssh=f1.createVariable('zeta','f',('ocean_time','eta_rho', 'xi_rho',),zlib=False)
236
        v_ssh.long_name = "sea level"
239
        v_ssh.long_name = "sea level"
237
        v_ssh.units = "meter"
240
        v_ssh.units = "meter"
238
        v_ssh.time = "ocean_time"
241
        v_ssh.time = "ocean_time"
239
        v_ssh.field="sea level, scalar, series"
242
        v_ssh.field="sea level, scalar, series"
240
        v_ssh.FillValue = grdROMS.fill_value
243
        v_ssh._FillValue = grdROMS.fill_value
241
        
244
        
242
        v_ubar=f1.createVariable('ubar', 'f', ('ocean_time', 'eta_u', 'xi_u',))
245
        v_ubar=f1.createVariable('ubar', 'f', ('ocean_time', 'eta_u', 'xi_u',),zlib=False)
243
        v_ubar.long_name = "u-2D momentum"
246
        v_ubar.long_name = "u-2D momentum"
244
        v_ubar.units = "meter second-1"
247
        v_ubar.units = "meter second-1"
245
        v_ubar.time = "ocean_time"
248
        v_ubar.time = "ocean_time"
246
        v_ubar.field= "u2-D velocity, scalar, series"
249
        v_ubar.field= "u2-D velocity, scalar, series"
247
        v_ubar.FillValue = grdROMS.fill_value
250
        v_ubar._FillValue = grdROMS.fill_value
248
        
251
        
249
        v_vbar=f1.createVariable('vbar', 'f', ('ocean_time', 'eta_v','xi_v',))
252
        v_vbar=f1.createVariable('vbar', 'f', ('ocean_time', 'eta_v','xi_v',),zlib=False)
250
        v_vbar.long_name = "v-2D momentum"
253
        v_vbar.long_name = "v-2D momentum"
251
        v_vbar.units = "meter second-1"
254
        v_vbar.units = "meter second-1"
252
        v_vbar.time = "ocean_time"
255
        v_vbar.time = "ocean_time"
253
        v_vbar.field= "v2-D velocity, scalar, series"
256
        v_vbar.field= "v2-D velocity, scalar, series"
254
        v_vbar.FillValue = grdROMS.fill_value
257
        v_vbar._FillValue = grdROMS.fill_value
255
     
258
     
256
     
259
     
257
     else:
260
     else:
...
...
269
        f1.variables['salt'][ntime,:,:,:]  = data1
272
        f1.variables['salt'][ntime,:,:,:]  = data1
270
     if var=='ssh':
273
     if var=='ssh':
271
        f1.variables['zeta'][ntime,:,:]    = data1
274
        f1.variables['zeta'][ntime,:,:]    = data1
272
     if var=='vvel':
275
     if var=='vvel':   
273
        
274
        f1.variables['u'][ntime,:,:,:]     = data1
276
        f1.variables['u'][ntime,:,:,:]     = data1
275
        f1.variables['v'][ntime,:,:,:]     = data2
277
        f1.variables['v'][ntime,:,:,:]     = data2
276
     
278
     

Updated main.py Download diff

9899
52
    """Create river runoff file based on NCEP-NCAR CORE data"""
52
    """Create river runoff file based on NCEP-NCAR CORE data"""
53
    createRiverRunoff=False
53
    createRiverRunoff=False
54
    
54
    
55
    """Define the paths to the CORE data (only river file), and the SODA/HYCOM data"""
55
    """Set the input data MODEL type: Current options are SODA or HYCOM"""
56
    type='HYCOM' 
57
    type='SODA'
58
    type='SODAMONTHLY'
59
    
60
    """Define the paths to the CORE data (only river file)"""
56
    corepath="/Users/trond/Projects/arcwarm/CORE/"
61
    corepath="/Users/trond/Projects/arcwarm/CORE/"
57
    sodapath="/Volumes/HankRaid/SODA/"
58
    sodapath="/Volumes/MacintoshHD2/Datasets/SODA/"
59
    sodapath="/Volumes/MacintoshHD2/Datasets/SODAMonthly/"
60
    #sodapath="/Users/trond/Projects/arcwarm/SODAmonthly/"
61
    hycompath="/Users/trond/Projects/arcwarm/SODA/HYCOM/"
62
    
62
    
63
    """Define the paths to the SODA/HYCOM data"""
64
    if type=='SODA':
65
        sodapath="/Volumes/HankRaid/SODA/"
66
        sodapath="/Volumes/MacintoshHD2/Datasets/SODA/"
67
    if type=='SODAMONTHLY':
68
        sodapath="/Volumes/MacintoshHD2/Datasets/SODAMonthly/"
69
    if type=='HYCOM':
70
        hycompath="/Users/trond/Projects/arcwarm/SODA/HYCOM/"
71
    
72
    """Define the path to the grid file"""
63
    romsgridpath="/Volumes/HankRaid/ROMS/GoM/grid/gom_grd.nc"
73
    romsgridpath="/Volumes/HankRaid/ROMS/GoM/grid/gom_grd.nc"
64
    romsgridpath="/Users/trond/Projects/Roms/GOMsmall/Inputs/gom_grd_small.nc"
74
    #romsgridpath="/Users/trond/Projects/Roms/GOMsmall/Inputs/gom_grd_small.nc"
65
    #romsgridpath="/Users/trond/Projects/Roms/GOMfull/Inputs/gom_grd.nc"
75
    #romsgridpath="/Users/trond/Projects/Roms/GOMsmall/Inputs/ns8_grd.nc"
66
    #romsgridpath="/Users/trond/Projects/arcwarm/nordic/imr_nordic_4km.nc"
76
    # CONTAINS NAN romsgridpath="/Users/trond/Projects/Roms/GOMfull/Inputs/gom_grd.nc"
67
    #romsgridpath="/Users/trond/Projects/arcwarm/SODA/soda2roms/imr_nordic_8km.nc"
77
    #romsgridpath="/Users/trond/Projects/Roms/Nordic/Inputs/imr_nordic_4km.nc"
78
    #romsgridpath="/Users/trond/Projects/Roms/Nordic/Inputs/imr_nordic_8km.nc"
79
    #romsgridpath="/Users/trond/Projects/Roms/Julia/NATLC/Data/natl_40km.nc"
68
    
80
    
69
    start_year      =1960
81
    start_year      =1960
70
    end_year        =1961
82
    end_year        =1961
71
    start_julianday =0
83
    start_julianday =0
72
    end_julianday   =95
84
    end_julianday   =135
73
    
85
    
86
    """Subset the input data. The more you subset the less memory is needed for calculations
87
    and the faster the process is performed. The subset is initially performed in IOsubset.py"""
88
    # TODO: Check if outputdomain is not overlapping input domain.
89
    minLat=30; maxLat=60; minLon=-90; maxLon=-10
90
    subset=np.zeros(4); subset[0]=minLat; subset[1]=maxLat; subset[2]=minLon; subset[3]=maxLon
91
    
74
    """Name of output files for CLIM, BRY, and INIT files"""
92
    """Name of output files for CLIM, BRY, and INIT files"""
75
    climName='gom_clim_'+str(start_year)+'.nc'
93
    climName='gom_clim_'+str(start_year)+'.nc'
76
    initName='gom_init_'+str(start_year)+'.nc'
94
    initName='gom_init_'+str(start_year)+'.nc'
77
    bryName='gom_bry_'+str(start_year)+'.nc'
95
    bryName='gom_bry_'+str(start_year)+'.nc'
78
    
96
    
79
    """Set the input data MODEL type: Current options are SODA or HYCOM"""
80
    type='HYCOM' 
81
    type='SODA'
82
    type='SODAMONTHLY'
83
    
84
    """Define what variables to include in the forcing files"""
97
    """Define what variables to include in the forcing files"""
85
    vars=['temperature','salinity','ssh','uvel','vvel']
98
    vars=['temperature','salinity','ssh','uvel','vvel']
86
   # vars=['ssh','uvel','vvel']
87
    
99
    
88
    """5 day or 30 day average files for SODA"""
100
    """5 day or 30 day average files for SODA"""
89
    if type=='SODA': aveDays=5.0
101
    if type=='SODA': aveDays=5.0
...
...
95
    lonlist=[ 2.4301, -22.6001, -47.0801,  13.3801, -67.2001]
107
    lonlist=[ 2.4301, -22.6001, -47.0801,  13.3801, -67.2001]
96
    latlist=[54.5601, 63.7010,  60.4201,  67.5001,  41.6423]
108
    latlist=[54.5601, 63.7010,  60.4201,  67.5001,  41.6423]
97
    
109
    
110
    stationNames=['NorthSea','Iceland','Lofoten', 'Georges Bank']
111
    lonlist=[ 2.4301, -22.6001, 13.3801, -67.2001]
112
    latlist=[54.5601, 63.7010, 67.5001,  41.6423]
113
    
98
        
114
        
99
    """" NO EDIT BELOW ========================================================="""
115
    """" NO EDIT BELOW ========================================================="""
100
    if compileAll is True:
116
    if compileAll is True:
...
...
121
        showInfo(vars,romsgridpath,climName,initName,bryName,start_year,end_year,start_julianday,end_julianday)
137
        showInfo(vars,romsgridpath,climName,initName,bryName,start_year,end_year,start_julianday,end_julianday)
122
        
138
        
123
        if type=='SODA' or type=='SODAMONTHLY':
139
        if type=='SODA' or type=='SODAMONTHLY':
124
            soda2roms.convertMODEL2ROMS(years,IDS,climName,initName,sodapath,romsgridpath,vars,show_progress,type)
140
            soda2roms.convertMODEL2ROMS(years,IDS,climName,initName,sodapath,romsgridpath,vars,show_progress,type,subset)
125
        elif type=='HYCOM':
141
        elif type=='HYCOM':
126
            soda2roms.convertMODEL2ROMS([1],[1,2,3],climName,initName,hycompath,romsgridpath,vars,show_progress,type)
142
            soda2roms.convertMODEL2ROMS([1],[1,2,3],climName,initName,hycompath,romsgridpath,vars,show_progress,type,subset)
127
    
143
    
128
        clim2bry.writeBry(grdROMS,start_year,bryName,climName)
144
        clim2bry.writeBry(grdROMS,start_year,bryName,climName)
129
    
145
    
...
...
144
160
145
if __name__ == "__main__":
161
if __name__ == "__main__":
146
    
162
    
147
    try:
163
    #try:
148
        import psyco
164
    #    import psyco
149
        psyco.log()
165
    #    psyco.log()
150
        psyco.full(memory=100)
166
    #    psyco.full(memory=100)
151
        psyco.profile(0.05, memory=100)
167
    #    psyco.profile(0.05, memory=100)
152
        psyco.profile(0.2)
168
    #    psyco.profile(0.2)
153
    except ImportError:
169
    #except ImportError:
154
        pass
170
    #    pass
155
171
156
    main()
172
    main()

Updated plotData.py Download diff

9899
34
                      resolution='l',area_thresh=100.,projection='npstere')
34
                      resolution='l',area_thresh=100.,projection='npstere')
35
        levels = np.arange(-2.0, 15.0, 0.1)
35
        levels = np.arange(-2.0, 15.0, 0.1)
36
        
36
        
37
    if grdROMS.grdName=='NorthSea':
38
        map = Basemap(llcrnrlon=grdROMS.lon_rho[0,:].min()-15.25,
39
                      llcrnrlat=grdROMS.lat_rho[:,0].min()-2.25,
40
                      urcrnrlon=grdROMS.lon_rho[0,:].max()+5.25,
41
                      urcrnrlat=grdROMS.lat_rho[:,0].max()+5.25,
42
                      resolution='i',projection='tmerc',lon_0=0,lat_0=50,area_thresh=10.)
43
        levels = np.arange(2.0, 15.0, 0.5)
44
        
37
    if grdROMS.grdName=='NA':
45
    if grdROMS.grdName=='NA':
38
        map = Basemap(lon_0=25,boundinglat=0,
46
        map = Basemap(lon_0=25,boundinglat=0,
39
                resolution='l',area_thresh=2000.,projection='npstere')
47
                resolution='l',area_thresh=2000.,projection='npstere')
40
        levels = np.arange(-2.0, 25.0, 0.5)
48
        levels = np.arange(-2.0, 25.0, 0.5)
41
    
49
        
50
    if grdROMS.grdName=='NATL':
51
        map = Basemap(lon_0=2,boundinglat=0,
52
                resolution='l',area_thresh=2000.,projection='npstere')
53
        levels = np.arange(-2.0, 30.0, 0.5)
54
        
42
    if grdROMS.grdName=='NA_Nathan':
55
    if grdROMS.grdName=='NA_Nathan':
43
        map = Basemap(lon_0=25,boundinglat=0,
56
        map = Basemap(lon_0=25,boundinglat=0,
44
                resolution='l',area_thresh=2000.,projection='npstere')
57
                resolution='l',area_thresh=2000.,projection='npstere')
...
...
63
    #map.drawparallels(np.arange(0,90,5))
76
    #map.drawparallels(np.arange(0,90,5))
64
77
65
    temp = np.ma.masked_values(temp,grdROMS.fill_value)
78
    temp = np.ma.masked_values(temp,grdROMS.fill_value)
66
    
79
    if var=='salinity':
80
        levels = np.arange(15.0, 40.0, 0.3)
67
    if var=='runoff':
81
    if var=='runoff':
68
        levels = np.arange(1e-4, 1e-8, 1e-10)
82
        levels = np.arange(1e-4, 1e-8, 1e-10)
69
    if var=='ssh':
83
    if var=='ssh':
...
...
87
    #plt.title('Variabel %s at depth %s'%(var,depthlevel))
101
    #plt.title('Variabel %s at depth %s'%(var,depthlevel))
88
    plotfile='uvel_'+str(depthlevel)+'.png'
102
    plotfile='uvel_'+str(depthlevel)+'.png'
89
    plt.savefig(plotfile)
103
    plt.savefig(plotfile)
90
    #plt.show()
104
    plt.show()
91
   
105
   

Updated soda2roms.py Download diff

9899
15
import barotropic
15
import barotropic
16
import IOinitial
16
import IOinitial
17
import plotData
17
import plotData
18
import IOsubset
18
19
19
__author__   = 'Trond Kristiansen'
20
__author__   = 'Trond Kristiansen'
20
__email__    = 'trond.kristiansen@imr.no'
21
__email__    = 'trond.kristiansen@imr.no'
21
__created__  = datetime(2008, 8, 15)
22
__created__  = datetime(2008, 8, 15)
22
__modified__ = datetime(2008, 8, 19)
23
__modified__ = datetime(2008, 8, 19)
23
__modified__ = datetime(2009,10, 1)
24
__modified__ = datetime(2010, 1, 7)
24
__version__  = "1.5"
25
__version__  = "1.5"
25
__status__   = "Development"
26
__status__   = "Development, modified on 15.08.2008,01.10.2009,07.01.2010"
26
27
27
def VerticalInterpolation(var,array1,array2,grdROMS,grdMODEL):
28
def VerticalInterpolation(var,array1,array2,grdROMS,grdMODEL):
28
    
29
    
...
...
36
    if var=='salinity' or var=='temperature':
37
    if var=='salinity' or var=='temperature':
37
        print 'Start vertical interpolation for %s (dimensions=%s x %s)'%(var,grdROMS.xi_rho,grdROMS.eta_rho)
38
        print 'Start vertical interpolation for %s (dimensions=%s x %s)'%(var,grdROMS.xi_rho,grdROMS.eta_rho)
38
        outdata=np.zeros((outINDEX_ST),dtype=np.float64, order='Fortran')
39
        outdata=np.zeros((outINDEX_ST),dtype=np.float64, order='Fortran')
39
    
40
        
40
        outdata = interp.interpolation.dovertinter(np.asarray(outdata,order='Fortran'),
41
        outdata = interp.interpolation.dovertinter(np.asarray(outdata,order='Fortran'),
41
                                                       np.asarray(array1,order='Fortran'),
42
                                                       np.asarray(array1,order='Fortran'),
42
                                                       np.asarray(grdROMS.depth,order='Fortran'),
43
                                                       np.asarray(grdROMS.depth,order='Fortran'),
...
...
50
                                                       int(grdROMS.eta_rho))
51
                                                       int(grdROMS.eta_rho))
51
        
52
        
52
            
53
            
53
    if var in ['temperature','salinity']:
54
    #if var in ['temperature','salinity']:
54
        #for k in range(grdROMS.Nlevels):
55
    #    for k in range(grdROMS.Nlevels):
55
        #    print k
56
    #        plotData.contourMap(grdROMS,grdMODEL,np.squeeze(outdata[k,:,:]),k,var)
56
        #    plotData.contourMap(grdROMS,grdMODEL,np.squeeze(outdata[k,:,:]),k,var)
57
        return outdata
57
        return outdata
58
        
58
        
59
        
59
        
...
...
277
       
277
       
278
        print '\nCurrent time of SODAMONTHLY file : %s/%s/%s'%(soda_date.year,soda_date.month,soda_date.day)
278
        print '\nCurrent time of SODAMONTHLY file : %s/%s/%s'%(soda_date.year,soda_date.month,soda_date.day)
279
    
279
    
280
def find_subset_indices(grdMODEL,min_lat,max_lat,min_lon,max_lon):
280
def convertMODEL2ROMS(years,IDS,climName,initName,dataPath,romsgridpath,vars,show_progress,type,subset):
281
    """
282
    Get the indices that covers the new grid, and enables us to only store a subset of
283
    the large input grid.
284
    """
285
    lat=grdMODEL.lat[:,0]
286
    lon=grdMODEL.lon[0,:]
287
 
288
    distances1 = []
289
    distances2 = []
290
    indices=[]
291
    index=0
292
    for point in lat:
293
        s1 = max_lat-point # (vector subtract)
294
        s2 = min_lat-point # (vector subtract)
295
        distances1.append((np.dot(s1, s1), point, index))
296
        distances2.append((np.dot(s2, s2), point, index))
297
        index=index+1
298
        
299
    distances1.sort()
300
    distances2.sort()
301
    indices.append(distances1[0])
302
    indices.append(distances2[0])
303
    
304
    distances1 = []
305
    distances2 = []
306
    index=0
307
   
308
    for point in lon:
309
        s1 = max_lon-point # (vector subtract)
310
        s2 = min_lon-point # (vector subtract)
311
        distances1.append((np.dot(s1, s1), point, index))
312
        distances2.append((np.dot(s2, s2), point, index))
313
        index=index+1
314
       
315
    distances1.sort()
316
    distances2.sort()
317
    indices.append(distances1[0])
318
    indices.append(distances2[0])
319
    
320
    """ Save final product: max_lat_indices,min_lat_indices,max_lon_indices,min_lon_indices"""
321
      
322
    grdMODEL.minJ=indices[1][2]
323
    grdMODEL.maxJ=indices[0][2]
324
    grdMODEL.minI=indices[3][2]
325
    grdMODEL.maxI=indices[2][2]
326
    
327
  
328
def convertMODEL2ROMS(years,IDS,climName,initName,dataPath,romsgridpath,vars,show_progress,type):
329
281
330
    if type=='SODA':
282
    if type=='SODA':
331
        fileNameIn=dataPath+'SODA_2.0.2_'+str(years[0])+'_'+str(IDS[0])+'.cdf'
283
        fileNameIn=dataPath+'SODA_2.0.2_'+str(years[0])+'_'+str(IDS[0])+'.cdf'
...
...
347
    """Now we want to subset the data to avoid storing more information than we need.
299
    """Now we want to subset the data to avoid storing more information than we need.
348
    We do this by finding the indices of maximum and minimum latitude and longitude in the matrixes"""
300
    We do this by finding the indices of maximum and minimum latitude and longitude in the matrixes"""
349
    if type=='SODA' or type=='SODAMONTHLY':
301
    if type=='SODA' or type=='SODAMONTHLY':
350
        find_subset_indices(grdMODEL,min_lat=30, max_lat=90, min_lon=0, max_lon=360)
302
        IOsubset.findSubsetIndices(grdMODEL,min_lat=subset[0], max_lat=subset[1], min_lon=subset[2], max_lon=subset[3])
351
        
303
    
352
    if type=='HYCOM':
304
    if type=='HYCOM':
353
        grdMODEL.minJ=1900
305
        grdMODEL.minJ=1900
354
        grdMODEL.maxJ=2400
306
        grdMODEL.maxJ=2400
...
...
356
        grdMODEL.maxI=2875
308
        grdMODEL.maxI=2875
357
     
309
     
358
310
359
    grdMODEL.lat=grdMODEL.lat[grdMODEL.minJ:grdMODEL.maxJ,grdMODEL.minI:grdMODEL.maxI]
311
    #grdMODEL.lat=grdMODEL.lat[int(grdMODEL.indices[0,2]):int(grdMODEL.indices[0,3]),int(grdMODEL.indices[0,0]):int(grdMODEL.indices[0,1])]
360
    grdMODEL.lon=grdMODEL.lon[grdMODEL.minJ:grdMODEL.maxJ,grdMODEL.minI:grdMODEL.maxI]
312
    #grdMODEL.lon=grdMODEL.lon[int(grdMODEL.indices[0,2]):int(grdMODEL.indices[0,3]),int(grdMODEL.indices[0,0]):int(grdMODEL.indices[0,1])]
361
  
313
362
    print "---> Selected area in output file spans from (longitude=%3.2f,latitude=%3.2f) to (longitude=%3.2f,latitude=%3.2f)"%(grdROMS.lon_rho.min(),grdROMS.lat_rho.min(),grdROMS.lon_rho.max(),grdROMS.lat_rho.max())
363
    print "---> Selected area in input file spans from  (longitude=%3.2f,latitude=%3.2f) to (longitude=%3.2f,latitude=%3.2f)"%(grdMODEL.lon.min(),grdMODEL.lat.min(),grdMODEL.lon.max(),grdMODEL.lat.max())
364
    
365
    print 'Initializing done'
314
    print 'Initializing done'
366
    print '\n--------------------------'
315
    print '\n--------------------------'
367
    
316
    
...
...
376
            if type=='SODA':
325
            if type=='SODA':
377
                file="SODA_2.0.2_"+str(year)+"_"+str(ID)+".cdf"
326
                file="SODA_2.0.2_"+str(year)+"_"+str(ID)+".cdf"
378
                filename=dataPath+file
327
                filename=dataPath+file
379
                variableNames=['TEMP','SALT','SSH','U','V']
328
                varNames=['TEMP','SALT','SSH','U','V']
380
                
329
                
381
            if type=='SODAMONTHLY':
330
            if type=='SODAMONTHLY':
382
                if ID <  10: filename=dataPath+'SODA_2.0.2_'+str(years[0])+'0'+str(ID)+'.cdf'
331
                if ID <  10: filename=dataPath+'SODA_2.0.2_'+str(years[0])+'0'+str(ID)+'.cdf'
383
                if ID >= 10: filename=dataPath+'SODA_2.0.2_'+str(years[0])+str(ID)+'.cdf'
332
                if ID >= 10: filename=dataPath+'SODA_2.0.2_'+str(years[0])+str(ID)+'.cdf'
384
                variableNames=['temp','salt','ssh','u','v']
333
                varNames=['temp','salt','ssh','u','v']
385
              
334
              
386
            if type=='HYCOM':
335
            if type=='HYCOM':
387
                filename=dataPath+'archv.2003_307_00_3zt.nc'
336
                filename=dataPath+'archv.2003_307_00_3zt.nc'
388
                variableNames=['temperature','salinity','SSH','U','V'] # NATHAN FIXME; give correct name of hycom variables
337
                varNames=['temperature','salinity','SSH','U','V'] # NATHAN FIXME; give correct name of hycom variables
389
                
338
                
390
            """Now open the input file"""    
339
            """Now open the input file"""    
391
            cdf = Dataset(filename)
340
            cdf = Dataset(filename)
...
...
397
            
346
            
398
            if firstRun is True:
347
            if firstRun is True:
399
                firstRun = False
348
                firstRun = False
400
   
349
                if type=='SODA' or type=='SODAMONTHLY':
350
                    """The first iteration we want to organize the subset indices we want to extract
351
                    from the input data to get the interpolation correct and to function fast"""
352
                    IOsubset.organizeSplit(grdMODEL,grdROMS,type,varNames,cdf)
401
                indexROMS_S_ST = (grdROMS.Nlevels,grdROMS.eta_rho,grdROMS.xi_rho)
353
                indexROMS_S_ST = (grdROMS.Nlevels,grdROMS.eta_rho,grdROMS.xi_rho)
402
                indexROMS_SSH  = (grdROMS.eta_rho,grdROMS.xi_rho)
354
                indexROMS_SSH  = (grdROMS.eta_rho,grdROMS.xi_rho)
403
                
355
                
...
...
413
            
365
            
414
            for var in vars:
366
            for var in vars:
415
                
367
                
416
                if var=='temperature':
368
                """Do the 3D variables first"""
417
                    STdata=np.zeros((indexROMS_S_ST),dtype=np.float64)
369
                if var in ['temperature','salinity','uvel','vvel']:
418
                    if type=="SODA": data = np.array(cdf.variables[str(variableNames[0])][0,:,grdMODEL.minJ:grdMODEL.maxJ,grdMODEL.minI:grdMODEL.maxI])
419
                    if type=="SODAMONTHLY": data = np.array(cdf.variables[str(variableNames[0])][:,grdMODEL.minJ:grdMODEL.maxJ,grdMODEL.minI:grdMODEL.maxI])
420
                    
370
                    
421
                    if time==0:
371
                    if var=='temperature': varN=0; STdata=np.zeros((indexROMS_S_ST),dtype=np.float64)
422
                        tmp=np.squeeze(data[0,:,:])
372
                    if var=='salinity':    varN=1; STdata=np.zeros((indexROMS_S_ST),dtype=np.float64)
423
                        grdMODEL.mask = np.zeros((grdMODEL.lon.shape),dtype=np.float64)
373
                    if var=='uvel':        varN=3; Udata = np.zeros((indexROMS_S_U),dtype=np.float64)
424
                        grdMODEL.mask[:,:] = np.where(tmp==grdROMS.fill_value,1,0)
374
                    if var=='vvel':        varN=4; Vdata = np.zeros((indexROMS_S_V),dtype=np.float64)
375
                    
376
                    if grdMODEL.splitExtract is True:
377
                        if type=="SODA":
378
                            data1 = cdf.variables[varNames[varN]][0,:,
379
                                                     int(grdMODEL.indices[0,2]):int(grdMODEL.indices[0,3]),
380
                                                     int(grdMODEL.indices[0,0]):int(grdMODEL.indices[0,1])]
381
                            data2 = cdf.variables[varNames[varN]][0,:,
382
                                                     int(grdMODEL.indices[1,2]):int(grdMODEL.indices[1,3]),
383
                                                     int(grdMODEL.indices[1,0]):int(grdMODEL.indices[1,1])]
384
                        if type=="SODAMONTHLY":
385
                            data1 = cdf.variables[str(varNames[varN])][:,int(grdMODEL.indices[0,2]):int(grdMODEL.indices[0,3]),
386
                                                    int(grdMODEL.indices[0,0]):int(grdMODEL.indices[0,1])]
387
                            data2 = cdf.variables[str(varNames[varN])][:,int(grdMODEL.indices[1,2]):int(grdMODEL.indices[1,3]),
388
                                                    int(grdMODEL.indices[1,0]):int(grdMODEL.indices[1,1])]
389
                        data = np.concatenate((data1,data2),axis=2)
425
                        
390
                        
426
                if var=='salinity':
391
                    else:
427
                    STdata = np.zeros((indexROMS_S_ST),dtype=np.float64)
392
                        if type=="SODA":
428
                    if type=="SODA": data  = np.array(cdf.variables[str(variableNames[1])][0,:,grdMODEL.minJ:grdMODEL.maxJ,grdMODEL.minI:grdMODEL.maxI])
393
                            data = cdf.variables[str(varNames[varN])][0,:,
429
                    if type=="SODAMONTHLY": data  = np.array(cdf.variables[str(variableNames[1])][:,grdMODEL.minJ:grdMODEL.maxJ,grdMODEL.minI:grdMODEL.maxI])
394
                                                    int(grdMODEL.indices[0,2]):int(grdMODEL.indices[0,3]),
430
                
395
                                                    int(grdMODEL.indices[0,0]):int(grdMODEL.indices[0,1])]
396
                        if type=="SODAMONTHLY":
397
                            data = cdf.variables[str(varNames[varN])][:,int(grdMODEL.indices[0,2]):int(grdMODEL.indices[0,3]),
398
                                                    int(grdMODEL.indices[0,0]):int(grdMODEL.indices[0,1])]
399
                        
400
                if time==0 and var==vars[0]:
401
                    tmp=np.squeeze(data[0,:,:])
402
                    grdMODEL.mask = np.zeros((grdMODEL.lon.shape),dtype=np.float64)
403
                    grdMODEL.mask[:,:] = np.where(tmp==grdROMS.fill_value,1,0)
404
                        
405
              
406
                """2D varibles"""
431
                if var=='ssh':
407
                if var=='ssh':
408
                    varN=2
432
                    SSHdata = np.zeros((indexROMS_SSH),dtype=np.float64)
409
                    SSHdata = np.zeros((indexROMS_SSH),dtype=np.float64)
433
                    if type=="SODA": data  = np.array(cdf.variables[str(variableNames[2])][0,grdMODEL.minJ:grdMODEL.maxJ,grdMODEL.minI:grdMODEL.maxI])
410
                    if grdMODEL.splitExtract is True:
434
                    if type=="SODAMONTHLY": data  = np.array(cdf.variables[str(variableNames[2])][grdMODEL.minJ:grdMODEL.maxJ,grdMODEL.minI:grdMODEL.maxI])
411
                        if type=="SODA":
435
                
412
                            data1 = cdf.variables[varNames[varN]][0,
436
                if var=='uvel':
413
                                                     int(grdMODEL.indices[0,2]):int(grdMODEL.indices[0,3]),
437
                    Udata = np.zeros((indexROMS_S_U),dtype=np.float64)
414
                                                     int(grdMODEL.indices[0,0]):int(grdMODEL.indices[0,1])]
438
                    if type=="SODA": data  = np.array(cdf.variables[str(variableNames[3])][0,:,grdMODEL.minJ:grdMODEL.maxJ,grdMODEL.minI:grdMODEL.maxI])
415
                            data2 = cdf.variables[varNames[varN]][0,
439
                    if type=="SODAMONTHLY": data  = np.array(cdf.variables[str(variableNames[3])][:,grdMODEL.minJ:grdMODEL.maxJ,grdMODEL.minI:grdMODEL.maxI])
416
                                                     int(grdMODEL.indices[1,2]):int(grdMODEL.indices[1,3]),
440
                    
417
                                                     int(grdMODEL.indices[1,0]):int(grdMODEL.indices[1,1])]
441
                if var=='vvel':
418
                        if type=="SODAMONTHLY":
442
                    Vdata = np.zeros((indexROMS_S_V),dtype=np.float64)
419
                            data1 = cdf.variables[str(varNames[varN])][int(grdMODEL.indices[0,2]):int(grdMODEL.indices[0,3]),
443
                    if type=="SODA": data  = np.array(cdf.variables[str(variableNames[4])][0,:,grdMODEL.minJ:grdMODEL.maxJ,grdMODEL.minI:grdMODEL.maxI])
420
                                                    int(grdMODEL.indices[0,0]):int(grdMODEL.indices[0,1])]
444
                    if type=="SODAMONTHLY": data  = np.array(cdf.variables[str(variableNames[4])][:,grdMODEL.minJ:grdMODEL.maxJ,grdMODEL.minI:grdMODEL.maxI])
421
                            data2 = cdf.variables[str(varNames[varN])][int(grdMODEL.indices[1,2]):int(grdMODEL.indices[1,3]),
445
                    
422
                                                    int(grdMODEL.indices[1,0]):int(grdMODEL.indices[1,1])]
423
                        data = np.concatenate((data1,data2),axis=1)
424
                        
425
                    else:
426
                        if type=="SODA":
427
                            data = cdf.variables[str(varNames[varN])][0,
428
                                                    int(grdMODEL.indices[0,2]):int(grdMODEL.indices[0,3]),
429
                                                    int(grdMODEL.indices[0,0]):int(grdMODEL.indices[0,1])]
430
                        if type=="SODAMONTHLY":
431
                            data = cdf.variables[str(varNames[varN])][int(grdMODEL.indices[0,2]):int(grdMODEL.indices[0,3]),
432
                                                    int(grdMODEL.indices[0,0]):int(grdMODEL.indices[0,1])]
433
              
434
                """Take the input data and horizontally interpolate to your grid."""    
446
                array1 = HorizontalInterpolation(var,grdROMS,grdMODEL,data,show_progress)
435
                array1 = HorizontalInterpolation(var,grdROMS,grdMODEL,data,show_progress)
447
                
436
                
448
                if var in ['temperature','salinity']:    
437
                if var in ['temperature','salinity']: