spectre-core 0.0.2__py3-none-any.whl → 0.0.4__py3-none-any.whl

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.
@@ -6,7 +6,7 @@
6
6
  from spectre_core.chunks.base import BaseChunk
7
7
  from spectre_core.file_handlers.configs import CaptureConfig
8
8
  from spectre_core.exceptions import ChunkNotFoundError
9
-
9
+ from spectre_core.chunks.chunk_register import chunk_map
10
10
 
11
11
  def get_chunk(chunk_key: str) -> BaseChunk:
12
12
  Chunk = chunk_map.get(chunk_key)
@@ -56,39 +56,13 @@ class BaseFileHandler(ABC):
56
56
  os.makedirs(self.parent_path, exist_ok=True)
57
57
 
58
58
 
59
- def delete(self,
60
- doublecheck_delete = True) -> None:
59
+ def delete(self) -> None:
61
60
  if not self.exists:
62
61
  warn(f"{self.file_path} does not exist. No deletion taking place")
63
62
  return
64
63
  else:
65
- if doublecheck_delete:
66
- self.doublecheck_delete()
67
64
  os.remove(self.file_path)
68
65
 
69
66
 
70
67
  def cat(self) -> None:
71
- print(self.read())
72
-
73
-
74
- def _doublecheck_action(self,
75
- action_message: str) -> None:
76
- proceed_with_action = False
77
- while not proceed_with_action:
78
- user_input = input(f"{action_message} [y/n]: ").strip().lower()
79
- if user_input == "y":
80
- proceed_with_action = True
81
- elif user_input == "n":
82
- print("Operation cancelled by the user")
83
- raise exit(1)
84
- else:
85
- print(f"Please enter one of [y/n], received {user_input}")
86
- proceed_with_action = False
87
-
88
-
89
- def doublecheck_overwrite(self) -> None:
90
- self._doublecheck_action(action_message=f"The file '{self.file_path}' already exists. Overwrite?")
91
-
92
-
93
- def doublecheck_delete(self) -> None:
94
- self._doublecheck_action(action_message=f"Are you sure you would like to delete '{self.file_path}'?")
68
+ print(self.read())
@@ -239,12 +239,14 @@ class FitsConfig(SPECTREConfig):
239
239
 
240
240
  def save_params(self,
241
241
  params: list[str],
242
- doublecheck_overwrite: bool = True
242
+ force: bool = False
243
243
  ) -> None:
244
244
  d = type_cast_params(params,
245
245
  self.type_template)
246
+ validate_against_type_template(d,
247
+ self.type_template)
246
248
  self.save(d,
247
- doublecheck_overwrite = doublecheck_overwrite)
249
+ force = force)
248
250
 
249
251
 
250
252
  class CaptureConfig(SPECTREConfig):
@@ -26,11 +26,15 @@ class JsonHandler(BaseFileHandler):
26
26
 
27
27
  def save(self,
28
28
  d: dict,
29
- doublecheck_overwrite: bool = True) -> None:
29
+ force: bool = False) -> None:
30
30
  self.make_parent_path()
31
31
 
32
- if self.exists and doublecheck_overwrite:
33
- self.doublecheck_overwrite()
34
-
32
+ if self.exists:
33
+ if force:
34
+ pass
35
+ else:
36
+ raise RuntimeError((f"{self.file_name} already exists, write has been abandoned. "
37
+ f"You can override this functionality with `force`"))
38
+
35
39
  with open(self.file_path, 'w') as file:
36
- json.dump(d, file, indent=4)
40
+ json.dump(d, file, indent=4)
spectre_core/logging.py CHANGED
@@ -12,6 +12,7 @@ from typing import Callable, Optional
12
12
  import warnings
13
13
  from collections import OrderedDict
14
14
  from datetime import datetime
15
+ from functools import wraps
15
16
 
16
17
  from spectre_core.file_handlers.text import TextHandler
