question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Wrong coordinates of events when producing a counts map

See original GitHub issue

Gammapy version 0.20.dev726+g57be15f25

Bug description When producing a counts map, the coordinates of the events seem to be shifted to the source position (current master branch): counts_gammapy_0 20 dev726+g57be15f25

Expected behavior Background counts are expected to peak at the pointing positions (which is the case for gammapy 0.19): counts_gammapy_0 19

To Reproduce

from gammapy.data import DataStore
from gammapy import __version__
import numpy as np
from astropy.coordinates.angle_utilities import angular_separation
import astropy.units as u
from astropy.coordinates import SkyCoord
from gammapy.makers import MapDatasetMaker
from gammapy.datasets import MapDataset, Datasets
from gammapy.maps import MapAxis, WcsGeom
import matplotlib.pyplot as plt

data_store = DataStore.from_dir(".")
observations = data_store.get_observations(required_irf=['aeff', 'edisp'])

ra_pnt = [obs.events.table.meta['RA_PNT'] for obs in observations] * u.deg
dec_pnt = [obs.events.table.meta['DEC_PNT'] for obs in observations] * u.deg
ra_obj = [obs.events.table.meta['RA_OBJ'] for obs in observations] * u.deg
dec_obj = [obs.events.table.meta['DEC_OBJ'] for obs in observations] * u.deg

separation = angular_separation(ra_pnt, dec_pnt, ra_obj, dec_obj)
mask = np.abs(separation - 1.8 * u.deg) < 0.05 * u.deg
observations18deg = data_store.get_observations(data_store.obs_table['OBS_ID'][mask], required_irf=["aeff", "edisp"])

source_pos = SkyCoord.from_name("Crab")

e_reco = MapAxis.from_energy_bounds(0.07, 2, 1, unit="TeV", name="energy")
geom = WcsGeom.create(skydir=source_pos, axes=[e_reco], width=4, binsz=0.1)
maker = MapDatasetMaker(selection=["counts"]) 

datasets = []

for obs in observations18deg:
    dataset = MapDataset.create(geom, name=str(obs.obs_id))
    dataset = maker.run(dataset, obs)
    datasets.append(dataset)
    
datasets = Datasets(datasets)
plt.figure()
counts = datasets.stack_reduce().counts.plot(add_cbar=True)
plt.tight_layout()
plt.savefig(f"counts_gammapy_{__version__}.png", dpi=300, bbox_inches='tight')

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
SimoneMendercommented, Apr 22, 2022

@adonath I just made a test with the “$GAMMAPY_DATA/cta-1dc/index/gps” dataset. In this case, it looks good. So probably there is a problem with my dataset and in the different gammapy branches, there is only a difference from where some information is read.

Current master branch (0.20.dev726+g57be15f25): counts_gammapy_hess_0 20 dev726+g57be15f25

0.19: counts_gammapy_hess_0 19

from gammapy.data import DataStore
from gammapy import __version__
import numpy as np
from astropy.coordinates.angle_utilities import angular_separation
import astropy.units as u
from astropy.coordinates import SkyCoord
from gammapy.makers import MapDatasetMaker
from gammapy.datasets import MapDataset, Datasets
from gammapy.maps import MapAxis, WcsGeom
import matplotlib.pyplot as plt

data_store = DataStore.from_dir("$GAMMAPY_DATA/cta-1dc/index/gps")
obs_id = [110380, 111140, 111159]
observations = data_store.get_observations(obs_id)

axis = MapAxis.from_edges(
    np.logspace(-1.0, 1.0, 2), unit="TeV", name="energy", interp="log"
)
e_reco = MapAxis.from_energy_bounds(0.07, 2, 1, unit="TeV", name="energy")
source_pos = SkyCoord.from_name("Galactic Center")
geom = WcsGeom.create(skydir=source_pos, axes=[e_reco], width=4, binsz=0.1)
maker = MapDatasetMaker(selection=["counts"]) 

datasets = []

for obs in observations:
    dataset = MapDataset.create(geom, name=str(obs.obs_id))
    dataset = maker.run(dataset, obs)
    datasets.append(dataset)
    
    
datasets = Datasets(datasets)
plt.figure()
counts = datasets.stack_reduce().counts.plot(add_cbar=True)
plt.tight_layout()
plt.savefig(f"counts_gammapy_hess_{__version__}.png", dpi=300, bbox_inches='tight')
0reactions
maxnoecommented, Apr 22, 2022

The reason was a wrong assumption about the observation order, leading to the wrong observations being selected. See #3891

Read more comments on GitHub >

github_iconTop Results From Across the Web

4 solutions to common problems when making location data ...
4 solutions to common problems when making location data maps · 1. How to visualize coincident points? · 2. How to visualize overlapping...
Read more >
Fix data when it appears in the wrong place - Learn ArcGIS
The only way to undo the tool is to run it again and redefine the original coordinate system. Click Run.
Read more >
Clicking on a point in map giving wrong latitude and longitude?
Works fine in aerial view, but when testing in a tilted(3d) view it was getting the wrong coordinates. I was using event.
Read more >
Solved: Incorrect map location - Microsoft Power BI Community
Solved: Hello, The Map visual seems to be plotting some of my locations incorrectly (see attached). Example of data; Florida, United States, 32217...
Read more >
Handle map events - Azure - Microsoft Learn
This article shows you how to use map events class. The property highlight events on the map and on different layers of the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found