Skip to content

Detect shadows from fixed objects in GHI data#101

Merged
wfvining merged 33 commits into
masterfrom
shadows
Jun 3, 2021
Merged

Detect shadows from fixed objects in GHI data#101
wfvining merged 33 commits into
masterfrom
shadows

Conversation

@wfvining

@wfvining wfvining commented Feb 11, 2021

Copy link
Copy Markdown
Collaborator

Description

This is a port of the pvl_detect_shadows function from MATLAB_PVLIB.

Checklist

  • Closes Add shadow detection #24
  • Added new API functions to docs/api.rst
  • Clearly documented all new API functions with PEP257 and numpydoc compliant docstrings
  • Adds description and name entries in the appropriate "what's new" file
    in docs/whatsnew
    for all changes. Includes link to the GitHub Issue with :issue:`num`
    or this Pull Request with :pull:`num`. Includes contributor name
    and/or GitHub username (link with :ghuser:`user`).
  • Non-API functions clearly documented with docstrings or comments as necessary
  • Added tests to cover all new or modified code
  • Pull request is nearly complete and ready for detailed review

This is a rought implementation that returns almost the correct shadow
image. There is still some work to be done. The output needs to be
returned as a series instead of an image and steps should be taken to
minimize memory use, especially in the _clean_wires() function, by
passing ndarrays rather than allocating a new array for every step.

Currently this implementation appears to be more sensitive than the
matlab version, and includes more remnants of clouds in the output.
Initially adds basic tests for data without any fixed shadows.
In the remove_pillars step the masks were passed in the wrong
order.
This is consistent with the comments in the original matlab
code, although it is not 100% clear to me that it matches the
implementation. Since it produces results that are closer to
the output (in addition to matching the comments) from the MATLAB
code, I will assume that my reading of the original
implementation was not correct.
Changes to better match the original implementation. Still not
completely sure that this correct though.
Rather than applying it on successively more cleaned up images.
This should be slightly more efficient, plus it matched the intent
of the code better.

Also updates name of structuring element to match its shape
Converts the image back to a series and re-indexes it like
the input series.
@wfvining

Copy link
Copy Markdown
Collaborator Author

@cwhanse I've pretty much got the Matlab version ported over. This version does not seem to do quite as good a job removing cloud shadows that are "connected" to wires in the demo data from PVLIB_MATLAB. If you have a little time, I would appreciate a second pair of eyes on the clean_wires function (or all of it really). Any other feedback on what parameters should be exposed to the user is also very welcome.

Still some work to do on tests and performance. As it stands it is pretty slow, but there are some obvious places for performance improvement (notably in the clean_wires function which can be made to operate in place rather than repeatedly copying the image).

@cwhanse cwhanse left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks well structured and readable. Do we want to add a test that produces an image similar to the output of the matlab code?

Comment thread pvanalytics/features/shading.py Outdated
Comment thread pvanalytics/features/shading.py
Comment thread pvanalytics/features/shading.py Outdated
Comment thread pvanalytics/features/shading.py
Comment thread pvanalytics/features/shading.py Outdated
Comment thread pvanalytics/features/shading.py Outdated
Comment thread pvanalytics/features/shading.py Outdated
Comment thread pvanalytics/features/shading.py Outdated
Comment thread pvanalytics/features/shading.py Outdated
Comment thread pvanalytics/features/shading.py Outdated
Comment thread pvanalytics/features/shading.py Outdated
Adds a better docstring for the returned series.
Following NEP 29, we can now require at least 0.24.0 which was
released 24 months ago.
Without specifying an output array the image processing and numpy
functions will allocate a new array for every operation. This can
be a very expensive operation; fortunately we can avoid it by using
a temporary array for the morphological operations and specifying
an output array for the resulting image with horizontal bars
removed.
Improves performance by reducing the number of new arrays that must
be allocated.
Comment thread pvanalytics/features/shading.py
@wfvining

Copy link
Copy Markdown
Collaborator Author

@cwhanse I think this is ready for a closer look. The test failure is in the features.clearsky.reno(), not features.shading, they will need to be resolved as part of #105. As far as I can tell, with the exception of the comment above, I have faithfully re-implemented the matlab code, but this version is not doing quite as good a job of eliminating the cloud shadows that are 'connected' to wire shadows.

@wfvining

Copy link
Copy Markdown
Collaborator Author

I verified that the structuring elements used in _filter_bars() include a vertical bar (spanning multiple days) and exclude a horizontal bar (within a single day).

@wfvining wfvining marked this pull request as ready for review May 28, 2021 17:28

@cwhanse cwhanse left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice piece of code @wfvining

Comment thread pvanalytics/features/shading.py Outdated
Comment thread pvanalytics/features/shading.py Outdated
Comment thread pvanalytics/features/shading.py Outdated
Comment thread pvanalytics/features/shading.py Outdated
Comment thread pvanalytics/features/shading.py Outdated
wfvining and others added 2 commits June 3, 2021 13:14
@wfvining wfvining merged commit a3d3860 into master Jun 3, 2021
@kandersolar kandersolar added this to the v0.1.1 milestone Feb 18, 2022
@kandersolar kandersolar deleted the shadows branch February 12, 2024 18:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add shadow detection

3 participants