Refactoring wavelet organisation indices (woi)#32
Refactoring wavelet organisation indices (woi)#32martinjanssens merged 7 commits intocloudsci:masterfrom
Conversation
leifdenby
left a comment
There was a problem hiding this comment.
Thanks for starting work on this!
cloudmetrics/metrics/woi.py
Outdated
| """ | ||
| Computes the three Wavelet Organisation Indices WOI1, WOI2, WOI3 proposed by | ||
| Brune et al. (2018) from the stationary/undecimated Direct Wavelet Transform | ||
| of a scalar field. |
There was a problem hiding this comment.
Could you include the DOI or URL to the paper (https://doi.org/10.1002/qj.3409)?
cloudmetrics/metrics/woi.py
Outdated
| # Compute wavelet coefficients | ||
| scale_max = int(np.log(cloud_scalar.shape[0]) / np.log(2)) | ||
| coeffs = pywt.swt2(cloud_scalar, wavelet, scale_max, norm=True, trim_approx=True) | ||
| # Bug in pywt -> trim_approx=False does opposite of its intention |
There was a problem hiding this comment.
Did you log this on the pywt repo? Sounds like they might want to know that :)
cloudmetrics/metrics/woi.py
Outdated
| separation_scale : int, optional | ||
| Which power of 2 to use as a cutoff scale that separates 'small' scales | ||
| from 'large' scales. The default is 5; i.e. energy contained in scales | ||
| larger than 2^5=32 pixles is considered 'large-scale energy'. |
|
Nice job finding that R-package, I don't think that was around when I wrote this script the first time! Consequently, my implementation is just an attempt to match what I could get from the original paper's text. At a glance, the two approaches have some methodological differences, though I don't think they're major. The R-package does handle non-periodic BCs very nicely by mirroring the fields, and chooses to zoom to an appropriate level (the field needs to be of a shape that is a power of 2), while we're padding periodically to get there. I think I'd like to include these two aspects, at least, so I'll try to rewrite accordingly. Also, do you have an opinion on whether we want this to be a single function that returns three indices or three functions returning one index each? |
That sounds great!
I'm about unsure what to do here. It's quite nice to only have one number returned by default since it makes analysis further down the pipeline simpler. I would probably like to have a dataset with
What do you think? |
…ans cached output from a single evaluation of the stationary wavelet transform
|
I'd be curious to hear what you think of this when you have time, it's basically trying to do your second option (I need to improve the tests still). :) |
| _CACHED_VALUES = dict() | ||
|
|
||
|
|
||
| def _get_swt(cloud_scalar, pad_method, wavelet, separation_scale): |
There was a problem hiding this comment.
:) We can put this kind of thing into a decorator at some point. I would use functools.lru_cache but that doesn't work with just numpy arrays because they can't always be serialized.
leifdenby
left a comment
There was a problem hiding this comment.
This is simply awesome, nice work! I think we should get this merged in. Remember to add an entry to the changelog
Begun refactoring this by using a single function that computes both the wavelet transformation and the metrics. We could make this more similar to the Fourier metrics or to the object metrics, as mentioned in #28 (comment), and we should probably make a decision on that before I continue with this.