Skip to content
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

Add SafeMaskMaker #2477

Merged
merged 5 commits into from Oct 18, 2019
Merged

Add SafeMaskMaker #2477

merged 5 commits into from Oct 18, 2019

Conversation

@adonath
Copy link
Member

adonath commented Oct 18, 2019

This PR implements a SafeMaskMaker. Currently it only support spectral datasets, it can be later adapted / extended to support MapDataset as well. This PR also adds a simple test. Again existing tests will be moved in subsequent PRs.

@adonath adonath self-assigned this Oct 18, 2019
@adonath adonath added the cleanup label Oct 18, 2019
@adonath adonath added this to the 0.15 milestone Oct 18, 2019
@cdeil

This comment has been minimized.

Copy link
Member

cdeil commented Oct 18, 2019

Introducing the SafeMaskMaker(TM)

Screenshot 2019-10-18 at 13 56 46

@adonath

This comment has been minimized.

Copy link
Member Author

adonath commented Oct 18, 2019

@cdeil I guess a SafeMaskMaker is what every gamma-ray scientist needs for healthy skin as well as healthy analysis results (hope we don't get a lawsuit for using the name, because we don't have funding to pay lawyers, but wait a second...what about renaming it to SafeMaskEstimator? :-)

"""

def __init__(
self, methods=["aeff-default"], aeff_percent=10, bias_percent=10

This comment has been minimized.

Copy link
@cdeil

cdeil Oct 18, 2019

Member

Don't put mutable contains like lists or dicts as default arguments. If needed, put None and put the default in the method. https://docs.python-guide.org/writing/gotchas/

log.warning(f"No thresholds defined for obs {observation}")
e_min, e_max = None, None

mask_safe = dataset.counts.energy_mask(emin=e_min, emax=e_max)

This comment has been minimized.

Copy link
@cdeil

cdeil Oct 18, 2019

Member

Just return mask_safe, no point in creating a temp variable.

This comment has been minimized.

Copy link
@adonath

adonath Oct 18, 2019

Author Member

Done

"""
aeff_thres = self.aeff_percent / 100 * dataset.aeff.max_area
e_min = dataset.aeff.find_energy(aeff_thres)
mask_safe = dataset.counts.energy_mask(emin=e_min)

This comment has been minimized.

Copy link
@cdeil

cdeil Oct 18, 2019

Member

Just return mask_safe, no point to create a temp variable.

This comment has been minimized.

Copy link
@adonath

adonath Oct 18, 2019

Author Member

Done

@@ -49,6 +49,11 @@ def spectrum_dataset_maker_crab():
return SpectrumDatasetMaker(region=region, e_reco=e_reco, e_true=e_true)


@pytest.fixture()
def safe_mask_maker():
return SafeMaskMaker()

This comment has been minimized.

Copy link
@cdeil

cdeil Oct 18, 2019

Member

Remove fixture, just put SafeMaskMaker() below.
Fixtures are only useful for resources that take time to produce (load from disk, compute) or lots of code.
Otherwise they are bad, because one has to scroll up and down from the tests to see what it is.

This comment has been minimized.

Copy link
@adonath

adonath Oct 18, 2019

Author Member

Done



def test_safe_mask_maker(spectrum_dataset_maker_crab, safe_mask_maker, observations_hess_dl3):

This comment has been minimized.

Copy link
@cdeil

cdeil Oct 18, 2019

Member

Never put empty lines at the start of functions (consistency coding style).

This comment has been minimized.

Copy link
@adonath

adonath Oct 18, 2019

Author Member

Done

@cdeil

This comment has been minimized.

Copy link
Member

cdeil commented Oct 18, 2019

One more thing: I'd suggest to never put backtick in GH titles. That's markdown, but it's not rendered in titles.
And we copy & paste the titles into RST where you'd have to write double backticks.
Easiest to just not put the backtick. It's mostly what we have in the past 2476 issues and PRs.

@cdeil cdeil changed the title Implement `SafeMaskMaker` Add SafeMaskMaker Oct 18, 2019
adonath added 3 commits Oct 18, 2019
@adonath adonath merged commit e32900e into gammapy:master Oct 18, 2019
9 checks passed
9 checks passed
Codacy/PR Quality Review Up to standards. A positive pull request.
Details
Scrutinizer Analysis: 7 updated code elements – Tests: passed
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
gammapy.gammapy Build #20191018.15 succeeded
Details
gammapy.gammapy (DevDocs) DevDocs succeeded
Details
gammapy.gammapy (Lint) Lint succeeded
Details
gammapy.gammapy (Test Python36) Test Python36 succeeded
Details
gammapy.gammapy (Test Windows36) Test Windows36 succeeded
Details
gammapy.gammapy (Test Windows37) Test Windows37 succeeded
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.