icecube-skyreader 1.2.2__tar.gz → 1.2.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: icecube-skyreader
3
- Version: 1.2.2
3
+ Version: 1.2.4
4
4
  Summary: An API for Results Produced by SkyDriver & the Skymap Scanner
5
5
  Home-page: https://github.com/icecube/skyreader
6
6
  Download-URL: https://pypi.org/project/icecube-skyreader/
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: icecube-skyreader
3
- Version: 1.2.2
3
+ Version: 1.2.4
4
4
  Summary: An API for Results Produced by SkyDriver & the Skymap Scanner
5
5
  Home-page: https://github.com/icecube/skyreader
6
6
  Download-URL: https://pypi.org/project/icecube-skyreader/
@@ -17,7 +17,7 @@ __all__ = [
17
17
  # is zero for an official release, positive for a development branch,
18
18
  # or negative for a release candidate or beta (after the base version
19
19
  # number has been incremented)
20
- __version__ = "1.2.2"
20
+ __version__ = "1.2.4"
21
21
  version_info = (
22
22
  int(__version__.split(".")[0]),
23
23
  int(__version__.split(".")[1]),
@@ -12,7 +12,7 @@ import logging
12
12
  import pickle
13
13
  from functools import cached_property
14
14
  from pathlib import Path
15
- from typing import Any, Dict, List, Optional, Tuple, TypedDict, Union
15
+ from typing import Any, Dict, Final, List, Optional, Tuple, TypedDict, Union
16
16
 
17
17
  import healpy # type: ignore[import]
18
18
  import matplotlib # type: ignore[import]
@@ -68,12 +68,13 @@ PyDictResult = Dict[str, PyDictNSidePixels]
68
68
  # MAIN CLASS
69
69
 
70
70
  class SkyScanResult:
71
- """This class parses a nsides_dict and stores the relevant numeric result
71
+ """This class parses a scan result and stores the relevant numeric results
72
72
  of the scan. Ideally it should serve as the basic data structure for
73
73
  plotting / processing / transmission of the scan result.
74
74
 
75
- nsides_dict is a dictionary keyed by 'nside' values for which a scan
76
- result is available (e.g. 8, 64, 512), see `pixel_classes.NSidesDict`.
75
+ `result` is a dictionary keyed by 'nside: str' values for which a scan
76
+ result is available (e.g. 8, 64, 512).
77
+
77
78
  The scan result is a dictionary:
78
79
  - i (pixel index, integer) ->
79
80
  'frame', 'llh', 'recoLossesInside', 'recoLossesTotal'
@@ -95,6 +96,8 @@ class SkyScanResult:
95
96
  PIXEL_FIELDS: Tuple[str, ...] = PIXEL_TYPE.names # type: ignore[assignment]
96
97
  ATOL = 1.0e-8 # 1.0e-8 is the default used by np.isclose()
97
98
 
99
+ MINIMAL_METADATA_FIELDS: Final[List[str]] = "run_id event_id mjd event_type nside".split()
100
+
98
101
  def __init__(self, result: Dict[str, np.ndarray]):
99
102
  self.logger = logging.getLogger(__name__)
100
103
 
@@ -201,9 +204,9 @@ class SkyScanResult:
201
204
 
202
205
  return diff_vals, test_vals
203
206
 
204
- def has_metadata(self) -> bool:
207
+ def has_minimal_metadata(self) -> bool:
205
208
  """Check that the minimum metadata is set."""
206
- for mk in "run_id event_id mjd event_type nside".split():
209
+ for mk in self.MINIMAL_METADATA_FIELDS:
207
210
  for k in self.result:
208
211
  if self.result[k].dtype.metadata is None:
209
212
  return False
@@ -213,7 +216,7 @@ class SkyScanResult:
213
216
 
214
217
  def get_event_metadata(self) -> EventMetadata:
215
218
  """Get the EventMetadata portion of the result's metadata."""
216
- if self.has_metadata():
219
+ if self.has_minimal_metadata():
217
220
  first_metadata = self.result[list(self.result.keys())[0]].dtype.metadata
218
221
  return EventMetadata(
219
222
  first_metadata['run_id'],
@@ -523,12 +526,25 @@ class SkyScanResult:
523
526
  """
524
527
  pydict: PyDictResult = {}
525
528
  for nside in self.result:
529
+ nside_data: np.ndarray = self.result[nside]
526
530
  df = pd.DataFrame(
527
- self.result[nside],
528
- columns=list(self.result[nside].dtype.names),
531
+ nside_data,
532
+ columns=list(nside_data.dtype.names),
529
533
  )
530
534
  pydict[nside] = {k:v for k,v in df.to_dict(orient='split').items() if k != 'index'} # type: ignore[assignment]
531
- pydict[nside]['metadata'] = dict(self.result[nside].dtype.metadata)
535
+ pydict[nside]['metadata'] = dict()
536
+
537
+ for key in nside_data.dtype.metadata:
538
+ # dtype.metadata is a mappingproxy (dict-like) containing numpy-typed values
539
+ # convert numpy types to python bultins to be JSON-friendly
540
+ val = nside_data.dtype.metadata[key]
541
+ if isinstance(val, np.generic):
542
+ # numpy type, non serializable
543
+ # convert to python built-in by calling item()
544
+ pydict[nside]['metadata'][key] = nside_data.dtype.metadata[key].item()
545
+ else:
546
+ # likely a natively serializable python built-in
547
+ pydict[nside]['metadata'][key] = val
532
548
  return pydict
533
549
 
534
550
  """
@@ -952,7 +968,7 @@ class SkyScanResult:
952
968
  contour_labels = [r'50% (IC160427A syst.)', r'90% (IC160427A syst.)']
953
969
  contour_colors=['k', 'r']
954
970
  else:
955
- # # Wilk's
971
+ # Wilks
956
972
  contour_levels = (np.array([1.39, 4.61, 11.83, 28.74])+min_value)[:3]
957
973
  contour_labels = [r'50%', r'90%', r'3$\sigma$', r'5$\sigma$'][:3]
958
974
  contour_colors=['k', 'r', 'g', 'b'][:3]
@@ -1240,7 +1256,7 @@ class SkyScanResult:
1240
1256
  if systematics is True:
1241
1257
  title = "Millipede contour, assuming IC160427A systematics:"
1242
1258
  else:
1243
- title = "Millipede contour, assuming Wilk's Theorum:"
1259
+ title = "Millipede contour, assuming Wilks' Theorem:"
1244
1260
 
1245
1261
  for i, ch in enumerate(final_channels):
1246
1262
  imgdata = io.BytesIO()