diff --git a/socat/ingest/textingest.py b/socat/ingest/textingest.py index 4196483..d715393 100644 --- a/socat/ingest/textingest.py +++ b/socat/ingest/textingest.py @@ -1,7 +1,7 @@ import pickle from pathlib import Path -import numpy as np +import pandas as pd from astropy import units as u from astropy.coordinates import ICRS @@ -28,25 +28,10 @@ def ingest_text_file( number_of_sources: int The number of sources added to the catalog. """ - - table = np.loadtxt( - filename, - dtype=[("ra", "f8"), ("dec", "f8"), ("name", "S20"), ("monitored", "S20")], - skiprows=1, - ) - names = [ - name.decode("utf-8") if isinstance(name, (bytes, np.bytes_)) else name - for name in table["name"] - ] - table["name"] = names - - table["monitored"] = [ - bool(monitored.decode("utf-8")) for monitored in table["monitored"] - ] - + table = pd.read_csv(filename) number_of_sources = 0 - for row in table: + for index, row in table.iterrows(): client.create_source( position=ICRS( ra=float(row["ra"]) * u.deg, diff --git a/tests/test_ingest.py b/tests/test_ingest.py index 01da93d..0d194c6 100644 --- a/tests/test_ingest.py +++ b/tests/test_ingest.py @@ -5,6 +5,7 @@ import os import numpy as np +import pandas as pd from astropy import units as u from astropy.coordinates import ICRS from astropy.io import fits @@ -44,15 +45,16 @@ def text_catalog(tmp_path): n_sources = 10 data = np.zeros( n_sources, - dtype=[("ra", "f8"), ("dec", "f8"), ("name", "U20"), ("monitored", "S20")], + dtype=[("ra", "f8"), ("dec", "f8"), ("name", "U20"), ("monitored", "U20")], ) data["ra"] = np.random.uniform(0, 360, n_sources) data["dec"] = np.random.uniform(-90, 90, n_sources) data["name"] = np.array([f"Source_{i}" for i in range(n_sources)], dtype="U20") data["monitored"] = np.random.choice(["True", "False"], size=n_sources) + data = pd.DataFrame(data) text_path = tmp_path / "text_catalog.txt" - np.savetxt(text_path, data, fmt="%f %f %s %s", header="ra dec name monitored") + data.to_csv(text_path, index=False) yield text_path