-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add site generation from astropy and user input
- Loading branch information
Showing
1 changed file
with
33 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|