OpenDrift / opendrift

Open source framework for ocean trajectory modelling
https://opendrift.github.io
GNU General Public License v2.0
246 stars 120 forks source link

Reseting seeded elements in a loop #797

Closed AndresSepulveda closed 2 years ago

AndresSepulveda commented 2 years ago

Hi all, I want to use a loop in my OpenDrift simulation (one run per month) and I want that to start with a new group of seeded elements each time. Is this well implemented in the the code below?

for i in range(12): ini_date=start_date+timedelta(days=i*30)

for lat, lon in zip(all_lats, all_lons): o.seed_elements(lon=lon, lat=lat, number=100, time=ini_date)

        o.run(end_time=ini_date+timedelta(days=30),
            time_step=timedelta(minutes=180),

Thanks,

Andrés

knutfrode commented 2 years ago

That should work well. There is some overhead for each seed-call, so you might achieve the same faster with the following:

times = [start_date + i*timedelta(days=30) for i in range(12)]
lons, dummy = np.meshgrid(all_lons, times)
lats, times = np.meshgrid(all_lats, times)

lons = np.repeat(lons, 100)
lats = np.repeat(lats, 100)
times = np.repeat(times, 100)

o.seed_elements(lon=lons, lat=lats, time=times)