From 05db02ef08e237a31e638df1b4af5b1706518d88 Mon Sep 17 00:00:00 2001 From: Sven Seeberg Date: Sun, 3 Dec 2023 16:12:35 +0100 Subject: [PATCH] Add options for more plots --- opendrift_leeway_webgui/leeway/forms.py | 4 ++ ...ysimulation_send_animation_sea_and_more.py | 42 +++++++++++++++++++ opendrift_leeway_webgui/leeway/models.py | 12 ++++++ opendrift_leeway_webgui/simulation.py | 9 ++++ 4 files changed, 67 insertions(+) create mode 100644 opendrift_leeway_webgui/leeway/migrations/0009_leewaysimulation_send_animation_sea_and_more.py diff --git a/opendrift_leeway_webgui/leeway/forms.py b/opendrift_leeway_webgui/leeway/forms.py index 9e04f9e..3b374a4 100644 --- a/opendrift_leeway_webgui/leeway/forms.py +++ b/opendrift_leeway_webgui/leeway/forms.py @@ -35,6 +35,10 @@ class Meta: "start_time", "duration", "radius", + "send_trajectories", + "send_heatmap", + "send_animation_wind", + "send_animation_sea", ] help_texts = { "duration": "Length of simulation in hours.", diff --git a/opendrift_leeway_webgui/leeway/migrations/0009_leewaysimulation_send_animation_sea_and_more.py b/opendrift_leeway_webgui/leeway/migrations/0009_leewaysimulation_send_animation_sea_and_more.py new file mode 100644 index 0000000..9da1f52 --- /dev/null +++ b/opendrift_leeway_webgui/leeway/migrations/0009_leewaysimulation_send_animation_sea_and_more.py @@ -0,0 +1,42 @@ +# Generated by Django 4.2.7 on 2023-12-03 14:59 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [("leeway", "0008_leewaysimulation_traceback")] + + operations = [ + migrations.AddField( + model_name="leewaysimulation", + name="send_animation_sea", + field=models.BooleanField( + default=False, + help_text="Attach Gif to e-mail with animation of particles with sea currents.", + ), + ), + migrations.AddField( + model_name="leewaysimulation", + name="send_animation_wind", + field=models.BooleanField( + default=False, + help_text="Attach Gif to e-mail with animation of particles and wind fields.", + ), + ), + migrations.AddField( + model_name="leewaysimulation", + name="send_heatmap", + field=models.BooleanField( + default=False, + help_text="Attach PNG to e-mail with heat map of final particle locations.", + ), + ), + migrations.AddField( + model_name="leewaysimulation", + name="send_trajectories", + field=models.BooleanField( + default=True, + help_text="Attach PNG to e-mail with particle trajectories.", + ), + ), + ] diff --git a/opendrift_leeway_webgui/leeway/models.py b/opendrift_leeway_webgui/leeway/models.py index a6e03b0..9dd8005 100644 --- a/opendrift_leeway_webgui/leeway/models.py +++ b/opendrift_leeway_webgui/leeway/models.py @@ -35,6 +35,18 @@ class LeewaySimulation(models.Model): simulation_started = models.DateTimeField(null=True) simulation_finished = models.DateTimeField(null=True) radius = models.IntegerField(default=1000) + send_trajectories = models.BooleanField( + default=True, + help_text="Attach PNG to e-mail with particle trajectories.") + send_heatmap = models.BooleanField( + default=False, + help_text="Attach PNG to e-mail with heat map of final particle locations.") + send_animation_wind = models.BooleanField( + default=False, + help_text="Attach Gif to e-mail with animation of particles and wind fields.") + send_animation_sea = models.BooleanField( + default=False, + help_text="Attach Gif to e-mail with animation of particles with sea currents.") img = models.FileField( null=True, storage=simulation_storage, verbose_name=_("Image file") ) diff --git a/opendrift_leeway_webgui/simulation.py b/opendrift_leeway_webgui/simulation.py index 91060fc..9f538cc 100644 --- a/opendrift_leeway_webgui/simulation.py +++ b/opendrift_leeway_webgui/simulation.py @@ -107,9 +107,18 @@ def main(): simulation.run( duration=timedelta(hours=args.duration), time_step=600, outfile=f"{outfile}.nc" ) + + simulation.plot( fast=True, legend=True, filename=f"{outfile}.png", linecolor="age_seconds" ) + + simulation.plot( + background=simulation.get_density_array(pixelsize_m=3000), + clabel='Probability of origin [%]', fast=True, markersize=.5, lalpha=.02, + outfile=f"{outfile}-density.png" + ) + print(f"Success: {outfile}.png written.")