Skip to content

Commit

Permalink
Start write method
Browse files Browse the repository at this point in the history
  • Loading branch information
mwcraig committed Jul 26, 2023
1 parent 37dd804 commit 8586223
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 5 deletions.
48 changes: 45 additions & 3 deletions stellarphot/io/aavso.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Class to representa file in AAVSO extended format
from dataclasses import dataclass
from dataclasses import dataclass, field
from typing import Union
from pathlib import Path
from importlib import resources
import yaml

from astropy.table import Table

Expand All @@ -16,8 +20,46 @@ class AAVSOExtendedFileFormat:
delim: str = ","
date: str = 'HJD'
obstype: str = 'CCD'
data: Table = Table()
variable_data: Table = field(default_factory=Table)
check_data: Table = field(default_factory=Table)
comparison_data: Union[Table, None] = None
ensemble: bool = False

@property
def type(self):
return self._type
return self._type

@property
def software(self):
return self._software

def set_data(self, destination, data,
time='time', mag='mag', error='err', airmass='airmass'):
"""
Set data for each thingy
"""
# Standardize column order

standard_data = {
time: data[time],
airmass: data[airmass],
mag: data[mag],
error: data[error],
}
standard_data = Table(standard_data)
if destination == "variable":
self.variable_data = standard_data
elif destination == "check":
self.check_data = standard_data
elif destination == "comparison":
if self.ensemble:
raise ValueError("Cannot set comparison data for ensemble magnitudeas")
self.comparison_data = standard_data

def write(self, file):
p = Path(file)

# Make a table
table_description = resources.read_text('stellarphot.io', 'aavso_submission_schema.yml')
table_structure = yaml.safe_load(table_description)
print(table_structure['data'].keys())
10 changes: 8 additions & 2 deletions stellarphot/io/tests/test_aavso.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,16 @@ def test_no_obscode_raises_error():
def test_default_values():
aef = AAVSOExtendedFileFormat(DEFAULT_OBSCODE)
assert aef.delim == ","
assert len(aef.data) == 0
assert len(aef.variable_data) == 0


def test_setting_type_raises_error():
aef = AAVSOExtendedFileFormat(DEFAULT_OBSCODE)
with pytest.raises(AttributeError, match="can't set attribute"):
aef.type = 'STD'
aef.type = 'STD'


def test_writing():
aef = AAVSOExtendedFileFormat(DEFAULT_OBSCODE)
aef.write('foo.csv')
assert 0

0 comments on commit 8586223

Please sign in to comment.