17
18
  from spectre_core.cfg import (
@@ -206,17 +207,15 @@ def configure_root_logger(process_type: str,
206
207
 
207
208
  return log_handler
208
209
 
209
- # Logger must be passed in to preserve context of the service function
210
- def log_call(logger: logging.Logger
211
- ) -> Callable:
212
- def decorator(func: Callable) -> Callable:
213
- def wrapper(*args, **kwargs):
214
- try:
215
- logger.info(f"Calling the function: {func.__name__}")
216
- return func(*args, **kwargs)
217
- except Exception as e:
218
- logger.error(f"An error occurred while calling the function: {func.__name__}",
219
- exc_info=True)
220
- raise
221
- return wrapper
222
- return decorator
210
+
211
+ def log_call(func: Callable) -> Callable:
212
+ @wraps(func)
213
+ def wrapper(*args, **kwargs):
214
+ logger = logging.getLogger(func.__module__) # Automatically get module-level logger
215
+ try:
216
+ logger.info(f"Calling the function: {func.__name__}")
217
+ return func(*args, **kwargs)
218
+ except Exception as e:
219
+ logger.error(f"Error in function: {func.__name__}", exc_info=True)
220
+ raise
221
+ return wrapper
@@ -155,7 +155,7 @@ class BaseReceiver(ABC):
155
155
  def save_params(self,
156
156
  params: list[str],
157
157
  tag: str,
158
- doublecheck_overwrite: bool = True) -> None:
158
+ force: bool = False) -> None:
159
159
  d = type_cast_params(params,
160
160
  self.type_template)
161
161
 
@@ -164,13 +164,13 @@ class BaseReceiver(ABC):
164
164
 
165
165
  self.save_capture_config(d,
166
166
  tag,
167
- doublecheck_overwrite=doublecheck_overwrite)
167
+ force = force)
168
168
 
169
169
 
170
170
  def save_capture_config(self,
171
171
  d: dict[str, Any],
172
172
  tag: str,
173
- doublecheck_overwrite: bool = True) -> None:
173
+ force: bool = False) -> None:
174
174
 
175
175
  self.validate_capture_config(d)
176
176
 
@@ -180,7 +180,7 @@ class BaseReceiver(ABC):
180
180
 
181
181
  capture_config = CaptureConfig(tag)
182
182
  capture_config.save(d,
183
- doublecheck_overwrite = doublecheck_overwrite)
183
+ force = force)
184
184
 
185
185
 
186
186
  def load_capture_config(self,
@@ -2,7 +2,7 @@
2
2
  # This file is part of SPECTRE
3
3
  # SPDX-License-Identifier: GPL-3.0-or-later
4
4
 
5
- from typing import Callable
5
+ from typing import Callable, Any
6
6
  from dataclasses import dataclass
7
7
 
8
8
  import numpy as np
@@ -23,15 +23,25 @@ class TestResults:
23
23
  # Maps each time to whether the corresponding spectrum matched analytically
24
24
  spectrum_validated: dict[float, bool] = None
25
25
 
26
+
26
27
  @property
27
28
  def num_validated_spectrums(self) -> int:
28
29
  """Counts the number of validated spectrums."""
29
30
  return sum(is_validated for is_validated in self.spectrum_validated.values())
30
31
 
32
+
31
33
  @property
32
34
  def num_invalid_spectrums(self) -> int:
33
35
  """Counts the number of spectrums that are not validated."""
34
36
  return len(self.spectrum_validated) - self.num_validated_spectrums
37
+
38
+
39
+ def jsonify(self) -> dict[str, Any]:
40
+ return {
41
+ "time_validated": self.times_validated,
42
+ "frequencies_validated": self.frequencies_validated,
43
+ "spectrum_validated": self.spectrum_validated
44
+ }
35
45
 
36
46
 
37
47
  class _AnalyticalFactory:
@@ -34,8 +34,8 @@ class EventHandler(BaseEventHandler):
34
34
 
35
35
  bin_chunk = chunk.get_file('bin')
36
36
  _LOGGER.info(f"Deleting {bin_chunk.file_path}")
37
- bin_chunk.delete(doublecheck_delete = False)
37
+ bin_chunk.delete()
38
38
 
39
39
  hdr_chunk = chunk.get_file('hdr')
40
40
  _LOGGER.info(f"Deleting {hdr_chunk.file_path}")
41
- hdr_chunk.delete(doublecheck_delete = False)
41
+ hdr_chunk.delete()
@@ -45,11 +45,11 @@ class EventHandler(BaseEventHandler):
45
45
  else:
46
46
  bin_chunk = self.previous_chunk.get_file('bin')
47
47
  _LOGGER.info(f"Deleting {bin_chunk.file_path}")
48
- bin_chunk.delete(doublecheck_delete = False)
48
+ bin_chunk.delete()
49
49
 
50
50
  hdr_chunk = self.previous_chunk.get_file('hdr')
51
51
  _LOGGER.info(f"Deleting {hdr_chunk.file_path}")
52
- hdr_chunk.delete(doublecheck_delete = False)
52
+ hdr_chunk.delete()
53
53
 
54
54
  # and reassign the current chunk to be used as the previous chunk at the next call of this method
55
55
  self.previous_chunk = chunk
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: spectre-core
3
- Version: 0.0.2
3
+ Version: 0.0.4
4
4
  Summary: The core Python package used by the spectre program.
5
5
  Maintainer-email: Jimmy Fitzpatrick <jcfitzpatrick12@gmail.com>
6
6
  License: GNU GENERAL PUBLIC LICENSE
@@ -2,11 +2,11 @@ spectre_core/__init__.py,sha256=oFSWmGoXQLK5X5xHvWzTdNr9amuaiiGjZirXZVogACU,154
2
2
  spectre_core/cfg.py,sha256=_CkQRKRtbkOJmSV58bW4lCsyuRell9dw1lwmirm4Jfc,3175
3
3
  spectre_core/dynamic_imports.py,sha256=hZbFA9QSVUmAA779qrwHe6RylpjeAG_L2KTVrRZE-Qk,987
4
4
  spectre_core/exceptions.py,sha256=i1uLL64DLESdzXTAPTsqc4Yg6LeU-ItOm5rhDlrDv7w,663
5
- spectre_core/logging.py,sha256=7mW3h3b-YrlGQsKAtuO10BMce45nSwAKb5XBZYzwBD0,6584
5
+ spectre_core/logging.py,sha256=mdTqHLHXm5ES0nsajy_b7SqT6P2SvMfFfqGg3QOU2F8,6486
6
6
  spectre_core/chunks/__init__.py,sha256=KqEz43Ifjbw_1cMdxt4s7iEUCOGmFruNN63qU2mgcmY,7148
7
7
  spectre_core/chunks/base.py,sha256=lVqVOmI5mxP7JUZ8Gf1VLAQuS3D8q0g7r_ipphxbTBo,5091
8
8
  spectre_core/chunks/chunk_register.py,sha256=sS-T6d59zbh8_trr_7bYlq2O9Ak7k_XXHM6-yalwxaE,435
9
- spectre_core/chunks/factory.py,sha256=VEqfpQnXHKTha4YbLYdunGMXiYS1YLaNuhHkDz2JKAE,1077
9
+ spectre_core/chunks/factory.py,sha256=gi0x7nsZZR8HUBxnpEfwZG5fI1jSzM2OVPwGR8i45YE,1133
10
10
  spectre_core/chunks/library/__init__.py,sha256=w2G2Ew_yLK1q--1pwN-UsDSSa73Z6VHnn3jC-XXQNWE,272
11
11
  spectre_core/chunks/library/callisto/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
12
  spectre_core/chunks/library/callisto/chunk.py,sha256=J_xZIL_9YChLZSK1pMjQZmNoUpcENPXeLlu7x7TbPZI,3931
@@ -14,9 +14,9 @@ spectre_core/chunks/library/fixed/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeR
14
14
  spectre_core/chunks/library/fixed/chunk.py,sha256=ckBiEtSa6_S06d_H9LQ0ske5JT2ycF-LstWbDX1oo1c,6941
15
15
  spectre_core/chunks/library/sweep/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
16
16
  spectre_core/chunks/library/sweep/chunk.py,sha256=bXpC43kylsaAc88VEc0lnLy8AFXZivejqXUyovDz51U,21219
17
- spectre_core/file_handlers/base.py,sha256=cuMdq4ThX3RDQHzSLWeRdO6d7kGiIiDf_y0ujwbjCak,2664
18
- spectre_core/file_handlers/configs.py,sha256=GCEqMKWEHpTlTkt_RXQSPB5u7z563aDVxnkAB1uy6l4,8445
19
- spectre_core/file_handlers/json.py,sha256=1z0wCjpWIw_wJcst8lhay4jGjWjHW8jZodTuAusOgqo,1066
17
+ spectre_core/file_handlers/base.py,sha256=V1R6Vbp3mjA29TI_y4bpslhVvCQT7nzmGY4lDLlN2iI,1653
18
+ spectre_core/file_handlers/configs.py,sha256=CiNHfy5lGrXDAcxCrKS9VE5Z1Aonp0CP9-SxlyP-ZHI,8500
19
+ spectre_core/file_handlers/json.py,sha256=PBwjtM29jqfa9ozeRIuarkCJBD8uYIKyDCbM1V2GmtE,1230
20
20
  spectre_core/file_handlers/text.py,sha256=K84BIab_qmbR5igCVJZu3uE47ykpM_bnsasd3WGNEuo,677
21
21
  spectre_core/plotting/__init__.py,sha256=ZRQmBzZ0HWcVDaM5a8AneGbyHwx7dhtBs2z5H8VVspc,192
22
22
  spectre_core/plotting/base.py,sha256=4HhPPP7BNe5_SUAl1Ee52_QP62Zzh3kmNJwLzCHKG3c,4808
@@ -30,7 +30,7 @@ spectre_core/plotting/library/integral_over_frequency/panel.py,sha256=tvro2MCtY4
30
30
  spectre_core/plotting/library/spectrogram/panel.py,sha256=CAaPz7sDYoWZ3-4Jb1kVRu9bvJYaBRiXvoMkV7QXWqk,3556
31
31
  spectre_core/plotting/library/time_cuts/panel.py,sha256=u9Sbnwy6ex61y5Jl-D77HlYvuuXdK8_YB-o2gCovCTY,2947
32
32
  spectre_core/receivers/__init__.py,sha256=kKfhqrGs9sSPGLbrpTqScv816iPZOvT3ry3zSMcqLkM,227
33
- spectre_core/receivers/base.py,sha256=sckMC0fnpcflMomj_pVRbZZi6GlXYyRD7CHj3wgiUzM,16241
33
+ spectre_core/receivers/base.py,sha256=Hx-jH7pnFyeSjaajujmzAYjODUNRgCBo3maHw9rIsyM,16149
34
34
  spectre_core/receivers/factory.py,sha256=aE-Yw_cnlkhRe5HxK0JqhDzd2AwZcKmB2QkAKwaq27Y,873
35
35
  spectre_core/receivers/receiver_register.py,sha256=xHcRnT-3NQxyIWL3nyT3P9qT14Wl5liM9HbflOvOUAM,617
36
36
  spectre_core/receivers/validators.py,sha256=udwOw92oCFR84JMaaOmWn_Ve9G4RKfzdqhpSpGDPqnY,8974
@@ -51,7 +51,7 @@ spectre_core/receivers/library/test/gr/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JC
51
51
  spectre_core/receivers/library/test/gr/cosine_signal_1.py,sha256=6XgYjYMh-QNPs_UUGUQcU_VQFr6BG4OLdsW-M-RU5Ww,2943
52
52
  spectre_core/receivers/library/test/gr/tagged_staircase.py,sha256=5rJHbB-3vdXjqT8DrcAGUSebaAqZ5RQtYHBWgH9iU2E,3465
53
53
  spectre_core/spectrograms/__init__.py,sha256=OFW82_itCktN8dFm_UO5gbgmzFs51v9KEHrSZWLuIUY,155
54
- spectre_core/spectrograms/analytical.py,sha256=BqbTZDaINdjxHyqI4gvgvlWf1JMVqYvTrEMAvJTZ9WQ,8279
54
+ spectre_core/spectrograms/analytical.py,sha256=36XWstSNP4n_8EOi8BFNHl_h2k5JrrtWTXN0CRGVZcI,8535
55
55
  spectre_core/spectrograms/array_operations.py,sha256=6qKd3y2z6Pmu_U8yxTR4FN4eMhS10KgZ8rH60B_IXqw,2577
56
56
  spectre_core/spectrograms/spectrogram.py,sha256=EqeQyvjzjoKaXou4vJbPbRx85BeMPB9iiJtFZcCyimI,19488
57
57
  spectre_core/spectrograms/transform.py,sha256=xo7ch2lrRkJ54cfIqbkaTHNo_AptBuK0zRELPf7SfIE,13860
@@ -62,11 +62,11 @@ spectre_core/watchdog/factory.py,sha256=Uqx4nIZPVRxx7hRgm1M-1p2Sc7m3ObkIKWIC_ru9
62
62
  spectre_core/watchdog/watcher.py,sha256=eRAuWAw-0JvfcH3b7qn6lRZVLhmPwubCduRCrV2gLhk,1660
63
63
  spectre_core/watchdog/library/__init__.py,sha256=vEwAnAV-sv7WcNYOdnjr1JVqZYr29Wr2cv01eoxwdmg,282
64
64
  spectre_core/watchdog/library/fixed/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
65
- spectre_core/watchdog/library/fixed/event_handler.py,sha256=-G8-bdwSk7ggX9m98kt8Hw4tqIdGQnDCVMflgUzuwaM,1439
66
- spectre_core/watchdog/library/sweep/event_handler.py,sha256=0PojO-C4xWoJGuuDbp3dI6Xzjc01_rz-H9s1MwDLjB4,2240
65
+ spectre_core/watchdog/library/fixed/event_handler.py,sha256=yWWS80LukB-cTrKBsF4-pRvw2obkX2MzQ5ZGytOtmAg,1387
66
+ spectre_core/watchdog/library/sweep/event_handler.py,sha256=wDISZiQXBeqLDPxgEMo0a2QAXqQVOO7fng3yhZWSR74,2188
67
67
  spectre_core/web_fetch/callisto.py,sha256=qiww6IURqNI0Dg5nc4uT8f4GFagWcapSgYkrBoRVmlg,3627
68
- spectre_core-0.0.2.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
69
- spectre_core-0.0.2.dist-info/METADATA,sha256=ePsYRL2vMB3oTqvoliGI_hPave8apgTve1Y8RSnZ098,42149
70
- spectre_core-0.0.2.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
71
- spectre_core-0.0.2.dist-info/top_level.txt,sha256=-UsyjpFohXgZpgcZ9QbVeXhsIyF3Am8RxNFNDV_Ta2Y,13
72
- spectre_core-0.0.2.dist-info/RECORD,,
68
+ spectre_core-0.0.4.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
69
+ spectre_core-0.0.4.dist-info/METADATA,sha256=KMnQMpsW1dD3TvZtn0wC-xKLjY-WyfnIgm4QHo7is94,42149
70
+ spectre_core-0.0.4.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
71
+ spectre_core-0.0.4.dist-info/top_level.txt,sha256=-UsyjpFohXgZpgcZ9QbVeXhsIyF3Am8RxNFNDV_Ta2Y,13
72
+ spectre_core-0.0.4.dist-info/RECORD,,