Coder Social home page Coder Social logo

acceptance_modelisation's Issues

Error with list of exclusion regions in the 3D case with gammapy 1.2

An exception is raised when provided a list of exclusion region when using gammapy 1.2.

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/Users/md274436/software/miniforge3/envs/gammapy-analysis/lib/python3.11/cProfile.py", line 191, in <module>
    main()
  File "/Users/md274436/software/miniforge3/envs/gammapy-analysis/lib/python3.11/cProfile.py", line 180, in main
    runctx(code, globs, None, options.outfile, options.sort)
  File "/Users/md274436/software/miniforge3/envs/gammapy-analysis/lib/python3.11/cProfile.py", line 20, in runctx
    return _pyprofile._Utils(Profile).runctx(statement, globals, locals,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/md274436/software/miniforge3/envs/gammapy-analysis/lib/python3.11/profile.py", line 63, in runctx
    prof.runctx(statement, globals, locals)
  File "/Users/md274436/software/miniforge3/envs/gammapy-analysis/lib/python3.11/cProfile.py", line 101, in runctx
    exec(cmd, globals, locals)
  File "Test3DFull_HESS.py", line 24, in <module>
    a = acceptance_creator.create_acceptance_map_per_observation(obs_collection, zenith_binning=True, zenith_interpolation=True)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/md274436/post_doc_cea/bkgmodel/test_dev/acceptance_modelisation/base_acceptance_map_creator.py", line 981, in create_acceptance_map_per_observation
    acceptance_map = self.create_acceptance_map_cos_zenith_interpolated(observations=observations,
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/md274436/post_doc_cea/bkgmodel/test_dev/acceptance_modelisation/base_acceptance_map_creator.py", line 902, in create_acceptance_map_cos_zenith_interpolated
    dict_binned_model = base_model or self.create_model_cos_zenith_binned(off_observations)
                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/md274436/post_doc_cea/bkgmodel/test_dev/acceptance_modelisation/base_acceptance_map_creator.py", line 636, in create_model_cos_zenith_binned
    binned_model = [self.create_acceptance_map(binned_obs) for binned_obs in binned_observations]
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/md274436/post_doc_cea/bkgmodel/test_dev/acceptance_modelisation/base_acceptance_map_creator.py", line 636, in <listcomp>
    binned_model = [self.create_acceptance_map(binned_obs) for binned_obs in binned_observations]
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/md274436/post_doc_cea/bkgmodel/test_dev/acceptance_modelisation/grid3d_acceptance_map_creator.py", line 210, in create_acceptance_map
    count_map_background, exp_map_background, exp_map_background_total, livetime = self._create_base_computation_map(
                                                                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/md274436/post_doc_cea/bkgmodel/test_dev/acceptance_modelisation/base_acceptance_map_creator.py", line 369, in _create_base_computation_map
    geom = RegionGeom.from_regions(self.exclude_regions)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/md274436/software/miniforge3/envs/gammapy-analysis/lib/python3.11/site-packages/gammapy/maps/region/geom.py", line 747, in from_regions
    return cls(region=regions, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/md274436/software/miniforge3/envs/gammapy-analysis/lib/python3.11/site-packages/gammapy/maps/region/geom.py", line 95, in __init__
    width=tuple(self.width),
                ^^^^^^^^^^
  File "/Users/md274436/software/miniforge3/envs/gammapy-analysis/lib/python3.11/site-packages/gammapy/maps/region/geom.py", line 165, in width
    rectangle = self._rectangle_bbox
                ^^^^^^^^^^^^^^^^^^^^
  File "/Users/md274436/software/miniforge3/envs/gammapy-analysis/lib/python3.11/site-packages/astropy/utils/decorators.py", line 837, in __get__
    val = self.fget(obj)
          ^^^^^^^^^^^^^^
  File "/Users/md274436/software/miniforge3/envs/gammapy-analysis/lib/python3.11/site-packages/gammapy/maps/region/geom.py", line 142, in _rectangle_bbox
    bbox = regions_pix[0].bounding_box
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/md274436/software/miniforge3/envs/gammapy-analysis/lib/python3.11/site-packages/regions/shapes/circle.py", line 103, in bounding_box
    return RegionBoundingBox.from_float(xmin, xmax, ymin, ymax)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/md274436/software/miniforge3/envs/gammapy-analysis/lib/python3.11/site-packages/regions/core/bounding_box.py", line 118, in from_float
    ixmin = int(np.floor(xmin + 0.5))
            ^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: cannot convert float NaN to integer

Accelerate zenith run splitting option

The option introduced in PR #19 make use of Observation.select_time on very fine bins. This is very expensive computationally.
Concern line 509 in acceptance_modelisation/base_acceptance_map_creator.py

bloc of code :

compute_observations = Observations()
            for obs in observations:
                time_interval = self._compute_time_intervals_based_on_zenith_bin(obs, zenith_bin)
                for i in range(len(time_interval) - 1):
                    compute_observations.append(obs.select_time(Time([time_interval[i], time_interval[i + 1]])))
        else:
            compute_observations = observations

Error with the 3D model in the case there are no exclusion region provided

When you only provide an empty list of exclusion regions for a 3D model, an error is raised.

The full stack trace :

  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/Users/md274436/software/miniforge3/envs/gammapy-analysis/lib/python3.11/cProfile.py", line 191, in <module>
    main()
  File "/Users/md274436/software/miniforge3/envs/gammapy-analysis/lib/python3.11/cProfile.py", line 180, in main
    runctx(code, globs, None, options.outfile, options.sort)
  File "/Users/md274436/software/miniforge3/envs/gammapy-analysis/lib/python3.11/cProfile.py", line 20, in runctx
    return _pyprofile._Utils(Profile).runctx(statement, globals, locals,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/md274436/software/miniforge3/envs/gammapy-analysis/lib/python3.11/profile.py", line 63, in runctx
    prof.runctx(statement, globals, locals)
  File "/Users/md274436/software/miniforge3/envs/gammapy-analysis/lib/python3.11/cProfile.py", line 101, in runctx
    exec(cmd, globals, locals)
  File "Test3DFull_HESS.py", line 25, in <module>
    a = acceptance_creator.create_acceptance_map_per_observation(obs_collection, zenith_binning=True, zenith_interpolation=True)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/md274436/post_doc_cea/bkgmodel/test_dev/acceptance_modelisation/base_acceptance_map_creator.py", line 981, in create_acceptance_map_per_observation
    acceptance_map = self.create_acceptance_map_cos_zenith_interpolated(observations=observations,
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/md274436/post_doc_cea/bkgmodel/test_dev/acceptance_modelisation/base_acceptance_map_creator.py", line 902, in create_acceptance_map_cos_zenith_interpolated
    dict_binned_model = base_model or self.create_model_cos_zenith_binned(off_observations)
                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/md274436/post_doc_cea/bkgmodel/test_dev/acceptance_modelisation/base_acceptance_map_creator.py", line 636, in create_model_cos_zenith_binned
    binned_model = [self.create_acceptance_map(binned_obs) for binned_obs in binned_observations]
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/md274436/post_doc_cea/bkgmodel/test_dev/acceptance_modelisation/base_acceptance_map_creator.py", line 636, in <listcomp>
    binned_model = [self.create_acceptance_map(binned_obs) for binned_obs in binned_observations]
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/md274436/post_doc_cea/bkgmodel/test_dev/acceptance_modelisation/grid3d_acceptance_map_creator.py", line 210, in create_acceptance_map
    count_map_background, exp_map_background, exp_map_background_total, livetime = self._create_base_computation_map(
                                                                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/md274436/post_doc_cea/bkgmodel/test_dev/acceptance_modelisation/base_acceptance_map_creator.py", line 370, in _create_base_computation_map
    mask = geom.contains(obs.events.radec)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/md274436/software/miniforge3/envs/gammapy-analysis/lib/python3.11/site-packages/gammapy/maps/region/geom.py", line 236, in contains
    raise ValueError("Region definition required.")```

Logging setup and usage

Current code uses logging in a limited way. It is in particular not using standard declaration of a logger which would allow to configure the logging level more easily.
An implementation of such a functionality is available in PR #15 .

A more in depth usage, could also be considered. Current messages in INFO level would probably be more adapted to DEBUG level. The possibility to implement more levels, e.g. MOREINFO between INFO and DEBUG could also be considered but this is not standard.

Also, we should decide if the log level should be configurable as an input to the classes (like ctapipe tools) or externally with a line like this logging.getLogger('acceptance_modelisation').setLevel(logging.INFO).

List of open items :

  • Implement loggers in all file and remove direct logging.log usage (also remove any 'print') (Merged PR #18 )
  • Adjust messages log level
  • Decide on log_levels to be used (custom for more verbose output? or only use debug for this purpose)
  • Decide on the strategy for log_level selection at execution time

Failing frame transformation when no events are provided

When splitting the observation in time intervals during count map creation, empty intervals can be provided.
This leads to the failure of the frame transformation from RaDec to AltAz during the call to BaseAcceptanceMapCreator._transform_obs_to_camera_frame.

Set `fov_alignment` for Background3D

Hi ๐Ÿ˜Š

I think the fov_alignment has to be given at the instantiation of Background3D here, e.g. fov_alignment=FoVAlignment.ALTAZ

acceptance_map = Background3D(axes=[self.energy_axis, extended_offset_axis_x, extended_offset_axis_y],
data=data_background.to(u.Unit('s-1 MeV-1 sr-1')))

Otherwise it's RADEC per default and as far as I can tell by roughly going through the code, the acceptance model is calculated in the SkyOffset frame of the camera in altaz

camera_frame = SkyOffsetFrame(origin=AltAz(alt=pointing_altaz.alt,
az=pointing_altaz.az,
obstime=obs.events.time,
location=obs.observatory_earth_location),
rotation=[0., ] * len(obs.events.time) * u.deg)

Take number of events into account for `_compute_time_intervals_based_on_fov_rotation`

I really like the idea of using the FoV rotation to calculate the time frame in which to evaluate the observations ๐Ÿ˜Š
Unfortunately I came across the problem that this can fail in the case that the time frame is so small that there are no events in the sub-observation you are looking at.
I guess one solution would be to check the number events for the time frame but this requires to do obs.select_time() inside the _compute_time_intervals_based_on_fov_rotation method. The other solution would be to required something like a deltaT_threshold so that there are no frames that have smaller duration than this threshold :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.