From b50f942f83b09ae4ebea4b5a1c6d57f58c000371 Mon Sep 17 00:00:00 2001 From: LukasK13 Date: Tue, 6 Oct 2020 12:15:06 +0200 Subject: [PATCH] Allow frequencies to be used in input files --- docs/source/configuration/configuration.rst | 3 ++- esbo_etc/lib/helpers.py | 10 +++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/docs/source/configuration/configuration.rst b/docs/source/configuration/configuration.rst index 0d0c718..a1e2bc6 100644 --- a/docs/source/configuration/configuration.rst +++ b/docs/source/configuration/configuration.rst @@ -71,7 +71,8 @@ Reading CSV-Files The format of a file has to be either structured text (e.g. CSV) or astropy ECSV. The format of the file will be automatically detected during read. In case of structured text, the units of the columns have to be defined in the column header within square brackets -(e.g. "wavelength [nm]"). The file must contain two columns with units: wavelength and the spectral quantity: +(e.g. "wavelength [nm]"). The file must contain two columns with units: wavelength/frequency and the spectral quantity. +The first column can be either a wavelength or a frequency. +-----------------+------------------------------+ | wavelength [nm] | emission [W/(nm\*m^2\*sr)] | diff --git a/esbo_etc/lib/helpers.py b/esbo_etc/lib/helpers.py index 21ef31c..9b65a19 100644 --- a/esbo_etc/lib/helpers.py +++ b/esbo_etc/lib/helpers.py @@ -103,7 +103,15 @@ def readCSV(file: str, units: list = None, format_: str = None) -> Table: data[data.colnames[i]].unit = units_header[i] if units is not None and len(units) == len(data.columns): for i in range(len(data.columns)): - data[data.colnames[i]] = data[data.colnames[i]].to(units[i]) + if data[data.colnames[i]].unit.is_equivalent(u.Hz) and units[i].is_equivalent(u.m): + data[data.colnames[i]] = data[data.colnames[i]].to(units[i], equivalencies=u.spectral()) + else: + try: + data[data.colnames[i]] = data[data.colnames[i]].to(units[i]) + except: + data[data.colnames[i]] = data[data.colnames[i]].to(units[i], + equivalencies=u.spectral_density( + data[data.colnames[0]])) # Use default units elif units is not None and len(units) == len(data.columns): for i in range(len(data.columns)):