diff --git a/download_daily_files.py b/download_daily_files.py index 17c27d9..69e7d9f 100755 --- a/download_daily_files.py +++ b/download_daily_files.py @@ -86,7 +86,7 @@ def main(): logger.info("SW ACE RT...") try: - SWACE().download_and_process(time_now) + SWACE().download_and_process(date_yesterday_start, time_now) except Exception: logger.error("Encountered error while downloading ACE RT solar wind. Traceback:") logger.error(traceback.format_exc()) @@ -100,7 +100,7 @@ def main(): logger.info("SW DSCOVR...") try: - DSCOVR().download_and_process(time_now) + DSCOVR().download_and_process(date_yesterday_start, time_now) except Exception: logger.error("Encountered error while downloading DSCOVR solar wind. Traceback:") logger.error(traceback.format_exc()) diff --git a/swvo/io/solar_wind/ace.py b/swvo/io/solar_wind/ace.py index 6df6207..87e6cf1 100644 --- a/swvo/io/solar_wind/ace.py +++ b/swvo/io/solar_wind/ace.py @@ -83,6 +83,10 @@ def download_and_process(self, start_time: datetime, end_time: datetime) -> None start_time = enforce_utc_timezone(start_time) end_time = enforce_utc_timezone(end_time) + current_time = datetime.now(timezone.utc) + + assert end_time < current_time, f"End time: {end_time} cannot be in the future. Current time: {current_time}!" + assert start_time < end_time, "Start time must be before end time!" temporary_dir = Path("./temp_sw_ace_wget") @@ -100,6 +104,11 @@ def download_and_process(self, start_time: datetime, end_time: datetime) -> None logger.debug(f"Processing ACE source files for {request_date.date()} ...") processed_df = self._process_single_file(temporary_dir, mag_file_name, swepam_file_name) self._save_processed_data(processed_df) + except Exception as e: + logger.error(f"Failed to download and process: {e}") + if temporary_dir.exists(): + rmtree(temporary_dir, ignore_errors=True) + raise finally: rmtree(temporary_dir, ignore_errors=True) diff --git a/swvo/io/solar_wind/read_solar_wind_from_multiple_models.py b/swvo/io/solar_wind/read_solar_wind_from_multiple_models.py index 24c9a9f..3926017 100644 --- a/swvo/io/solar_wind/read_solar_wind_from_multiple_models.py +++ b/swvo/io/solar_wind/read_solar_wind_from_multiple_models.py @@ -118,9 +118,7 @@ def read_solar_wind_from_multiple_models( # noqa: PLR0913 ) except ValueError as e: if not isinstance(model, DSCOVR): - raise - - logger.warning(f"Failed to read DSCOVR data because: {e}. Falling back to ACE.") + logger.warning(f"Failed to read DSCOVR data because: {e}. Falling back to ACE.") # switch to SWACE if SWACE is already in the model_order, otherwise create a new instance of SWACE with "./data" as the data directory # also log this fallback action active_model = next((m for m in model_order if isinstance(m, SWACE)), None)