tess-ida-tools 1.0.0__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.
- tess/__init__.py +0 -0
- tess/_version.py +16 -0
- tess/ida/__init__.py +9 -0
- tess/ida/_version.py +16 -0
- tess/ida/constants.py +100 -0
- tess/ida/dbase/__init__.py +24 -0
- tess/ida/dbase/api.py +113 -0
- tess/ida/dbase/schema.py +254 -0
- tess/ida/dbase/sql/__init__.py +0 -0
- tess/ida/dbase/sql/schema.sql +32 -0
- tess/ida/download.py +357 -0
- tess/ida/pipeline.py +272 -0
- tess/ida/timeseries.py +573 -0
- tess/ida/utils.py +81 -0
- tess_ida_tools-1.0.0.dist-info/LICENSE +21 -0
- tess_ida_tools-1.0.0.dist-info/METADATA +343 -0
- tess_ida_tools-1.0.0.dist-info/RECORD +20 -0
- tess_ida_tools-1.0.0.dist-info/WHEEL +5 -0
- tess_ida_tools-1.0.0.dist-info/entry_points.txt +5 -0
- tess_ida_tools-1.0.0.dist-info/top_level.txt +1 -0
tess/__init__.py
ADDED
|
File without changes
|
tess/_version.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# file generated by setuptools_scm
|
|
2
|
+
# don't change, don't track in version control
|
|
3
|
+
TYPE_CHECKING = False
|
|
4
|
+
if TYPE_CHECKING:
|
|
5
|
+
from typing import Tuple, Union
|
|
6
|
+
VERSION_TUPLE = Tuple[Union[int, str], ...]
|
|
7
|
+
else:
|
|
8
|
+
VERSION_TUPLE = object
|
|
9
|
+
|
|
10
|
+
version: str
|
|
11
|
+
__version__: str
|
|
12
|
+
__version_tuple__: VERSION_TUPLE
|
|
13
|
+
version_tuple: VERSION_TUPLE
|
|
14
|
+
|
|
15
|
+
__version__ = version = '0.1.6'
|
|
16
|
+
__version_tuple__ = version_tuple = (0, 1, 6)
|
tess/ida/__init__.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# ----------------------------------------------------------------------
|
|
2
|
+
# Copyright (c) 2024 Rafael Gonzalez.
|
|
3
|
+
#
|
|
4
|
+
# See the LICENSE file for details
|
|
5
|
+
# ----------------------------------------------------------------------
|
|
6
|
+
|
|
7
|
+
from ._version import __version__
|
|
8
|
+
|
|
9
|
+
__all__ = ["__version__"]
|
tess/ida/_version.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# file generated by setuptools_scm
|
|
2
|
+
# don't change, don't track in version control
|
|
3
|
+
TYPE_CHECKING = False
|
|
4
|
+
if TYPE_CHECKING:
|
|
5
|
+
from typing import Tuple, Union
|
|
6
|
+
VERSION_TUPLE = Tuple[Union[int, str], ...]
|
|
7
|
+
else:
|
|
8
|
+
VERSION_TUPLE = object
|
|
9
|
+
|
|
10
|
+
version: str
|
|
11
|
+
__version__: str
|
|
12
|
+
__version_tuple__: VERSION_TUPLE
|
|
13
|
+
version_tuple: VERSION_TUPLE
|
|
14
|
+
|
|
15
|
+
__version__ = version = '1.0.0'
|
|
16
|
+
__version_tuple__ = version_tuple = (1, 0, 0)
|
tess/ida/constants.py
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# ----------------------------------------------------------------------
|
|
2
|
+
# Copyright (c) 2024 Rafael Gonzalez.
|
|
3
|
+
#
|
|
4
|
+
# See the LICENSE file for details
|
|
5
|
+
# ----------------------------------------------------------------------
|
|
6
|
+
|
|
7
|
+
# ------------------------
|
|
8
|
+
# Standard Python imports
|
|
9
|
+
# -----------------------
|
|
10
|
+
try:
|
|
11
|
+
from enum import StrEnum # from Python 3.11 on
|
|
12
|
+
except:
|
|
13
|
+
from strenum import StrEnum
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
# -------------------------
|
|
17
|
+
# Constant and Enumerations
|
|
18
|
+
# -------------------------
|
|
19
|
+
|
|
20
|
+
IDA_HEADER_LEN = 35
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class StringEnum(StrEnum):
|
|
24
|
+
@classmethod
|
|
25
|
+
def names(cls):
|
|
26
|
+
"""Get the values in the order defined"""
|
|
27
|
+
return [member.name for _, member in cls.__members__.items()]
|
|
28
|
+
|
|
29
|
+
@classmethod
|
|
30
|
+
def values(cls):
|
|
31
|
+
"""Get the values in the order defined"""
|
|
32
|
+
return [member.value for _, member in cls.__members__.items()]
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
# IDA keywords in the comments section of the IDA file
|
|
36
|
+
class IDA_KEYWORDS(StringEnum):
|
|
37
|
+
LICENSE = "License"
|
|
38
|
+
NUM_HEADERS = "Number of header lines"
|
|
39
|
+
NUM_CHANNELS = "Number of channels"
|
|
40
|
+
OBSERVER = "Data supplier"
|
|
41
|
+
LOCATION = "Location name"
|
|
42
|
+
TIMEZONE = "Local timezone"
|
|
43
|
+
POSITION = "Position"
|
|
44
|
+
FOV = "Field of view"
|
|
45
|
+
COVER_OFFSET = "TESS cover offset value"
|
|
46
|
+
NUM_COLS = "Number of fields per line"
|
|
47
|
+
ZP = "TESS zero point"
|
|
48
|
+
AIM = "Measurement direction per channel"
|
|
49
|
+
FILTERS = "Filters per channel"
|
|
50
|
+
PHOT_NAME = "Instrument ID"
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
# TESS-W Data column names
|
|
54
|
+
# order is imporant: it is the oroder in the IDA file
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
class TESSW_COLS(StringEnum):
|
|
58
|
+
UTC_TIME = "time" # always 'time' for TimeSeries Astropy Class
|
|
59
|
+
LOCAL_TIME = "Local Date & Time"
|
|
60
|
+
BOX_TEMP = "Enclosure Temperature"
|
|
61
|
+
SKY_TEMP = "Sky Temperature"
|
|
62
|
+
FREQ = "Frequency"
|
|
63
|
+
MAG = "MSAS"
|
|
64
|
+
ZP = "ZP"
|
|
65
|
+
SEQ_NUM = "Sequence Number"
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
# TESS-4C data column names
|
|
69
|
+
# order is imporant: it is the order in the IDA file
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
class TESS4C_COLS(StringEnum):
|
|
73
|
+
UTC_TIME = "time" # always 'time' for TimeSeries Astropy Class
|
|
74
|
+
LOCAL_TIME = "Local Date & Time"
|
|
75
|
+
BOX_TEMP = "Enclosure Temperature"
|
|
76
|
+
SKY_TEMP = "Sky Temperature"
|
|
77
|
+
FREQ1 = "Freq1"
|
|
78
|
+
MAG1 = "MSAS1"
|
|
79
|
+
ZP1 = "ZP1"
|
|
80
|
+
FREQ2 = "Freq2"
|
|
81
|
+
MAG2 = "MSAS2"
|
|
82
|
+
ZP2 = "ZP2"
|
|
83
|
+
FREQ3 = "Freq3"
|
|
84
|
+
MAG3 = "MSAS3"
|
|
85
|
+
ZP3 = "ZP3"
|
|
86
|
+
FREQ4 = "Freq4"
|
|
87
|
+
MAG4 = "MSAS4"
|
|
88
|
+
ZP4 = "ZP4"
|
|
89
|
+
SEQ_NUM = "Sequence Number"
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
# Additional data column names that can appear in the Time Series
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
class TIMESERIES_COLS(StringEnum):
|
|
96
|
+
SUN_ALT = "Sun Alt"
|
|
97
|
+
SUN_AZ = "Sun Az"
|
|
98
|
+
MOON_AZ = "Moon Az"
|
|
99
|
+
MOON_ALT = "Moon Alt"
|
|
100
|
+
MOON_ILLUM = "Moon Illumination"
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# ----------------------------------------------------------------------
|
|
2
|
+
# Copyright (c) 2024 Rafael Gonzalez.
|
|
3
|
+
#
|
|
4
|
+
# See the LICENSE file for details
|
|
5
|
+
# ----------------------------------------------------------------------
|
|
6
|
+
|
|
7
|
+
from .api import (
|
|
8
|
+
aux_table_hashes_lookup,
|
|
9
|
+
aux_table_hashes_insert,
|
|
10
|
+
aux_table_hashes_update,
|
|
11
|
+
aux_dbase_load,
|
|
12
|
+
aux_dbase_save,
|
|
13
|
+
aux_table_coords_lookup,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
__all__ = [
|
|
18
|
+
"aux_dbase_load",
|
|
19
|
+
"aux_dbase_save",
|
|
20
|
+
"aux_table_hashes_lookup",
|
|
21
|
+
"aux_table_hashes_insert",
|
|
22
|
+
"aux_table_hashes_update",
|
|
23
|
+
"aux_table_coords_lookup",
|
|
24
|
+
]
|
tess/ida/dbase/api.py
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# ----------------------------------------------------------------------
|
|
2
|
+
# Copyright (c) 2024 Rafael Gonzalez.
|
|
3
|
+
#
|
|
4
|
+
# See the LICENSE file for details
|
|
5
|
+
# ----------------------------------------------------------------------
|
|
6
|
+
|
|
7
|
+
# -----------------------
|
|
8
|
+
# Standard Python imports
|
|
9
|
+
# ----------------------
|
|
10
|
+
|
|
11
|
+
import logging
|
|
12
|
+
import sqlite3
|
|
13
|
+
|
|
14
|
+
from typing import Union, Iterator
|
|
15
|
+
from collections.abc import Sequence
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
# -------------------
|
|
19
|
+
# Third party imports
|
|
20
|
+
# -------------------
|
|
21
|
+
|
|
22
|
+
import decouple
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
# --------------
|
|
26
|
+
# local imports
|
|
27
|
+
# -------------
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
# ----------------
|
|
31
|
+
# Module constants
|
|
32
|
+
# ----------------
|
|
33
|
+
|
|
34
|
+
DESCRIPTION = "Database utility to speed up pipeline processing"
|
|
35
|
+
|
|
36
|
+
OptRow = Union[tuple, None]
|
|
37
|
+
|
|
38
|
+
# -----------------------
|
|
39
|
+
# Module global variables
|
|
40
|
+
# -----------------------
|
|
41
|
+
|
|
42
|
+
# get the module logger
|
|
43
|
+
log = logging.getLogger(__name__.split(".")[-2])
|
|
44
|
+
|
|
45
|
+
try:
|
|
46
|
+
theDatabaseFile = decouple.config("DATABASE_FILE")
|
|
47
|
+
|
|
48
|
+
def aux_dbase_load() -> None:
|
|
49
|
+
global theDatabaseFile
|
|
50
|
+
log.info("Opening auxiliar database from %s", theDatabaseFile)
|
|
51
|
+
_ = sqlite3.connect(theDatabaseFile)
|
|
52
|
+
|
|
53
|
+
def aux_dbase_save() -> None:
|
|
54
|
+
pass
|
|
55
|
+
|
|
56
|
+
def aux_table_hashes_insert(data: Sequence[str, str]) -> None:
|
|
57
|
+
global theDatabaseFile
|
|
58
|
+
with sqlite3.connect(theDatabaseFile) as conn:
|
|
59
|
+
conn.execute("INSERT INTO ecsv_t(filename, hash) VALUES(?,?)", data)
|
|
60
|
+
conn.close()
|
|
61
|
+
|
|
62
|
+
def aux_table_hashes_update(data: Sequence[str, str]) -> None:
|
|
63
|
+
global theDatabaseFile
|
|
64
|
+
with sqlite3.connect(theDatabaseFile) as conn:
|
|
65
|
+
conn.execute(
|
|
66
|
+
"UPDATE ecsv_t SET hash = ? WHERE filename = ?", (data[1], data[0])
|
|
67
|
+
)
|
|
68
|
+
conn.close()
|
|
69
|
+
|
|
70
|
+
def aux_table_hashes_lookup(filename: str) -> Iterator[OptRow]:
|
|
71
|
+
global theDatabaseFile
|
|
72
|
+
with sqlite3.connect(theDatabaseFile) as conn:
|
|
73
|
+
cursor = conn.cursor()
|
|
74
|
+
cursor.execute(
|
|
75
|
+
"SELECT filename, hash FROM ecsv_t WHERE filename = ?", (filename,)
|
|
76
|
+
)
|
|
77
|
+
yield cursor.fetchone()
|
|
78
|
+
conn.close()
|
|
79
|
+
|
|
80
|
+
def aux_table_coords_lookup(name: str) -> Iterator[OptRow]:
|
|
81
|
+
global theDatabaseFile
|
|
82
|
+
with sqlite3.connect(theDatabaseFile) as conn:
|
|
83
|
+
cursor = conn.cursor()
|
|
84
|
+
cursor.execute(
|
|
85
|
+
"SELECT phot_name, latitude, longitude, height FROM coords_t WHERE phot_name = ?",
|
|
86
|
+
(name,),
|
|
87
|
+
)
|
|
88
|
+
yield cursor.fetchone()
|
|
89
|
+
conn.close()
|
|
90
|
+
|
|
91
|
+
except decouple.UndefinedValueError:
|
|
92
|
+
|
|
93
|
+
def aux_dbase_load() -> None:
|
|
94
|
+
log.warning(
|
|
95
|
+
"No Auxiliar database was configured. Check 'DATABASE_FILE' environment variable"
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
def aux_dbase_save() -> None:
|
|
99
|
+
log.warning(
|
|
100
|
+
"No Auxiliar database was configured. Check 'DATABASE_FILE' environment variable"
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
def aux_table_hashes_lookup(filename: str) -> Iterator[OptRow]:
|
|
104
|
+
yield None
|
|
105
|
+
|
|
106
|
+
def aux_table_hashes_insert(data: Sequence[str, str]) -> None:
|
|
107
|
+
pass
|
|
108
|
+
|
|
109
|
+
def aux_table_hashes_update(data: Sequence[str, str]) -> None:
|
|
110
|
+
pass
|
|
111
|
+
|
|
112
|
+
def aux_table_coords_lookup(name) -> Iterator[OptRow]:
|
|
113
|
+
yield None
|
tess/ida/dbase/schema.py
ADDED
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
# ----------------------------------------------------------------------
|
|
2
|
+
# Copyright (c) 2024 Rafael Gonzalez.
|
|
3
|
+
#
|
|
4
|
+
# See the LICENSE file for details
|
|
5
|
+
# ----------------------------------------------------------------------
|
|
6
|
+
|
|
7
|
+
# -----------------------
|
|
8
|
+
# Standard Python imports
|
|
9
|
+
# ----------------------
|
|
10
|
+
|
|
11
|
+
import os
|
|
12
|
+
import sys
|
|
13
|
+
import logging
|
|
14
|
+
import sqlite3
|
|
15
|
+
|
|
16
|
+
from argparse import Namespace, ArgumentParser
|
|
17
|
+
|
|
18
|
+
# -------------------
|
|
19
|
+
# Third party imports
|
|
20
|
+
# -------------------
|
|
21
|
+
|
|
22
|
+
import decouple
|
|
23
|
+
|
|
24
|
+
from lica.cli import execute
|
|
25
|
+
from lica.tabulate import paging
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
# --------------
|
|
29
|
+
# local imports
|
|
30
|
+
# -------------
|
|
31
|
+
|
|
32
|
+
from .. import __version__
|
|
33
|
+
|
|
34
|
+
_SQL_PKG = "tess.ida.dbase.sql"
|
|
35
|
+
_SQL_RES = "schema.sql"
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
# Instead of a long, embeddded string, we read it as a Python resource
|
|
39
|
+
if sys.version_info[1] < 11:
|
|
40
|
+
from pkg_resources import resource_string as resource_bytes
|
|
41
|
+
|
|
42
|
+
SCHEMA_SQL_TEXT = resource_bytes(_SQL_PKG, _SQL_RES).decode("utf-8")
|
|
43
|
+
else:
|
|
44
|
+
from importlib.resources import files
|
|
45
|
+
|
|
46
|
+
SCHEMA_SQL_TEXT = files(_SQL_PKG).joinpath(_SQL_RES).read_text()
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
# ----------------
|
|
50
|
+
# Module constants
|
|
51
|
+
# ----------------
|
|
52
|
+
|
|
53
|
+
DESCRIPTION = "Database utility to speed up pipeline processing"
|
|
54
|
+
|
|
55
|
+
# get the module logger
|
|
56
|
+
log = logging.getLogger(__name__.split(".")[-1])
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
# ================================
|
|
60
|
+
# COMMAND LINE INTERFACE FUNCTIONS
|
|
61
|
+
# ================================
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def cli_schema_create(args: Namespace) -> None:
|
|
65
|
+
dbase_path = decouple.config("DATABASE_FILE")
|
|
66
|
+
if os.path.isfile(dbase_path):
|
|
67
|
+
log.info("Deleting auxiliar database: %s", dbase_path)
|
|
68
|
+
os.remove(dbase_path)
|
|
69
|
+
output_dir = os.path.dirname(dbase_path)
|
|
70
|
+
output_dir = os.getcwd() if not output_dir else output_dir
|
|
71
|
+
os.makedirs(output_dir, exist_ok=True)
|
|
72
|
+
log.info("Creating SQLite Schema on %s", dbase_path)
|
|
73
|
+
try:
|
|
74
|
+
with sqlite3.connect(dbase_path) as connection:
|
|
75
|
+
connection.executescript(SCHEMA_SQL_TEXT)
|
|
76
|
+
except sqlite3.OperationalError as e:
|
|
77
|
+
log.error("Error creating the database: %s", e)
|
|
78
|
+
finally:
|
|
79
|
+
connection.close()
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def cli_coords_add(args: Namespace) -> None:
|
|
83
|
+
data = (args.name, args.latitude, args.longitude, args.height)
|
|
84
|
+
dbase_path = decouple.config("DATABASE_FILE")
|
|
85
|
+
try:
|
|
86
|
+
with sqlite3.connect(dbase_path) as connection:
|
|
87
|
+
connection.execute(
|
|
88
|
+
"INSERT OR IGNORE INTO coords_t(phot_name, latitude, longitude, height) VALUES(?,?,?,?)",
|
|
89
|
+
data,
|
|
90
|
+
)
|
|
91
|
+
except Exception as e:
|
|
92
|
+
log.error(e)
|
|
93
|
+
connection.close()
|
|
94
|
+
log.info(
|
|
95
|
+
"[%s] Added coordinates entry: Lat = %s, Long = %s, Height = %s",
|
|
96
|
+
args.name,
|
|
97
|
+
args.latitude,
|
|
98
|
+
args.longitude,
|
|
99
|
+
args.height,
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def cli_coords_update(args: Namespace) -> None:
|
|
104
|
+
dbase_path = decouple.config("DATABASE_FILE")
|
|
105
|
+
setters = list()
|
|
106
|
+
data = {"name": args.name}
|
|
107
|
+
if args.latitude is not None:
|
|
108
|
+
setters.append("latitude = :latitude")
|
|
109
|
+
data["latitude"] = args.latitude
|
|
110
|
+
if args.longitude is not None:
|
|
111
|
+
setters.append("longitude = :longitude")
|
|
112
|
+
data["longitude"] = args.longitude
|
|
113
|
+
if args.height is not None:
|
|
114
|
+
setters.append("height = :height")
|
|
115
|
+
data["height"] = args.height
|
|
116
|
+
if not setters:
|
|
117
|
+
log.error("at least one argument must be given")
|
|
118
|
+
return
|
|
119
|
+
sql = "UPDATE coords_t SET " + ", ".join(setters) + " WHERE phot_name = :name"
|
|
120
|
+
try:
|
|
121
|
+
with sqlite3.connect(dbase_path) as connection:
|
|
122
|
+
connection.execute(sql, data)
|
|
123
|
+
except Exception as e:
|
|
124
|
+
log.error(e)
|
|
125
|
+
connection.close()
|
|
126
|
+
log.info("[%s] Modified coordinates entry", args.name)
|
|
127
|
+
log.warning(
|
|
128
|
+
"[%s] Sun/Moon data no longer valid. Delete your %s ECSV files and re-run the pipeline",
|
|
129
|
+
args.name,
|
|
130
|
+
args.name,
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def cli_coords_delete(args: Namespace) -> None:
|
|
135
|
+
dbase_path = decouple.config("DATABASE_FILE")
|
|
136
|
+
data = (args.name,)
|
|
137
|
+
try:
|
|
138
|
+
with sqlite3.connect(dbase_path) as connection:
|
|
139
|
+
connection.execute("DELETE FROM coords_t WHERE phot_name = ?", data)
|
|
140
|
+
except Exception as e:
|
|
141
|
+
log.error(e)
|
|
142
|
+
connection.close()
|
|
143
|
+
log.info("[%s] Deleted coordinates entry", args.name)
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def cli_coords_list(args: Namespace) -> None:
|
|
147
|
+
dbase_path = decouple.config("DATABASE_FILE")
|
|
148
|
+
data = (args.name,)
|
|
149
|
+
try:
|
|
150
|
+
with sqlite3.connect(dbase_path) as connection:
|
|
151
|
+
cursor = connection.cursor()
|
|
152
|
+
if args.name:
|
|
153
|
+
sql = "SELECT phot_name, latitude, longitude, height FROM coords_t WHERE phot_name = ?"
|
|
154
|
+
cursor.execute(sql, data)
|
|
155
|
+
else:
|
|
156
|
+
sql = "SELECT phot_name, latitude, longitude, height FROM coords_t ORDER BY phot_name"
|
|
157
|
+
cursor.execute(sql)
|
|
158
|
+
paging(cursor, ("NAME", "LONGITUDE", "LATITUDE", "HEIGHT"))
|
|
159
|
+
except Exception as e:
|
|
160
|
+
log.error(e)
|
|
161
|
+
connection.close()
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def add_args(parser: ArgumentParser) -> ArgumentParser:
|
|
165
|
+
# Now parse the application specific parts
|
|
166
|
+
subparser = parser.add_subparsers(dest="command")
|
|
167
|
+
parser_schema = subparser.add_parser(
|
|
168
|
+
"schema", help="Administrative database schema"
|
|
169
|
+
)
|
|
170
|
+
parser_coords = subparser.add_parser("coords", help="Coordinates Table management")
|
|
171
|
+
|
|
172
|
+
subparser = parser_schema.add_subparsers(dest="subcommand")
|
|
173
|
+
sch_cre = subparser.add_parser( # noqa: F841
|
|
174
|
+
"create", help="Create AstroPy tables and serialize to ECSV files"
|
|
175
|
+
)
|
|
176
|
+
|
|
177
|
+
subparser = parser_coords.add_subparsers(dest="subcommand")
|
|
178
|
+
loc_add = subparser.add_parser("add", help="Add coordinates to a photometer")
|
|
179
|
+
loc_add.add_argument(
|
|
180
|
+
"-n", "--name", type=str, required=True, help="Photometer name"
|
|
181
|
+
)
|
|
182
|
+
loc_add.add_argument(
|
|
183
|
+
"-la", "--latitude", type=float, required=True, help="Latitude [degrees]"
|
|
184
|
+
)
|
|
185
|
+
loc_add.add_argument(
|
|
186
|
+
"-lo", "--longitude", type=float, required=True, help="Longitude [degrees]"
|
|
187
|
+
)
|
|
188
|
+
loc_add.add_argument(
|
|
189
|
+
"-he",
|
|
190
|
+
"--height",
|
|
191
|
+
type=float,
|
|
192
|
+
default=0.0,
|
|
193
|
+
help="Height above sea level [m] (default: %(default)s)",
|
|
194
|
+
)
|
|
195
|
+
loc_del = subparser.add_parser("delete", help="Remove coordinates from photometer")
|
|
196
|
+
loc_del.add_argument(
|
|
197
|
+
"-n", "--name", type=str, required=True, help="Photometer name"
|
|
198
|
+
)
|
|
199
|
+
loc_del = subparser.add_parser("list", help="List photometer coordinates")
|
|
200
|
+
loc_del.add_argument(
|
|
201
|
+
"-n", "--name", type=str, default=None, help="Optional photometer name"
|
|
202
|
+
)
|
|
203
|
+
loc_upd = subparser.add_parser("update", help="Update coordinates to photometer")
|
|
204
|
+
loc_upd.add_argument(
|
|
205
|
+
"-n", "--name", type=str, required=True, help="Photometer name"
|
|
206
|
+
)
|
|
207
|
+
loc_upd.add_argument(
|
|
208
|
+
"-la", "--latitude", type=float, default=None, help="Latitude [degrees]"
|
|
209
|
+
)
|
|
210
|
+
loc_upd.add_argument(
|
|
211
|
+
"-lo", "--longitude", type=float, default=None, help="Longitude [degrees]"
|
|
212
|
+
)
|
|
213
|
+
loc_upd.add_argument(
|
|
214
|
+
"-he",
|
|
215
|
+
"--height",
|
|
216
|
+
type=float,
|
|
217
|
+
default=None,
|
|
218
|
+
help="Height above sea level [m] (default: %(default)s)",
|
|
219
|
+
)
|
|
220
|
+
return parser
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
CMD_TABLE = {
|
|
224
|
+
"schema_create": cli_schema_create,
|
|
225
|
+
"coords_add": cli_coords_add,
|
|
226
|
+
"coords_delete": cli_coords_delete,
|
|
227
|
+
"coords_update": cli_coords_update,
|
|
228
|
+
"coords_list": cli_coords_list,
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
def cli_schema(args: Namespace) -> None:
|
|
233
|
+
"""Create an empty able serializable to ECSV file"""
|
|
234
|
+
try:
|
|
235
|
+
args.subcommand
|
|
236
|
+
except AttributeError:
|
|
237
|
+
log.error("Missing subcommand fro command (%s)", args.command)
|
|
238
|
+
else:
|
|
239
|
+
func = CMD_TABLE[f"{args.command}_{args.subcommand}"]
|
|
240
|
+
func(args)
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
def main() -> None:
|
|
244
|
+
execute(
|
|
245
|
+
main_func=cli_schema,
|
|
246
|
+
add_args_func=add_args,
|
|
247
|
+
name=__name__,
|
|
248
|
+
version=__version__,
|
|
249
|
+
description=DESCRIPTION,
|
|
250
|
+
)
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
if __name__ == "__main__":
|
|
254
|
+
main()
|
|
File without changes
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
------------------------------------------------------------
|
|
2
|
+
-- TESS IDA TOOLS ADMINISTRATIVE DATA MODEL
|
|
3
|
+
------------------------------------------------------------
|
|
4
|
+
|
|
5
|
+
BEGIN TRANSACTION;
|
|
6
|
+
|
|
7
|
+
-- --------------------------------------------------------
|
|
8
|
+
-- Optimizing ECSV computation when including Sun/Moon data
|
|
9
|
+
-- --------------------------------------------------------
|
|
10
|
+
|
|
11
|
+
CREATE TABLE IF NOT EXISTS ecsv_t
|
|
12
|
+
(
|
|
13
|
+
filename TEXT NOT NULL, -- without path (i.e stars1-2024-01.dat)
|
|
14
|
+
hash TEXT NOT NULL, -- printable version of MD5 hash
|
|
15
|
+
UNIQUE(hash), -- No two files should have the same hash
|
|
16
|
+
PRIMARY KEY(filename)
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
-- -----------------
|
|
20
|
+
-- Coordinates table
|
|
21
|
+
-- -----------------
|
|
22
|
+
|
|
23
|
+
CREATE TABLE IF NOT EXISTS coords_t
|
|
24
|
+
(
|
|
25
|
+
phot_name TEXT NOT NULL,
|
|
26
|
+
longitude REAL NOT NULL, -- [degrees]
|
|
27
|
+
latitude REAL NOT NULL, -- [degrees]
|
|
28
|
+
height REAL NOT NULL, -- meters above sea level [meters]
|
|
29
|
+
PRIMARY KEY(phot_name)
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
COMMIT;
|