Skip to content

Commit

Permalink
Merge pull request #1227 from knutfrode/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
knutfrode authored Feb 14, 2024
2 parents a3fa11b + 3968423 commit 4ac4e00
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
8 changes: 5 additions & 3 deletions opendrift/models/oceandrift.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def update(self):
# Optional machine learning correction
self.machine_learning_correction()

def simulate_trajectories(self, outfile, trajectories,
def simulate_trajectories(self, outfile, trajectories, number=1,
wind_drift_factors=None, current_drift_factors=None,
time_step=None, time_step_output=None,
simulation_duration=None, simulation_interval=None):
Expand All @@ -208,7 +208,7 @@ def simulate_trajectories(self, outfile, trajectories,
time_step_output = pd.Timedelta(time_step_output)
simulation_interval = pd.Timedelta(simulation_interval)
# Interpolate trajectories to output time step
trajectories = trajectories.traj.gridtime(time_step_output)
#trajectories = trajectories.traj.gridtime(time_step_output)
# Find all seed combinations: position, time, wdf, cdf
# Loop også over trajektorier -> origin_marker
step = int(simulation_interval / time_step_output)
Expand All @@ -217,11 +217,13 @@ def simulate_trajectories(self, outfile, trajectories,
start_lats = trajectories.isel(time=tind).isel(trajectory=0).lat.values
start_times = trajectories.time[tind]
self.set_config('drift:max_age_seconds', simulation_duration.total_seconds())
kwargs = {'wind_drift_factor': wind_drift_factors[0],
'current_drift_factor': current_drift_factors[0]}
for (lo,la,ti) in zip(start_lons, start_lats, start_times):
if np.isnan(lo):
continue
ti = pd.Timestamp(ti.values).to_pydatetime()
self.seed_elements(lon=lo, lat=la, time=ti)
self.seed_elements(lon=lo, lat=la, time=ti, number=number, **kwargs)
print(self)
self.run(outfile=outfile, end_time=pd.Timestamp(start_times[-1].values).to_pydatetime()+simulation_duration)
# Simulate and save to file
Expand Down
11 changes: 9 additions & 2 deletions opendrift/readers/reader_netCDF_CF_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,12 @@ def __init__(self, filename=None, zarr_storage_options=None, name=None, proj4=No
# We load lon and lat arrays into memory
lon_var = self.Dataset.variables[lon_var_name]
lat_var = self.Dataset.variables[lat_var_name]
self.xname = lon_var_name
self.yname = lat_var_name
if lon_var.ndim == 1:
logger.debug('Lon and lat are 1D arrays - using as projection coordinates')
x = lon_var.data
y = lat_var.data
self.xname = lon_var_name
self.yname = lat_var_name
self.dimensions['x'] = lon_var.dims[0]
self.dimensions['y'] = lat_var.dims[0]
if self.proj4 is None:
Expand All @@ -261,11 +261,15 @@ def __init__(self, filename=None, zarr_storage_options=None, name=None, proj4=No
logger.debug('Lon and lat are 2D arrays - dataset is unprojected')
self.lon = lon_var.data
self.lat = lat_var.data
self.dimensions['x'] = lon_var.dims[0]
self.dimensions['y'] = lat_var.dims[1]
self.projected = False
elif lon_var.ndim == 3:
logger.debug('Lon lat are 3D arrays, reading first time')
self.lon = lon_var[0,:,:].data
self.lat = lat_var[0,:,:].data
self.dimensions['x'] = lon_var.dims[1]
self.dimensions['y'] = lat_var.dims[2]
self.projected = False
else:
if self.proj4 is None:
Expand Down Expand Up @@ -511,6 +515,9 @@ def get_variables(self, requested_variables, time=None,
from opendrift.readers.basereader import vector_pairs_xy
for vectorpair in vector_pairs_xy:
if vectorpair[0] in self.rotate_mapping and vectorpair[0] in variables.keys():
if self.proj.__class__.__name__ == 'fakeproj':
logger.warning('Rotation from fakeproj is not yet implemented, skipping.')
continue
logger.debug(f'Rotating vector from east/north to xy orientation: {vectorpair[0:2]}')
variables[vectorpair[0]], variables[vectorpair[1]] = self.rotate_vectors(
lon, lat, variables[vectorpair[0]], variables[vectorpair[1]],
Expand Down

0 comments on commit 4ac4e00

Please sign in to comment.