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

Re-write Galaxy modelling code #157

Merged
merged 3 commits into from Aug 7, 2014

Conversation

Projects
None yet
2 participants
@adonath
Member

adonath commented Jul 26, 2014

Revision of the galaxy source modelling code, including the following changes:

  • Implementation of the spatial and velocity distribution models as astropy.modeling.Fittable1DModel
  • Use of astropy.units.Quantity throughout the code
  • Added tests
  • Added minimal docs
Show outdated Hide outdated docs/astro/population/index.rst Outdated
Show outdated Hide outdated docs/astro/population/index.rst Outdated
Show outdated Hide outdated docs/astro/source/index.rst Outdated
Show outdated Hide outdated docs/astro/population/index.rst Outdated
Show outdated Hide outdated docs/astro/source/snr.rst Outdated
Show outdated Hide outdated docs/astro/source/snr.rst Outdated
Show outdated Hide outdated gammapy/astro/population/simulate.py Outdated
theta : `~astropy.units.Quantity`
Angle coordinate
amount: float
Amount of blurring of the position, given as a fraction of `radius`.

This comment has been minimized.

@cdeil

cdeil Jul 27, 2014

Member

If you're documenting the Parameters, maybe document the Returns as well?

@cdeil

cdeil Jul 27, 2014

Member

If you're documenting the Parameters, maybe document the Returns as well?

This comment has been minimized.

@adonath

adonath Jul 31, 2014

Member

I started to document the function, than I realized that it is not visible to the end-user. What's the policy in this case? How should "private" functions be documented?

@adonath

adonath Jul 31, 2014

Member

I started to document the function, than I realized that it is not visible to the end-user. What's the policy in this case? How should "private" functions be documented?

This comment has been minimized.

@cdeil

cdeil Aug 4, 2014

Member

There is no policy for documentation of private functions.

Writing code / docs such that you think it would be easiest to understand for someone else (or yourself in a year) is best. But there's also the 80:20 rule that says you should stop when it's in an OK state, which in this case, for well-structured code, means that it's OK to leave private functions without docstrings or just a one-line comment and instead move on to the next job.

@cdeil

cdeil Aug 4, 2014

Member

There is no policy for documentation of private functions.

Writing code / docs such that you think it would be easiest to understand for someone else (or yourself in a year) is best. But there's also the 80:20 rule that says you should stop when it's in an OK state, which in this case, for well-structured code, means that it's OK to leave private functions without docstrings or just a one-line comment and instead move on to the next job.

dx, dy = cartesian(dr, dtheta)
return polar(x + dx, y + dy)
def _gc_correction(self, radius, theta, r_corr=Quantity(2.857, 'kpc')):

This comment has been minimized.

@cdeil

cdeil Jul 27, 2014

Member

If you're documenting the Parameters, maybe document the Returns as well?

@cdeil

cdeil Jul 27, 2014

Member

If you're documenting the Parameters, maybe document the Returns as well?

Show outdated Hide outdated gammapy/astro/population/velocity.py Outdated
Density in velocity ``v``
amplitude : float
Value of the integral
sigma1 : float

This comment has been minimized.

@cdeil

cdeil Jul 27, 2014

Member

You can combine multiple parameters on one line ... I think here it makes sense:

sigma1, sigma2, w : float
    See model formula
@cdeil

cdeil Jul 27, 2014

Member

You can combine multiple parameters on one line ... I think here it makes sense:

sigma1, sigma2, w : float
    See model formula
