pvlib / pvanalytics

Quality control, filtering, feature labeling, and other tools for working with data from photovoltaic energy systems.
https://pvanalytics.readthedocs.io
MIT License
97 stars 32 forks source link

Create nighttime_offset_correction function #173

Open AdamRJensen opened 1 year ago

AdamRJensen commented 1 year ago

This PR proposes one method for calculating the nighttime offsets discussed in #170. It is by no means a suggestion for this specific implementation to be the way forward, but making a PR simple makes it more efficient to discuss this particular implementation.

AdamRJensen commented 1 year ago

The current implementation manually corrects midnight to be included in the day before/after corresponding to whether the data is right or left labeled, and then passes the adjusted time series to .groupby:

grouping_category = irradiance.index.date
if label == 'right':
    grouping_category[irradiance.index.time == dt.time(0)] += -dt.timedelta(days=1)
nighttime_offset = nighttime_irradiance.groupby(grouping_category).transform(aggregation_method)

However, this could automatically be handled by the .resample function which natively supports the label parameter:

nighttime_offset = nighttime_irradiance.resample('1d', label=label, closed=label).transform(aggregation_method)

If reviewers agree, I prefer the latter implementation as it's a lot cleaner and easier to read.