-
Hello, I am trying to convert my .netcdf file from Delft3D, but the file format and variable names are not compatible with the netcdf format that OpenDrift reads. To address this, I am working on converting this file to a new netcdf file that OpenDrift can read. The file is loading correctly, but for some reason, the point’s trajectory is stationary, as if there were no velocity field. Could anyone help me figure out what I might be doing wrong? I've attached the file with the original data. I am only using the depth-integrated mean current velocity. `import netCDF4 as nc fn = 'D:/Dropbox/Doutorado/LC08_RS/Model_artigo2/trim-Modelo_Dir207_Mag5.nc' x = ds.variables['XCOR'][9:91, 2:72] U = np.mean(ds.variables['U1'][-1, :, 9:91, 2:72], axis=0) plt.figure(figsize=(6, 6)) resolucao_metros = 100 # Defina a resolução desejada em metros x_flat = np.ravel(x) xmin, xmax = np.min(x_flat), np.max(x_flat) num_pontos_x = int((xmax - xmin) / resolucao_metros) + 1 xi = np.linspace(xmin, xmax, resolucao_metros) U_grid = griddata((y_flat, x_flat), U_flat, (yi, xi), method='linear') gx_1 = xi[0,:] M = np.sqrt(U_grid2 + V_grid2) plt.figure(figsize=(6, 6)) t = np.arange(0, 18000, 600) r_u = np.expand_dims(U_grid, axis=0) r_u = np.expand_dims(r_u, axis=0) r_u = np.concatenate([r_u, r_u, r_u, r_u, r_u, r_u, r_u, r_u, r_u, r_u, r_u, r_u, r_u, r_u, r_u, r_u, r_u, r_u, r_u, r_u, r_u, r_u, r_u, r_u, r_u, r_u, r_u, r_u, r_u, r_u]) np.shape(r_u) #DS_Open.close() UTM WGS84 Zona 22S)crs = DS_Open.createVariable('crs', np.int32, ()) D_var = DS_Open.createVariable('depth', np.float32, ('depth',)) time_var = DS_Open.createVariable('time', np.int32, ('time',)) U_var = DS_Open.createVariable('u', datatype=np.float32, V_var = DS_Open.createVariable('v', datatype=np.float32, y_var = DS_Open.createVariable('y', np.float32, ('X',)) x_var = DS_Open.createVariable('x', np.float32, ('Y',)) DS_Open.variables ` |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I managed to convert the Delft3D NetCDF file for OpenDrift, but I had to make some modifications to the code. The issue seemed to be with the TIME variable I created and the time_step in o.run(time_step=600). I didn't fully understand why this happened, but here is the code that worked: ` fn = 'C:/Users/guioc/Documents/Art3_OD/trim-Modelo_Dir207_Mag5.nc' k = 1 dim0 = len(U) x_f = np.ravel(x) r_u = []
[gy_Deg,gx_Deg] = utm.to_latlon(gx, gy, 22, 'H') gx_1 = x_utm[0,:] gx_Deg = np.nan_to_num(gx_Deg) t = np.arange(0, 6000, 600) fig, ax = plt.subplots(dpi=600) DS_Open = nc.Dataset('./OD_25x100_Wind10ms_opendrift.nc', 'w', format='NETCDF4_CLASSIC', diskless=True, persist=True) crs = DS_Open.createVariable('latitude_longitude', np.int32, ()) D_var = DS_Open.createVariable('depth', np.float32, ('depth',)) time_var = DS_Open.createVariable('time', np.int32, ('time',)) U_var = DS_Open.createVariable('u', datatype=np.float32, V_var = DS_Open.createVariable('v', datatype=np.float32, lon_var = DS_Open.createVariable('lon', np.float32, ('Y', 'X')) lat_var = DS_Open.createVariable('lat', np.float32, ('Y', 'X')) DS_Open.variables DS_Open.close() reader = reader_netCDF_CF_generic.Reader('./OD_25x100_Wind10ms_opendrift.nc') o.seed_elements(lon=-52.08, lat=-32.192, number=100, radius =1000, z= 0, time=reader.start_time) o.plot(markersize=5) |
Beta Was this translation helpful? Give feedback.
I managed to convert the Delft3D NetCDF file for OpenDrift, but I had to make some modifications to the code. The issue seemed to be with the TIME variable I created and the time_step in o.run(time_step=600). I didn't fully understand why this happened, but here is the code that worked:
`
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 matplotli…