Allow frequencies to be used in input files

This commit is contained in:
Lukas Klass 2020-10-06 12:15:06 +02:00
parent eb0bd71813
commit b50f942f83
2 changed files with 11 additions and 2 deletions

View File

@ -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)] |

View File

@ -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)):
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)):