Running a virtual fleet simulation#

If you have all the requirements fulfilled:

  • a deployment plan, from a dictionary with lat/lon/time arrays,

  • a velocity fieldset, from a parcels.fieldset.FieldSet instance, or possibly from a VelocityField instance,

  • and a float mission configuration, from a dictionary, or possibly from a FloatConfiguration instance.

you can move on to run a simulation.

So let’s import the usual suspects:

from datetime import timedelta
from virtualargofleet import VirtualFleet

and create a virtual fleet with all requirements:

VFleet = VirtualFleet(plan=my_plan, fieldset=VELfield.fieldset, mission=cfg.mission)
<VirtualFleet>
- 10 floats in the deployment plan
- No simulation performed

Warning

This code assumes you named the deployment plan dictionary my_plan, the velocity field instance VELfield and the float mission configuration instance cfg following the standard “Preparation of a simulation”.

Note

You can also provide the fieldset and mission arguments directly with VirtualFleet objects:

VFleet = VirtualFleet(plan=my_plan, fieldset=VELfield, mission=cfg)

To execute the simulation, we use the VirtualFleet.simulate() method by providing at least the total simulation duration time as a timedelta (or number of days):

VFleet.simulate(duration=timedelta(days=2))
<VirtualFleet>
- 10 floats in the deployment plan
- Number of simulation(s): 1
- Last simulation meta-data:
    - Duration: 02d 00h 00m 00s
    - Data recording every: 01h 00m
    - Trajectory file: ./v24co0jc.zarr
    - Execution time: 00d 00h 00m 04s
    - Executed on: laptop_guillaume_boulot.lan

By default, virtual floats positions are saved hourly along their trajectories. This is enough to properly resolve profile positions but can be increased using the record argument. See the method documentation here VirtualFleet.simulate().

The simulated floats trajectories will be saved in the current directory as a zarr file. You can control where to save trajectories with the output_folder and output_file options, or set the output option to False to not save results at all.

Note that you can continue the simulation where it was left, using the restart option:

VFleet.simulate(duration=timedelta(days=3), restart=True)
<VirtualFleet>
- 10 floats in the deployment plan
- Number of simulation(s): 2
- Last simulation meta-data:
    - Duration: 03d 00h 00m 00s
    - Data recording every: 01h 00m
    - Trajectory file: ./ns6hj1__.zarr
    - Execution time: 00d 00h 00m 06s
    - Executed on: laptop_guillaume_boulot.lan

In this scenario, a new output file is created and trajectories start from where the previous simulation left virtual floats.