New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve continuous wavelet transform #661

Merged
merged 1 commit into from Aug 23, 2016

Conversation

Projects
None yet
3 participants
@OlgaVorokh
Member

OlgaVorokh commented Aug 3, 2016

This PR improves CWT, which was added in #25 and recently improved directly in Gammapy master.

On this PR the follow work was done:

  • quality of CWT code was improved
  • all the data images and information about using kernels was been separated from CWT class into CWTData and CWTKernels classes
  • the tests were added for all the created classes
  • docs was been modernized
  • ipython tutorial was written for CWT algorithm (see here)
Show outdated Hide outdated gammapy/detect/cwt.py
Show outdated Hide outdated gammapy/detect/cwt.py
number of scales considered
scale_step : float
base scaling factor
n_scale : int

This comment has been minimized.

@OlgaVorokh

OlgaVorokh Aug 4, 2016

Member

Can I do parameters n_scale, min_scale and step_scale optional and if I can what default values I can setup?

@OlgaVorokh

OlgaVorokh Aug 4, 2016

Member

Can I do parameters n_scale, min_scale and step_scale optional and if I can what default values I can setup?

@cdeil cdeil added this to the 0.5 milestone Aug 4, 2016

@OlgaVorokh

This comment has been minimized.

Show comment
Hide comment
@OlgaVorokh

OlgaVorokh Aug 4, 2016

Member

@cdeil @adonath I prefer to implement the follow style of using CWT:

cwt = CWT(... set parameters... )
data = .. some data, maybe CWTData ...
cwt.analyze(data)

So we firstly setup the parameters and than start to analyze data and after computing we can use created CWT for analyzing other data.

What are you thinking about it?

Member

OlgaVorokh commented Aug 4, 2016

@cdeil @adonath I prefer to implement the follow style of using CWT:

cwt = CWT(... set parameters... )
data = .. some data, maybe CWTData ...
cwt.analyze(data)

So we firstly setup the parameters and than start to analyze data and after computing we can use created CWT for analyzing other data.

What are you thinking about it?

@cdeil

This comment has been minimized.

Show comment
Hide comment
@cdeil

cdeil Aug 4, 2016

Member

No strong opinion on this, maybe small +1 to what you propose, to use the sklearn style of passing data only later to run or whatever it's called and not already to __init__.

Member

cdeil commented Aug 4, 2016

No strong opinion on this, maybe small +1 to what you propose, to use the sklearn style of passing data only later to run or whatever it's called and not already to __init__.

@cdeil

This comment has been minimized.

Show comment
Hide comment
@cdeil

cdeil Aug 4, 2016

Member

I think my preference would be to split out the scales and kernels into a separate class.
Mostly to have it nicely grouped, not necessarily for code re-use from other applications, although that might be possible later.

class CWTKernels:
    def __init__(self, scales):
        scales = np.array(scales)
        # compute kernels here, like previously done in `CWT.__init__`

    @classmethod
    def from_scale_grid(cls, n, min, step):
        scales = [min * step ** _ for _ in range(n)]
        return cls(scales)

    def __str__():
        # print useful info about the grid of scales, can be added later

We will be able to re-use that class for other multi-scale algorithms, so I think it's good to split it out now. To use it for CWT:

from gammapy.detect import CWTKernels, CWT

kernels = CWTKernels.from_scale_grid(... parameters ...)
print(scales) # for debugging
cwt = CWT(scales)
cwt.run(data)

OK to split out the scale / kernel handling this way, or do you prefer to keep the scales / kernel handling in CWT.__init__?

Member

cdeil commented Aug 4, 2016

I think my preference would be to split out the scales and kernels into a separate class.
Mostly to have it nicely grouped, not necessarily for code re-use from other applications, although that might be possible later.

class CWTKernels:
    def __init__(self, scales):
        scales = np.array(scales)
        # compute kernels here, like previously done in `CWT.__init__`

    @classmethod
    def from_scale_grid(cls, n, min, step):
        scales = [min * step ** _ for _ in range(n)]
        return cls(scales)

    def __str__():
        # print useful info about the grid of scales, can be added later

We will be able to re-use that class for other multi-scale algorithms, so I think it's good to split it out now. To use it for CWT:

from gammapy.detect import CWTKernels, CWT

kernels = CWTKernels.from_scale_grid(... parameters ...)
print(scales) # for debugging
cwt = CWT(scales)
cwt.run(data)

OK to split out the scale / kernel handling this way, or do you prefer to keep the scales / kernel handling in CWT.__init__?

Show outdated Hide outdated gammapy/detect/cwt.py
max_iter : int, optional (default 10)
The maximum number of iterations of the CWT algorithm.
tol : double, optional (default 1e-5)
Tolerance for stopping criterion.

This comment has been minimized.

@cdeil

cdeil Aug 8, 2016

Member

You should add an explanation what the stopping criterion is.
A sentence or formula or something like that. Maybe as part of the main docstring text, or in a Notes section below?

@cdeil

cdeil Aug 8, 2016

Member

You should add an explanation what the stopping criterion is.
A sentence or formula or something like that. Maybe as part of the main docstring text, or in a Notes section below?

Show outdated Hide outdated gammapy/detect/cwt.py
Show outdated Hide outdated gammapy/detect/cwt.py
Show outdated Hide outdated gammapy/detect/cwt.py
Show outdated Hide outdated gammapy/detect/cwt.py
Show outdated Hide outdated gammapy/detect/cwt.py
Show outdated Hide outdated gammapy/detect/cwt.py
Show outdated Hide outdated gammapy/detect/cwt.py
@cdeil

This comment has been minimized.

Show comment
Hide comment
@cdeil

cdeil Aug 23, 2016

Member

Merging this no.

@OlgaVorokh - Thank you for this big contribution and your patience with review / merging on this PR!

Member

cdeil commented Aug 23, 2016

Merging this no.

@OlgaVorokh - Thank you for this big contribution and your patience with review / merging on this PR!

@cdeil cdeil merged commit e55c751 into gammapy:master Aug 23, 2016

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@cdeil cdeil changed the title from Improve detect.CWT to Improve continuous wavelet transform Aug 23, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment