OpenDrift / opendrift

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

Seed points scrambled during run #886

Open calquigs opened 2 years ago

calquigs commented 2 years ago

I'm having a bizarre behavior where the particles refuse to release from where I'm seeding them. I am specifying the lats and lons for each release, but after I run the simulation and check the trajectories, all the seed points have moved. E.g. here is a script where I plotted the run right after seeding:

thumbnail_image

And again after running:

thumbnail_image (1)

I've double checked the seed locations by calling o.elements_scheduled.lon/lat right before o.run(), and they seem like they're all where they supposed to be, but then one line later when I run it they're already moving. Even stranger, when I plug the script manually line by line in a python interpreter, I don't have this problem. Any ideas as to what is happening?

knutfrode commented 2 years ago

Hi, This is the same issue as described here: https://github.com/OpenDrift/opendrift/discussions/854 In short, the positions are only recorded at output time steps, but the correct seeding locations are still used, although shown wrongly on the map. The plotting issue will be fixed in the near future.

calquigs commented 2 years ago

Thank you so much for the fast response! That is exactly what is going on (my script has a 12 hour output timestep, and when I was running it manually in the interpretter it was defaulting to one hour). Apologies for the repeat issue.

I did see in #845 you mention that the seed locations are available in the metadata of the output netCDF. Is that simple enough to access? I would prefer that to having to save the locations using o.elements_scheduled.lon/lat in a seperate file.

knutfrode commented 2 years ago

The input arguments to seed method are given in metadata (lon,lat,radius), thus you can reproduce this afterwards with a new object, and then select o.elements.elements_scheduled.lon/lat

On Sun, Mar 20, 2022, 15:17 Calvin Quigley @.***> wrote:

Thank you so much for the fast response! That is exactly what is going on (my script has a 12 hour output timestep, and when I was running it manually in the interpretter it was defaulting to one hour). Apologies for the repeat issue.

I did see in #845 https://github.com/OpenDrift/opendrift/discussions/854 you mention that the seed locations are available in the metadata of the output netCDF. Is that simple enough to access? I would prefer that to having to save the locations using o.elements_scheduled.lon/lat in a seperate file.

— Reply to this email directly, view it on GitHub https://github.com/OpenDrift/opendrift/issues/886#issuecomment-1073261056, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABH25IYWE3URL2XOXPV4K5DVA4XOFANCNFSM5RE3G73A . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you commented.Message ID: @.***>

calquigs commented 2 years ago

I'm not sure I understood. New object?

I am currently trying to open one of these trajectory files using o = opendrift.open(<PATH_TO_NETCDF>) and then calling o.elements.elements_scheduled.lon, and the error I get is AttributeError: 'Lagrangian3DArray' object has no attribute 'elements_scheduled'.

Is there a way to access the seed positions from the netCDF after the fact, or will I need to rerun the simulations?

knutfrode commented 2 years ago

After reading the object (e.g. o) from a file, you can create an independent object like this:

o2 = OceanDrift()
o2 = o2.seed_elements(<same arguments as used for the simulation>)
lon = o2.elements_scheduled.lon
lon = o2.elements_scheduled.lat

This will then be the exact seeding locations as for the run (i.e. o).

erickfredj commented 2 years ago

Thx, but how do I add the lon/lat to the Netcdf output file?

calquigs commented 2 years ago

Hi erick, I had the same problem. The seed lon/lats aren't included in the netCDF, what I did was save all the seed lat/lons to a separate .txt file and matched them together in postprocessing. Here is the code I used, just before calling o.run().

lons_start = o.elements_scheduled.lon
lats_start = o.elements_scheduled.lat
seed_pts = np.array((lons_start,lats_start))

outFile = open('<PATH>/<FILENAME>_seeds.txt', 'w')
np.savetxt(outFile,seed_pts)
outFile.close()