diff --git a/examples/rivers/make_river_clim.py b/examples/rivers/make_river_clim.py index 2386324..ff12052 100644 --- a/examples/rivers/make_river_clim.py +++ b/examples/rivers/make_river_clim.py @@ -6,7 +6,7 @@ import pycnal_toolbox -# load 2-dimentional discharge data +# load 2-dimentional discharge data print('Load discharge data') nc_data = netCDF.Dataset('CI_runoff.nc', 'r') nc_rivers = netCDF.Dataset('Cook_Inlet_rivers.nc', 'a') @@ -54,7 +54,7 @@ frac = 1.0/count[j,i] k = rivers[j,i][n] runoff[k] = frac*data[t,j,i] - + if t==180: sum180 = np.sum(runoff) diff --git a/pycnal/pycnal/grid.py b/pycnal/pycnal/grid.py index 401d65b..315e5a9 100644 --- a/pycnal/pycnal/grid.py +++ b/pycnal/pycnal/grid.py @@ -43,10 +43,10 @@ class ROMS_gridinfo(object): There are two ways to define the grid information. If grid_file and hist_file are not passed to the object when it is created, the - information is retrieved from gridid.txt. - To add new grid please edit your gridid.txt. You need to define - an environment variable PYCNAL_GRIDID_FILE pointing to your - gridid.txt file. Just copy an existing grid and modify the + information is retrieved from gridid.txt. + To add new grid please edit your gridid.txt. You need to define + an environment variable PYCNAL_GRIDID_FILE pointing to your + gridid.txt file. Just copy an existing grid and modify the definition accordingly to your case (Be carefull with space and blank line). @@ -69,7 +69,7 @@ def __init__(self, gridid,grid_file=None,hist_file=None): #the grid and history files from the model self.id = gridid self._get_grid_info(grid_file,hist_file) - + #now save the data in the dictionary, so we don't need to get it again gridid_dictionary[gridid]=self @@ -119,7 +119,7 @@ def _get_grid_info(self,grid_file,hist_file): self.theta_b = np.float(info[7]) self.Tcline = np.float(info[8]) - elif info[4] == 'z': + elif info[4] == 'z': nline = len(info) dep = info[5] for line in range(6,nline): @@ -140,7 +140,7 @@ def _get_grid_info(self,grid_file,hist_file): assert type(grid_file)!=type(None), 'if specify history file you must specify grid file' assert type(hist_file)!=type(None), 'if specify grid file you must specify history file' - #open history file and get necessary grid information from it. + #open history file and get necessary grid information from it. hist=netCDF.Dataset(hist_file,'r') #put data into ROMS_gridinfo object @@ -164,7 +164,7 @@ def _get_grid_info(self,grid_file,hist_file): self.theta_s=np.float(hist.variables['theta_s'][:]) self.theta_b=np.float(hist.variables['theta_b'][:]) self.Tcline=np.float(hist.variables['Tcline'][:]) - + def print_ROMS_gridinfo(gridid): """ @@ -202,7 +202,7 @@ def list_ROMS_gridid(): data = open(gridid_file,'r') lines = data.readlines() data.close() - + gridid_list = [] for line in lines: s = line.split() @@ -227,7 +227,7 @@ def get_ROMS_hgrid(gridid): #Check for cartesian or geographical grid spherical = nc.variables['spherical'][:] - #Get horizontal grid + #Get horizontal grid if ((spherical == 0) or (spherical == 'F')): #cartesian grid print('Load cartesian grid from file') @@ -359,7 +359,7 @@ def get_ROMS_hgrid(gridid): else: angle = None - #Get geographical grid + #Get geographical grid hgrd = CGrid_geo(lon_vert, lat_vert, proj, \ lon_rho=lon_rho, lat_rho=lat_rho, \ lon_u=lon_u, lat_u=lat_u, lon_v=lon_v, lat_v=lat_v, \ @@ -367,9 +367,9 @@ def get_ROMS_hgrid(gridid): dndx=dndx, dmde=dmde, angle_rho=angle) #load the mask - try: + try: hgrd.mask_rho = np.array(nc.variables['mask_rho'][:]) - except: + except: hgrd.mask_rho = np.ones(hgrd.lat_rho.shape) return hgrd @@ -382,11 +382,11 @@ def get_ROMS_vgrid(gridid, zeta=None): Load ROMS vertical grid object. vgrid is a s_coordinate or a z_coordinate object, depending on gridid.grdtype. vgrid.z_r and vgrid.z_w (vgrid.z for a z_coordinate object) - can be indexed in order to retreive the actual depths. The - free surface time serie zeta can be provided as an optional - argument. Note that the values of zeta are not calculated - until z is indexed, so a netCDF variable for zeta may be passed, - even if the file is large, as only the values that are required + can be indexed in order to retreive the actual depths. The + free surface time serie zeta can be provided as an optional + argument. Note that the values of zeta are not calculated + until z is indexed, so a netCDF variable for zeta may be passed, + even if the file is large, as only the values that are required will be retrieved from the file. """ @@ -417,10 +417,10 @@ def get_ROMS_vgrid(gridid, zeta=None): elif Vtrans == 2: vgrid = s_coordinate_2(h, theta_b, theta_s, Tcline, N, hraw=hraw, zeta=zeta) elif Vtrans == 4: - vgrid = s_coordinate_4(h, theta_b, theta_s, Tcline, N, hraw=hraw, zeta=zeta) + vgrid = s_coordinate_4(h, theta_b, theta_s, Tcline, N, hraw=hraw, zeta=zeta) elif Vtrans == 5: vgrid = s_coordinate_5(h, theta_b, theta_s, Tcline, N, hraw=hraw, zeta=zeta) - + else: raise Warning('Unknown vertical transformation Vtrans') @@ -451,15 +451,15 @@ def get_ROMS_grid(gridid, zeta=None, hist_file=None,grid_file=None): grid information will be extracted from those files, and gridid will be used to name that grid for the rest of the python session. - + grd.vgrid is a s_coordinate or a z_coordinate object, depending on gridid.grdtype. - grd.vgrid.z_r and grd.vgrid.z_w (grd.vgrid.z for a - z_coordinate object) can be indexed in order to retreive the - actual depths. The free surface time serie zeta can be provided - as an optional argument. Note that the values of zeta are not - calculated until z is indexed, so a netCDF variable for zeta may - be passed, even if the file is large, as only the values that + grd.vgrid.z_r and grd.vgrid.z_w (grd.vgrid.z for a + z_coordinate object) can be indexed in order to retreive the + actual depths. The free surface time serie zeta can be provided + as an optional argument. Note that the values of zeta are not + calculated until z is indexed, so a netCDF variable for zeta may + be passed, even if the file is large, as only the values that are required will be retrieved from the file. """ @@ -489,7 +489,6 @@ def write_ROMS_grid(grd, filename='roms_grd.nc'): Mm, Lm = grd.hgrid.x_rho.shape - # Write ROMS grid to file nc = netCDF.Dataset(filename, 'w', format='NETCDF3_64BIT') nc.Description = 'ROMS grid' @@ -501,7 +500,7 @@ def write_ROMS_grid(grd, filename='roms_grd.nc'): nc.createDimension('xi_u', Lm-1) nc.createDimension('xi_v', Lm) nc.createDimension('xi_psi', Lm-1) - + nc.createDimension('eta_rho', Mm) nc.createDimension('eta_u', Mm) nc.createDimension('eta_v', Mm-1)