Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions download_daily_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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())
Expand Down
9 changes: 9 additions & 0 deletions swvo/io/solar_wind/ace.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)

Expand Down
4 changes: 1 addition & 3 deletions swvo/io/solar_wind/read_solar_wind_from_multiple_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading