spectre-core 0.0.16__py3-none-any.whl → 0.0.18__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,8 @@
6
6
  """General `spectre` package configurations."""
7
7
 
8
8
  from ._paths import (
9
- get_spectre_data_dir_path, get_batches_dir_path, get_configs_dir_path, get_logs_dir_path
9
+ get_spectre_data_dir_path, get_batches_dir_path, get_configs_dir_path,
10
+ get_logs_dir_path, trim_spectre_data_dir_path
10
11
  )
11
12
  from ._time_formats import (
12
13
  TimeFormat
@@ -14,5 +15,5 @@ from ._time_formats import (
14
15
 
15
16
  __all__ = [
16
17
  "get_spectre_data_dir_path", "get_batches_dir_path", "get_configs_dir_path", "get_logs_dir_path",
17
- "TimeFormat"
18
+ "TimeFormat", "trim_spectre_data_dir_path"
18
19
  ]
@@ -115,3 +115,35 @@ def get_configs_dir_path(
115
115
  :return: The directory path for configuration files.
116
116
  """
117
117
  return _CONFIGS_DIR_PATH
118
+
119
+
120
+ def trim_spectre_data_dir_path(
121
+ full_path: str
122
+ ) -> str:
123
+ """Remove the `SPECTRE_DATA_DIR_PATH` prefix from a full file path.
124
+
125
+ This function returns the relative path of `full_path` with respect to
126
+ `SPECTRE_DATA_DIR_PATH`. It is useful for trimming absolute paths
127
+ to maintain consistency across different environments where the base
128
+ directory might differ.
129
+
130
+ :param full_path: The full file path to be trimmed.
131
+ :return: The relative path with `SPECTRE_DATA_DIR_PATH` removed.
132
+ """
133
+ return os.path.relpath(full_path, _SPECTRE_DATA_DIR_PATH)
134
+
135
+
136
+ def add_spectre_data_dir_path(
137
+ rel_path: str
138
+ ) -> str:
139
+ """Prepend the `SPECTRE_DATA_DIR_PATH` prefix to a relative file path.
140
+
141
+ This function constructs an absolute path by joining the given relative
142
+ path with `SPECTRE_DATA_DIR_PATH`. It is useful for converting stored
143
+ relative paths back into full paths within the mounted directory.
144
+
145
+ :param rel_path: The relative file path to be appended.
146
+ :return: The full file path prefixed with `SPECTRE_DATA_DIR_PATH`.
147
+ """
148
+ return os.path.join(_SPECTRE_DATA_DIR_PATH, rel_path)
149
+
@@ -8,7 +8,9 @@ import shutil
8
8
  import gzip
9
9
  from datetime import datetime
10
10
 
11
- from spectre_core.config import get_spectre_data_dir_path, get_batches_dir_path, TimeFormat
11
+ from spectre_core.config import (
12
+ get_spectre_data_dir_path, get_batches_dir_path, TimeFormat, trim_spectre_data_dir_path
13
+ )
12
14
 
13
15
  from enum import Enum
14
16
 
@@ -129,30 +131,37 @@ def _get_batch_path(
129
131
 
130
132
  def _unzip_file_to_batches(
131
133
  gz_path: str
132
- ) -> None:
134
+ ) -> str:
133
135
  """
134
136
  Decompress a `.fit.gz` file and save it as a `.fits` batch file.
135
137
 
136
138
  :param gz_path: Path to the `.fit.gz` file.
139
+ :return: The file path of the newly created batch file, relative to `SPECTRE_DATA_DIR_PATH`.
137
140
  """
138
141
  fits_path = _get_batch_path(gz_path)
139
142
  with gzip.open(gz_path, "rb") as f_in, open(fits_path, "wb") as f_out:
140
143
  shutil.copyfileobj(f_in, f_out)
144
+ return trim_spectre_data_dir_path(f_out.name)
141
145
 
142
146
 
143
147
  def _unzip_to_batches(
144
148
  tmp_dir: str
145
- ) -> None:
149
+ ) -> list[str]:
146
150
  """
147
151
  Decompress all `.gz` files in a temporary directory and save them as `spectre`
148
152
  batch files.
149
153
 
150
154
  :param tmp_dir: Path to the temporary directory containing `.gz` files.
155
+ :return: A list of file names of all newly created batch files, relative to `SPECTRE_DATA_DIR_PATH`.
151
156
  """
157
+ batch_file_names = []
152
158
  for entry in os.scandir(tmp_dir):
153
159
  if entry.is_file() and entry.name.endswith(".gz"):
154
- _unzip_file_to_batches(entry.path)
160
+ batch_file_names.append( _unzip_file_to_batches(entry.path) )
155
161
  os.remove(entry.path)
162
+ shutil.rmtree(tmp_dir)
163
+ return batch_file_names
164
+
156
165
 
157
166
 
158
167
  def _wget_callisto_data(
@@ -186,7 +195,7 @@ def download_callisto_data(
186
195
  year: int,
187
196
  month: int,
188
197
  day: int
189
- ) -> None:
198
+ ) -> list[str]:
190
199
  """
191
200
  Download and decompress e-Callisto FITS files, saving them as `spectre` batch files.
192
201
 
@@ -194,6 +203,7 @@ def download_callisto_data(
194
203
  :param year: Year of the observation.
195
204
  :param month: Month of the observation.
196
205
  :param day: Day of the observation.
206
+ :return: A list of file names of all newly created batch files, relative to `SPECTRE_DATA_DIR_PATH`.
197
207
  """
198
208
  tmp_dir = os.path.join(get_spectre_data_dir_path(), "tmp")
199
209
  # if there are any residual files in the temporary directory, remove them.
@@ -202,5 +212,4 @@ def download_callisto_data(
202
212
  os.makedirs(tmp_dir, exist_ok=True)
203
213
 
204
214
  _wget_callisto_data(instrument_code.value, year, month, day, tmp_dir)
205
- _unzip_to_batches(tmp_dir)
206
- shutil.rmtree(tmp_dir)
215
+ return sorted( _unzip_to_batches(tmp_dir) )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: spectre-core
3
- Version: 0.0.16
3
+ Version: 0.0.18
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
@@ -20,8 +20,8 @@ spectre_core/capture_configs/_pconstraints.py,sha256=bnl1m6M9iyo5KOsPKT_arwrrAZb
20
20
  spectre_core/capture_configs/_pnames.py,sha256=3bJhT4kM5WuiH9SSs4UyBcq_mDybzx-bRiWJcIOqeLA,1975
21
21
  spectre_core/capture_configs/_ptemplates.py,sha256=Pepzs7eq31WPdTYmIICJjIVOzf-j5LdA2SD_f2RUZ54,25609
22
22
  spectre_core/capture_configs/_pvalidators.py,sha256=fRlFL3rTIpDU2G4iUKp3Lb_jFX5ddHNuUbY5hTzZQQg,10325
23
- spectre_core/config/__init__.py,sha256=CVddibAIWU4cNerXCxfeUn_cvnWWDBm4pWeUifqM6Ko,502
24
- spectre_core/config/_paths.py,sha256=Qn0KVe27P6Bo65MfHe4LpH_ryPvLgbTxKjc4MTw1BB8,4090
23
+ spectre_core/config/__init__.py,sha256=TwQAiDUJLWuwx4IFlStG7Mvb9EFU3u82z5ilPfVH6e0,565
24
+ spectre_core/config/_paths.py,sha256=k9jyPlaFHlM2pAwqPWlpivdc0jCiFFpy4tOny1uxc64,5224
25
25
  spectre_core/config/_time_formats.py,sha256=gS0j5zIvBhnV7KMYvTloloIbVwmCYn8MMKn3zNeQ4Xc,857
26
26
  spectre_core/jobs/__init__.py,sha256=WKTvxvpciedm6tsKjU02iXJhIdNsMDt-BnMVwVme2Bo,412
27
27
  spectre_core/jobs/_jobs.py,sha256=gGpxsLZZ7EdXBYGH-r_pKnRGWSapr78E5SK_VnulaGg,3844
@@ -70,9 +70,9 @@ spectre_core/spectrograms/_array_operations.py,sha256=79vddwWqR5i6OkeD5L_84t8svs
70
70
  spectre_core/spectrograms/_spectrogram.py,sha256=WhHEt_QpmzspDqYlzdZcJ8CAXxRfs8-JfP0T3NHpjLQ,28205
71
71
  spectre_core/spectrograms/_transform.py,sha256=WZ5jAe3bOpNldxHDSHPf8Q_1ifBdWqXB_mlF6DL1VuE,11734
72
72
  spectre_core/wgetting/__init__.py,sha256=UkS0Z0wuuqpoZ1EL35wJcDpjBiAaZgdZ7064yGESxNE,341
73
- spectre_core/wgetting/_callisto.py,sha256=m9II6ayswrY4h_ST3TodioZ4C865lN_uOF-BozvjZAg,6952
74
- spectre_core-0.0.16.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
75
- spectre_core-0.0.16.dist-info/METADATA,sha256=7CfIEsTWqo1hw0GvOBc0NKv1o5jIezp0_WcpK5xAbx4,42100
76
- spectre_core-0.0.16.dist-info/WHEEL,sha256=jB7zZ3N9hIM9adW7qlTAyycLYW9npaWKLRzaoVcLKcM,91
77
- spectre_core-0.0.16.dist-info/top_level.txt,sha256=-UsyjpFohXgZpgcZ9QbVeXhsIyF3Am8RxNFNDV_Ta2Y,13
78
- spectre_core-0.0.16.dist-info/RECORD,,
73
+ spectre_core/wgetting/_callisto.py,sha256=B2cb1sqF7SGgHfJ2YDOY-6hbJAqQfwK3NH1NS0Jwfxg,7469
74
+ spectre_core-0.0.18.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
75
+ spectre_core-0.0.18.dist-info/METADATA,sha256=Agk1kfSTqOqArQD6bCUQmVK8n3g07fXSnguK0MR4d5E,42100
76
+ spectre_core-0.0.18.dist-info/WHEEL,sha256=jB7zZ3N9hIM9adW7qlTAyycLYW9npaWKLRzaoVcLKcM,91
77
+ spectre_core-0.0.18.dist-info/top_level.txt,sha256=-UsyjpFohXgZpgcZ9QbVeXhsIyF3Am8RxNFNDV_Ta2Y,13
78
+ spectre_core-0.0.18.dist-info/RECORD,,