pypsa-usa icon indicating copy to clipboard operation
pypsa-usa copied to clipboard

Create utility function for creating snapshots

Open trevorb1 opened this issue 1 year ago • 0 comments

Feature Request

We have this bit of code in a few places:

snapshot_config = snakemake.config["snapshots"]
sns_start = pd.to_datetime(snapshot_config["start"])
sns_end = pd.to_datetime(snapshot_config["end"])
sns_inclusive = snapshot_config["inclusive"]

snapshots = pd.date_range(
    freq="h",
    start=sns_start,
    end=sns_end,
    inclusive=sns_inclusive,
)

We should probably turn it into a utility function that we just pass in the snapshot_config variable and we get the datetime out

Suggested Solution


def create_snapshots(snapshot_config: Dict[str,str]) -> pd.date_range

    return pd.date_range(
            freq="h",
            start=pd.to_datetime(snapshot_config["start"]),
            end=pd.to_datetime(snapshot_config["end"]),
            inclusive=snapshot_config["inclusive"],
    )

Additional Info

No response

trevorb1 avatar Mar 19 '24 19:03 trevorb1