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 new flux point class #810

Merged
merged 10 commits into from Dec 8, 2016
Merged

Conversation

adonath
Copy link
Member

@adonath adonath commented Dec 7, 2016

This PR adds a prototype for the FluxPoints class, that implements the data specification defined by
http://gamma-astro-data-formats.readthedocs.io/en/latest/results/flux_points/index.html#flux-points

So far it mainly handles validation of the input tables and plotting of flux points with errors and upper limits. I'll make a second PR to adapt gammapy.catalog to use this class.

@cdeil @joleroi @woodmd

@adonath adonath added the feature label Dec 7, 2016
@adonath adonath added this to the 0.6 milestone Dec 7, 2016
@adonath adonath self-assigned this Dec 7, 2016
Copy link
Contributor

@cdeil cdeil left a comment

Choose a reason for hiding this comment

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

Looks good to me.
Maybe let's continue with this now and re-discuss whether to introduce a separate class for int fluxes later?

How much extra work would it be to remove DifferentialFluxPoints here?
I think we should do this ASAP, so that it's clear what code to work on and start adapting other scripts.

def test_plot(self, flux_points):
import matplotlib.pyplot as plt
ax = plt.gca()
flux_points.plot(ax=ax)
Copy link
Contributor

Choose a reason for hiding this comment

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

All plotting functions should do

if ax is None:
    ax = plt.gca()

at the start, so no need to create an ax and pass it from the test.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done


def test_e_ref(self, flux_points):
actual = flux_points.e_ref
if flux_points.sed_type == 'dnde':
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess all of these if / else aren't ideal.
Maybe at least two test classes to get rid of this would make sense?
(not sure)

Copy link
Member Author

Choose a reason for hiding this comment

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

For now I prefer to keep it because I don't want to duplicate the testing code.

info += "Flux points of type '{}'".format(self.sed_type)
return info

def info(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggest to remove info and just keep __str__.
This is what we've done for most classes, at least for now.

Examples
--------

>>> from gammapy.spectrum import FluxPoints
Copy link
Contributor

Choose a reason for hiding this comment

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

This is the same example as in the class-level docstring.
Suggest to remove it here and keep it in the class-level docstring, like we have for most other classes.

Filename
kwargs : dict
Keyword arguments passed to `~astropy.table.Table.write`.
"""
Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest to also pass filename through:

filename = make_path(filename)

It does e.g. os environ variable expansion, which is something I find convenient and use frequently.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

try:
return self.table['e_min'].quantity
except KeyError:
raise NotImplementedError
Copy link
Contributor

Choose a reason for hiding this comment

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

KeyError is better than NotImplementedError for something that isn't available.
Suggest to remove try-except here completely.
(and to not invent some e_min based on other columns)

@adonath adonath merged commit 81a5910 into gammapy:master Dec 8, 2016
@cdeil
Copy link
Contributor

cdeil commented Dec 8, 2016

🎉

@cdeil cdeil changed the title Add flux point class Add new flux point class Dec 12, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants