Skip to content

Commit ddff59f

Browse files
keflavichbsipocz
authored andcommitted
docuemntation cleanup, fix to some parameter validation
1 parent 94f3c79 commit ddff59f

File tree

2 files changed

+112
-115
lines changed

2 files changed

+112
-115
lines changed

astroquery/splatalogue/core.py

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ class SplatalogueClass(BaseQuery):
4646
# global constant, not user-configurable
4747
ALL_LINE_LISTS = ('LovasNIST', 'SLAIM', 'JPL', 'CDMS', 'ToyaMA', 'OSU',
4848
'TopModel', 'Recombination', 'RFI')
49+
VALID_LINE_STRENGTHS = ('CDMSJPL', 'SijMu2', 'Sij', 'Aij', 'LovasAST')
50+
VALID_ENERGY_LEVELS = {'One': 'EL_cm-1',
51+
'Two': 'EL_K',
52+
'Three': 'EU_cm-1',
53+
'Four': 'EU_K'}
54+
VALID_ENERGY_TYPES = ('el_cm1', 'eu_cm1', 'eu_k', 'el_k')
55+
VALID_INTENSITY_TYPES = ('CDMS/JPL (log)', 'Sij-mu2', 'Aij (log)')
4956

5057
def __init__(self, **kwargs):
5158
"""
@@ -137,8 +144,8 @@ def _default_kwargs(self):
137144
max_frequency=100 * u.THz,
138145
chemical_name='',
139146
line_lists=self.ALL_LINE_LISTS,
140-
line_strengths=('CDMSJPL', 'SijMu2', 'Sij', 'Aij', 'LovasAST'),
141-
energy_levels=('One', 'Two', 'Three', 'Four'),
147+
line_strengths=self.VALID_LINE_STRENGTHS,
148+
energy_levels=self.VALID_ENERGY_LEVELS.keys(),
142149
exclude=('potential', 'atmospheric', 'probable'),
143150
version='v3.0',
144151
only_NRAO_recommended=None,
@@ -237,10 +244,10 @@ def _parse_kwargs(self, *, min_frequency=None, max_frequency=None,
237244
* Aij : ls4
238245
* Lovas/AST : ls5
239246
energy_levels : list
240-
* E_lower (cm^-1) : el1
241-
* E_lower (K) : el2
242-
* E_upper (cm^-1) : el3
243-
* E_upper (K) : el4
247+
* E_lower (cm^-1) : "One"
248+
* E_lower (K) : "Two"
249+
* E_upper (cm^-1) : "Three"
250+
* E_upper (K) : "Four"
244251
export : bool
245252
Set up arguments for the export server (as opposed to the HTML
246253
server)?
@@ -361,14 +368,17 @@ def _parse_kwargs(self, *, min_frequency=None, max_frequency=None,
361368
if energy_max is not None:
362369
payload['energyTo'] = float(energy_max)
363370
if energy_type is not None:
364-
validate_energy_type(energy_type)
371+
if energy_type not in self.VALID_ENERGY_TYPES:
372+
raise ValueError(f'energy_type must be one of {self.VALID_ENERGY_TYPES}')
365373
payload['energyRangeType'] = energy_type
366374

367-
# I don't know how to enter this right now
368-
# if intensity_type is not None:
369-
# payload['lineIntensity'] = 'lill_' + intensity_type
370-
# if intensity_lower_limit is not None:
371-
# payload[payload['lill']] = intensity_lower_limit
375+
if intensity_lower_limit is not None:
376+
if intensity_type is None:
377+
raise ValueError("If you specify an intensity lower limit, you must also specify its intensity_type.")
378+
elif intensity_type not in self.VALID_INTENSITY_TYPES:
379+
raise ValueError(f'intensity_type must be one of {self.VALID_INTENSITY_TYPES}')
380+
payload['lineIntensity'] = intensity_type
381+
payload['lineIntensityLowerLimit'] = intensity_lower_limit
372382

373383
if version in self.versions:
374384
payload['dataVersion'] = version
@@ -401,10 +411,15 @@ def _parse_kwargs(self, *, min_frequency=None, max_frequency=None,
401411

402412
if line_strengths is not None:
403413
for LS in line_strengths:
414+
if LS not in self.VALID_LINE_STRENGTHS:
415+
raise ValueError(f"Line strengths must be one of {self.VALID_LINE_STRENGTHS}")
404416
payload['lineStrengthDisplay' + LS] = True
405417

406418
if energy_levels is not None:
407419
for EL in energy_levels:
420+
if EL not in self.VALID_ENERGY_LEVELS:
421+
raise ValueError("Energy levels must be a number spelled out, i.e., "
422+
f"one of {self.VALID_ENERGY_LEVELS}")
408423
payload['energyLevel' + EL] = True
409424

410425
for b in ("displayHFSIntensity", "displayUnresolvedQuantumNumbers",
@@ -525,11 +540,4 @@ def get_fixed_table(self, *, columns=None):
525540
return table
526541

527542

528-
def validate_energy_type(etype):
529-
valid_energy_types = ('el_cm1', 'eu_cm1', 'eu_k', 'el_k')
530-
if etype not in valid_energy_types:
531-
raise ValueError("Energy type must be one of {0}"
532-
.format(valid_energy_types))
533-
534-
535543
Splatalogue = SplatalogueClass()

0 commit comments

Comments
 (0)