From a24b4c21a0c6dd5509095e3d877a2570f57587ed Mon Sep 17 00:00:00 2001 From: Mike McCann Date: Tue, 23 Dec 2025 09:31:37 -0800 Subject: [PATCH 1/2] Check for src_file existence. --- src/data/archive.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/data/archive.py b/src/data/archive.py index 5251c14..c57a0f1 100755 --- a/src/data/archive.py +++ b/src/data/archive.py @@ -119,7 +119,7 @@ def copy_to_AUVTCD(self, nc_file_base: Path, freq: str = FREQ) -> None: # noqa: if src_file.exists(): shutil.copyfile(src_file, dst_file) self.logger.info("copyfile %s %s done.", src_file, surveynetcdfs_dir) - else: + elif src_file.exists(): self.logger.info( "%26s exists, but is not being archived because --clobber is not specified.", # noqa: E501 src_file.name, @@ -145,7 +145,7 @@ def copy_to_AUVTCD(self, nc_file_base: Path, freq: str = FREQ) -> None: # noqa: if src_file.exists(): shutil.copyfile(src_file, missionnetcdfs_dir / src_file.name) self.logger.info("copyfile %s %s done.", src_file, missionnetcdfs_dir) - else: + elif src_file.exists(): self.logger.info( "%26s exists, but is not being archived because --clobber is not specified.", # noqa: E501 src_file.name, @@ -178,7 +178,7 @@ def copy_to_AUVTCD(self, nc_file_base: Path, freq: str = FREQ) -> None: # noqa: # src_dir, dst_dir, dirs_exist_ok=True, copy_function=shutil.copy # ) # self.logger.info("copytree %s/* %s done.", src_dir, dst_dir) - else: + elif src_dir.exists(): self.logger.info( "%26s exists, but is not being archived because --clobber is not specified.", # noqa: E501 src_dir.name, @@ -200,7 +200,7 @@ def copy_to_AUVTCD(self, nc_file_base: Path, freq: str = FREQ) -> None: # noqa: self.logger.info("copyfile %s %s", src_file, surveynetcdfs_dir) shutil.copyfile(src_file, dst_file) self.logger.info("copyfile %s %s done.", src_file, surveynetcdfs_dir) - else: + elif src_file.exists(): self.logger.info( "%26s exists, but is not being archived because --clobber is not specified.", # noqa: E501 src_file.name, @@ -228,7 +228,7 @@ def copy_to_LRAUV(self, log_file: str, freq: str = FREQ) -> None: # noqa: C901, if src_file.exists(): shutil.copyfile(src_file, dst_file) self.logger.info("copyfile %s %s done.", src_file, dst_dir) - else: + elif src_file.exists(): self.logger.info( "%-75s exists, but is not being archived because --clobber is not specified.", src_file.name, @@ -256,7 +256,7 @@ def copy_to_LRAUV(self, log_file: str, freq: str = FREQ) -> None: # noqa: C901, self.logger.info("copyfile %s %s", src_file, dst_dir) shutil.copyfile(src_file, dst_file) self.logger.info("copyfile %s %s done.", src_file, dst_dir) - else: + elif src_file.exists(): self.logger.info( "%26s exists, but is not being archived because --clobber is not specified.", # noqa: E501 src_file.name, From aa970940dbb48a978471338d773de35851e12ee0 Mon Sep 17 00:00:00 2001 From: Mike McCann Date: Tue, 23 Dec 2025 09:34:37 -0800 Subject: [PATCH 2/2] Tolerate resampled data without time data. Processing should not fail in this instance, but instead go as far as possible and not create a final _1S.nc file that is corrupt, i.e. has no time data. --- .vscode/launch.json | 4 +++- src/data/create_products.py | 13 ++++++++----- src/data/resample.py | 10 ++++++++-- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index adc43d2..a5ada5b 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -354,7 +354,9 @@ // File "/src/data/create_products.py", line 806, ValueError: max() iterable argument is empty //"args": ["-v", "1", "--mission", "2013.079.00", "--noinput", "--no_cleanup" ], // Add --add_seconds argument for 2025.316.02 mission when procss_missions is used - "args": ["-v", "1", "--noinput", "--start_year", "2025", "--end_year", "2025", "--start_yd", "316", "--num_cores", "1", "--no_cleanup"] + //"args": ["-v", "1", "--noinput", "--start_year", "2025", "--end_year", "2025", "--start_yd", "316", "--num_cores", "1", "--no_cleanup"] + // Do not write _1S.nc file if it has no time data + "args": ["-v", "1", "--mission", "2006.338.11", "--noinput", "--no_cleanup" ], }, diff --git a/src/data/create_products.py b/src/data/create_products.py index 3d65a7d..e9ea8c4 100755 --- a/src/data/create_products.py +++ b/src/data/create_products.py @@ -377,7 +377,7 @@ def _grid_dims(self) -> tuple: try: utm_zone = int(31 + (self.ds.cf["longitude"].mean() // 6)) - except ValueError: + except (KeyError, ValueError): self.logger.warning( "Cannot compute mean longitude for UTM zone calculation, " "longitude data may be empty or contain NaNs", @@ -1157,7 +1157,7 @@ def plot_2column(self) -> str: # noqa: C901, PLR0912, PLR0915 try: profile_bottoms = self._profile_bottoms(distnav) - except ValueError as e: # noqa: BLE001 + except (TypeError, ValueError) as e: self.logger.warning("Error computing profile bottoms: %s", e) # noqa: TRY400 profile_bottoms = None @@ -1230,7 +1230,7 @@ def plot_2column(self) -> str: # noqa: C901, PLR0912, PLR0915 self.logger.info("Saved 2column plot to %s", output_file) return str(output_file) - def plot_biolume(self) -> str: # noqa: C901 + def plot_biolume(self) -> str: # noqa: C901, PLR0912 """Create bioluminescence plot showing raw signal and proxy variables""" # Skip plotting in pytest environment - too many prerequisites for CI if "pytest" in sys.modules: @@ -1249,8 +1249,11 @@ def plot_biolume(self) -> str: # noqa: C901 if idist is None or iz is None or distnav is None: self.logger.warning("Skipping plot_biolume due to missing gridding dimensions") return None - - profile_bottoms = self._profile_bottoms(distnav) + try: + profile_bottoms = self._profile_bottoms(distnav) + except (TypeError, ValueError) as e: + self.logger.warning("Error computing profile bottoms: %s", e) # noqa: TRY400 + profile_bottoms = None # Create figure with subplots for biolume variables num_plots = min(len(biolume_vars), 6) # Limit to 6 most important variables diff --git a/src/data/resample.py b/src/data/resample.py index 039e7c9..e6b0772 100755 --- a/src/data/resample.py +++ b/src/data/resample.py @@ -2054,8 +2054,14 @@ def resample_align_file( # noqa: C901, PLR0912, PLR0915, PLR0913 # Append flash_threshold to output filename ft_ending = f"_ft{self.flash_threshold:.0E}.nc".replace("E+", "E") out_fn = out_fn.replace(".nc", ft_ending) - self.resampled_nc.to_netcdf(path=out_fn, format="NETCDF4_CLASSIC") - self.logger.info("Saved resampled mission to %s", out_fn) + if self.resampled_nc["time"].any(): + self.resampled_nc.to_netcdf(path=out_fn, format="NETCDF4_CLASSIC") + self.logger.info("Saved resampled mission to %s", out_fn) + else: + self.logger.warning( + "No resampled time data available - not saving resampled file %s", + out_fn, + ) def process_command_line(self): """Process command line arguments using shared parser infrastructure."""