Skip to content

Commit

Permalink
add site generation from astropy and user input
Browse files Browse the repository at this point in the history
  • Loading branch information
emirkmo committed Feb 8, 2023
1 parent b3eb4b5 commit 0ea4179
Showing 1 changed file with 33 additions and 4 deletions.
37 changes: 33 additions & 4 deletions flows/instruments/sites.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,47 @@
from dataclasses import dataclass
from astropy.coordinates import EarthLocation
import astropy.units as u
from typing import Optional
from tendrils import api

@dataclass
class Site:
siteid: int
sitename: str
longtitude: float
longitude: float
latitude: float
elevation: float
earth_location: EarthLocation
earth_location: Optional[EarthLocation] = None
site_keyword: Optional[str] = None

def __post_init__(self):
if self.earth_location is None:
return
self.earth_location = EarthLocation(
lat=self.latitude*u.deg,
lon=self.longitude*u.deg,
height=self.elevation*u.m
)

@classmethod
def get_site(cls, siteid: int) -> 'Site':
return cls(**api.get_site(siteid))
def from_flows(cls, siteid: int) -> 'Site':
return cls(**api.get_site(siteid))

@classmethod
def from_astropy(cls, sitename: str) -> 'Site':
loc = EarthLocation.of_site(sitename)
return cls(siteid=999, sitename=sitename,
longitude=loc.long.value, latitude=loc.lat.value,
elevation=loc.height.value, earth_location=loc)

@classmethod
def from_query(cls) -> 'Site':
sitename = input('Enter a site name for logging: ')
longitude = float(input('Enter longitude in degrees: '))
lat = float(input('Enter latitude in degrees: '))
elevation = float(input('Enter elevation in meters: '))
siteid = 1000 # hardcoded for user defined site
return cls(siteid=999, sitename=sitename,
longitude=longitude, latitude=lat,
elevation=elevation)

0 comments on commit 0ea4179

Please sign in to comment.