Tasku
Tasku

Reputation: 1

Why does PyPSA/atlite `convert_and_aggregate` aggregate over time by default?

In PyPSA/atlite, all of the high-level methods on cutout for accessing and processing the weather data pass through the convert_and_aggregate method, which first calls the desired conversion function to get the data you want, before proceeding to aggregate it based on given input arguments. There's code specifically handling the case when no aggregation-related input arguments are not provided (lines 126-143 of convert.py):

    no_args = all(v is None for v in [layout, shapes, matrix])

    if no_args:
        if per_unit or return_capacity:
            raise ValueError(
                "One of `matrix`, `shapes` and `layout` must be "
                "given for `per_unit` or `return_capacity`"
            )
        if capacity_factor or capacity_factor_timeseries:
            if capacity_factor_timeseries:
                res = da.rename("capacity factor")
            else:
                res = da.mean("time").rename("capacity factor")
            res.attrs["units"] = "p.u."
            return maybe_progressbar(res, show_progress, **dask_kwargs)
        else:
            res = da.sum("time", keep_attrs=True)
            return maybe_progressbar(res, show_progress, **dask_kwargs)

My question is, why is this? Why does the function assume aggregation over time if no aggregation-related input arguments are given? It would be nice to be able to skip this step if desired.

I ran into the above when using PyPSA/atlite for doing some temperature and solar irradiation processing for building stock heating/cooling demand calculations, as I was hoping to be able to use the high-level cutout.temperature and cutout.irradiation directly. For my purposes, I need to work on the non-aggregated xarray level, and I was expecting to get the full xarrays if no aggregation instructions were provided. Instead, I got arbitrary sums over the time dimension.

This is not a deal-breaker by any means, though. I just need to access the raw xarray data from the cutout directly and use the lower level irradiation-related functions for my processing needs.

Upvotes: 0

Views: 60

Answers (1)

Fabian Neumann
Fabian Neumann

Reputation: 126

I agree, the default choice is a bit confusing.

Have you tried passing the argument capacity_factor_timeseries=True and possibly also capacity_factor=True? This should prevent the time aggregation.

You can also access the underlying raw data with cutout.data.

Upvotes: 0

Related Questions