From 2f5a670fdaff8a61fbc2c054954f9bbec0e91c22 Mon Sep 17 00:00:00 2001 From: Sujay Shankar Date: Wed, 31 Jan 2024 23:36:57 -0500 Subject: [PATCH] Add parquet read in --- src/gollum/V2/phoenix.py | 24 +++++++++++++----------- src/gollum/V2/simple_spectrum.py | 8 +++++--- test.parquet.gz | Bin 0 -> 2481 bytes 3 files changed, 18 insertions(+), 14 deletions(-) create mode 100644 test.parquet.gz diff --git a/src/gollum/V2/phoenix.py b/src/gollum/V2/phoenix.py index 70cb748..225ff33 100644 --- a/src/gollum/V2/phoenix.py +++ b/src/gollum/V2/phoenix.py @@ -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): @@ -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()') - 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) diff --git a/src/gollum/V2/simple_spectrum.py b/src/gollum/V2/simple_spectrum.py index f7be245..d89b4a7 100644 --- a/src/gollum/V2/simple_spectrum.py +++ b/src/gollum/V2/simple_spectrum.py @@ -151,14 +151,14 @@ 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 ---------- @@ -166,3 +166,5 @@ def configure(cls, 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() \ No newline at end of file diff --git a/test.parquet.gz b/test.parquet.gz new file mode 100644 index 0000000000000000000000000000000000000000..9c0962bce5fdd1ab7cf4d996ea808d635f5913f4 GIT binary patch literal 2481 zcmcguOK;*<6uwC)Mb#|QYK%aNRAi|rRT&Bd(lDAXu1z3jfDBAx9&JVZf|$8B3>b_P zMar&Ht8PZ~7iQOG_uX_?%^&Eli*BoS+f~oK9lM_u>Wd)%Zzx{gr9%!R4*0(rcID`C~;SjgIn@A*Lk#sy0izMQ(gWJcP zFX#{cvKIViJ^E!d@L!ULV}KEH>lDByJOIgEnDt8(-F|)V)!NtJ{rt&l%p2fOS17PH z+aQX0SqjR3!Ti@dx0v5=w@q6&rfp(O4AM@t+jDq-@M~1~WY8ZN)Oc#U2v^79GpLU!rY=$HS9;hji*C0frjt;+Tk7GF zl*8k)_{?01x#ZDu2-Qy|IEqT;96FLo##a_k#d~WDr(lz94!e|JD@!o@=h;9&n7* zgQQM*YVH&X^kkx$(1QcuxIj$J%6kUI0DU*=c~7&lJFJIxi)eObpr+ESzvZJU@SXM~ zoAv9qMoadz6q%?rrYL!(-u}1(eWhod9eFGq(;b|DjLSzbWP7mL7hz~H7TJ)nEq%oT z-2xA*xS^v|%3b-xq%eC-hZE+h2~&h&fY@AJ&#!<_sRV`(7RygJ7|ZnbIM;N`IeLz& z