Wrong coordinates of events when producing a counts map
See original GitHub issueGammapy 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):
Expected behavior
Background counts are expected to peak at the pointing positions (which is the case for 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:
- Created a year ago
- Comments:8 (8 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@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):
0.19:
The reason was a wrong assumption about the observation order, leading to the wrong observations being selected. See #3891