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

Raise error to test what cannot be stored in json config #2688

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions src/ctapipe/core/provenance.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,16 +371,31 @@ def provenance(self):
def as_json(self, **kwargs):
"""return all finished provenance as JSON. Kwargs for `json.dumps`
may be included, e.g. ``indent=4``"""
from ctapipe.io.metadata import Contact, Instrument, Reference, _to_dict

def set_default(obj):
"""handle sets (not part of JSON) by converting to list"""
if isinstance(obj, set):
return list(obj)
if isinstance(obj, UserList):
if isinstance(obj, (set, UserList)):
return list(obj)

if isinstance(obj, Path):
return str(obj)

if isinstance(obj, Reference):
print(type(obj), obj.to_dict())
return obj.to_dict()

if isinstance(
obj,
(
Contact,
Instrument,
),
):
return _to_dict(obj)

raise TypeError(f"{obj!r} cannot be serialized to json")

return json.dumps(self.provenance, default=set_default, **kwargs)

@property
Expand Down
6 changes: 3 additions & 3 deletions src/ctapipe/instrument/optics.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""

import logging
from enum import Enum, auto, unique
from enum import IntEnum, auto, unique

import astropy.units as u
import numpy as np
Expand All @@ -22,7 +22,7 @@


@unique
class FocalLengthKind(Enum):
class FocalLengthKind(IntEnum):
"""
Enumeration for the different kinds of focal lengths.
"""
Expand Down Expand Up @@ -55,7 +55,7 @@ class SizeType(StrEnum):


@unique
class ReflectorShape(Enum):
class ReflectorShape(StrEnum):
"""
Enumeration of the different reflector shapes
"""
Expand Down
6 changes: 3 additions & 3 deletions src/ctapipe/io/simteleventsource.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import enum
import warnings
from contextlib import nullcontext
from enum import Enum, auto, unique
from enum import auto, unique
from gzip import GzipFile
from io import BufferedReader
from pathlib import Path
Expand Down Expand Up @@ -122,7 +122,7 @@ def _clip_altitude_if_close(altitude):


@enum.unique
class MirrorClass(enum.Enum):
class MirrorClass(enum.IntEnum):
"""Enum for the sim_telarray MIRROR_CLASS values"""

SINGLE_SEGMENTED_MIRROR = 0
Expand Down Expand Up @@ -312,7 +312,7 @@ def apply_simtel_r1_calibration(


@unique
class AtmosphereProfileKind(Enum):
class AtmosphereProfileKind(enum.IntEnum):
"""
choice for which kind of atmosphere density profile to load if more than
one is present"""
Expand Down
4 changes: 2 additions & 2 deletions src/ctapipe/reco/reconstructor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import weakref
from abc import abstractmethod
from enum import Flag, auto
from enum import IntEnum, auto

import astropy.units as u
import joblib
Expand All @@ -22,7 +22,7 @@
]


class ReconstructionProperty(Flag):
class ReconstructionProperty(IntEnum):
"""
Primary particle properties estimated by a `Reconstructor`

Expand Down
Loading