Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
gnthibault committed Aug 25, 2023
1 parent 70a178c commit a3c7fa8
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 65 deletions.
55 changes: 0 additions & 55 deletions apps/prototyping/database/datamodel.py

This file was deleted.

11 changes: 9 additions & 2 deletions apps/prototyping/database/test_base_read.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from Base.Base import Base

from utils.database import FileDB, create_storage_obj
#from utils.datamodel import

b = Base()
print(b.db.collection_names)
Expand All @@ -18,7 +19,13 @@
]
"""

# Test actual DB
latest_observation = b.db.get_current(collection="observations")
latest_calibration = b.db.get_current(collection='calibrations')

# Test DB creation and usage
file_db = FileDB()

def find(self, collection, obj_id):
# test storage object (unstructured)
obj = create_storage_obj()
print(obj)
15 changes: 7 additions & 8 deletions utils/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
import weakref

# Local
from Service.HostTimeService import HostTimeService
from utils import serializers as json_util
from utils.config import load_config
from Service.HostTimeService import HostTimeService
#from utils.datamodel import

class AbstractDB(metaclass=abc.ABCMeta):
def __init__(self, db_name=None, collection_names=list(), logger=None,
Expand Down Expand Up @@ -406,8 +407,7 @@ def insert(self, collection, obj):
json_util.dumps_file(collection_fn, obj)
return obj_id
except Exception as e:
self._warn('Problem inserting object into collection: '
'{}, {!r}'.format(e, obj))
self._warn(f"Problem inserting object {obj} into collection: {collection}: {e}")
return None

@thread_safe
Expand All @@ -416,7 +416,7 @@ def get_current(self, collection):
try:
return json_util.loads_file(current_fn)
except FileNotFoundError as e:
self._warn("No record found for {}".format(collection))
self._warn(f"No record found for collection {collection}")
return None

@thread_safe
Expand All @@ -435,18 +435,17 @@ def find(self, collection, obj_id):

@thread_safe
def clear_current(self, type):
current_f = os.path.join(self._storage_dir,
'current_{}.json'.format(type))
current_f = os.path.join(self._storage_dir, f"current_{type}.json")
try:
os.remove(current_f)
except FileNotFoundError as e:
pass

def get_file(self, collection, permanent=True):
if permanent:
name = '{}.json'.format(collection)
name = f'{collection}.json'
else:
name = 'current_{}.json'.format(collection)
name = f'current_{collection}.json'
return os.path.join(self._storage_dir, name)

def _make_id(self):
Expand Down
85 changes: 85 additions & 0 deletions utils/datamodel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
from datetime import datetime
from enum import Enum
from typing import List, Optional
from pydantic import BaseModel

class Sequence(BaseModel):
id: str

class SequenceType(str, Enum):
SPECTRO_SEQUENCE = "spectro_sequence"
IMAGING_SEQUENCE = "imaging_sequence"
CALIBRATION_SEQUENCE = "calibration_sequence"

class SequenceImageType(str, Enum):
POINTING = "pointing"
ADJUST_POINTING = "adjust_pointing"
FIELD_MONITORING = "field_monitoring"

# Generic calib
OFFSET_CALIB = "offset_calib"
DARK_CALIB = "dark_calib"

# Imaging stuff
FIELD_SCIENCE = "field_science"
FLAT_CALIB = "flat_calib"

# Spectro stuff
SPECTRO_SCIENCE = "spectro_science"
SPECTRO_FLAT_CALIB = "spectro_flat_calib"
SPECTRO_SPECTRAL_CALIB = "spectro_spectral_calib"

class Image(BaseModel):
image_id: str # Altair AA183MPRO_012345_20230822T220825
camera_name: str # Altair AA183MPRO
camera_uid: str # 012345
file_path: str # /var/RemoteObservatory/images/targets/Alioth/012345/20230822T220718/pointing01.fits

creator: str # RemoteObservatory_0.0.0
observer: str # Remote observatory
elevation: float # 650.0000000006121
latitude: float # 43.93499999999999
longitude: float # 5.710999999999999

start_time: str # 20230822T220825
exp_time: float # 10.0
temperature_degC: float # 15
gain: float # 150 #TODO WARNING OBSERVATION
offset: float # 30 #TODO WARNING OBSERVATION
filter: str # no-filter

class SequenceImage(Image):
seq_type: SequenceImageType # POINTING: bool True / calibration_name': 'dark',
sequence_id: str # 20230822T220718
seq_time: str # 20230822T220718

number_exposure: int # 2
time_per_exposure: float # 5.0
total_exposure: float # 10.0
current_exp: int # 0

class ObservationSequenceImage(SequenceImage):
observation_id: str # Alioth_8781831698517
target_name: str # Alioth
airmass: float # 2.468465912826544
moon_fraction: float # 0.34879647646572376
moon_separation: float # 125.02644862252754
ra_mnt: float # 193.50543122078386
ha_mnt: float # 12.900362081385593
dec_mnt: float # 55.959837368488195
track_mode_mnt: str # TRACK_SIDEREAL
slew_rate_mnt: str # 2x
guide_rate_ns_mnt: float # 0.5
guide_rate_we_mnt: float # 0.5
equinox: float # 2000.0
field_name: str # Alioth
field_ra: float # 193.50728958333332
field_ha: float # 12.900485972222224
field_dec: float # 55.95982277777778
merit: float # 1.0
priority: float # 0

# WARNING FOR CALIBRATION
# sequence_id: None

#erdantic erdantic.examples.pydantic.Party -t erdantic erdantic.examples.pydantic.Quest -o party.png

0 comments on commit a3c7fa8

Please sign in to comment.