From 5181bab22d0f92309b95f70a9fe799adfb97aab1 Mon Sep 17 00:00:00 2001 From: LukasK13 Date: Tue, 14 Apr 2020 12:49:51 +0200 Subject: [PATCH] File reader moved to SpectraQty --- esbo_etc/classes/target/FileTarget.py | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/esbo_etc/classes/target/FileTarget.py b/esbo_etc/classes/target/FileTarget.py index c44314a..0593998 100644 --- a/esbo_etc/classes/target/FileTarget.py +++ b/esbo_etc/classes/target/FileTarget.py @@ -22,22 +22,7 @@ class FileTarget(ATarget): `astropy.io.ascii.read(). If the file doesn't provide units via astropy's enhanced CSV format, the units will be read from the column headers or otherwise assumed to be *nm* and *W / m^2 / nm*. """ - # Read the file - data = ascii.read(file) - # Check if units are given - if data[data.colnames[0]].unit is None: - # Convert values to float - data[data.colnames[0]] = list(map(float, data[data.colnames[0]])) - data[data.colnames[1]] = list(map(float, data[data.colnames[1]])) - # Check if units are given in column headers - if all([re.search("\\[.+\\]", x) for x in data.colnames]): - # Extract units from headers and apply them on the columns - units = [u.Unit(re.findall("(?<=\\[).+(?=\\])", x)[0]) for x in data.colnames] - data[data.colnames[0]].unit = units[0] - data[data.colnames[1]].unit = units[1] - # Use default units - else: - data[data.colnames[0]].unit = u.nm - data[data.colnames[1]].unit = u.W / (u.m ** 2 * u.nm) - # Create a spectral quantity from the data and initialize the super class - super().__init__(SpectralQty(data[data.colnames[0]].quantity, data[data.colnames[1]].quantity)) + # Create spectral quantity from file + sfd = SpectralQty.fromFile(file, u.nm, u.W / (u.m ** 2 * u.nm)) + # Initialize the super class + super().__init__(sfd)