Skip to content

Commit

Permalink
Minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ladsmund committed Aug 7, 2024
1 parent e4adfe9 commit 2da6d71
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions src/pypromice/postprocess/get_bufr.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import sys
from datetime import datetime, timedelta
from pathlib import Path
from typing import List, Dict, Optional, Collection, Sequence, Mapping, BinaryIO
from typing import List, Dict, Optional, Sequence, Mapping

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -121,9 +121,6 @@ def get_bufr(
if target_timestamp is None:
target_timestamp = datetime.utcnow()

# if earliest_timestamp is None:
# earliest_timestamp = now_timestamp - timedelta(days=2)

# Prepare (latest) positions
positions = dict()
if positions_seed_path:
Expand All @@ -150,9 +147,6 @@ def get_bufr(
# Setup diagnostic lists (logger.info at end)
skipped = []
no_recent_data = []
no_entry_latest_timestamps = []
failed_min_data_wx = []
failed_min_data_pos = []

# Iterate through csv files
for file_path in input_files:
Expand Down Expand Up @@ -186,6 +180,7 @@ def get_bufr(
)
if latest_data is None:
logger.info("No valid instantaneous timestamps!")
skipped.append(stid)
continue

# Create station positions
Expand All @@ -209,13 +204,15 @@ def get_bufr(
write_bufr_message(bufr_variables, output_file)
else:
logger.info(f"No new data {latest_data.name} <= {time_window_start}")
no_recent_data.append(stid)

except Exception:
logger.exception(f"Failed processing {stid}")
if output_path.exists():
output_path.unlink()
if break_on_error:
raise
skipped.append(stid)
continue

# Write the most recent timestamps back to the pickle on disk
Expand All @@ -235,12 +232,9 @@ def get_bufr(
positions_df.to_csv(positions_filepath, index_label="stid")

logger.info("--------------------------------")
not_processed_wx_pos = set(failed_min_data_wx + failed_min_data_pos)
not_processed_count = (
len(skipped)
+ len(no_recent_data)
+ len(no_entry_latest_timestamps)
+ len(not_processed_wx_pos)
)
logger.info(
"BUFR exported for {} of {} fpaths.".format(
Expand All @@ -250,9 +244,6 @@ def get_bufr(
logger.info("")
logger.info("skipped: {}".format(skipped))
logger.info("no_recent_data: {}".format(no_recent_data))
logger.info("no_entry_latest_timestamps: {}".format(no_entry_latest_timestamps))
logger.info("failed_min_data_wx: {}".format(failed_min_data_wx))
logger.info("failed_min_data_pos: {}".format(failed_min_data_pos))
logger.info("--------------------------------")


Expand Down

0 comments on commit 2da6d71

Please sign in to comment.