spectre-core 0.0.1__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.
- spectre_core/__init__.py +3 -0
- spectre_core/cfg.py +116 -0
- spectre_core/chunks/__init__.py +206 -0
- spectre_core/chunks/base.py +160 -0
- spectre_core/chunks/chunk_register.py +15 -0
- spectre_core/chunks/factory.py +26 -0
- spectre_core/chunks/library/__init__.py +8 -0
- spectre_core/chunks/library/callisto/__init__.py +0 -0
- spectre_core/chunks/library/callisto/chunk.py +101 -0
- spectre_core/chunks/library/fixed/__init__.py +0 -0
- spectre_core/chunks/library/fixed/chunk.py +185 -0
- spectre_core/chunks/library/sweep/__init__.py +0 -0
- spectre_core/chunks/library/sweep/chunk.py +400 -0
- spectre_core/dynamic_imports.py +22 -0
- spectre_core/exceptions.py +17 -0
- spectre_core/file_handlers/base.py +94 -0
- spectre_core/file_handlers/configs.py +269 -0
- spectre_core/file_handlers/json.py +36 -0
- spectre_core/file_handlers/text.py +21 -0
- spectre_core/logging.py +222 -0
- spectre_core/plotting/__init__.py +5 -0
- spectre_core/plotting/base.py +194 -0
- spectre_core/plotting/factory.py +26 -0
- spectre_core/plotting/format.py +19 -0
- spectre_core/plotting/library/__init__.py +7 -0
- spectre_core/plotting/library/frequency_cuts/panel.py +74 -0
- spectre_core/plotting/library/integral_over_frequency/panel.py +34 -0
- spectre_core/plotting/library/spectrogram/panel.py +92 -0
- spectre_core/plotting/library/time_cuts/panel.py +77 -0
- spectre_core/plotting/panel_register.py +13 -0
- spectre_core/plotting/panel_stack.py +148 -0
- spectre_core/receivers/__init__.py +6 -0
- spectre_core/receivers/base.py +415 -0
- spectre_core/receivers/factory.py +19 -0
- spectre_core/receivers/library/__init__.py +7 -0
- spectre_core/receivers/library/rsp1a/__init__.py +0 -0
- spectre_core/receivers/library/rsp1a/gr/__init__.py +0 -0
- spectre_core/receivers/library/rsp1a/gr/fixed.py +104 -0
- spectre_core/receivers/library/rsp1a/gr/sweep.py +129 -0
- spectre_core/receivers/library/rsp1a/receiver.py +68 -0
- spectre_core/receivers/library/rspduo/__init__.py +0 -0
- spectre_core/receivers/library/rspduo/gr/__init__.py +0 -0
- spectre_core/receivers/library/rspduo/gr/tuner_1_fixed.py +110 -0
- spectre_core/receivers/library/rspduo/gr/tuner_1_sweep.py +135 -0
- spectre_core/receivers/library/rspduo/receiver.py +68 -0
- spectre_core/receivers/library/test/__init__.py +0 -0
- spectre_core/receivers/library/test/gr/__init__.py +0 -0
- spectre_core/receivers/library/test/gr/cosine_signal_1.py +83 -0
- spectre_core/receivers/library/test/gr/tagged_staircase.py +93 -0
- spectre_core/receivers/library/test/receiver.py +174 -0
- spectre_core/receivers/receiver_register.py +22 -0
- spectre_core/receivers/validators.py +205 -0
- spectre_core/spectrograms/__init__.py +3 -0
- spectre_core/spectrograms/analytical.py +205 -0
- spectre_core/spectrograms/array_operations.py +77 -0
- spectre_core/spectrograms/spectrogram.py +461 -0
- spectre_core/spectrograms/transform.py +267 -0
- spectre_core/watchdog/__init__.py +6 -0
- spectre_core/watchdog/base.py +105 -0
- spectre_core/watchdog/event_handler_register.py +15 -0
- spectre_core/watchdog/factory.py +22 -0
- spectre_core/watchdog/library/__init__.py +10 -0
- spectre_core/watchdog/library/fixed/__init__.py +0 -0
- spectre_core/watchdog/library/fixed/event_handler.py +41 -0
- spectre_core/watchdog/library/sweep/event_handler.py +55 -0
- spectre_core/watchdog/watcher.py +50 -0
- spectre_core/web_fetch/callisto.py +101 -0
- spectre_core-0.0.1.dist-info/LICENSE +674 -0
- spectre_core-0.0.1.dist-info/METADATA +40 -0
- spectre_core-0.0.1.dist-info/RECORD +72 -0
- spectre_core-0.0.1.dist-info/WHEEL +5 -0
- spectre_core-0.0.1.dist-info/top_level.txt +1 -0
@@ -0,0 +1,101 @@
|
|
1
|
+
# SPDX-FileCopyrightText: © 2024 Jimmy Fitzpatrick <jcfitzpatrick12@gmail.com>
|
2
|
+
# This file is part of SPECTRE
|
3
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
4
|
+
|
5
|
+
import os
|
6
|
+
import subprocess
|
7
|
+
import shutil
|
8
|
+
import gzip
|
9
|
+
from datetime import datetime
|
10
|
+
from typing import Optional
|
11
|
+
|
12
|
+
from spectre_core.cfg import (
|
13
|
+
DEFAULT_DATETIME_FORMAT,
|
14
|
+
CALLISTO_INSTRUMENT_CODES
|
15
|
+
)
|
16
|
+
from spectre_core.cfg import get_chunks_dir_path
|
17
|
+
|
18
|
+
temp_dir = os.path.join(os.environ['SPECTRE_DIR_PATH'], "tmp")
|
19
|
+
|
20
|
+
def get_chunk_name(station: str, date: str, time: str, instrument_code: str) -> str:
|
21
|
+
dt = datetime.strptime(f"{date}T{time}", '%Y%m%dT%H%M%S')
|
22
|
+
formatted_time = dt.strftime(DEFAULT_DATETIME_FORMAT)
|
23
|
+
return f"{formatted_time}_callisto-{station.lower()}-{instrument_code}.fits"
|
24
|
+
|
25
|
+
|
26
|
+
def get_chunk_components(gz_path: str):
|
27
|
+
file_name = os.path.basename(gz_path)
|
28
|
+
if not file_name.endswith(".fit.gz"):
|
29
|
+
raise ValueError(f"Unexpected file extension in {file_name}. Expected .fit.gz")
|
30
|
+
|
31
|
+
file_base_name = file_name.rstrip(".fit.gz")
|
32
|
+
parts = file_base_name.split('_')
|
33
|
+
if len(parts) != 4:
|
34
|
+
raise ValueError("Filename does not conform to the expected format of [station]_[date]_[time]_[instrument_code]")
|
35
|
+
|
36
|
+
return parts
|
37
|
+
|
38
|
+
|
39
|
+
def get_chunk_path(gz_path: str) -> str:
|
40
|
+
station, date, time, instrument_code = get_chunk_components(gz_path)
|
41
|
+
fits_chunk_name = get_chunk_name(station, date, time, instrument_code)
|
42
|
+
chunk_start_time = fits_chunk_name.split('_')[0]
|
43
|
+
chunk_start_datetime = datetime.strptime(chunk_start_time, DEFAULT_DATETIME_FORMAT)
|
44
|
+
chunk_parent_path = get_chunks_dir_path(year = chunk_start_datetime.year,
|
45
|
+
month = chunk_start_datetime.month,
|
46
|
+
day = chunk_start_datetime.day)
|
47
|
+
if not os.path.exists(chunk_parent_path):
|
48
|
+
os.makedirs(chunk_parent_path)
|
49
|
+
return os.path.join(chunk_parent_path, fits_chunk_name)
|
50
|
+
|
51
|
+
|
52
|
+
def unzip_file_to_chunks(gz_path: str):
|
53
|
+
fits_path = get_chunk_path(gz_path)
|
54
|
+
with gzip.open(gz_path, 'rb') as f_in, open(fits_path, 'wb') as f_out:
|
55
|
+
shutil.copyfileobj(f_in, f_out)
|
56
|
+
|
57
|
+
|
58
|
+
def unzip_to_chunks():
|
59
|
+
for entry in os.scandir(temp_dir):
|
60
|
+
if entry.is_file() and entry.name.endswith('.gz'):
|
61
|
+
unzip_file_to_chunks(entry.path)
|
62
|
+
os.remove(entry.path)
|
63
|
+
|
64
|
+
|
65
|
+
def download_callisto_data(instrument_code: str,
|
66
|
+
year: int,
|
67
|
+
month: int,
|
68
|
+
day: int):
|
69
|
+
date_str = f"{year:04d}/{month:02d}/{day:02d}"
|
70
|
+
base_url = f"http://soleil.i4ds.ch/solarradio/data/2002-20yy_Callisto/{date_str}/"
|
71
|
+
command = [
|
72
|
+
'wget', '-r', '-l1', '-nd', '-np',
|
73
|
+
'-R', '.tmp',
|
74
|
+
'-A', f'{instrument_code}*.fit.gz',
|
75
|
+
'-P', temp_dir,
|
76
|
+
base_url
|
77
|
+
]
|
78
|
+
|
79
|
+
try:
|
80
|
+
subprocess.run(command, check=True)
|
81
|
+
except subprocess.CalledProcessError as e:
|
82
|
+
print(f"An error occurred: {e}")
|
83
|
+
|
84
|
+
def fetch_chunks(instrument_code: Optional[str],
|
85
|
+
year: Optional[int],
|
86
|
+
month: Optional[int],
|
87
|
+
day: Optional[int]):
|
88
|
+
|
89
|
+
|
90
|
+
if (year is None) or (month is None) or (day is None):
|
91
|
+
raise ValueError(f"All of year, month and day should be specified")
|
92
|
+
|
93
|
+
if not os.path.exists(temp_dir):
|
94
|
+
os.mkdir(temp_dir)
|
95
|
+
|
96
|
+
if instrument_code not in CALLISTO_INSTRUMENT_CODES:
|
97
|
+
raise ValueError(f"No match found for \"{instrument_code}\". Expected one of {CALLISTO_INSTRUMENT_CODES}")
|
98
|
+
|
99
|
+
download_callisto_data(instrument_code, year, month, day)
|
100
|
+
unzip_to_chunks()
|
101
|
+
shutil.rmtree(temp_dir)
|