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

Remove lon wrapping in spatial models #2366

Merged
merged 1 commit into from Sep 22, 2019

Conversation

@cdeil
Copy link
Member

commented Sep 15, 2019

This PR removes long wrapping in the __init__ of spatial models.

Currently the code wraps to lon = -180 to +180, with the intent to get correct results at lon = 0 and to avoid wrapping issues with 0 = 360, and I think because it's considered user friendly to have a "standard range" for lon and to never get e.g. lon = 181 deg or lon = 361 deg or lon = -185 deg.

I think it would be better to not wrap at all: if a user puts a starting value of lon = 200 deg, fine, it's their choice. Changing this to -160 deg in model init will be confusing for them. Also wrapping to any fixed range means fitting a source at the edge of that range will be problematic, because the lon value is jumping by 360 deg. So with the current implementation one cannot fit a source at or near 180 deg. Not wrapping avoids this issue.

As discussed offline with @adonath and @QRemy a week or two ago, in the future we might want to add logic to the source fitting to avoid sources leaving the sky map to get more user-friendly behaviour, i.e. the optimiser finding a source position more often. But "inside a sky map" does not correspond to a simple min/max limit on lon, we'll have to implement this in a different way (and that can be Gammapy v2.0, not urgent at all, Fermi ST or other codes don't have that).

@adonath - While working on this I noticed one possible issue with SkyPointSource evaluation, I'll open a separate issue for that.

@cdeil cdeil added the cleanup label Sep 15, 2019
@cdeil cdeil added this to the 0.14 milestone Sep 15, 2019
@cdeil cdeil added this to In progress in Modeling via automation Sep 15, 2019
@cdeil

This comment has been minimized.

Copy link
Member Author

commented Sep 15, 2019

This did break the GC point source analysis in the tutorial:
https://travis-ci.org/gammapy/gammapy/jobs/585252198#L1327

So probably it's simplest to first tackle point source evaluate (see #2367) and to only merge this PR if that works without lon wrapping (or by only wrapping after taking the diff).

@cdeil cdeil force-pushed the cdeil:no-wrap branch from 937253c to 6f8d5cd Sep 21, 2019
@cdeil

This comment has been minimized.

Copy link
Member Author

commented Sep 21, 2019

@adonath - this should be ready to merge.

I had to change Longitude -> Angle actually, because Longitude has this behaviour:

In [3]: Longitude("-1d")                                                                                                                                                                             
Out[3]: <Longitude 359. deg>

and then in analysis.ipynb what happened was that the optimiser took a large step and that error that the source is outside the image occurred.

For now this change to use Angle instead to preserve the user choice of -0.05 deg near the Galactic center in that case works. But I think we'll eventually need something where we have good defaults for initial steps (e.g. 0.01 deg for point source position), and probably that error when the source is outside should be removed. Also, I noticed that the Parameter init isn't well-done, e.g. one can set values outside min / max. But that's a future PR (coming soon) to improve Parameter handling, I won't go there here.

Copy link
Member

left a comment

Thanks @cdeil! No further comments from my side.

@adonath adonath merged commit b3e5802 into gammapy:master Sep 22, 2019
9 checks passed
9 checks passed
Codacy/PR Quality Review Up to standards. A positive pull request.
Details
Scrutinizer Analysis: No new issues – Tests: passed
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
gammapy.gammapy Build #20190921.9 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
Modeling automation moved this from In progress to Done Sep 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Modeling
  
Done
2 participants
You can’t perform that action at this time.