From 0b16d7e009971b092cf6da04aeca85021d453684 Mon Sep 17 00:00:00 2001 From: Michael Coughlin Date: Sat, 27 Apr 2024 21:41:37 -0500 Subject: [PATCH] more path stuff --- gwemopt/catalogs/glade.py | 4 ++-- gwemopt/catalogs/nedlvs.py | 10 ++++++---- gwemopt/catalogs/twomrs.py | 4 ++-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/gwemopt/catalogs/glade.py b/gwemopt/catalogs/glade.py index b647154..c7aa93b 100644 --- a/gwemopt/catalogs/glade.py +++ b/gwemopt/catalogs/glade.py @@ -34,9 +34,9 @@ def download_catalog(self): df.rename(columns=key_map, inplace=True) df["PGC"] = df["PGC"].astype(str) cat = Table.from_pandas(df) - write_table_hdf5(cat, save_path, path="df") + write_table_hdf5(cat, str(save_path), path="df") def load_catalog(self) -> pd.DataFrame: - cat = read_table_hdf5(self.get_catalog_path(), path="df") + cat = read_table_hdf5(str(self.get_catalog_path()), path="df") df = cat.to_pandas() return df diff --git a/gwemopt/catalogs/nedlvs.py b/gwemopt/catalogs/nedlvs.py index fdb5ed2..434ce4c 100644 --- a/gwemopt/catalogs/nedlvs.py +++ b/gwemopt/catalogs/nedlvs.py @@ -4,6 +4,8 @@ import numpy as np import pandas as pd from astropy.io import fits +from astropy.io.misc.hdf5 import read_table_hdf5, write_table_hdf5 +from astropy.table import Table from gwemopt.catalogs.base_catalog import BaseCatalog @@ -41,14 +43,14 @@ def download_catalog(self): inplace=True, ) df = df[df["redshift"] > 0] - - df.to_hdf(self.get_catalog_path(), key="df") + cat = Table.from_pandas(df) + write_table_hdf5(cat, str(self.get_catalog_path()), path="df") temp_path.unlink() def get_temp_path(self): return self.get_catalog_path(filetype="fits").with_stem(f"temp_{self.name}") def load_catalog(self) -> pd.DataFrame: - df = pd.read_hdf(self.get_catalog_path(), key="df") - + cat = read_table_hdf5(str(self.get_catalog_path()), path="df") + df = cat.to_pandas() return df diff --git a/gwemopt/catalogs/twomrs.py b/gwemopt/catalogs/twomrs.py index 4eb83aa..8fb7ecc 100644 --- a/gwemopt/catalogs/twomrs.py +++ b/gwemopt/catalogs/twomrs.py @@ -46,9 +46,9 @@ def download_catalog(self): mask = mk < mk_max df = df[mask] cat = Table.from_pandas(df) - write_table_hdf5(cat, save_path, path="df") + write_table_hdf5(cat, str(save_path), path="df") def load_catalog(self) -> pd.DataFrame: - cat = read_table_hdf5(self.get_catalog_path(), path="df") + cat = read_table_hdf5(str(self.get_catalog_path()), path="df") df = cat.to_pandas() return df