I have weather data in directories. The directory structure is /YYYY_MM_DD//report.json . For each station, I’d like to know if there are any hours missing for provided days?
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Certainly! To check for missing hours in your weather data directory structure, you can write a Python script that:
Iterates through each station directory.
For each date (YYYY_MM_DD) subdirectory, lists all hour subdirectories.
Checks if all 24 hours (00 to 23) are present.
Reports any missing hours for each station and date.
Here's a script to do this:
python
import os
def find_missing_hours(base_dir):
stations = [d for d in os.listdir(base_dir) if os.path.isdir(os.path.join(base_dir, d))]
for station in stations:
station_path = os.path.join(base_dir, station)
dates = [d for d in os.listdir(station_path) if os.path.isdir(os.path.join(station_path, d))]
for date in dates:
date_path = os.path.join(station_path, date)
hours = [h for h in os.listdir(date_path) if os.path.isdir(os.path.join(date_path, h))]
# Only consider directories that are two-digit hours
hours_present = set(h for h in hours if h.isdigit() and len(h) == 2)
all_hours = set(f"{i:02d}" for i in range(24))
missing = sorted(all_hours - hours_present)
if missing:
print(f"Station: {station}, Date: {date}, Missing hours: {', '.join(missing)}")
# Example usage:
# find_missing_hours('/path/to/weather_data')
How to use:
Replace '/path/to/weather_data' with the path to your data root directory.
Run the script. It will print out any missing hours for each station and date.
Notes:
This assumes your hour directories are named as two-digit strings (00, 01, ..., 23).
If you want to check for missing report.json files inside each hour, you can add an extra check:
python
for hour in all_hours:
hour_path = os.path.join(date_path, hour)
report_file = os.path.join(hour_path, 'report.json')
if not os.path.isfile(report_file):
missing.append(hour)
Let me know if you need the script to check for missing report.json files as well!