Skip to content

Commit 06fd596

Browse files
Omesh37cwhanse
andauthored
shading: use morphology.footprint_rectangle((1, 3)) for 1x3 structuring element (#233)
* shading: use morphology.footprint_rectangle((1, 3)) for 1x3 structuring element * Fix read-only array error in _prepare_images by copying to_numpy() output * Move footprint_rectangle import to module level with version fallback for skimage < 0.23 * Apply suggestion from @cwhanse * fixed flake8 error * Fix DatetimeIndex.diff() AttributeError in completeness_score --------- Co-authored-by: Cliff Hansen <cwhanse@sandia.gov>
1 parent ea119dd commit 06fd596

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

pvanalytics/features/shading.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from skimage import morphology, measure
66
import pvlib
77
from pvanalytics import util
8+
from skimage.morphology import rectangle as footprint_rectangle
89

910

1011
def _to_image(data, width):
@@ -113,7 +114,7 @@ def _prepare_images(ghi, clearsky, daytime, interval):
113114
ghi_image = pd.DataFrame(cloudless_image).interpolate(
114115
axis=0,
115116
limit_direction='both'
116-
).to_numpy()
117+
).to_numpy().copy()
117118
# set night to nan
118119
ghi_image[~_to_image(daytime.to_numpy(), image_width)] = np.nan
119120
return (
@@ -365,7 +366,7 @@ def fixed(ghi, daytime, clearsky, interval=None, min_gradient=2):
365366
threshold = gradient > min_gradient # binary image of wire candidates
366367

367368
# From here we CAN use skimage because we are working with binary images.
368-
three_minute_mask = morphology.rectangle(1, 3)
369+
three_minute_mask = footprint_rectangle(1, 3)
369370
wires = morphology.remove_small_objects(
370371
morphology.binary_closing(threshold, three_minute_mask),
371372
min_size=200,

pvanalytics/quality/gaps.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ def completeness_score(series, keep_index=True):
274274
(fraction of the day for which `series` has data).
275275
276276
"""
277-
seconds_per_sample = series.index.diff().total_seconds()[1]
277+
seconds_per_sample = (series.index[1] - series.index[0]).total_seconds()
278278
daily_counts = series.resample('D').count()
279279
daily_completeness = (daily_counts * seconds_per_sample) / (1440*60)
280280
if keep_index:

0 commit comments

Comments
 (0)