Closed GuiCruz closed 3 years ago
Hi,
This log is a bit hard to understand.
Are you seeding elements from a shapefile with 95 polygons? And you are using another shapefile for the landmask?
Can you try o.plot()
after your seeding, but before you do run()
?
You might also need to do the following, which you are perhaps already doing:
o.set_config('general:use_auto_landmask', False) # Disabling the automatic GSHHG landmask
Also it would help if you can post your script.
Yes, I am seeding from a shapefile with around 100 polygons, and I am also using a custom shapefile for my landmask
seed_shp = 'D:/Dropbox/Doutorado/LC08_RS/Ideal_model/45degree/seeder.shp'
fn_shp = 'D:/Dropbox/Doutorado/LC08_RS/Ideal_model/Coastline_25x100km_GCS.shp'
o = OceanDrift(loglevel=0)
o.set_config('general:use_auto_landmask', False)
o.set_config('general:coastline_action', 'previous')
reader = reader_netCDF_CF_generic.Reader(fn_nc)
reader_shp = reader_shape.Reader.from_shpfiles(fn_shp)
o.add_reader([reader])
o.add_reader([reader_shp])
lats= np.linspace(-32.15, -32.15, 200)
#lons = np.linspace(-52.18633433, -51.97683977, 200)
o.seed_from_shapefile(seed_shp,number=9500, radius = 90,time=[reader.start_time, reader.end_time])
#o.seed_from_shapefile(seed_shp,number=9500, radius = 90,time=[datetime.datetime(2020, 7, 9, 0, 5), datetime.datetime(2020, 7, 9, 0, 20)])
o.set_config('environment:fallback:land_binary_mask', 0)
o.run()
This seems ok. Can you insert o.plot() before run, and post the graphics you get?
On Sun, Apr 18, 2021, 20:37 Guilherme Cruz @.***> wrote:
Yes, I am seeding from a shapefile with around 100 polygons, and I am also using a custom shapefile for my landmask
seed_shp = 'D:/Dropbox/Doutorado/LC08_RS/Ideal_model/45degree/seeder.shp' fn_shp = 'D:/Dropbox/Doutorado/LC08_RS/Ideal_model/Coastline_25x100km_GCS.shp'
o = OceanDrift(loglevel=0) o.set_config('general:use_auto_landmask', False) o.set_config('general:coastline_action', 'previous')
reader = reader_netCDF_CF_generic.Reader(fn_nc) reader_shp = reader_shape.Reader.from_shpfiles(fn_shp)
o.add_reader([reader]) o.add_reader([reader_shp])
lats= np.linspace(-32.15, -32.15, 200)
lons = np.linspace(-52.18633433, -51.97683977, 200)
o.seed_from_shapefile(seed_shp,number=9500, radius = 90,time=[reader.start_time, reader.end_time])
o.seed_from_shapefile(seed_shp,number=9500, radius = 90,time=[datetime.datetime(2020, 7, 9, 0, 5), datetime.datetime(2020, 7, 9, 0, 20)])
o.set_config('environment:fallback:land_binary_mask', 0)
o.run()
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/OpenDrift/opendrift/issues/593#issuecomment-822039227, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABH25IYWDWAHUEMUAH25INLTJMRFNANCNFSM43EBN6ZQ .
Here is my complete code... Not sure if you will understand is a little confused:
import datetime
import utm
from pyproj import CRS
from opendrift.readers import reader_netCDF_CF_generic
from opendrift.readers import reader_netCDF_CF_unstructured
from opendrift.readers import reader_shape
from opendrift.readers import reader_global_landmask
from opendrift.models.oceandrift import OceanDrift
from scipy.interpolate import griddata
import numpy as np
import netCDF4 as nc
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D #
from matplotlib import cm
from metpy.interpolate import (interpolate_to_grid, remove_nan_observations,
remove_repeat_coordinates)
fn_nc = './wind10_225deg_+2500.nc'
fn = 'D:/Dropbox/Doutorado/LC08_RS/Ideal_model/5min_step_25x100km_Wind10_225deg_Rev1_+2500vaz.nc'#E:/5min_step_25x100km_Wind5_225deg_Rev1_0vaz.nc'
fn_shp = 'D:/Dropbox/Doutorado/LC08_RS/Ideal_model/Coastline_25x100km_GCS.shp'
ds = nc.Dataset(fn)
x = ds.variables['XCOR'][9:92,1:51]
y = ds.variables['YCOR'][9:92,1:51]
dpo = ds.variables['DP0'][9:92,1:51]
wls = ds.variables['S1'][2305:2309,9:92,1:51]
U = ds.variables['U1'][2305:2309,:,9:92,1:51]
V = ds.variables['V1'][2305:2309,:,9:92,1:51]
W = ds.variables['WPHY'][2305:2309,:,9:92,1:51]#W-velocity per layer in zeta point
diff = ds.variables['DICWW'][2305:2309,:,9:92,1:51]#Vertical eddy diffusivity-3D in zeta point
sal = ds.variables['R1'][2305:2309,0,:,9:92,1:51]#Concentrations per layer in zeta point - Salinity
dim0 = len(U)
dim2 = len(U[0][0])
dim3 = len(U[0][0][0])
x_f = np.ravel(x)
y_f = np.ravel(y)
dpo_f = np.ravel(dpo)
gx, gy, dpo_tp = interpolate_to_grid(x_f, y_f, dpo_f, interp_type='nearest', hres=100)#sea_floor_depth_below_sea_level
r_u = []
r_v = []
r_wl = []
r_W = []
r_d = []
r_s = []
t_u = []
t_v = []
t_W = []
t_d = []
t_s = []
r_m = []
i = 0
ii = 0
while i < dim0:
wl_fp = np.ravel(wls[i,:,:])
while ii < 10:
u_fp = np.ravel(U[i,ii,:,:])
v_fp = np.ravel(V[i,ii,:,:])
w_fp = np.ravel(W[i,ii,:,:])
s_fp = np.ravel(sal[i,ii,:,:])
d_fp = np.ravel(diff[i,ii,:,:])
for t in range (len(u_fp)):
if u_fp[t]==-999:
u_fp[t]=0
for t in range (len(v_fp)):
if v_fp[t]==-999:
v_fp[t]=0
gx, gy, u_tp = interpolate_to_grid(x_f, y_f, u_fp, interp_type='linear', hres=100)
gx, gy, v_tp = interpolate_to_grid(x_f, y_f, v_fp, interp_type='linear', hres=100)
gx, gy, w_tp = interpolate_to_grid(x_f, y_f, w_fp, interp_type='linear', hres=100)
gx, gy, s_tp = interpolate_to_grid(x_f, y_f, s_fp, interp_type='linear', hres=100)
gx, gy, d_tp = interpolate_to_grid(x_f, y_f, d_fp, interp_type='linear', hres=100)
v_tp = v_tp*-1
t_u.append(u_tp)
t_v.append(v_tp)
t_W.append(w_tp)
t_d.append(d_tp)
t_s.append(s_tp)
ii+=1
r_u.append(t_u)
r_v.append(t_v)
r_W.append(t_W)
r_d.append(t_d)
r_s.append(t_s)
t_u = []
t_v = []
t_W = []
t_d = []
t_s = []
gx, gy, wl_tp = interpolate_to_grid(x_f, y_f, wl_fp, interp_type='linear', hres=100)
r_wl.append(wl_tp)
ii = 0
i+=1
print(i)
[gy_Deg,gx_Deg] = utm.to_latlon(gx, gy, 22, 'H')
gx_1 = gx_Deg[0,:]
gy_1 = gy_Deg[:,0]
gx_Deg = np.nan_to_num(gx_Deg)
gy_Deg = np.nan_to_num(gy_Deg)
r_wl = np.nan_to_num(r_wl)
r_u = np.nan_to_num(r_u)
r_v = np.nan_to_num(r_v)
r_W = np.nan_to_num(r_W)
r_d = np.nan_to_num(r_d)
r_s = np.nan_to_num(r_s)
dim0 = len(r_u)
dim2 = len(r_u[0][0])
dim3 = len(r_u[0][0][0])
z_reg = np.arange(0,20.1,0.1)
U_z = np.zeros((dim0,len(z_reg),dim2,dim3))
V_z = np.zeros((dim0,len(z_reg),dim2,dim3))
W_z = np.zeros((dim0,len(z_reg),dim2,dim3))
D_z = np.zeros((dim0,len(z_reg),dim2,dim3))
S_z = np.zeros((dim0,len(z_reg),dim2,dim3))
z_tsh = []
i = 0
ii = 0
iii = 0
while i < dim0:
wl = r_wl[i][:][:]
z_tsh = wl+dpo_tp
while ii < dim2:
while iii < dim3:
z_sigma = [0.05*z_tsh[ii,iii], 0.15*z_tsh[ii,iii], 0.25*z_tsh[ii,iii], 0.35*z_tsh[ii,iii], 0.45*z_tsh[ii,iii], 0.55*z_tsh[ii,iii], 0.65*z_tsh[ii,iii], 0.75*z_tsh[ii,iii], 0.85*z_tsh[ii,iii], 0.95*z_tsh[ii,iii]]
u_sigma = [r_u[i,0,ii,iii],r_u[i,1,ii,iii],r_u[i,2,ii,iii],r_u[i,3,ii,iii],r_u[i,4,ii,iii],r_u[i,5,ii,iii],r_u[i,6,ii,iii],r_u[i,7,ii,iii],r_u[i,8,ii,iii],r_u[i,9,ii,iii]]
v_sigma = [r_v[i,0,ii,iii],r_v[i,1,ii,iii],r_v[i,2,ii,iii],r_v[i,3,ii,iii],r_v[i,4,ii,iii],r_v[i,5,ii,iii],r_v[i,6,ii,iii],r_v[i,7,ii,iii],r_v[i,8,ii,iii],r_v[i,9,ii,iii]]
w_sigma = [r_W[i,0,ii,iii],r_W[i,1,ii,iii],r_W[i,2,ii,iii],r_W[i,3,ii,iii],r_W[i,4,ii,iii],r_W[i,5,ii,iii],r_W[i,6,ii,iii],r_W[i,7,ii,iii],r_W[i,8,ii,iii],r_W[i,9,ii,iii]]
d_sigma = [r_d[i,0,ii,iii],r_d[i,1,ii,iii],r_d[i,2,ii,iii],r_d[i,3,ii,iii],r_d[i,4,ii,iii],r_d[i,5,ii,iii],r_d[i,6,ii,iii],r_d[i,7,ii,iii],r_d[i,8,ii,iii],r_d[i,9,ii,iii]]
s_sigma = [r_s[i,0,ii,iii],r_s[i,1,ii,iii],r_s[i,2,ii,iii],r_s[i,3,ii,iii],r_s[i,4,ii,iii],r_s[i,5,ii,iii],r_s[i,6,ii,iii],r_s[i,7,ii,iii],r_s[i,8,ii,iii],r_s[i,9,ii,iii]]
U_reg = np.interp(z_reg,z_sigma,u_sigma,right=0)
V_reg = np.interp(z_reg,z_sigma,v_sigma,right=0)
W_reg = np.interp(z_reg,z_sigma,w_sigma,right=0)
D_reg = np.interp(z_reg,z_sigma,d_sigma,right=0)
S_reg = np.interp(z_reg,z_sigma,s_sigma,right=0)
U_z[i,:,ii,iii] = U_reg#
V_z[i,:,ii,iii] = V_reg#
W_z[i,:,ii,iii] = V_reg#upward_sea_water_velocity - Opendrift
D_z[i,:,ii,iii] = D_reg#ocean_vertical_diffusivity - Opendrift
S_z[i,:,ii,iii] = S_reg#sea_water_salinity
iii+=1
iii = 0
ii+=1
ii = 0
i+=1
print(i)
t = ds.variables['time'][2305:2309]
DS_Open.close()
DS_Open = nc.Dataset(fn_nc, 'w', format='NETCDF4_CLASSIC', diskless=True, persist=True)
DS_Open.Conventions = 'CF-1.7'
DS_Open.title = '25x100_Wind05ms_opendrift'
DS_Open.institution = 'Unidata'
DS_Open.source = 'WRF-1.5'
DS_Open.history = ''
DS_Open.references = ''
DS_Open.comment = ''
DS_Open.createDimension('time', None)
DS_Open.createDimension('depth', z_reg.size)
DS_Open.createDimension('X', gx_1.size)
DS_Open.createDimension('Y', gy_1.size)
crs = DS_Open.createVariable('latitude_longitude', np.int32, ())
crs.grid_mapping_name = 'latitude_longitude'
Dph_var = DS_Open.createVariable('depth', np.float32, ('depth',))
Dph_var[:] = z_reg
Dph_var.units = 'm'
Dph_var.positive = 'down'
Dph_var.axis = 'Z' # Optional
Dph_var.standard_name = 'depth'
time_var = DS_Open.createVariable('t', np.int32, ('time',))
time_var[:] = t
time_var.long_name = 'time since initialization'
time_var.units = 'seconds since 2020-07-01 00:00:00'
time_var.calendar = 'proleptic_gregorian'
time_var.standard_name = 'time' # Optional
U_var = DS_Open.createVariable('u', datatype=np.float32,
dimensions=('time', 'depth', 'Y', 'X'),
zlib=True)
U_var[:] = U_z
U_var.units = 'meter second-1'
U_var.standard_name = 'y_sea_water_velocity'
U_var.long_name = 'Sea water y velocity'
V_var = DS_Open.createVariable('v', datatype=np.float32,
dimensions=('time', 'depth', 'Y', 'X'),
zlib=True)
V_var[:] = V_z
V_var.units = 'meter second-1'
V_var.standard_name = 'x_sea_water_velocity'
V_var.long_name = 'Sea water x velocity'
W_var = DS_Open.createVariable('w', datatype=np.float32,
dimensions=('time', 'depth', 'Y', 'X'),
zlib=True)
W_var[:] = W_z
W_var.units = 'meter second-1'
W_var.standard_name = 'upward_sea_water_velocity'
W_var.long_name = 'W-velocity per layer in zeta point'
D_var = DS_Open.createVariable('d', datatype=np.float32,
dimensions=('time', 'depth', 'Y', 'X'),
zlib=True)
D_var[:] = D_z
D_var.units = 'm2 s-1'
D_var.standard_name = 'ocean_vertical_diffusivity'
D_var.long_name = 'Vertical eddy diffusivity-3D in zeta point'
S_var = DS_Open.createVariable('s', datatype=np.float32,
dimensions=('time', 'depth', 'Y', 'X'),
zlib=True)
S_var[:] = S_z
S_var.units = 'ppt'
S_var.standard_name = 'sea_water_salinity'
S_var.long_name = 'concentrations per layer in zeta point - Salinity'
lon_var = DS_Open.createVariable('lon', np.float32, ('Y', 'X'))
lon_var[:] = gx_Deg
lon_var.units = ''
lon_var.standard_name = 'longitude' # Optional
lon_var.long_name = 'longitude'
lat_var = DS_Open.createVariable('lat', np.float32, ('Y', 'X'))
lat_var[:] = gy_Deg
lat_var.units = ''
lat_var.standard_name = 'latitude' # Optional
lat_var.long_name = 'latitude'
#m_var = DS_Open.createVariable('mask', np.float32, ('Y', 'X'))
#m_var[:] = m_tp
#m_var.units = ''
#m_var.standard_name = 'mask' # Optional
#m_var.long_name = 'mask'
DS_Open.variables
seed_shp = 'D:/Dropbox/Doutorado/LC08_RS/Ideal_model/45degree/seeder.shp'
o = OceanDrift(loglevel=0)
o.set_config('general:use_auto_landmask', False)
o.set_config('general:coastline_action', 'previous')
reader = reader_netCDF_CF_generic.Reader(fn_nc)
reader_shp = reader_shape.Reader.from_shpfiles(fn_shp)
o.add_reader([reader])
o.add_reader([reader_shp])
lats= np.linspace(-32.15, -32.15, 200)
#lons = np.linspace(-52.18633433, -51.97683977, 200)
o.seed_from_shapefile(seed_shp,number=9500, radius = 90,time=[reader.start_time, reader.end_time])
#o.seed_from_shapefile(seed_shp,number=9500, radius = 90,time=[datetime.datetime(2020, 7, 9, 0, 5), datetime.datetime(2020, 7, 9, 0, 20)])
o.set_config('environment:fallback:land_binary_mask', 0)
o.plot()
o.run()
This seems ok. Can you insert o.plot() before run, and post the graphics you get? … On Sun, Apr 18, 2021, 20:37 Guilherme Cruz @.***> wrote: Yes, I am seeding from a shapefile with around 100 polygons, and I am also using a custom shapefile for my landmask seed_shp = 'D:/Dropbox/Doutorado/LC08_RS/Ideal_model/45degree/seeder.shp' fn_shp = 'D:/Dropbox/Doutorado/LC08_RS/Ideal_model/Coastline_25x100km_GCS.shp' o = OceanDrift(loglevel=0) o.set_config('general:use_auto_landmask', False) o.set_config('general:coastline_action', 'previous') reader = reader_netCDF_CF_generic.Reader(fn_nc) reader_shp = reader_shape.Reader.from_shpfiles(fn_shp) o.add_reader([reader]) o.add_reader([reader_shp]) lats= np.linspace(-32.15, -32.15, 200) #lons = np.linspace(-52.18633433, -51.97683977, 200) o.seed_from_shapefile(seed_shp,number=9500, radius = 90,time=[reader.start_time, reader.end_time]) #o.seed_from_shapefile(seed_shp,number=9500, radius = 90,time=[datetime.datetime(2020, 7, 9, 0, 5), datetime.datetime(2020, 7, 9, 0, 20)]) o.set_config('environment:fallback:land_binary_mask', 0) o.run() — You are receiving this because you commented. Reply to this email directly, view it on GitHub <#593 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABH25IYWDWAHUEMUAH25INLTJMRFNANCNFSM43EBN6ZQ .
I guess the problem is that the temporal coverage of your current reader is only 15 minutes, which is even less than a calculation time step.
That was the problem! with a time_step = 5 worked perfectly...
I got just another question for you. With the model sedimentdrift it is possible to set a "hindered settling" for the sediment? I need to simulate cohesive sediment and this parameter is important for me.
Thanks again for you support! Iam getting interesting results from opendrift... I hope to publish it soon
There is no built in feature for "hinders", but I guess you could add an artificial island to the landmsak reader, combined with coastline-interaction=previous.
On Sun, Apr 18, 2021, 21:04 Guilherme Cruz @.***> wrote:
That was the problem! with a time_step = 5 worked perfectly...
I got just another question for you. With the model sedimentdrift it is possible to set a "hindered settling" for the sediment? I need to simulate cohesive sediment and this parameter is important for me
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/OpenDrift/opendrift/issues/593#issuecomment-822043226, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABH25I6VBI5J2PT7FNMBLPLTJMULTANCNFSM43EBN6ZQ .
Hello, I am trying to implement my results obtained by delft3D model on opendrift. I had to convert the sigma coordinates to z-coordinate and the opendrift seems to have read it correctly. First I used this example for the conversion (https://rdrr.io/github/edwardlavender/fvcom.tbx/src/R/depth_from_known.R ) and then interpolated the data to a regular z-coordinate. However I am getting the following error:
Previously I was using only one sigma layer from delft3D, so as not to have to convert to the z coordinate, and I had no problem running the opendrift.
My netCDF file:
My netCDF file+