Skip to content

Commit

Permalink
Add parquet read in
Browse files Browse the repository at this point in the history
  • Loading branch information
Sujay-Shankar committed Feb 1, 2024
1 parent d36ff54 commit 2f5a670
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
24 changes: 13 additions & 11 deletions src/gollum/V2/phoenix.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from gollum.V2.simple_spectrum import SimpleSpectrum

import pandas as pd

from dataclasses import dataclass
from dotenv import get_key
from pandas import read_parquet

@dataclass(slots=True)
class PHOENIXSpectrum(SimpleSpectrum):
Expand Down Expand Up @@ -31,17 +30,20 @@ class PHOENIXSpectrum(SimpleSpectrum):
Z: float
alpha: float

def __init__(self, teff: int, logg: float, Z: float, alpha: float, extent: tuple[float, float] = None, **kwargs):
self.teff, self.logg, self.Z, self.alpha = teff, logg, Z, alpha
def __init__(self, teff: int = None, logg: float = None, Z: float = None, alpha: float = None, extent: tuple[float, float] = None, **kwargs):
self.teff, self.logg, self.Z, self.alpha = point = teff, logg, Z, alpha
if kwargs:
super(PHOENIXSpectrum, self).__init__(**kwargs)
return
if not self._env().exists() or not (path := get_key(self._env(), 'PHOENIX_PATH')):
self._env().touch()
raise RuntimeError('PHOENIX data path not set. Set it with: PHOENIXSpectrum.configure(<path>)')
super(PHOENIXSpectrum, self).__init__([10, 20, 30], [40, 50, 60])

path = get_key(self._env(), 'PHOENIX_PATH') or 'zenodo link'
df = read_parquet(path, 'pyarrow', [str(point)], filters=[('index', '>=', extent[0]), ('index', '<=', extent[1])] if extent else None)
super(PHOENIXSpectrum, self).__init__(df.index, df[str(point)])


import pandas as pd
pd.DataFrame(index=[1, 2, 3], data={'(6000, 4.5, 0.0, 0.0)': [4, 5, 6]}).to_parquet('test.parquet.gz', compression='gzip')

x = PHOENIXSpectrum(6000, 4.5, 0.0, 0.0)
print(x)

x = PHOENIXSpectrum(1, 2, 3, 7, (4, 5))
y = PHOENIXSpectrum(1, 2, 3, 7, wavelength=[1, 2, 3], flux=[4, 5, 6])
print(x + y)
8 changes: 5 additions & 3 deletions src/gollum/V2/simple_spectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,18 +151,20 @@ def blackbody(spectral_axis: ArrayLike, T: float):
@staticmethod
def _env():
'''
[ACCESS] The path to gollum's environment file.
[ACCESS] The path to `gollum`'s environment file.
'''
return Path(getfile(SimpleSpectrum)).parent / '.env'

@classmethod
def configure(cls, data_path: str):
def _configure(cls, data_path: str):
'''
[SETUP] Configure gollum's environment for a model grid.
[SETUP] Configure `gollum`'s environment for a model grid.
Parameters
----------
`data_path: str`
The path to the data directory.
'''
set_key(cls._env(), cls.__name__.replace('Spectrum', '_PATH'), str(Path(data_path).expanduser().resolve()))

SimpleSpectrum._env().touch()
Binary file added test.parquet.gz
Binary file not shown.

0 comments on commit 2f5a670

Please sign in to comment.