def load_pv_timeseries(start_date: str, end_date: str, metadata_filename: str=METADATA_FILENAME, stats_filename: str=PV_STATS_FILENAME, timeseries_filename: str=TIMESERIES_FILENAME) -> xr.Dataset:
    'Load the PV timeseries as an xarray dataset, restricted to a given time range, and including location metadata.'
    ds = xr.open_dataset(timeseries_filename)
    subset = ds.sel(datetime=slice(start_date, end_date))
    df = subset.to_dataframe()
    df = df.dropna(axis=1, how='all')
    pv_df = load_pv_systems(metadata_filename, stats_filename, timeseries_filename).to_dataframe()
    pv_metadata_system_ids = pv_df.index.tolist()
    timeseries_system_ids = [int(system_id) for system_id in df.columns.tolist()]
    system_ids = list(set(pv_metadata_system_ids).intersection(set(timeseries_system_ids)))
    system_id_columns = [str(system_id) for system_id in system_ids]
    df = df[system_id_columns]
    df['datetime'] = df.index
    df = pd.melt(df, id_vars=['datetime'], var_name='system_id', value_name='pv_yield')
    df = df.astype({'system_id': 'int64'})
    df = df.set_index(['system_id', 'datetime'])
    ds = xr.Dataset.from_dataframe(df)
    new_coords = {'latitude': (['system_id'], pv_df.lookup(system_ids, (['latitude'] * len(system_ids)))), 'longitude': (['system_id'], pv_df.lookup(system_ids, (['longitude'] * len(system_ids)))), 'easting': (['system_id'], pv_df.lookup(system_ids, (['easting'] * len(system_ids)))), 'northing': (['system_id'], pv_df.lookup(system_ids, (['northing'] * len(system_ids))))}
    ds = ds.assign_coords(new_coords)
    return ds
Load the PV timeseries as an xarray dataset, restricted to a given time range, and including location metadata.
def load_pv_timeseries(start_date: str, end_date: str, metadata_filename: str=METADATA_FILENAME, stats_filename: str=PV_STATS_FILENAME, timeseries_filename: str=TIMESERIES_FILENAME) -> xr.Dataset:
    
    ds = xr.open_dataset(timeseries_filename)
    subset = ds.sel(datetime=slice(start_date, end_date))
    df = subset.to_dataframe()
    df = df.dropna(axis=1, how='all')
    pv_df = load_pv_systems(metadata_filename, stats_filename, timeseries_filename).to_dataframe()
    pv_metadata_system_ids = pv_df.index.tolist()
    timeseries_system_ids = [int(system_id) for system_id in df.columns.tolist()]
    system_ids = list(set(pv_metadata_system_ids).intersection(set(timeseries_system_ids)))
    system_id_columns = [str(system_id) for system_id in system_ids]
    df = df[system_id_columns]
    df['datetime'] = df.index
    df = pd.melt(df, id_vars=['datetime'], var_name='system_id', value_name='pv_yield')
    df = df.astype({'system_id': 'int64'})
    df = df.set_index(['system_id', 'datetime'])
    ds = xr.Dataset.from_dataframe(df)
    new_coords = {'latitude': (['system_id'], pv_df.lookup(system_ids, (['latitude'] * len(system_ids)))), 'longitude': (['system_id'], pv_df.lookup(system_ids, (['longitude'] * len(system_ids)))), 'easting': (['system_id'], pv_df.lookup(system_ids, (['easting'] * len(system_ids)))), 'northing': (['system_id'], pv_df.lookup(system_ids, (['northing'] * len(system_ids))))}
    ds = ds.assign_coords(new_coords)
    return ds