-
Notifications
You must be signed in to change notification settings - Fork 49
Description
Hello,
I'm trying to run a reverse trajectory simulation using PyGNOME, and I would appreciate some help with this issue.
I have multiple oil slicks (111 points) located on the coast from shapefile data (geometry type PointZ), each with a specific release_time, longitude, and latitude, spanning from 2025-06-18 18:06:53 to 2025-06-19 16:54:58. My goal is to simulate how the particles move backward in time from the last recorded position on the coast.
To do this, I set run_backwards=True and use model.start_time = 2025-06-19 16:54:58, which is the latest timestamp among all slicks. However, I'm facing a problem: particles from any spill whose release_time is earlier than model.start_time are treated as already existing at the start of the simulation. As a result, instead of seeing each slick "appear" (become active) incrementally as the simulation steps backward through its specific release_time, all particles (from both June 18th and June 19th observations) are present immediately at model.start_time (which is in June 19th). This leads to visual overlap in the output GIF/images, making it hard to distinguish individual trajectories. My analysis of the NetCDF output confirms that Day 18 particles are indeed in_water at Time Step 1 (the model.start_time). What I expected was that each slick would only "appear" (become active) as the simulation passes backward through its specific release_time, but that doesn’t seem to be happening.
--> Code information about introducing the shapefile, setting the model and adding map:
gdf = (gpd.read_file("ocorrencias_18_19_06_2025.shp")
.to_crs(epsg=4326))
gdf['data_hora'] = pd.to_datetime(gdf['data_hora'])
model = gs.Model(start_time=gdf['data_hora'].max(),
duration=gs.hours(30),
time_step=gs.hours(1),
run_backwards=True,
timezone_offset=-3)
mapfile = gs.get_datafile(os.path.join(base_dir, 'coast_menor.bna'))
print('Adicionando Mapa')
model.map = gs.MapFromBNA("coast_menor.bna", refloat_halflife=1)
--> I've tried different approaches for creating the spills within a single Model run:
#Using gs.surface_point_line_spill:
for idx, row in gdf.iterrows():
spill = gs.surface_point_line_spill(
num_elements=50,
start_position=(row.geometry.x, row.geometry.y, 0.0),
release_time=row['data_hora'],
amount=0.0027,
units='m^3',
name=f"patch_{row['data_hora'].strftime('%Y%m%d_%H%M%S')}_{idx}",
substance=oil,
windage_range = (0.03,0.035),
windage_persist = -1
)
model.spills += spil
#Using PointLineRelease:
for idx, row in gdf.iterrows():
release = gs.PointLineRelease(
num_elements=50,
release_time=row['data_hora'],
start_position=(row.geometry.x, row.geometry.y, 0.0)
)
spill = gs.Spill(release=release,
substance=oil,
amount=0.0027,
units='m^3',
name=f"patch_{row['data_hora'].strftime('%Y%m%d_%H%M%S')}_{idx}"
)
model.spills += spill
I also have tried different timesteps. Is there a way to have particles activated only when the reversed simulation reaches their respective release_time, even when run_backwards=True?
Thanks in advance for any guidance or suggestions!