Show outdated Hide outdated gammapy/astro/source/pulsar.py Outdated
Show outdated Hide outdated gammapy/astro/source/pulsar.py Outdated
Show outdated Hide outdated gammapy/astro/source/pulsar.py Outdated
Show outdated Hide outdated gammapy/astro/source/pulsar.py Outdated
Show outdated Hide outdated gammapy/astro/source/pulsar.py Outdated
Show outdated Hide outdated gammapy/astro/source/pulsar.py Outdated
Show outdated Hide outdated gammapy/astro/source/pulsar.py Outdated
Show outdated Hide outdated gammapy/astro/source/pwn.py Outdated
class PWN(object):
"""
Simple pulsar wind nebula (PWN) evolution model.
Parameters

This comment has been minimized.

@cdeil

cdeil Jul 27, 2014

Member

Document all parameters here?

@cdeil

cdeil Jul 27, 2014

Member

Document all parameters here?

Show outdated Hide outdated gammapy/astro/source/pwn.py Outdated
Show outdated Hide outdated gammapy/astro/source/pwn.py Outdated
Show outdated Hide outdated gammapy/astro/source/pwn.py Outdated
# TODO: The following PWN model should be adapted to use gammafit classes.
class PWNElectronSpectrum(PWN):

This comment has been minimized.

@cdeil

cdeil Jul 27, 2014

Member

Can you open a new issue that this class needs to be finished or removed so that we don't forget about it?

@cdeil

cdeil Jul 27, 2014

Member

Can you open a new issue that this class needs to be finished or removed so that we don't forget about it?

Show outdated Hide outdated gammapy/astro/source/snr.py Outdated
Show outdated Hide outdated gammapy/astro/source/snr.py Outdated
Show outdated Hide outdated gammapy/astro/source/snr.py Outdated
t = self.age
else:
raise ValueError('Need time variable or age attribute.')
r = np.where(t > self.sedov_taylor_begin, self._radius_sedov_taylor(t).to('cm'),

This comment has been minimized.

@cdeil

cdeil Jul 27, 2014

Member

Add line break after comma? (I find this a bit more readable.)

@cdeil

cdeil Jul 27, 2014

Member

Add line break after comma? (I find this a bit more readable.)

Show outdated Hide outdated gammapy/astro/source/snr.py Outdated
Show outdated Hide outdated gammapy/astro/source/snr.py Outdated
Show outdated Hide outdated gammapy/astro/source/snr.py Outdated
Show outdated Hide outdated gammapy/astro/source/snr.py Outdated
Show outdated Hide outdated gammapy/astro/source/snr.py Outdated
self.r_c = self.m_ejecta ** (1. / 3) * self.rho_ISM ** (-1. / 3)
self.t_c = self.e_sn ** (-1. / 2) * self.m_ejecta ** (5. / 6) * self.rho_ISM ** (-1. / 3)
def radius(self, t=None):

This comment has been minimized.

@cdeil

cdeil Jul 27, 2014

Member

Same comments apply here that I made for the other SNR class.

@cdeil

cdeil Jul 27, 2014

Member

Same comments apply here that I made for the other SNR class.

__all__ = ['coordinate_iau_format',
'ra_iau_format',
'dec_iau_format']
'dec_iau_format',
'as_quantity']

This comment has been minimized.

@cdeil

cdeil Jul 27, 2014

Member

This doesn't belong in gammapy.catalog ... should go somewhere in gammapy.utils ... maybe gammapy.utils.array is better than starting a new sub-module?
(This should go away anyways with Astropy 1.0 when Table / Quantity integration happens (hopefully)).

@cdeil

cdeil Jul 27, 2014

Member

This doesn't belong in gammapy.catalog ... should go somewhere in gammapy.utils ... maybe gammapy.utils.array is better than starting a new sub-module?
(This should go away anyways with Astropy 1.0 when Table / Quantity integration happens (hopefully)).

This comment has been minimized.

@cdeil

cdeil Jul 27, 2014

Member

Or maybe simply not add it to __all__ so that it doesn't show up in the docs, i.e. it's a "hidden function" and it can stay here?

@cdeil

cdeil Jul 27, 2014

Member

Or maybe simply not add it to __all__ so that it doesn't show up in the docs, i.e. it's a "hidden function" and it can stay here?

r = np.sqrt(x ** 2 + y_prime ** 2)
v_glon = (-y_prime * vx + x * vy) / r ** 2
v_glat = (vz / (np.sqrt(1 - (z / d) ** 2) * d) - np.sqrt(vx ** 2 + vy ** 2 + vz ** 2) * z /

This comment has been minimized.

@cdeil

cdeil Jul 27, 2014

Member

I find such very long formulas very hard to read.
Python makes temp variables anyways, so without performance hit you can use temp variables (or split the expression into more lines if you don't like temp variables)

@cdeil

cdeil Jul 27, 2014

Member

I find such very long formulas very hard to read.
Python makes temp variables anyways, so without performance hit you can use temp variables (or split the expression into more lines if you don't like temp variables)

@@ -12,8 +12,14 @@ def normalize(func, x_min, x_max):
return normalized_func
def pdf(func):

This comment has been minimized.

@cdeil

cdeil Jul 27, 2014

Member

The name is not specific enough ... maybe this?

radial_density_to_pdf
radial_pdf_to_density
@cdeil

cdeil Jul 27, 2014

Member

The name is not specific enough ... maybe this?

radial_density_to_pdf
radial_pdf_to_density
@cdeil

This comment has been minimized.

Show comment
Hide comment
@cdeil

cdeil Jul 27, 2014

Member

Thanks for cleaning all this up!

I did a review just based on reading the code.

Feel free to merge after making travis-ci pass and addressing the comment, or ping me again if you want me to have a second look or actually try this stuff out.

Member

cdeil commented Jul 27, 2014

Thanks for cleaning all this up!

I did a review just based on reading the code.

Feel free to merge after making travis-ci pass and addressing the comment, or ping me again if you want me to have a second look or actually try this stuff out.

@cdeil

This comment has been minimized.

Show comment
Hide comment
@cdeil

cdeil Jul 27, 2014

Member

One thing that I don't like is that the radial distribution classes like FaucherKaspi2006 are simply listed in gammapy.astro.source and their name doesn't contain GalacticRadialDistribution or something that describes what they actually are.

The names get super-long if you write GalacticRadialDistributionFaucherKaspi2006, so I can see why you didn't do it, but still, it's not nice to have classes where the name doesn't describe at all what they are.
@adonath What do you think?

Member

cdeil commented Jul 27, 2014

One thing that I don't like is that the radial distribution classes like FaucherKaspi2006 are simply listed in gammapy.astro.source and their name doesn't contain GalacticRadialDistribution or something that describes what they actually are.

The names get super-long if you write GalacticRadialDistributionFaucherKaspi2006, so I can see why you didn't do it, but still, it's not nice to have classes where the name doesn't describe at all what they are.
@adonath What do you think?

@cdeil

This comment has been minimized.

Show comment
Hide comment
@cdeil

cdeil Aug 4, 2014

Member

@adonath - I think Ellis wants to produce the main results for the SciNeGhe proceeding this week ... maybe it's possible to merge this on Thursday or Friday latest? (you can always make new PRs or smaller changes directly in master)

Member

cdeil commented Aug 4, 2014

@adonath - I think Ellis wants to produce the main results for the SciNeGhe proceeding this week ... maybe it's possible to merge this on Thursday or Friday latest? (you can always make new PRs or smaller changes directly in master)

adonath added a commit that referenced this pull request Aug 7, 2014

@adonath adonath merged commit f30420f into gammapy:master Aug 7, 2014

1 check passed

continuous-integration/travis-ci The Travis CI build passed
Details
@cdeil

This comment has been minimized.

Show comment
Hide comment
@cdeil

cdeil Aug 7, 2014

Member

Thanks!

Member

cdeil commented Aug 7, 2014

Thanks!

@cdeil cdeil changed the title from Galaxy modelling code revision to Re-write Galaxy modelling code Apr 8, 2015

@cdeil cdeil added the feature label Apr 8, 2015

@cdeil cdeil added this to the 0.1 milestone Apr 8, 2015

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