diff --git a/stellarphot/io/aavso.py b/stellarphot/io/aavso.py index 66d7b153..99b6737c 100644 --- a/stellarphot/io/aavso.py +++ b/stellarphot/io/aavso.py @@ -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 @@ -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 \ No newline at end of file + 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()) \ No newline at end of file diff --git a/stellarphot/io/tests/test_aavso.py b/stellarphot/io/tests/test_aavso.py index 7bd01682..27a8cb67 100644 --- a/stellarphot/io/tests/test_aavso.py +++ b/stellarphot/io/tests/test_aavso.py @@ -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' \ No newline at end of file + aef.type = 'STD' + + +def test_writing(): + aef = AAVSOExtendedFileFormat(DEFAULT_OBSCODE) + aef.write('foo.csv') + assert 0 \ No newline at end of file