def generate_weather_files(data_path: Path | str, weather_path: Path | str, forcing: str, date_start: datetime, date_end: datetime, *,
hourly: bool=False, locations: LocationInput=None, header: bool=True) -> None:
"""Generate Cycles weather files for selected locations and dates.
Args:
data_path: Directory containing downloaded forcing files.
weather_path: Output directory for generated weather files.
forcing: Name of reanalysis product.
date_start: Start date of generated records.
date_end: End date of generated records.
hourly: If True, write hourly weather files.
locations: Optional coordinates or named coordinates.
header: If True, write weather file headers.
"""
reanalysis = REANALYSIS[forcing]
resolution = Resolution.HOURLY if hourly else Resolution.DAILY
Path(weather_path).mkdir(parents=True, exist_ok=True)
grid_df = _find_grids(reanalysis, locations, screen_output=False, remove_duplicates=True)
if reanalysis is REANALYSIS.gridMET:
weather_data = _process_gridmet(Path(data_path), date_start, date_end, grid_df)
elif reanalysis in [REANALYSIS.GLDAS, REANALYSIS.NLDAS]:
weather_data = _process_xldas(Path(data_path), reanalysis, date_start, date_end, grid_df, resolution)
if resolution is Resolution.HOURLY:
start = max(date_start, reanalysis.start_time)
freq = '1h'
elif resolution is Resolution.DAILY:
start = date_start
freq = '1d'
time_index = pd.date_range(start=start, end=date_end + timedelta(days=1), freq=freq, inclusive='left')
weather_data = {key: _interpolate_to_hourly(reanalysis, np.array(value)) if hourly and reanalysis.data_interval > 1 else np.array(value) for key, value in weather_data.items()}
_write_weather_files(Path(weather_path), time_index, weather_data, grid_df, header, resolution)