From 5c40bee6aa84d2431229ca05307893c2391f2c2b Mon Sep 17 00:00:00 2001 From: j-atkins <106238905+j-atkins@users.noreply.github.com> Date: Fri, 29 May 2026 13:34:32 +0100 Subject: [PATCH] try/except block for handling out of bounds errors --- src/virtualship/instruments/base.py | 30 ++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/virtualship/instruments/base.py b/src/virtualship/instruments/base.py index d4e078e6..1cb1de72 100644 --- a/src/virtualship/instruments/base.py +++ b/src/virtualship/instruments/base.py @@ -10,6 +10,7 @@ import copernicusmarine import xarray as xr from parcels import FieldSet +from parcels.tools import FieldOutOfBoundError from yaspin import yaspin from virtualship.errors import CopernicusCatalogueError @@ -128,20 +129,27 @@ def simulate( def execute(self, measurements: list, out_path: str | Path) -> None: """Run instrument simulation.""" - if not self.verbose_progress: - with yaspin( - text=f"Simulating {self.__class__.__name__.split('Instrument')[0]} measurements... ", - side="right", - spinner=ship_spinner, - ) as spinner: + instrument_name = self.__class__.__name__.split("Instrument")[0] + try: + if not self.verbose_progress: + with yaspin( + text=f"Simulating {instrument_name} measurements... ", + side="right", + spinner=ship_spinner, + ) as spinner: + self.simulate(measurements, out_path) + spinner.ok("āœ…\n") + else: + print(f"Simulating {instrument_name} measurements... ") self.simulate(measurements, out_path) - spinner.ok("āœ…\n") - else: + print("\n") + + # do not exit simulation after out of bounds errors (rare and only possible for Argo Floats, but will handle for any future instruments too) + except FieldOutOfBoundError as e: print( - f"Simulating {self.__class__.__name__.split('Instrument')[0]} measurements... " + f"\nā—ļø ERROR: during {instrument_name} simulation: {e}\n\nAny subsequent instrument simulations will continue but {instrument_name} results may be incomplete.\n" + "Carrying on with the expedition...\n", ) - self.simulate(measurements, out_path) - print("\n") def _get_copernicus_ds( self,