From 3da7e65753112d958ed4e8ef93b3d9c83c70cac9 Mon Sep 17 00:00:00 2001 From: "Adam Ginsburg (keflavich)" Date: Tue, 27 Feb 2024 16:54:20 -0500 Subject: [PATCH 01/30] WIP: first attempt to fix splatalogue [skip ci] --- astroquery/splatalogue/__init__.py | 2 +- astroquery/splatalogue/core.py | 184 ++++++++++++++++++----------- 2 files changed, 116 insertions(+), 70 deletions(-) diff --git a/astroquery/splatalogue/__init__.py b/astroquery/splatalogue/__init__.py index 6f86305997..2e0e55a87e 100644 --- a/astroquery/splatalogue/__init__.py +++ b/astroquery/splatalogue/__init__.py @@ -21,7 +21,7 @@ class Conf(_config.ConfigNamespace): 'Splatalogue SLAP interface URL (not used).') base_url = 'https://splatalogue.online' query_url = _config.ConfigItem( - f'{base_url}/c_export.php', + f'{base_url}/splata-slap/advanceded/false', # defunct as of Sep 4, 2020? (keeping because this is likely the true host) # 'https://www.cv.nrao.edu/php/splat/c_export.php', 'Splatalogue web interface URL.') diff --git a/astroquery/splatalogue/core.py b/astroquery/splatalogue/core.py index d535b285f4..20b518f7f3 100644 --- a/astroquery/splatalogue/core.py +++ b/astroquery/splatalogue/core.py @@ -7,6 +7,7 @@ :author: Adam Ginsburg """ import warnings +import json from astropy.io import ascii from astropy import units as u from astroquery import log @@ -150,8 +151,8 @@ def _default_kwargs(self): max_frequency=100 * u.THz, chemical_name='', line_lists=self.ALL_LINE_LISTS, - line_strengths=('ls1', 'ls2', 'ls3', 'ls4', 'ls5'), - energy_levels=('el1', 'el2', 'el3', 'el4'), + line_strengths=('CDMSJPL', 'SijMu2', 'Sij', 'Aij', 'LovasAST'), + energy_levels=('One', 'Two', 'Three', 'Four'), exclude=('potential', 'atmospheric', 'probable'), version='v3.0', only_NRAO_recommended=None, @@ -179,7 +180,10 @@ def _parse_kwargs(self, *, min_frequency=None, max_frequency=None, show_qn_code=None, show_lovas_labref=None, show_lovas_obsref=None, show_orderedfreq_only=None, show_nrao_recommended=None, - parse_chemistry_locally=True): + parse_chemistry_locally=True, + export_start=0, + export_stop=250, + ): """ The Splatalogue service returns lines with rest frequencies in the range [min_frequency, max_frequency]. @@ -296,119 +300,161 @@ def _parse_kwargs(self, *, min_frequency=None, max_frequency=None, 'frequency_units': 'GHz', } - if band != 'any': - if band not in self.FREQUENCY_BANDS: - raise ValueError("Invalid frequency band.") - if min_frequency is not None or max_frequency is not None: - warnings.warn("Band was specified, so the frequency " - "specification is overridden") - payload['band'] = band - elif min_frequency is not None and max_frequency is not None: + payload = {"searchSpecies":"", + "speciesSelectBox":[], + "dataVersion":"v3.0", + "userInputFrequenciesFrom":[], + "userInputFrequenciesTo":[], + "userInputFrequenciesUnit":"GHz", + "frequencyRedshift":0, + "energyFrom":0, + "energyTo":0, + "energyRangeType":"el_cm-1", + "lineIntensity":"None", + "lineIntensityLowerLimit":0, + "excludeAtmosSpecies":False, + "excludePotentialInterstellarSpecies":False, + "excludeProbableInterstellarSpecies":False, + "excludeKnownASTSpecies":False, + "showOnlyAstronomicallyObservedTransitions":False, + "showOnlyNRAORecommendedFrequencies":False, + "lineListDisplayJPL":True, + "lineListDisplayCDMS":True, + "lineListDisplayLovasNIST":True, + "lineListDisplaySLAIM":True, + "lineListDisplayToyaMA":True, + "lineListDisplayOSU":True, + "lineListDisplayRecombination":True, + "lineListDisplayTopModel":True, + "lineListDisplayRFI":True, + "lineStrengthDisplayCDMSJPL":True, + "lineStrengthDisplaySijMu2":False, + "lineStrengthDisplaySij":False, + "lineStrengthDisplayAij":False, + "lineStrengthDisplayLovasAST":True, + "energyLevelOne":True, + "energyLevelTwo":False, + "energyLevelThree":False, + "energyLevelFour":False, + "displayObservedTransitions":False, + "displayG358MaserTransitions":False, + "displayObservationReference":False, + "displayObservationSource":False, + "displayTelescopeLovasNIST":False, + "frequencyErrorLimit":False, + "displayHFSIntensity":False, + "displayUnresolvedQuantumNumbers":False, + "displayUpperStateDegeneracy":False, + "displayMoleculeTag":False, + "displayQuantumNumberCode":False, + "displayLabRef":False, + "displayOrderedFrequencyOnly":False, + "displayNRAORecommendedFrequencies":False, + "displayUniqueSpeciesTag":False, + "displayUniqueLineIDNumber":False, + "exportType":"current", + "exportDelimiter":"tab", + "exportLimit":"allRecords", + "exportStart":1, + "exportStop":250} + + if min_frequency is not None and max_frequency is not None: # allow setting payload without having *ANY* valid frequencies set min_frequency = min_frequency.to(u.GHz, u.spectral()) max_frequency = max_frequency.to(u.GHz, u.spectral()) if min_frequency > max_frequency: min_frequency, max_frequency = max_frequency, min_frequency - payload['from'] = min_frequency.value - payload['to'] = max_frequency.value + payload['userInputFrequenciesFrom'] = [min_frequency.value] + payload['userInputFrequenciesTo'] = [max_frequency.value] - if top20 is not None: - if top20 in self.TOP20_LIST: - payload['top20'] = top20 - else: - raise ValueError("Top20 is not one of the allowed values") - elif chemical_name in ('', {}, (), [], set()): + if chemical_name in ('', {}, (), [], set()): # include all - payload['sid[]'] = [] + payload['speciesSelectBox'] = [] elif chemical_name is not None: if parse_chemistry_locally: species_ids = self.get_species_ids(species_regex=chemical_name, reflags=chem_re_flags) if len(species_ids) == 0: raise ValueError("No matching chemical species found.") - payload['sid[]'] = list(species_ids.values()) + payload['speciesSelectBox'] = list(species_ids.values()) else: - payload['chemical_name'] = chemical_name + payload['searchSpecies'] = chemical_name if energy_min is not None: - payload['energy_range_from'] = float(energy_min) + payload['energyFrom'] = float(energy_min) if energy_max is not None: - payload['energy_range_to'] = float(energy_max) + payload['energyTo'] = float(energy_max) if energy_type is not None: validate_energy_type(energy_type) - payload['energy_range_type'] = energy_type + payload['energyRangeType'] = energy_type - if intensity_type is not None: - payload['lill'] = 'lill_' + intensity_type - if intensity_lower_limit is not None: - payload[payload['lill']] = intensity_lower_limit + # I don't know how to enter this right now + # if intensity_type is not None: + # payload['lineIntensity'] = 'lill_' + intensity_type + # if intensity_lower_limit is not None: + # payload[payload['lill']] = intensity_lower_limit - if transition is not None: - payload['tran'] = transition + #if transition is not None: + # payload['tran'] = transition if version in self.versions: - payload['data_version'] = version + payload['dataVersion'] = version elif version is not None: raise ValueError("Invalid version specified. Allowed versions " "are {vers}".format(vers=str(self.versions))) - if exclude == 'none': - for e in ('potential', 'atmospheric', 'probable', 'known'): - # Setting a keyword value to 'None' removes it (see query_lines_async) - log.debug("Setting no_{0} to None".format(e)) - payload['no_' + e] = None - elif exclude is not None: - for e in exclude: - payload['no_' + e] = 'no_' + e + if exclude is not None: + if 'potential' in exclude: + payload['excludePotentialInterstellarSpecies'] = True + if 'atmospheric' in exclude: + payload['excludeAtmosSpecies'] = True + if 'probable' in exclude: + payload['excludeProbableInterstellarSpecies'] = True + if 'known' in exclude: + payload['excludeKnownASTSpecies'] = True if only_astronomically_observed: - payload['include_only_observed'] = 'include_only_observed' + payload['showOnlyAstronomicallyObservedTransitions'] = True if only_NRAO_recommended: - payload['include_only_nrao'] = 'include_only_nrao' + payload['showOnlyNRAORecommendedFrequencies'] = True if line_lists is not None: if type(line_lists) not in (tuple, list): raise TypeError("Line lists should be a list of linelist " "names. See Splatalogue.ALL_LINE_LISTS") for L in self.ALL_LINE_LISTS: - kwd = 'display' + L - if L in line_lists: - payload[kwd] = kwd - else: - payload[kwd] = '' + kwd = 'lineListDisplay' + L + payload[kwd] = L in line_lists if line_strengths is not None: for LS in line_strengths: - payload[LS] = LS + payload['lineStrengthDisplay' + LS] = True if energy_levels is not None: for EL in energy_levels: - payload[EL] = EL - - for b in ("noHFS", "displayHFS", "show_unres_qn", - "show_upper_degeneracy", "show_molecule_tag", - "show_qn_code", "show_lovas_labref", - "show_orderedfreq_only", "show_lovas_obsref", - "show_nrao_recommended"): - if locals()[b]: - payload[b] = b + payload['energyLevel' + EL] = True - # default arg, unmodifiable... - payload['jsMath'] = 'font:symbol,warn:0' - payload['__utma'] = '' - payload['__utmc'] = '' + for b in ("displayHFSIntensity", "displayUnresolvedQuantumNumbers", + "displayUpperStateDegeneracy", "displayMoleculeTag", + "displayQuantumNumberCode", "displayLabRef", + "displayOrderedFrequencyOnly", "displayNRAORecommendedFrequencies", + "displayUniqueLineIDNumber", "displayUniqueSpeciesTag"): + if b in locals() and locals()[b]: + payload[b] = True if export: - payload['submit'] = 'Export' - payload['export_delimiter'] = 'colon' # or tab or comma - payload['export_type'] = 'current' - payload['offset'] = 0 - payload['range'] = 'on' + payload['exportDelimiter'] = 'tab' # or tab or comma + payload['exportType'] = 'current' + payload['exportStart'] = export_start + payload['exportStop'] = export_stop if export_limit is not None: - payload['limit'] = export_limit + payload['exportLimit'] = export_limit else: - payload['limit'] = self.LINES_LIMIT + payload['exportLimit'] = self.LINES_LIMIT + + payload = {'body': json.dumps(payload), + 'headers': {'normalizedNames': {}, 'lazyUpdate': None}} return payload @@ -458,7 +504,7 @@ def query_lines_async(self, min_frequency=None, max_frequency=None, *, response = self._request(method='POST', url=self.QUERY_URL, - data=data_payload, + json=data_payload, timeout=self.TIMEOUT, cache=cache) From caf274654bc716574b823f530f2d2e9bab2276d0 Mon Sep 17 00:00:00 2001 From: "Adam Ginsburg (keflavich)" Date: Tue, 27 Feb 2024 17:02:32 -0500 Subject: [PATCH 02/30] fix table parsing. Everything works again now? whitespace whitespace --- astroquery/splatalogue/core.py | 126 ++++++++++++++++----------------- 1 file changed, 61 insertions(+), 65 deletions(-) diff --git a/astroquery/splatalogue/core.py b/astroquery/splatalogue/core.py index 20b518f7f3..b17fcac6a8 100644 --- a/astroquery/splatalogue/core.py +++ b/astroquery/splatalogue/core.py @@ -8,7 +8,7 @@ """ import warnings import json -from astropy.io import ascii +from astropy.table import Table from astropy import units as u from astroquery import log from ..query import BaseQuery @@ -182,8 +182,7 @@ def _parse_kwargs(self, *, min_frequency=None, max_frequency=None, show_nrao_recommended=None, parse_chemistry_locally=True, export_start=0, - export_stop=250, - ): + export_stop=250): """ The Splatalogue service returns lines with rest frequencies in the range [min_frequency, max_frequency]. @@ -300,63 +299,63 @@ def _parse_kwargs(self, *, min_frequency=None, max_frequency=None, 'frequency_units': 'GHz', } - payload = {"searchSpecies":"", - "speciesSelectBox":[], - "dataVersion":"v3.0", - "userInputFrequenciesFrom":[], - "userInputFrequenciesTo":[], - "userInputFrequenciesUnit":"GHz", - "frequencyRedshift":0, - "energyFrom":0, - "energyTo":0, - "energyRangeType":"el_cm-1", - "lineIntensity":"None", - "lineIntensityLowerLimit":0, - "excludeAtmosSpecies":False, - "excludePotentialInterstellarSpecies":False, - "excludeProbableInterstellarSpecies":False, - "excludeKnownASTSpecies":False, - "showOnlyAstronomicallyObservedTransitions":False, - "showOnlyNRAORecommendedFrequencies":False, - "lineListDisplayJPL":True, - "lineListDisplayCDMS":True, - "lineListDisplayLovasNIST":True, - "lineListDisplaySLAIM":True, - "lineListDisplayToyaMA":True, - "lineListDisplayOSU":True, - "lineListDisplayRecombination":True, - "lineListDisplayTopModel":True, - "lineListDisplayRFI":True, - "lineStrengthDisplayCDMSJPL":True, - "lineStrengthDisplaySijMu2":False, - "lineStrengthDisplaySij":False, - "lineStrengthDisplayAij":False, - "lineStrengthDisplayLovasAST":True, - "energyLevelOne":True, - "energyLevelTwo":False, - "energyLevelThree":False, - "energyLevelFour":False, - "displayObservedTransitions":False, - "displayG358MaserTransitions":False, - "displayObservationReference":False, - "displayObservationSource":False, - "displayTelescopeLovasNIST":False, - "frequencyErrorLimit":False, - "displayHFSIntensity":False, - "displayUnresolvedQuantumNumbers":False, - "displayUpperStateDegeneracy":False, - "displayMoleculeTag":False, - "displayQuantumNumberCode":False, - "displayLabRef":False, - "displayOrderedFrequencyOnly":False, - "displayNRAORecommendedFrequencies":False, - "displayUniqueSpeciesTag":False, - "displayUniqueLineIDNumber":False, - "exportType":"current", - "exportDelimiter":"tab", - "exportLimit":"allRecords", - "exportStart":1, - "exportStop":250} + payload = {"searchSpecies": "", + "speciesSelectBox": [], + "dataVersion": "v3.0", + "userInputFrequenciesFrom": [], + "userInputFrequenciesTo": [], + "userInputFrequenciesUnit": "GHz", + "frequencyRedshift": 0, + "energyFrom": 0, + "energyTo": 0, + "energyRangeType": "el_cm-1", + "lineIntensity": "None", + "lineIntensityLowerLimit": 0, + "excludeAtmosSpecies": False, + "excludePotentialInterstellarSpecies": False, + "excludeProbableInterstellarSpecies": False, + "excludeKnownASTSpecies": False, + "showOnlyAstronomicallyObservedTransitions": False, + "showOnlyNRAORecommendedFrequencies": False, + "lineListDisplayJPL": True, + "lineListDisplayCDMS": True, + "lineListDisplayLovasNIST": True, + "lineListDisplaySLAIM": True, + "lineListDisplayToyaMA": True, + "lineListDisplayOSU": True, + "lineListDisplayRecombination": True, + "lineListDisplayTopModel": True, + "lineListDisplayRFI": True, + "lineStrengthDisplayCDMSJPL": True, + "lineStrengthDisplaySijMu2": False, + "lineStrengthDisplaySij": False, + "lineStrengthDisplayAij": False, + "lineStrengthDisplayLovasAST": True, + "energyLevelOne": True, + "energyLevelTwo": False, + "energyLevelThree": False, + "energyLevelFour": False, + "displayObservedTransitions": False, + "displayG358MaserTransitions": False, + "displayObservationReference": False, + "displayObservationSource": False, + "displayTelescopeLovasNIST": False, + "frequencyErrorLimit": False, + "displayHFSIntensity": False, + "displayUnresolvedQuantumNumbers": False, + "displayUpperStateDegeneracy": False, + "displayMoleculeTag": False, + "displayQuantumNumberCode": False, + "displayLabRef": False, + "displayOrderedFrequencyOnly": False, + "displayNRAORecommendedFrequencies": False, + "displayUniqueSpeciesTag": False, + "displayUniqueLineIDNumber": False, + "exportType": "current", + "exportDelimiter": "tab", + "exportLimit": "allRecords", + "exportStart": 1, + "exportStop": 250} if min_frequency is not None and max_frequency is not None: # allow setting payload without having *ANY* valid frequencies set @@ -394,9 +393,6 @@ def _parse_kwargs(self, *, min_frequency=None, max_frequency=None, # if intensity_lower_limit is not None: # payload[payload['lill']] = intensity_lower_limit - #if transition is not None: - # payload['tran'] = transition - if version in self.versions: payload['dataVersion'] = version elif version is not None: @@ -523,8 +519,8 @@ def _parse_result(self, response, *, verbose=False): splatalogue to make them more terminal-friendly """ - result = ascii.read(response.text.split('\n'), delimiter=':', - format='basic', fast_reader=False) + jdat = response.json() + result = Table([x for x in jdat if x['species_id'] is not None]) return result From 311ae178551f4acc2383e3a9ce5cd070b3b4e26f Mon Sep 17 00:00:00 2001 From: "Adam Ginsburg (keflavich)" Date: Tue, 27 Feb 2024 17:32:54 -0500 Subject: [PATCH 03/30] fix some of the broken tests --- astroquery/splatalogue/core.py | 23 +++++++++---------- .../splatalogue/tests/test_splatalogue.py | 9 ++++---- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/astroquery/splatalogue/core.py b/astroquery/splatalogue/core.py index b17fcac6a8..7ce60c96d6 100644 --- a/astroquery/splatalogue/core.py +++ b/astroquery/splatalogue/core.py @@ -77,7 +77,7 @@ def set_default_options(self, **kwargs): Modify the default options. See `query_lines` """ - self.data.update(self._parse_kwargs(**kwargs)) + self.data.update(json.loads(self._parse_kwargs(**kwargs)['body'])) @deprecated_renamed_argument("restr", "species_regex", since="0.4.7") def get_species_ids(self, species_regex=None, *, reflags=0, recache=False): @@ -163,7 +163,7 @@ def _default_kwargs(self): show_qn_code=False, show_lovas_labref=False, show_lovas_obsref=False, show_orderedfreq_only=False, show_nrao_recommended=False,) - return self._parse_kwargs(**kwargs) + return json.loads(self._parse_kwargs(**kwargs)['body']) def _parse_kwargs(self, *, min_frequency=None, max_frequency=None, band='any', top20=None, chemical_name=None, @@ -481,19 +481,18 @@ def query_lines_async(self, min_frequency=None, max_frequency=None, *, self._validate_kwargs(min_frequency=min_frequency, max_frequency=max_frequency, **kwargs) + data_payload = self._parse_kwargs(min_frequency=min_frequency, + max_frequency=max_frequency, + **kwargs) if hasattr(self, 'data'): - data_payload = self.data.copy() - data_payload.update(self._parse_kwargs(min_frequency=min_frequency, - max_frequency=max_frequency, - **kwargs)) + body = self.data.copy() else: - data_payload = self._default_kwargs() - data_payload.update(self._parse_kwargs(min_frequency=min_frequency, - max_frequency=max_frequency, - **kwargs)) + body = self._default_kwargs() - # Add an extra step: sometimes, need to REMOVE keywords - data_payload = {k: v for k, v in data_payload.items() if v is not None} + body.update(json.loads( + self._parse_kwargs(min_frequency=min_frequency, + max_frequency=max_frequency, **kwargs)['body'])) + data_payload['body'] = json.dumps(body) if get_query_payload: return data_payload diff --git a/astroquery/splatalogue/tests/test_splatalogue.py b/astroquery/splatalogue/tests/test_splatalogue.py index 45ad70fcc1..4512ae4f70 100644 --- a/astroquery/splatalogue/tests/test_splatalogue.py +++ b/astroquery/splatalogue/tests/test_splatalogue.py @@ -8,7 +8,7 @@ from ... import splatalogue -SPLAT_DATA = 'CO_colons.csv' +SPLAT_DATA = 'CO.json' def data_path(filename): @@ -48,7 +48,8 @@ def test_get_payload(): q = splatalogue.core.Splatalogue.query_lines_async(min_frequency=1 * u.GHz, max_frequency=10 * u.GHz, get_query_payload=True) - assert '__utma' in q + assert q['body']["userInputFrequenciesFrom"] == [1.0] + assert q['body']["userInputFrequenciesTo"] == [10.0] # regression test: line lists should ask for only one line list, not all @@ -57,8 +58,8 @@ def test_line_lists(): max_frequency=10 * u.GHz, line_lists=['JPL'], get_query_payload=True) - assert q['displayJPL'] == 'displayJPL' - assert q['displaySLAIM'] == '' + assert q['body']['lineListDisplayCDMSJPL'] + assert not q['body']['lineListDisplaySLAIM'] # regression test: raise an exception if a string is passed to line_lists From 9ebf6dacb668154d28456d5fa8ce705561826211 Mon Sep 17 00:00:00 2001 From: "Adam Ginsburg (keflavich)" Date: Tue, 27 Feb 2024 20:50:35 -0500 Subject: [PATCH 04/30] fix keywords invovled in refactor --- astroquery/splatalogue/core.py | 6 +-- .../splatalogue/tests/test_splatalogue.py | 40 +++++++++---------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/astroquery/splatalogue/core.py b/astroquery/splatalogue/core.py index 7ce60c96d6..0092f260ca 100644 --- a/astroquery/splatalogue/core.py +++ b/astroquery/splatalogue/core.py @@ -34,8 +34,8 @@ class SplatalogueClass(BaseQuery): LINES_LIMIT = conf.lines_limit versions = ('v1.0', 'v2.0', 'v3.0', 'vall') # global constant, not user-configurable - ALL_LINE_LISTS = ('Lovas', 'SLAIM', 'JPL', 'CDMS', 'ToyoMA', 'OSU', - 'Recomb', 'Lisa', 'RFI') + ALL_LINE_LISTS = ('LovasNIST', 'SLAIM', 'JPL', 'CDMS', 'ToyaMA', 'OSU', + 'Recombination', 'RFI') TOP20_LIST = ('comet', 'planet', 'top20', 'ism_hotcore', 'ism_darkcloud', 'ism_diffusecloud') FREQUENCY_BANDS = {"any": "Any", @@ -251,7 +251,7 @@ def _parse_kwargs(self, *, min_frequency=None, max_frequency=None, Show only NRAO recommended species? line_lists : list Options: - Lovas, SLAIM, JPL, CDMS, ToyoMA, OSU, Recomb, Lisa, RFI + Lovas, SLAIM, JPL, CDMS, ToyaMA, OSU, Recombination, RFI line_strengths : list * CDMS/JPL Intensity : ls1 * Sij : ls3 diff --git a/astroquery/splatalogue/tests/test_splatalogue.py b/astroquery/splatalogue/tests/test_splatalogue.py index 4512ae4f70..3c681fe77c 100644 --- a/astroquery/splatalogue/tests/test_splatalogue.py +++ b/astroquery/splatalogue/tests/test_splatalogue.py @@ -111,30 +111,30 @@ def test_band_crashorno(): def test_exclude(patch_post): # regression test for issue 616 - d = splatalogue.Splatalogue.query_lines_async(min_frequency=114 * u.GHz, - max_frequency=116 * u.GHz, - chemical_name=' CO ', - exclude=None, - get_query_payload=True) - - exclusions = {'no_atmospheric': 'no_atmospheric', - 'no_potential': 'no_potential', - 'no_probable': 'no_probable', } + payload = splatalogue.Splatalogue.query_lines_async(min_frequency=114 * u.GHz, + max_frequency=116 * u.GHz, + chemical_name=' CO ', + exclude=None, + get_query_payload=True) + + exclusions = {'excludePotentialInterstellarSpecies': False, + 'excludeAtmosSpecies': False, + 'excludeProbableInterstellarSpecies': False + 'excludeKnownASTSpecies': False + } for k, v in exclusions.items(): - assert d[k] == v - - d = splatalogue.Splatalogue.query_lines_async(min_frequency=114 * u.GHz, - max_frequency=116 * u.GHz, - chemical_name=' CO ', - exclude='none', - get_query_payload=True) + assert payload[k] == v - for k, v in exclusions.items(): - assert k not in d + # 'none' doesn't mean None, but it should have the same effect + payload = splatalogue.Splatalogue.query_lines_async(min_frequency=114 * u.GHz, + max_frequency=116 * u.GHz, + chemical_name=' CO ', + exclude='none', + get_query_payload=True) - for k in d: - assert k[:3] != 'no_' + for key in exclusions: + assert not payload[key] @pytest.mark.remote_data From 11e31a9b3225165654b5f79500191a8d1c96302b Mon Sep 17 00:00:00 2001 From: "Adam Ginsburg (keflavich)" Date: Thu, 29 Feb 2024 08:37:57 -0500 Subject: [PATCH 05/30] add a dictionary that _can_ be used to restore new tables to old format --- astroquery/splatalogue/core.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/astroquery/splatalogue/core.py b/astroquery/splatalogue/core.py index 0092f260ca..0553e9c986 100644 --- a/astroquery/splatalogue/core.py +++ b/astroquery/splatalogue/core.py @@ -24,6 +24,16 @@ # example query of SPLATALOGUE directly: # https://www.cv.nrao.edu/php/splat/c.php?sid%5B%5D=64&sid%5B%5D=108&calcIn=&data_version=v3.0&from=&to=&frequency_units=MHz&energy_range_from=&energy_range_to=&lill=on&tran=&submit=Search&no_atmospheric=no_atmospheric&no_potential=no_potential&no_probable=no_probable&include_only_nrao=include_only_nrao&displayLovas=displayLovas&displaySLAIM=displaySLAIM&displayJPL=displayJPL&displayCDMS=displayCDMS&displayToyaMA=displayToyaMA&displayOSU=displayOSU&displayRecomb=displayRecomb&displayLisa=displayLisa&displayRFI=displayRFI&ls1=ls1&ls5=ls5&el1=el1 +# for backward-compatibility +colname_mapping_feb2024 = { + 'Species': 'name', + 'Chemical Name': 'chemical_name', + 'Resolved QNs': 'resolved_QNs', + 'Freq-GHz(rest frame,redshifted)': 'orderedfreq', + 'Log10 (Aij)': 'aij', + 'E_U (K)': 'upper_state_energy_K', +} + @async_to_sync class SplatalogueClass(BaseQuery): From 60af30e804aaf3b792ca2903b80f0fe8c5399bf1 Mon Sep 17 00:00:00 2001 From: "Adam Ginsburg (keflavich)" Date: Tue, 5 Mar 2024 08:31:45 -0500 Subject: [PATCH 06/30] add fixes for minimize_table and column merging --- astroquery/splatalogue/core.py | 4 +++- astroquery/splatalogue/utils.py | 38 +++++++++++---------------------- 2 files changed, 15 insertions(+), 27 deletions(-) diff --git a/astroquery/splatalogue/core.py b/astroquery/splatalogue/core.py index 0553e9c986..140be527d2 100644 --- a/astroquery/splatalogue/core.py +++ b/astroquery/splatalogue/core.py @@ -25,11 +25,13 @@ # https://www.cv.nrao.edu/php/splat/c.php?sid%5B%5D=64&sid%5B%5D=108&calcIn=&data_version=v3.0&from=&to=&frequency_units=MHz&energy_range_from=&energy_range_to=&lill=on&tran=&submit=Search&no_atmospheric=no_atmospheric&no_potential=no_potential&no_probable=no_probable&include_only_nrao=include_only_nrao&displayLovas=displayLovas&displaySLAIM=displaySLAIM&displayJPL=displayJPL&displayCDMS=displayCDMS&displayToyaMA=displayToyaMA&displayOSU=displayOSU&displayRecomb=displayRecomb&displayLisa=displayLisa&displayRFI=displayRFI&ls1=ls1&ls5=ls5&el1=el1 # for backward-compatibility +# (As of March 5, this is incomplete, but is enough to make `minimize_table` work) colname_mapping_feb2024 = { 'Species': 'name', 'Chemical Name': 'chemical_name', 'Resolved QNs': 'resolved_QNs', - 'Freq-GHz(rest frame,redshifted)': 'orderedfreq', + 'Freq-GHz(rest frame,redshifted)': 'orderedFreq', + 'Meas Freq-GHz(rest frame,redshifted)': 'measFreq', 'Log10 (Aij)': 'aij', 'E_U (K)': 'upper_state_energy_K', } diff --git a/astroquery/splatalogue/utils.py b/astroquery/splatalogue/utils.py index 3e34346677..f22e5b043d 100644 --- a/astroquery/splatalogue/utils.py +++ b/astroquery/splatalogue/utils.py @@ -5,32 +5,14 @@ import numpy as np import astropy -# Remap column headings to something IPAC-compatible -column_headings_map = {'Log10 (Aij)': 'log10_Aij', - 'Resolved QNs': 'QNs', - 'CDMS/JPL Intensity': 'CDMSJPL_Intensity', - 'Sij': 'Sij', - 'Freq-GHz': 'FreqGHz', - 'Meas Freq-GHz': 'MeasFreqGHz', - 'Lovas/AST Intensity': 'LovasAST_Intensity', - 'E_L (cm^-1)': 'EL_percm', - 'E_L (K)': 'EL_K', - 'E_U (cm^-1)': 'EU_percm', - 'E_U (K)': 'EU_K', - 'Chemical Name': 'ChemicalName', - 'Freq Err': 'FreqErr', - 'Meas Freq Err': 'MeasFreqErr', - 'Freq-GHz(rest frame,redshifted)': 'FreqGHz', - 'Freq Err(rest frame,redshifted)': 'eFreqGHz', - 'Meas Freq-GHz(rest frame,redshifted)': 'MeasFreqGHz', - 'Meas Freq Err(rest frame,redshifted)': 'eMeasFreqGHz', - } - - -def clean_column_headings(table, *, renaming_dict=column_headings_map): + +def clean_column_headings(table, *, renaming_dict={}): """ Rename column headings to shorter version that are easier for display on-screen / at the terminal + + As of March 2024, the default column names are all valid and no longer need + renaming. """ for key in renaming_dict: @@ -41,10 +23,10 @@ def clean_column_headings(table, *, renaming_dict=column_headings_map): def merge_frequencies(table, *, prefer='measured', - theor_kwd='Freq-GHz(rest frame,redshifted)', - meas_kwd='Meas Freq-GHz(rest frame,redshifted)'): + theor_kwd='orderedFreq', + meas_kwd='measFreq'): """ - Replace "Freq-GHz" and "Meas Freq-GHz" with a single "Freq" column. + Replace "orderedFreq" and "measFreq" with a single "Freq" column. Parameters ---------- @@ -101,6 +83,10 @@ def minimize_table(table, *, columns=['Species', 'Chemical Name', clean_column_headings : bool Run clean_column_headings to shorted the headers? """ + from .core import colname_mapping_feb2024 + + columns = [colname_mapping_feb2024[c] if c in colname_mapping_feb2024 else c + for c in columns] table = table[columns] From a97d07a4f470a4bcd9323d48ee7d3c2bc4bf7cbc Mon Sep 17 00:00:00 2001 From: "Adam Ginsburg (keflavich)" Date: Tue, 5 Mar 2024 08:38:29 -0500 Subject: [PATCH 07/30] remove unused, unsupported slap code --- astroquery/splatalogue/slap.py | 58 ---------------------------------- 1 file changed, 58 deletions(-) delete mode 100644 astroquery/splatalogue/slap.py diff --git a/astroquery/splatalogue/slap.py b/astroquery/splatalogue/slap.py deleted file mode 100644 index f1af3893b2..0000000000 --- a/astroquery/splatalogue/slap.py +++ /dev/null @@ -1,58 +0,0 @@ -# Licensed under a 3-clause BSD style license - see LICENSE.rst -""" -Construct a SLAP query. - -This is not presently used, since I don't know how to construct a complete SLAP -query. -""" - - -def slap_default_payload(*, request='queryData', version='2.0', wavelength='', - chemical_element='', initial_level_energy='', - final_level_energy='', temperature='', einstein_a=''): - """ - Parse the valid parameters specified by the `IVOA SLAP`_ interface - document. - - .. _IVOA SLAP: http://www.ivoa.net/documents/SLAP/20101209/REC-SLAP-1.0-20101209.pdf - - - Parameters - ---------- - request : 'queryData' - No other valid entries are known - version : '2.0' - A valid data version number - wavelength : 'x/y' or 'x' or 'x,y/z' or 'x/' - Wavelength range in meters. - 'x/y' means 'in the range from x to y' - 'x/' means 'wavelength > x' - 'x' means 'wavelength == x' - 'x/y,y/z' means 'wavelength in range [x,y] or [y,z]' - See Appendix A of the `IVOA SLAP`_ manual - - Other Parameters - ---------------- - chemical_element : str - A chemical element name. Can be specified as a comma-separated list - initial_level_energy : float - Unit: Joules - final_level_energy : float - Unit: Joules - temperature : float - Unit : Kelvin - Expected temperature of object. Not needed for splatalogue - einstein_a : float - Unit : s^-1 - process_type : str - process_name : str - Examples: - "Photoionization", "Collisional excitation", - "Gravitational redshift", "Stark broadening", "Resonance broadening", - "Van de Waals broadening" - - Returns - ------- - Dictionary of parameters which can then be POSTed to the service - """ - return locals() From d12a7da22b6a9dafe0e8a9e31db39a5e01890592 Mon Sep 17 00:00:00 2001 From: "Adam Ginsburg (keflavich)" Date: Tue, 5 Mar 2024 08:40:08 -0500 Subject: [PATCH 08/30] fix tests for updated utils fix syntax err whitespace --- astroquery/splatalogue/core.py | 6 ++---- astroquery/splatalogue/tests/test_splatalogue.py | 5 ++--- astroquery/splatalogue/tests/test_utils.py | 7 ++++--- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/astroquery/splatalogue/core.py b/astroquery/splatalogue/core.py index 140be527d2..0cd00da4ee 100644 --- a/astroquery/splatalogue/core.py +++ b/astroquery/splatalogue/core.py @@ -6,11 +6,9 @@ :author: Adam Ginsburg """ -import warnings import json from astropy.table import Table from astropy import units as u -from astroquery import log from ..query import BaseQuery from ..utils import async_to_sync, prepend_docstr_nosections from . import conf @@ -494,8 +492,8 @@ def query_lines_async(self, min_frequency=None, max_frequency=None, *, max_frequency=max_frequency, **kwargs) data_payload = self._parse_kwargs(min_frequency=min_frequency, - max_frequency=max_frequency, - **kwargs) + max_frequency=max_frequency, + **kwargs) if hasattr(self, 'data'): body = self.data.copy() else: diff --git a/astroquery/splatalogue/tests/test_splatalogue.py b/astroquery/splatalogue/tests/test_splatalogue.py index 3c681fe77c..327d9426ce 100644 --- a/astroquery/splatalogue/tests/test_splatalogue.py +++ b/astroquery/splatalogue/tests/test_splatalogue.py @@ -119,9 +119,8 @@ def test_exclude(patch_post): exclusions = {'excludePotentialInterstellarSpecies': False, 'excludeAtmosSpecies': False, - 'excludeProbableInterstellarSpecies': False - 'excludeKnownASTSpecies': False - } + 'excludeProbableInterstellarSpecies': False, + 'excludeKnownASTSpecies': False} for k, v in exclusions.items(): assert payload[k] == v diff --git a/astroquery/splatalogue/tests/test_utils.py b/astroquery/splatalogue/tests/test_utils.py index b37514c2ed..e29659173d 100644 --- a/astroquery/splatalogue/tests/test_utils.py +++ b/astroquery/splatalogue/tests/test_utils.py @@ -13,7 +13,7 @@ def test_clean(patch_post): chemical_name=' CO ') c = utils.clean_column_headings(x) assert 'Resolved QNs' not in c.colnames - assert 'QNs' in c.colnames + assert 'resolved_QNs' in c.colnames def test_merge(patch_post): @@ -49,5 +49,6 @@ def test_minimize_issue2135(): minimized = utils.minimize_table(rslt) - theomask = rslt['Freq-GHz(rest frame,redshifted)'].mask - np.testing.assert_allclose(minimized['Freq'][theomask], rslt['Meas Freq-GHz(rest frame,redshifted)'][theomask]) + theomask = rslt['orderedFreq'].mask + np.testing.assert_allclose(minimized['Freq'][theomask], + rslt['measFreq'][theomask]) From 91aec4caec0037a6fb223dbec9dd0c43ecc6f4ec Mon Sep 17 00:00:00 2001 From: "Adam Ginsburg (keflavich)" Date: Tue, 12 Mar 2024 23:30:01 -0400 Subject: [PATCH 09/30] add changelog entry --- CHANGES.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index 8ac2770682..49cc7ddf1a 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -13,6 +13,11 @@ mpc - Parse star catalog information when querying observations database [#2957] +splatalogue +^^^^^^^^^^^ + +- Fix incompatibilities with the major changes made to the Splatalogue's upstream server in March 2024. [#2960] + vizier ^^^^^^ From 62cf9b9c159ea69cae3bff384d3bf682ce3f7d9c Mon Sep 17 00:00:00 2001 From: "Adam Ginsburg (keflavich)" Date: Tue, 12 Mar 2024 23:36:40 -0400 Subject: [PATCH 10/30] fix data in conftest --- astroquery/splatalogue/tests/conftest.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/astroquery/splatalogue/tests/conftest.py b/astroquery/splatalogue/tests/conftest.py index 6fd73cc14f..a0eaf176cc 100644 --- a/astroquery/splatalogue/tests/conftest.py +++ b/astroquery/splatalogue/tests/conftest.py @@ -2,11 +2,12 @@ import pytest import requests +import json from astroquery.utils.mocks import MockResponse -SPLAT_DATA = 'CO_colons.csv' +SPLAT_DATA = 'CO.json' def data_path(filename): @@ -27,6 +28,6 @@ def post_mockreturn(self, method, url, data=None, timeout=10, files=None, if method != 'POST': raise ValueError("A 'post request' was made with method != POST") filename = data_path(SPLAT_DATA) - with open(filename, 'rb') as infile: - content = infile.read() + with open(filename, 'r') as infile: + content = json.load(infile) return MockResponse(content, **kwargs) From cb656fa1ac8a653796067b62b68241a9fcbb4426 Mon Sep 17 00:00:00 2001 From: "Adam Ginsburg (keflavich)" Date: Tue, 12 Mar 2024 23:37:10 -0400 Subject: [PATCH 11/30] fix data: remove old/outdated csv and add json --- astroquery/splatalogue/tests/data/CO.json | 1 + astroquery/splatalogue/tests/data/CO_colons.csv | 7 ------- 2 files changed, 1 insertion(+), 7 deletions(-) create mode 100644 astroquery/splatalogue/tests/data/CO.json delete mode 100644 astroquery/splatalogue/tests/data/CO_colons.csv diff --git a/astroquery/splatalogue/tests/data/CO.json b/astroquery/splatalogue/tests/data/CO.json new file mode 100644 index 0000000000..fa6a201b01 --- /dev/null +++ b/astroquery/splatalogue/tests/data/CO.json @@ -0,0 +1 @@ +[{"species_id": 990, "name": "CO v = 1", "chemical_name": "Carbon Monoxide", "resolved_QNs": " 1- 0", "linelist": "CDMS", "LovasASTIntensity": " ", "lower_state_energy": 2143.2711, "upper_state_energy": 2147.08113, "sijmu2": 0.00723, "sij": 1.0, "aij": -7.37879, "intintensity": "-9.7069", "Lovas_NRAO": 1, "orderedfreq": 114221.7523, "lower_state_energy_K": 3083.67129, "upper_state_energy_K": 3089.15304, "orderedFreq": "114221.7523 (0.0013), 114221.7523", "measFreq": " ", "upperStateDegen": "3", "moleculeTag": 28512, "qnCode": 1202, "labref_Lovas_NIST": " ", "rel_int_HFS_Lovas": " ", "unres_quantum_numbers": " 1 1 0 1", "lineid": 6187001, "transition_in_space": 0, "transition_in_G358": 0, "obsref_Lovas_NIST": " ", "source_Lovas_NIST": " ", "telescope_Lovas_NIST": " ", "orderFreqColName": "Freq in GHz (Err)
(rest frame,

redshifted)

", "measFreqColName": "Meas Freq in GHz (Err)
(rest frame,

redshifted)

", "transitionBandColor": "datatableskyblue", "searchErrorMessage": "", "sqlquery": null}, {"species_id": 990, "name": "CO v = 1", "chemical_name": "Carbon Monoxide", "resolved_QNs": " 1- 0", "linelist": "SLAIM", "LovasASTIntensity": " ", "lower_state_energy": 2143.272, "upper_state_energy": 2147.08203, "sijmu2": 0.01212, "sij": 1.0, "aij": -7.15428, "intintensity": "", "Lovas_NRAO": 0, "orderedfreq": 114221.757, "lower_state_energy_K": 3083.67258, "upper_state_energy_K": 3089.15433, "orderedFreq": "114221.757 (0.003), 114221.757", "measFreq": "114221.74 (0.04), 114221.74", "upperStateDegen": "3", "moleculeTag": 0, "qnCode": 0, "labref_Lovas_NIST": " Dix77", "rel_int_HFS_Lovas": "", "unres_quantum_numbers": " 1 - 0 v=1", "lineid": 3768099, "transition_in_space": 0, "transition_in_G358": 0, "obsref_Lovas_NIST": " ", "source_Lovas_NIST": " ", "telescope_Lovas_NIST": " ", "orderFreqColName": null, "measFreqColName": null, "transitionBandColor": "datatableskyblue", "searchErrorMessage": "", "sqlquery": null}, {"species_id": 204, "name": "CO v = 0", "chemical_name": "Carbon Monoxide", "resolved_QNs": "1-0", "linelist": "CDMS", "LovasASTIntensity": "60.0", "lower_state_energy": 0.0, "upper_state_energy": 3.84503, "sijmu2": 0.01212, "sij": 1.0, "aij": -7.14246, "intintensity": "-5.0105", "Lovas_NRAO": 1, "orderedfreq": 115271.2018, "lower_state_energy_K": 0.0, "upper_state_energy_K": 5.53211, "orderedFreq": " ", "measFreq": "115271.2018 (5.0E-4), 115271.2018", "upperStateDegen": "3", "moleculeTag": -28503, "qnCode": 101, "labref_Lovas_NIST": " ", "rel_int_HFS_Lovas": " ", "unres_quantum_numbers": "J=1-0", "lineid": 363613, "transition_in_space": 0, "transition_in_G358": 0, "obsref_Lovas_NIST": "Uli76", "source_Lovas_NIST": " OriMC-1", "telescope_Lovas_NIST": " NRAO 11m", "orderFreqColName": null, "measFreqColName": null, "transitionBandColor": "datatableskyblue", "searchErrorMessage": "", "sqlquery": null}, {"species_id": 204, "name": "CO v = 0", "chemical_name": "Carbon Monoxide", "resolved_QNs": "1-0", "linelist": "JPL", "LovasASTIntensity": " ", "lower_state_energy": 0.0, "upper_state_energy": 3.84503, "sijmu2": 0.01212, "sij": 1.0, "aij": -7.14246, "intintensity": "-5.0105", "Lovas_NRAO": 0, "orderedfreq": 115271.2018, "lower_state_energy_K": 0.0, "upper_state_energy_K": 5.53211, "orderedFreq": " ", "measFreq": "115271.2018 (5.0E-4), 115271.2018", "upperStateDegen": "3", "moleculeTag": -28001, "qnCode": 101, "labref_Lovas_NIST": " ", "rel_int_HFS_Lovas": " ", "unres_quantum_numbers": "J=1-0", "lineid": 824116, "transition_in_space": 0, "transition_in_G358": 0, "obsref_Lovas_NIST": " ", "source_Lovas_NIST": " ", "telescope_Lovas_NIST": " ", "orderFreqColName": null, "measFreqColName": null, "transitionBandColor": "datatableskyblue", "searchErrorMessage": "", "sqlquery": null}, {"species_id": 204, "name": "CO v = 0", "chemical_name": "Carbon Monoxide", "resolved_QNs": "1-0", "linelist": "Lovas/NIST", "LovasASTIntensity": "60.0", "lower_state_energy": 0.0, "upper_state_energy": 0.0, "sijmu2": 0.0, "sij": 0.0, "aij": 0.0, "intintensity": "", "Lovas_NRAO": 0, "orderedfreq": 115271.202, "lower_state_energy_K": 0.0, "upper_state_energy_K": 0.0, "orderedFreq": "115271.202 (0.001), 115271.202", "measFreq": " ", "upperStateDegen": "", "moleculeTag": 0, "qnCode": 0, "labref_Lovas_NIST": "", "rel_int_HFS_Lovas": " ", "unres_quantum_numbers": "1-0", "lineid": 3732287, "transition_in_space": 0, "transition_in_G358": 0, "obsref_Lovas_NIST": "Uli76", "source_Lovas_NIST": " OriMC-1", "telescope_Lovas_NIST": " NRAO 11m", "orderFreqColName": null, "measFreqColName": null, "transitionBandColor": "datatableskyblue", "searchErrorMessage": "", "sqlquery": null}, {"species_id": 204, "name": "CO v = 0", "chemical_name": "Carbon Monoxide", "resolved_QNs": " 1- 0", "linelist": "SLAIM", "LovasASTIntensity": "60.0", "lower_state_energy": 0.0, "upper_state_energy": 3.84503, "sijmu2": 0.01212, "sij": 1.0, "aij": -7.14236, "intintensity": "", "Lovas_NRAO": 0, "orderedfreq": 115271.202, "lower_state_energy_K": 0.0, "upper_state_energy_K": 5.53211, "orderedFreq": "115271.202, 115271.202", "measFreq": "115271.202 (0.001), 115271.202", "upperStateDegen": "3", "moleculeTag": 0, "qnCode": 0, "labref_Lovas_NIST": " Win97", "rel_int_HFS_Lovas": "", "unres_quantum_numbers": " 1 - 0 v=0", "lineid": 3768098, "transition_in_space": 1, "transition_in_G358": 0, "obsref_Lovas_NIST": " ", "source_Lovas_NIST": " ", "telescope_Lovas_NIST": " ", "orderFreqColName": null, "measFreqColName": null, "transitionBandColor": "datatableskyblue", "searchErrorMessage": "", "sqlquery": null}, {"species_id": null, "name": null, "chemical_name": null, "resolved_QNs": null, "linelist": null, "LovasASTIntensity": null, "lower_state_energy": null, "upper_state_energy": null, "sijmu2": null, "sij": null, "aij": null, "intintensity": null, "Lovas_NRAO": null, "orderedfreq": null, "lower_state_energy_K": null, "upper_state_energy_K": null, "orderedFreq": null, "measFreq": null, "upperStateDegen": null, "moleculeTag": null, "qnCode": null, "labref_Lovas_NIST": null, "rel_int_HFS_Lovas": null, "unres_quantum_numbers": null, "lineid": null, "transition_in_space": null, "transition_in_G358": null, "obsref_Lovas_NIST": null, "source_Lovas_NIST": null, "telescope_Lovas_NIST": null, "orderFreqColName": null, "measFreqColName": null, "transitionBandColor": null, "searchErrorMessage": null, "sqlquery": "SELECT /*+ MAX_EXECUTION_TIME(60000) */species.species_id, species.name, species.chemical_name, main.resolved_QNs, main.frequency, main.uncertainty, main.measfreq, main.measerrfreq, main.rel_int_HFS_Lovas, main.quantum_numbers, main.upper_state_degeneracy, main.molecule_tag, main.qn_code, main.labref_Lovas_NIST, main.line_id ,main.transition_in_space, main.transition_in_G358, main.obsref_Lovas_NIST, main.source_Lovas_NIST, main.telescope_Lovas_NIST , linelists.linelist, main.lower_state_energy ,main.upper_state_energy ,main.upper_state_energy_K ,main.lower_state_energy_K , main.sijmu2, main.aij, main.sij, main.intintensity, main.obsintensity_Lovas_NIST as LovasASTIntensity , main.Lovas_NRAO, main.orderedfreq, main.lower_state_energy_K, main.upper_state_energy_K FROM main INNER JOIN species ON main.species_id = species.species_id INNER JOIN linelists ON main.ll_id = linelists.ll_id AND main.ll_id IN ( 10 ,11 , 12 ,14 ,15 ,16 ,17 ,18 ,19 ) AND (main.species_id = 204 OR main.species_id = 990 OR main.species_id = 991 OR main.species_id = 1343) AND (main.`v3.0` != 0) AND((main.orderedfreq >= 114000.0 AND main.orderedfreq <= 116000.0)) ORDER BY main.orderedfreq"}] \ No newline at end of file diff --git a/astroquery/splatalogue/tests/data/CO_colons.csv b/astroquery/splatalogue/tests/data/CO_colons.csv deleted file mode 100644 index 6541c3b901..0000000000 --- a/astroquery/splatalogue/tests/data/CO_colons.csv +++ /dev/null @@ -1,7 +0,0 @@ -Species:Chemical Name:Freq-GHz(rest frame,redshifted):Freq Err(rest frame,redshifted):Meas Freq-GHz(rest frame,redshifted):Meas Freq Err(rest frame,redshifted):Resolved QNs:CDMS/JPL Intensity:Sijμ2 (D2):Sij:Log10 (Aij):Lovas/AST Intensity:E_L (cm^-1):E_L (K):E_U (cm^-1):E_U (K):Linelist -COv=1:Carbon Monoxide:114.2217523:1.3e-06:::1-0:-9.7069:0.00723:1.0:-7.37879::2143.2711:3083.67129:2147.08113:3089.15304:CDMS -COv=1:Carbon Monoxide:114.221757:3e-06:114.22174:4e-05:1-0:0.0:0.01212:1.0:-7.15428::2143.272:3083.67258:2147.08203:3089.15433:SLAIM -COv=0:Carbon Monoxide:::115.2712018:5e-07:1-0:-5.0105:0.01212:1.0:-7.14246:60.0:0.0:0.0:3.84503:5.53211:CDMS -COv=0:Carbon Monoxide:::115.2712018:5e-07:1-0:-5.0105:0.01212:1.0:-7.14246::0.0:0.0:3.84503:5.53211:JPL -COv=0:Carbon Monoxide:115.271202:1e-06:::1-0:0.0:0.0:0.0:0.0:60.0:0.0:0.0:0.0:0.0:Lovas -COv=0:Carbon Monoxide:115.271202:0.0:115.271202:1e-06:1-0:0.0:0.01212:1.0:-7.14236:60.0:0.0:0.0:3.84503:5.53211:SLAIM From 9c47f9d6eb5793a17fbd44e1e96a83e276e5fb76 Mon Sep 17 00:00:00 2001 From: "Adam Ginsburg (keflavich)" Date: Tue, 12 Mar 2024 23:59:34 -0400 Subject: [PATCH 12/30] add more cleanup of html junk --- astroquery/splatalogue/core.py | 17 ++++++++++++++--- astroquery/splatalogue/utils.py | 29 ++++++++++++++++++++++++++--- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/astroquery/splatalogue/core.py b/astroquery/splatalogue/core.py index 0cd00da4ee..279902c7d8 100644 --- a/astroquery/splatalogue/core.py +++ b/astroquery/splatalogue/core.py @@ -523,14 +523,25 @@ def _parse_result(self, response, *, verbose=False): Parameters ---------- - clean_headers : bool - Attempt to simplify / clean up the column headers returned by - splatalogue to make them more terminal-friendly + verbose : bool + Has no effect; kept for API compatibility """ + # these are metadata items not intended to be part of the table + meta_columns = ['orderFreqColName', 'measFreqColName'] + meta = {} + jdat = response.json() + result = Table([x for x in jdat if x['species_id'] is not None]) + for key in meta_columns: + if key in result.colnames: + meta[key] = result[key][0] + del result[key] + + result.meta = meta + return result def get_fixed_table(self, *, columns=None): diff --git a/astroquery/splatalogue/utils.py b/astroquery/splatalogue/utils.py index f22e5b043d..0e1bf74724 100644 --- a/astroquery/splatalogue/utils.py +++ b/astroquery/splatalogue/utils.py @@ -4,6 +4,7 @@ """ import numpy as np import astropy +from bs4 import BeautifulSoup def clean_column_headings(table, *, renaming_dict={}): @@ -22,6 +23,26 @@ def clean_column_headings(table, *, renaming_dict={}): return table +def try_clean(row): + if row: + return BeautifulSoup(row, features='html5lib').text + + +def clean_columns(table): + """ + Remove HTML tags in table columns + + (modifies table inplace) + """ + for col in table.colnames: + # check for any html tag + if isinstance(table[col][0], str) and '<' in table[col][0]: + table[col] = [ + try_clean(row) + for row in table[col] + ] + + def merge_frequencies(table, *, prefer='measured', theor_kwd='orderedFreq', meas_kwd='measFreq'): @@ -63,8 +84,7 @@ def merge_frequencies(table, *, prefer='measured', def minimize_table(table, *, columns=['Species', 'Chemical Name', 'Resolved QNs', - 'Freq-GHz(rest frame,redshifted)', - 'Meas Freq-GHz(rest frame,redshifted)', + 'orderedfreq', 'Log10 (Aij)', 'E_U (K)'], merge=True, @@ -85,13 +105,16 @@ def minimize_table(table, *, columns=['Species', 'Chemical Name', """ from .core import colname_mapping_feb2024 + clean_columns(table) + columns = [colname_mapping_feb2024[c] if c in colname_mapping_feb2024 else c for c in columns] table = table[columns] if merge: - table = merge_frequencies(table) + #table = merge_frequencies(table) + table.rename_column('orderedfreq', 'Freq') if clean: table = clean_column_headings(table) From 675c377ce2b6c1ed300f19aa63297c963d3d4510 Mon Sep 17 00:00:00 2001 From: "Adam Ginsburg (keflavich)" Date: Wed, 13 Mar 2024 00:00:01 -0400 Subject: [PATCH 13/30] remove obsolete merge_frequeencies (there is now a unified frequency column in the returned data) --- astroquery/splatalogue/utils.py | 39 --------------------------------- 1 file changed, 39 deletions(-) diff --git a/astroquery/splatalogue/utils.py b/astroquery/splatalogue/utils.py index 0e1bf74724..6dc889e250 100644 --- a/astroquery/splatalogue/utils.py +++ b/astroquery/splatalogue/utils.py @@ -43,45 +43,6 @@ def clean_columns(table): ] -def merge_frequencies(table, *, prefer='measured', - theor_kwd='orderedFreq', - meas_kwd='measFreq'): - """ - Replace "orderedFreq" and "measFreq" with a single "Freq" column. - - Parameters - ---------- - table : table - The Splatalogue table - prefer: 'measured' or 'theoretical' - Which of the two columns to prefer if there is a conflict - """ - - if prefer == 'measured': - Freq = np.copy(table[theor_kwd]).astype('float') - if hasattr(table[meas_kwd], 'mask'): - measmask = np.logical_not(table[meas_kwd].mask) - else: - measmask = slice(None) # equivalent to [:] - all data are good - Freq[measmask] = table[meas_kwd][measmask].astype('float') - elif prefer == 'theoretical': - Freq = np.copy(table[meas_kwd]).astype('float') - if hasattr(table[theor_kwd], 'mask'): - theomask = np.logical_not(table[theor_kwd].mask) - else: - theomask = slice(None) # equivalent to [:] - all data are good - Freq[theomask] = table[theor_kwd][theomask].astype('float') - else: - raise ValueError('prefer must be one of "measured" or "theoretical"') - - index = table.index_column(theor_kwd) - table.remove_columns([theor_kwd, meas_kwd]) - newcol = astropy.table.Column(name='Freq', data=Freq) - table.add_column(newcol, index=index) - - return table - - def minimize_table(table, *, columns=['Species', 'Chemical Name', 'Resolved QNs', 'orderedfreq', From 9c20d54c799beed5f289e34ec1950ba712d0b7d9 Mon Sep 17 00:00:00 2001 From: "Adam Ginsburg (keflavich)" Date: Wed, 13 Mar 2024 23:17:18 -0400 Subject: [PATCH 14/30] rename some things --- astroquery/splatalogue/tests/test_splatalogue.py | 3 +++ astroquery/splatalogue/tests/test_utils.py | 11 +---------- astroquery/splatalogue/utils.py | 6 +++--- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/astroquery/splatalogue/tests/test_splatalogue.py b/astroquery/splatalogue/tests/test_splatalogue.py index 327d9426ce..f7a98195d5 100644 --- a/astroquery/splatalogue/tests/test_splatalogue.py +++ b/astroquery/splatalogue/tests/test_splatalogue.py @@ -2,6 +2,7 @@ import os import pytest +import json from astropy import units as u @@ -117,6 +118,7 @@ def test_exclude(patch_post): exclude=None, get_query_payload=True) + payload = json.loads(payload['body']) exclusions = {'excludePotentialInterstellarSpecies': False, 'excludeAtmosSpecies': False, 'excludeProbableInterstellarSpecies': False, @@ -131,6 +133,7 @@ def test_exclude(patch_post): chemical_name=' CO ', exclude='none', get_query_payload=True) + payload = json.loads(payload['body']) for key in exclusions: assert not payload[key] diff --git a/astroquery/splatalogue/tests/test_utils.py b/astroquery/splatalogue/tests/test_utils.py index e29659173d..d57302fbed 100644 --- a/astroquery/splatalogue/tests/test_utils.py +++ b/astroquery/splatalogue/tests/test_utils.py @@ -16,15 +16,6 @@ def test_clean(patch_post): assert 'resolved_QNs' in c.colnames -def test_merge(patch_post): - x = splatalogue.Splatalogue.query_lines(min_frequency=114 * u.GHz, - max_frequency=116 * u.GHz, - chemical_name=' CO ') - c = utils.merge_frequencies(x) - assert 'Freq' in c.colnames - assert np.all(c['Freq'] > 0) - - def test_minimize(patch_post): x = splatalogue.Splatalogue.query_lines(min_frequency=114 * u.GHz, max_frequency=116 * u.GHz, @@ -34,7 +25,7 @@ def test_minimize(patch_post): assert 'Freq' in c.colnames assert np.all(c['Freq'] > 0) assert 'Resolved QNs' not in c.colnames - assert 'QNs' in c.colnames + assert 'resolved_QNs' in c.colnames @pytest.mark.remote_data diff --git a/astroquery/splatalogue/utils.py b/astroquery/splatalogue/utils.py index 6dc889e250..a71ad475d1 100644 --- a/astroquery/splatalogue/utils.py +++ b/astroquery/splatalogue/utils.py @@ -43,10 +43,10 @@ def clean_columns(table): ] -def minimize_table(table, *, columns=['Species', 'Chemical Name', - 'Resolved QNs', +def minimize_table(table, *, columns=['name', 'chemical_name', + 'resolved_QNs', 'orderedfreq', - 'Log10 (Aij)', + 'aij', 'E_U (K)'], merge=True, clean=True): From ad414a23b0fe3879f758bc1bb361252545cc1210 Mon Sep 17 00:00:00 2001 From: "Adam Ginsburg (keflavich)" Date: Sat, 16 Mar 2024 09:59:21 -0400 Subject: [PATCH 15/30] remove "band" keyword argument as it is no longer used or supported --- astroquery/splatalogue/core.py | 37 +++++----------------------------- 1 file changed, 5 insertions(+), 32 deletions(-) diff --git a/astroquery/splatalogue/core.py b/astroquery/splatalogue/core.py index 279902c7d8..ce60673063 100644 --- a/astroquery/splatalogue/core.py +++ b/astroquery/splatalogue/core.py @@ -48,28 +48,6 @@ class SplatalogueClass(BaseQuery): 'Recombination', 'RFI') TOP20_LIST = ('comet', 'planet', 'top20', 'ism_hotcore', 'ism_darkcloud', 'ism_diffusecloud') - FREQUENCY_BANDS = {"any": "Any", - "alma3": "ALMA Band 3 (84-116 GHz)", - "alma4": " ALMA Band 4 (125-163 GHz)", - "alma5": " ALMA Band 5 (163-211 GHz)", - "alma6": "ALMA Band 6 (211-275 GHz)", - "alma7": "ALMA Band 7 (275-373 GHz)", - "alma8": "ALMA Band 8 (385-500 GHz)", - "alma9": "ALMA Band 9 (602-720 GHz)", - "alma10": "ALMA Band 10 (787-950 GHz)", - "pf1": "GBT PF1 (0.29-0.92 GHz)", - "pf2": "GBT PF2 (0.91-1.23 GHz)", - "l": "GBT/VLA L (1-2 GHz)", - "s": "GBT/VLA S (1.7-4 GHz)", - "c": "GBT/VLA C (3.9-8 GHz)", - "x": "GBT/VLA X (8-12 GHz)", - "ku": " GBT/VLA Ku (12-18 GHz)", - "kfpa": "GBT KFPA (18-27.5 GHz)", - "k": "VLA K (18-26.5 GHz)", - "ka": " GBT/VLA Ka (26-40 GHz)", - "q": "GBT/VLA Q (38-50 GHz)", - "w": "GBT W (67-93.3 GHz)", - "mustang": "GBT Mustang (80-100 GHz)", } def __init__(self, **kwargs): """ @@ -176,7 +154,7 @@ def _default_kwargs(self): return json.loads(self._parse_kwargs(**kwargs)['body']) def _parse_kwargs(self, *, min_frequency=None, max_frequency=None, - band='any', top20=None, chemical_name=None, + top20=None, chemical_name=None, chem_re_flags=0, energy_min=None, energy_max=None, energy_type=None, intensity_lower_limit=None, intensity_type=None, transition=None, version=None, @@ -203,9 +181,6 @@ def _parse_kwargs(self, *, min_frequency=None, max_frequency=None, Minimum frequency (or any spectral() equivalent) max_frequency : `astropy.units` Maximum frequency (or any spectral() equivalent) - band : str - The observing band. If it is not 'any', it overrides - minfreq/maxfreq. top20: str One of ``'comet'``, ``'planet'``, ``'top20'``, ``'ism_hotcore'``, ``'ism_darkcloud'``, ``'ism_diffusecloud'``. @@ -465,14 +440,12 @@ def _parse_kwargs(self, *, min_frequency=None, max_frequency=None, return payload def _validate_kwargs(self, *, min_frequency=None, max_frequency=None, - band='any', **kwargs): + **kwargs): """ - Check that either min_frequency + max_frequency or band are specified + Check that min_frequency + max_frequency are specified """ - if band == 'any': - if min_frequency is None or max_frequency is None: - raise ValueError("Must specify either min/max frequency or " - "a valid Band.") + if min_frequency is None or max_frequency is None: + raise ValueError("Must specify min/max frequency") @prepend_docstr_nosections("\n" + _parse_kwargs.__doc__) def query_lines_async(self, min_frequency=None, max_frequency=None, *, From ceecde0b091464b47dceb902993224f490ea1da2 Mon Sep 17 00:00:00 2001 From: "Adam Ginsburg (keflavich)" Date: Sat, 16 Mar 2024 10:01:08 -0400 Subject: [PATCH 16/30] remove "top20" keyword argument as it is no longer used or supported --- astroquery/splatalogue/core.py | 10 ++---- .../splatalogue/tests/test_splatalogue.py | 35 ------------------- 2 files changed, 2 insertions(+), 43 deletions(-) diff --git a/astroquery/splatalogue/core.py b/astroquery/splatalogue/core.py index ce60673063..852522ce79 100644 --- a/astroquery/splatalogue/core.py +++ b/astroquery/splatalogue/core.py @@ -45,9 +45,7 @@ class SplatalogueClass(BaseQuery): versions = ('v1.0', 'v2.0', 'v3.0', 'vall') # global constant, not user-configurable ALL_LINE_LISTS = ('LovasNIST', 'SLAIM', 'JPL', 'CDMS', 'ToyaMA', 'OSU', - 'Recombination', 'RFI') - TOP20_LIST = ('comet', 'planet', 'top20', 'ism_hotcore', 'ism_darkcloud', - 'ism_diffusecloud') + 'TopModel', 'Recombination', 'RFI') def __init__(self, **kwargs): """ @@ -154,7 +152,7 @@ def _default_kwargs(self): return json.loads(self._parse_kwargs(**kwargs)['body']) def _parse_kwargs(self, *, min_frequency=None, max_frequency=None, - top20=None, chemical_name=None, + chemical_name=None, chem_re_flags=0, energy_min=None, energy_max=None, energy_type=None, intensity_lower_limit=None, intensity_type=None, transition=None, version=None, @@ -181,10 +179,6 @@ def _parse_kwargs(self, *, min_frequency=None, max_frequency=None, Minimum frequency (or any spectral() equivalent) max_frequency : `astropy.units` Maximum frequency (or any spectral() equivalent) - top20: str - One of ``'comet'``, ``'planet'``, ``'top20'``, ``'ism_hotcore'``, - ``'ism_darkcloud'``, ``'ism_diffusecloud'``. - Overrides chemical_name chemical_name : str Name of the chemical to search for. Treated as a regular expression. An empty set ('', (), [], {}) will match *any* diff --git a/astroquery/splatalogue/tests/test_splatalogue.py b/astroquery/splatalogue/tests/test_splatalogue.py index f7a98195d5..7bbcbad29d 100644 --- a/astroquery/splatalogue/tests/test_splatalogue.py +++ b/astroquery/splatalogue/tests/test_splatalogue.py @@ -75,41 +75,6 @@ def test_linelist_type(): "names. See Splatalogue.ALL_LINE_LISTS") -def test_top20_crashorno(): - splatalogue.core.Splatalogue.query_lines_async(min_frequency=114 * u.GHz, - max_frequency=116 * u.GHz, - top20='top20', - get_query_payload=True) - with pytest.raises(ValueError) as exc: - splatalogue.core.Splatalogue.query_lines_async( - min_frequency=114 * u.GHz, max_frequency=116 * u.GHz, - top20='invalid', get_query_payload=True) - assert exc.value.args[0] == "Top20 is not one of the allowed values" - - -def test_band_crashorno(): - splatalogue.core.Splatalogue.query_lines_async(band='alma3', - get_query_payload=True) - with pytest.raises(ValueError) as exc: - splatalogue.core.Splatalogue.query_lines_async(band='invalid', - get_query_payload=True) - assert exc.value.args[0] == "Invalid frequency band." - - -# Upstream changed: there is no distinction between versions for this molecule -# # regression test : version selection should work -# # Unfortunately, it looks like version1 = version2 on the web page now, so this -# # may no longer be a valid test -# @pytest.mark.remote_data -# def test_version_selection(): -# results = splatalogue.Splatalogue.query_lines( -# min_frequency= 703*u.GHz, -# max_frequency=706*u.GHz, -# chemical_name='Acetaldehyde', -# version='v1.0' -# ) -# assert len(results)==1 - def test_exclude(patch_post): # regression test for issue 616 payload = splatalogue.Splatalogue.query_lines_async(min_frequency=114 * u.GHz, From d40a486619b0509f18c8878a5bd2aeeca042e18b Mon Sep 17 00:00:00 2001 From: "Adam Ginsburg (keflavich)" Date: Sat, 16 Mar 2024 10:03:07 -0400 Subject: [PATCH 17/30] fix a few more tests --- astroquery/splatalogue/tests/test_splatalogue.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/astroquery/splatalogue/tests/test_splatalogue.py b/astroquery/splatalogue/tests/test_splatalogue.py index 7bbcbad29d..01aa24bea9 100644 --- a/astroquery/splatalogue/tests/test_splatalogue.py +++ b/astroquery/splatalogue/tests/test_splatalogue.py @@ -46,21 +46,24 @@ def test_load_species_table(): # regression test: get_query_payload should work (#308) def test_get_payload(): - q = splatalogue.core.Splatalogue.query_lines_async(min_frequency=1 * u.GHz, + payload = splatalogue.core.Splatalogue.query_lines_async(min_frequency=1 * u.GHz, max_frequency=10 * u.GHz, get_query_payload=True) - assert q['body']["userInputFrequenciesFrom"] == [1.0] - assert q['body']["userInputFrequenciesTo"] == [10.0] + payload = json.loads(payload['body']) + assert payload["userInputFrequenciesFrom"] == [1.0] + assert payload["userInputFrequenciesTo"] == [10.0] # regression test: line lists should ask for only one line list, not all def test_line_lists(): - q = splatalogue.core.Splatalogue.query_lines_async(min_frequency=1 * u.GHz, + payload = splatalogue.core.Splatalogue.query_lines_async(min_frequency=1 * u.GHz, max_frequency=10 * u.GHz, line_lists=['JPL'], get_query_payload=True) - assert q['body']['lineListDisplayCDMSJPL'] - assert not q['body']['lineListDisplaySLAIM'] + payload = json.loads(payload['body']) + assert payload['lineListDisplayJPL'] + assert not payload['lineListDisplaySLAIM'] + assert not payload['lineListDisplayCDMS'] # regression test: raise an exception if a string is passed to line_lists From 090f737701f242559e3058b2cd99e4861cb39296 Mon Sep 17 00:00:00 2001 From: "Adam Ginsburg (keflavich)" Date: Sat, 16 Mar 2024 10:32:18 -0400 Subject: [PATCH 18/30] finally fixed all tests --- astroquery/splatalogue/core.py | 12 +++++------- .../splatalogue/tests/test_splatalogue.py | 17 ++++++++++++++--- astroquery/splatalogue/tests/test_utils.py | 8 +++++--- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/astroquery/splatalogue/core.py b/astroquery/splatalogue/core.py index 852522ce79..9651652cef 100644 --- a/astroquery/splatalogue/core.py +++ b/astroquery/splatalogue/core.py @@ -274,10 +274,6 @@ def _parse_kwargs(self, *, min_frequency=None, max_frequency=None, """ - payload = {'submit': 'Search', - 'frequency_units': 'GHz', - } - payload = {"searchSpecies": "", "speciesSelectBox": [], "dataVersion": "v3.0", @@ -346,9 +342,11 @@ def _parse_kwargs(self, *, min_frequency=None, max_frequency=None, payload['userInputFrequenciesFrom'] = [min_frequency.value] payload['userInputFrequenciesTo'] = [max_frequency.value] - if chemical_name in ('', {}, (), [], set()): - # include all - payload['speciesSelectBox'] = [] + if chemical_name in ('', {}, (), [], set(), None): + # include all by default, or whatever default was set + payload['speciesSelectBox'] = (self.data['speciesSelectBox'] + if hasattr(self, 'data') + else []) elif chemical_name is not None: if parse_chemistry_locally: species_ids = self.get_species_ids(species_regex=chemical_name, reflags=chem_re_flags) diff --git a/astroquery/splatalogue/tests/test_splatalogue.py b/astroquery/splatalogue/tests/test_splatalogue.py index 01aa24bea9..2c70e8ae39 100644 --- a/astroquery/splatalogue/tests/test_splatalogue.py +++ b/astroquery/splatalogue/tests/test_splatalogue.py @@ -24,7 +24,7 @@ def test_simple(patch_post): @pytest.mark.remote_data -def test_init(patch_post): +def test_init_remote(patch_post): x = splatalogue.Splatalogue.query_lines(min_frequency=114 * u.GHz, max_frequency=116 * u.GHz, chemical_name=' CO ') @@ -34,10 +34,21 @@ def test_init(patch_post): # masked arrays fail # assert y == x assert len(x) == len(y) - assert all(y['Species'] == x['Species']) - assert all(x['Chemical Name'] == y['Chemical Name']) + assert all(y['species_id'] == x['species_id']) + assert all(y['name'] == x['name']) + assert all(y['chemical_name'] == x['chemical_name']) +def test_init(): + splat = splatalogue.Splatalogue(chemical_name=' CO ') + assert splat.data['speciesSelectBox'] == ['204', '990', '991', '1343'] + payload = splat.query_lines(min_frequency=114 * u.GHz, max_frequency=116 * u.GHz, + get_query_payload=True) + payload = json.loads(payload['body']) + assert payload['speciesSelectBox'] == ['204', '990', '991', '1343'] + assert payload['userInputFrequenciesFrom'] == [114.0] + assert payload['userInputFrequenciesTo'] == [116.0] + def test_load_species_table(): tbl = splatalogue.load_species_table.species_lookuptable() CO = tbl.find(' CO ') diff --git a/astroquery/splatalogue/tests/test_utils.py b/astroquery/splatalogue/tests/test_utils.py index d57302fbed..527c98a0e8 100644 --- a/astroquery/splatalogue/tests/test_utils.py +++ b/astroquery/splatalogue/tests/test_utils.py @@ -30,6 +30,10 @@ def test_minimize(patch_post): @pytest.mark.remote_data def test_minimize_issue2135(): + """ + This was a regression test for 2135, but is now just a basic test for the + new (March 2024) keywords + """ rslt = splatalogue.Splatalogue.query_lines(min_frequency=100*u.GHz, max_frequency=200*u.GHz, chemical_name=' SiO ', @@ -40,6 +44,4 @@ def test_minimize_issue2135(): minimized = utils.minimize_table(rslt) - theomask = rslt['orderedFreq'].mask - np.testing.assert_allclose(minimized['Freq'][theomask], - rslt['measFreq'][theomask]) + np.testing.assert_allclose(minimized['Freq'], rslt['orderedfreq']) From 4193f93b07fd6b16bbe7822f2696dba5b2d476f4 Mon Sep 17 00:00:00 2001 From: "Adam Ginsburg (keflavich)" Date: Sat, 16 Mar 2024 10:36:33 -0400 Subject: [PATCH 19/30] whitespace/style cleanup --- astroquery/splatalogue/tests/test_splatalogue.py | 11 ++++++----- astroquery/splatalogue/utils.py | 3 --- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/astroquery/splatalogue/tests/test_splatalogue.py b/astroquery/splatalogue/tests/test_splatalogue.py index 2c70e8ae39..187369af0f 100644 --- a/astroquery/splatalogue/tests/test_splatalogue.py +++ b/astroquery/splatalogue/tests/test_splatalogue.py @@ -49,6 +49,7 @@ def test_init(): assert payload['userInputFrequenciesFrom'] == [114.0] assert payload['userInputFrequenciesTo'] == [116.0] + def test_load_species_table(): tbl = splatalogue.load_species_table.species_lookuptable() CO = tbl.find(' CO ') @@ -58,8 +59,8 @@ def test_load_species_table(): # regression test: get_query_payload should work (#308) def test_get_payload(): payload = splatalogue.core.Splatalogue.query_lines_async(min_frequency=1 * u.GHz, - max_frequency=10 * u.GHz, - get_query_payload=True) + max_frequency=10 * u.GHz, + get_query_payload=True) payload = json.loads(payload['body']) assert payload["userInputFrequenciesFrom"] == [1.0] assert payload["userInputFrequenciesTo"] == [10.0] @@ -68,9 +69,9 @@ def test_get_payload(): # regression test: line lists should ask for only one line list, not all def test_line_lists(): payload = splatalogue.core.Splatalogue.query_lines_async(min_frequency=1 * u.GHz, - max_frequency=10 * u.GHz, - line_lists=['JPL'], - get_query_payload=True) + max_frequency=10 * u.GHz, + line_lists=['JPL'], + get_query_payload=True) payload = json.loads(payload['body']) assert payload['lineListDisplayJPL'] assert not payload['lineListDisplaySLAIM'] diff --git a/astroquery/splatalogue/utils.py b/astroquery/splatalogue/utils.py index a71ad475d1..06b591d99b 100644 --- a/astroquery/splatalogue/utils.py +++ b/astroquery/splatalogue/utils.py @@ -2,8 +2,6 @@ """ Utilities for working with Splatalogue query results """ -import numpy as np -import astropy from bs4 import BeautifulSoup @@ -74,7 +72,6 @@ def minimize_table(table, *, columns=['name', 'chemical_name', table = table[columns] if merge: - #table = merge_frequencies(table) table.rename_column('orderedfreq', 'Freq') if clean: table = clean_column_headings(table) From b46834a020f68a42a5b92b66425af6ce8f1269a5 Mon Sep 17 00:00:00 2001 From: "Adam Ginsburg (keflavich)" Date: Sat, 16 Mar 2024 10:40:14 -0400 Subject: [PATCH 20/30] package .json data --- astroquery/splatalogue/setup_package.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/astroquery/splatalogue/setup_package.py b/astroquery/splatalogue/setup_package.py index 47b3c59d70..3c41ffcd54 100644 --- a/astroquery/splatalogue/setup_package.py +++ b/astroquery/splatalogue/setup_package.py @@ -5,7 +5,7 @@ def get_package_data(): - paths_test = [os.path.join('data', 'CO_colons.csv'), + paths_test = [os.path.join('data', 'CO.json'), ] paths_data = [os.path.join('data', '*.json'), From b9384f93bf9e81a0b636702807eb26eb4dfe9571 Mon Sep 17 00:00:00 2001 From: "Adam Ginsburg (keflavich)" Date: Sat, 16 Mar 2024 10:58:28 -0400 Subject: [PATCH 21/30] fix mocks (did these _ever_ work?) --- .../splatalogue/tests/test_splatalogue.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/astroquery/splatalogue/tests/test_splatalogue.py b/astroquery/splatalogue/tests/test_splatalogue.py index 187369af0f..823babfdc0 100644 --- a/astroquery/splatalogue/tests/test_splatalogue.py +++ b/astroquery/splatalogue/tests/test_splatalogue.py @@ -6,7 +6,8 @@ from astropy import units as u -from ... import splatalogue +from astroquery.utils.mocks import MockResponse +from astroquery import splatalogue SPLAT_DATA = 'CO.json' @@ -23,8 +24,22 @@ def test_simple(patch_post): chemical_name=' CO ') +def mockreturn(*args, method='POST', data={}, url='', **kwargs): + with open(data_path("CO.json"), 'rb') as fh: + jdata = fh.read() + return MockResponse(content=jdata) + + +@pytest.fixture +def patch_post(request): + mp = request.getfixturevalue("monkeypatch") + + mp.setattr(splatalogue.Splatalogue, '_request', mockreturn) + return mp + + @pytest.mark.remote_data -def test_init_remote(patch_post): +def test_init_remote(): x = splatalogue.Splatalogue.query_lines(min_frequency=114 * u.GHz, max_frequency=116 * u.GHz, chemical_name=' CO ') From 35a03241a45bbef530d761e373b99c98ed2d4e16 Mon Sep 17 00:00:00 2001 From: "Adam Ginsburg (keflavich)" Date: Sat, 16 Mar 2024 10:59:12 -0400 Subject: [PATCH 22/30] fix order --- astroquery/splatalogue/tests/test_splatalogue.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/astroquery/splatalogue/tests/test_splatalogue.py b/astroquery/splatalogue/tests/test_splatalogue.py index 823babfdc0..9d4b0a6f08 100644 --- a/astroquery/splatalogue/tests/test_splatalogue.py +++ b/astroquery/splatalogue/tests/test_splatalogue.py @@ -18,12 +18,6 @@ def data_path(filename): return os.path.join(data_dir, filename) -def test_simple(patch_post): - splatalogue.Splatalogue.query_lines(min_frequency=114 * u.GHz, - max_frequency=116 * u.GHz, - chemical_name=' CO ') - - def mockreturn(*args, method='POST', data={}, url='', **kwargs): with open(data_path("CO.json"), 'rb') as fh: jdata = fh.read() @@ -38,6 +32,12 @@ def patch_post(request): return mp +def test_simple(patch_post): + splatalogue.Splatalogue.query_lines(min_frequency=114 * u.GHz, + max_frequency=116 * u.GHz, + chemical_name=' CO ') + + @pytest.mark.remote_data def test_init_remote(): x = splatalogue.Splatalogue.query_lines(min_frequency=114 * u.GHz, From 5e3eebcd9641c638a5e4ad088da6517b57bb138f Mon Sep 17 00:00:00 2001 From: "Adam Ginsburg (keflavich)" Date: Sat, 16 Mar 2024 11:24:10 -0400 Subject: [PATCH 23/30] mocks, etc., are set up in conftest --- astroquery/splatalogue/tests/conftest.py | 4 ++-- .../splatalogue/tests/test_splatalogue.py | 22 ------------------- 2 files changed, 2 insertions(+), 24 deletions(-) diff --git a/astroquery/splatalogue/tests/conftest.py b/astroquery/splatalogue/tests/conftest.py index a0eaf176cc..b3b4be5917 100644 --- a/astroquery/splatalogue/tests/conftest.py +++ b/astroquery/splatalogue/tests/conftest.py @@ -28,6 +28,6 @@ def post_mockreturn(self, method, url, data=None, timeout=10, files=None, if method != 'POST': raise ValueError("A 'post request' was made with method != POST") filename = data_path(SPLAT_DATA) - with open(filename, 'r') as infile: - content = json.load(infile) + with open(filename, 'rb') as infile: + content = infile.read() return MockResponse(content, **kwargs) diff --git a/astroquery/splatalogue/tests/test_splatalogue.py b/astroquery/splatalogue/tests/test_splatalogue.py index 9d4b0a6f08..3ec78ce8db 100644 --- a/astroquery/splatalogue/tests/test_splatalogue.py +++ b/astroquery/splatalogue/tests/test_splatalogue.py @@ -10,28 +10,6 @@ from astroquery import splatalogue -SPLAT_DATA = 'CO.json' - - -def data_path(filename): - data_dir = os.path.join(os.path.dirname(__file__), 'data') - return os.path.join(data_dir, filename) - - -def mockreturn(*args, method='POST', data={}, url='', **kwargs): - with open(data_path("CO.json"), 'rb') as fh: - jdata = fh.read() - return MockResponse(content=jdata) - - -@pytest.fixture -def patch_post(request): - mp = request.getfixturevalue("monkeypatch") - - mp.setattr(splatalogue.Splatalogue, '_request', mockreturn) - return mp - - def test_simple(patch_post): splatalogue.Splatalogue.query_lines(min_frequency=114 * u.GHz, max_frequency=116 * u.GHz, From 5803174fef8396ce06d533841cac16015d1edf6a Mon Sep 17 00:00:00 2001 From: "Adam Ginsburg (keflavich)" Date: Sat, 16 Mar 2024 11:26:34 -0400 Subject: [PATCH 24/30] codestyle: remove imports --- astroquery/splatalogue/tests/conftest.py | 1 - astroquery/splatalogue/tests/test_splatalogue.py | 2 -- 2 files changed, 3 deletions(-) diff --git a/astroquery/splatalogue/tests/conftest.py b/astroquery/splatalogue/tests/conftest.py index b3b4be5917..a60bcd410b 100644 --- a/astroquery/splatalogue/tests/conftest.py +++ b/astroquery/splatalogue/tests/conftest.py @@ -2,7 +2,6 @@ import pytest import requests -import json from astroquery.utils.mocks import MockResponse diff --git a/astroquery/splatalogue/tests/test_splatalogue.py b/astroquery/splatalogue/tests/test_splatalogue.py index 3ec78ce8db..ab6f281902 100644 --- a/astroquery/splatalogue/tests/test_splatalogue.py +++ b/astroquery/splatalogue/tests/test_splatalogue.py @@ -1,12 +1,10 @@ # Licensed under a 3-clause BSD style license - see LICENSE.rst -import os import pytest import json from astropy import units as u -from astroquery.utils.mocks import MockResponse from astroquery import splatalogue From 3b6adf928cb1d5cfb54a45a219d6e485dc995df9 Mon Sep 17 00:00:00 2001 From: "Adam Ginsburg (keflavich)" Date: Sat, 16 Mar 2024 13:20:17 -0400 Subject: [PATCH 25/30] add another test to increase coverage slightly --- astroquery/splatalogue/tests/test_splatalogue.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/astroquery/splatalogue/tests/test_splatalogue.py b/astroquery/splatalogue/tests/test_splatalogue.py index ab6f281902..696d131c5b 100644 --- a/astroquery/splatalogue/tests/test_splatalogue.py +++ b/astroquery/splatalogue/tests/test_splatalogue.py @@ -14,6 +14,13 @@ def test_simple(patch_post): chemical_name=' CO ') +def test_backward_freqs(patch_post): + """ check that reversed frequencies still work """ + splatalogue.Splatalogue.query_lines(min_frequency=116 * u.GHz, + max_frequency=114 * u.GHz, + chemical_name=' CO ') + + @pytest.mark.remote_data def test_init_remote(): x = splatalogue.Splatalogue.query_lines(min_frequency=114 * u.GHz, From 09f6211eb210831067571affb14a7a4265cd0fe9 Mon Sep 17 00:00:00 2001 From: "Adam Ginsburg (keflavich)" Date: Sat, 16 Mar 2024 13:23:47 -0400 Subject: [PATCH 26/30] add another test to improve coverage (remote) --- .../splatalogue/tests/test_splatalogue.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/astroquery/splatalogue/tests/test_splatalogue.py b/astroquery/splatalogue/tests/test_splatalogue.py index 696d131c5b..a07207682d 100644 --- a/astroquery/splatalogue/tests/test_splatalogue.py +++ b/astroquery/splatalogue/tests/test_splatalogue.py @@ -127,3 +127,20 @@ def test_exclude_remote(): chemical_name='Formaldehyde', exclude='none') assert len(results) >= 1 + + +@pytest.mark.remote_data +def test_energy_limits(): + # first, check that there are high-energy things to exclude + rslt = splatalogue.Splatalogue.query_lines(min_frequency=114 * u.GHz, + max_frequency=116 * u.GHz, + chemical_name=' CO ') + assert rslt['upper_state_energy'].max() > 1000 + + # then, verify that they are successfully excluded + rslt = splatalogue.Splatalogue.query_lines(min_frequency=114 * u.GHz, + max_frequency=116 * u.GHz, + energy_max=1000, + energy_min=0, + chemical_name=' CO ') + assert rslt['upper_state_energy'].max() < 5 From 94f3c79c4abe0d11f5f11b38a46431b315e4307d Mon Sep 17 00:00:00 2001 From: Adam Ginsburg Date: Sat, 6 Apr 2024 12:25:49 -0400 Subject: [PATCH 27/30] Remove unnecessary comment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Brigitta Sipőcz --- astroquery/splatalogue/__init__.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/astroquery/splatalogue/__init__.py b/astroquery/splatalogue/__init__.py index 2e0e55a87e..46e49a7c68 100644 --- a/astroquery/splatalogue/__init__.py +++ b/astroquery/splatalogue/__init__.py @@ -22,8 +22,6 @@ class Conf(_config.ConfigNamespace): base_url = 'https://splatalogue.online' query_url = _config.ConfigItem( f'{base_url}/splata-slap/advanceded/false', - # defunct as of Sep 4, 2020? (keeping because this is likely the true host) - # 'https://www.cv.nrao.edu/php/splat/c_export.php', 'Splatalogue web interface URL.') timeout = _config.ConfigItem( 60, From ddff59f29ae9b7a0a315d3b25e07b914ed2f258e Mon Sep 17 00:00:00 2001 From: "Adam Ginsburg (keflavich)" Date: Sat, 6 Apr 2024 14:40:52 -0400 Subject: [PATCH 28/30] docuemntation cleanup, fix to some parameter validation --- astroquery/splatalogue/core.py | 46 ++++---- docs/splatalogue/splatalogue.rst | 181 +++++++++++++++---------------- 2 files changed, 112 insertions(+), 115 deletions(-) diff --git a/astroquery/splatalogue/core.py b/astroquery/splatalogue/core.py index 9651652cef..49273c2da2 100644 --- a/astroquery/splatalogue/core.py +++ b/astroquery/splatalogue/core.py @@ -46,6 +46,13 @@ class SplatalogueClass(BaseQuery): # global constant, not user-configurable ALL_LINE_LISTS = ('LovasNIST', 'SLAIM', 'JPL', 'CDMS', 'ToyaMA', 'OSU', 'TopModel', 'Recombination', 'RFI') + VALID_LINE_STRENGTHS = ('CDMSJPL', 'SijMu2', 'Sij', 'Aij', 'LovasAST') + VALID_ENERGY_LEVELS = {'One': 'EL_cm-1', + 'Two': 'EL_K', + 'Three': 'EU_cm-1', + 'Four': 'EU_K'} + VALID_ENERGY_TYPES = ('el_cm1', 'eu_cm1', 'eu_k', 'el_k') + VALID_INTENSITY_TYPES = ('CDMS/JPL (log)', 'Sij-mu2', 'Aij (log)') def __init__(self, **kwargs): """ @@ -137,8 +144,8 @@ def _default_kwargs(self): max_frequency=100 * u.THz, chemical_name='', line_lists=self.ALL_LINE_LISTS, - line_strengths=('CDMSJPL', 'SijMu2', 'Sij', 'Aij', 'LovasAST'), - energy_levels=('One', 'Two', 'Three', 'Four'), + line_strengths=self.VALID_LINE_STRENGTHS, + energy_levels=self.VALID_ENERGY_LEVELS.keys(), exclude=('potential', 'atmospheric', 'probable'), version='v3.0', only_NRAO_recommended=None, @@ -237,10 +244,10 @@ def _parse_kwargs(self, *, min_frequency=None, max_frequency=None, * Aij : ls4 * Lovas/AST : ls5 energy_levels : list - * E_lower (cm^-1) : el1 - * E_lower (K) : el2 - * E_upper (cm^-1) : el3 - * E_upper (K) : el4 + * E_lower (cm^-1) : "One" + * E_lower (K) : "Two" + * E_upper (cm^-1) : "Three" + * E_upper (K) : "Four" export : bool Set up arguments for the export server (as opposed to the HTML server)? @@ -361,14 +368,17 @@ def _parse_kwargs(self, *, min_frequency=None, max_frequency=None, if energy_max is not None: payload['energyTo'] = float(energy_max) if energy_type is not None: - validate_energy_type(energy_type) + if energy_type not in self.VALID_ENERGY_TYPES: + raise ValueError(f'energy_type must be one of {self.VALID_ENERGY_TYPES}') payload['energyRangeType'] = energy_type - # I don't know how to enter this right now - # if intensity_type is not None: - # payload['lineIntensity'] = 'lill_' + intensity_type - # if intensity_lower_limit is not None: - # payload[payload['lill']] = intensity_lower_limit + if intensity_lower_limit is not None: + if intensity_type is None: + raise ValueError("If you specify an intensity lower limit, you must also specify its intensity_type.") + elif intensity_type not in self.VALID_INTENSITY_TYPES: + raise ValueError(f'intensity_type must be one of {self.VALID_INTENSITY_TYPES}') + payload['lineIntensity'] = intensity_type + payload['lineIntensityLowerLimit'] = intensity_lower_limit if version in self.versions: payload['dataVersion'] = version @@ -401,10 +411,15 @@ def _parse_kwargs(self, *, min_frequency=None, max_frequency=None, if line_strengths is not None: for LS in line_strengths: + if LS not in self.VALID_LINE_STRENGTHS: + raise ValueError(f"Line strengths must be one of {self.VALID_LINE_STRENGTHS}") payload['lineStrengthDisplay' + LS] = True if energy_levels is not None: for EL in energy_levels: + if EL not in self.VALID_ENERGY_LEVELS: + raise ValueError("Energy levels must be a number spelled out, i.e., " + f"one of {self.VALID_ENERGY_LEVELS}") payload['energyLevel' + EL] = True for b in ("displayHFSIntensity", "displayUnresolvedQuantumNumbers", @@ -525,11 +540,4 @@ def get_fixed_table(self, *, columns=None): return table -def validate_energy_type(etype): - valid_energy_types = ('el_cm1', 'eu_cm1', 'eu_k', 'el_k') - if etype not in valid_energy_types: - raise ValueError("Energy type must be one of {0}" - .format(valid_energy_types)) - - Splatalogue = SplatalogueClass() diff --git a/docs/splatalogue/splatalogue.rst b/docs/splatalogue/splatalogue.rst index 0ce76f1093..97c7cf029e 100644 --- a/docs/splatalogue/splatalogue.rst +++ b/docs/splatalogue/splatalogue.rst @@ -104,32 +104,32 @@ size of the printout and assist with doctests; it is not needed as the default >>> from astropy import units as u >>> CO1to0 = Splatalogue.query_lines(115.271*u.GHz, 115.273*u.GHz) - >>> CO1to0.pprint(max_width=100) - Species Chemical Name ... E_U (K) Linelist - ------------------- ------------------------------------ ... ---------- -------- - GA-n-C4H9CN n-Butyl cyanide ... 332.23706 CDMS - NH2CH2CH2OHv26=1 Aminoethanol ... 390.35352 JPL - COv=0 Carbon Monoxide ... 5.53211 CDMS - COv=0 Carbon Monoxide ... 5.53211 JPL - COv=0 Carbon Monoxide ... 0.0 Lovas - COv=0 Carbon Monoxide ... 5.53211 SLAIM - FeCO Iron Monocarbonyl ... 103.95656 CDMS - CH3CHNH2COOH-I α-Alanine ... 129.92964 CDMS - s-trans-H2C=CHCOOH Propenoic acid ... 18.49667 CDMS - CH3CHOv=0,1&2 Acetaldehyde ... 223.65667 SLAIM - CH3CHOv=0,1&2 Acetaldehyde ... 223.6558 JPL - c-C5H5N Pyridine ... 230.47644 CDMS - c-C5H5N Pyridine ... 230.47644 CDMS - c-CH2CHCHO Propenal ... 1266.35462 JPL - c-CH2CHCHO Propenal ... 1266.35462 JPL - NH2CH2CH2OHv26=1 Aminoethanol ... 766.11681 JPL - NH2CH2CH2OHv26=1 Aminoethanol ... 766.11681 JPL - NH2CH2CH2OHv26=1 Aminoethanol ... 766.11681 JPL - NH2CH2CH2OHv26=1 Aminoethanol ... 766.11681 JPL - CH3O13CHO(TopModel) Methyl Formate ... 272.75041 TopModel - CH3O13CHO,vt=0,1 Methyl formate, vt = 0, 1 ... 272.75358 CDMS - H2NCH2COOH-IIv=1 Glycine ... 2355.1427 JPL - cis-CH2OHCHOv=3 Glycolaldehyde ... 887.56625 JPL + >>> CO1to0.pprint(max_width=200) + species_id name chemical_name ... searchErrorMessage sqlquery requestnumber + ---------- -------------------------------------------------------------------------------------- ------------------------------------ ... ------------------ -------- ------------- + 21228 GA-n-C4H9CN n-Butyl cyanide ... None 0 + 1288 NH2CH2CH2OH v26=1 Aminoethanol ... None 0 + 204 CO v = 0 Carbon Monoxide ... None 0 + 204 CO v = 0 Carbon Monoxide ... None 0 + 204 CO v = 0 Carbon Monoxide ... None 0 + 204 CO v = 0 Carbon Monoxide ... None 0 + 8 FeCO Iron Monocarbonyl ... None 0 + 1321 CH3CHNH2COOH - I α-Alanine ... None 0 + 21092 s-trans-H2C=CHCOOH Propenoic acid ... None 0 + 529 CH3CHO v = 0, 1 & 2 Acetaldehyde ... None 0 + 529 CH3CHO v = 0, 1 & 2 Acetaldehyde ... None 0 + 21067 c-C5H5N Pyridine ... None 0 + 21067 c-C5H5N Pyridine ... None 0 + 1275 c-CH2CHCHO Propenal ... None 0 + 1275 c-CH2CHCHO Propenal ... None 0 + 1288 NH2CH2CH2OH v26=1 Aminoethanol ... None 0 + 1288 NH2CH2CH2OH v26=1 Aminoethanol ... None 0 + 1288 NH2CH2CH2OH v26=1 Aminoethanol ... None 0 + 1288 NH2CH2CH2OH v26=1 Aminoethanol ... None 0 + 1370 CH3O13CHO (TopModel) Methyl Formate ... None 0 + 21026 CH3O13CHO, vt = 0, 1 Methyl formate, vt = 0, 1 ... None 0 + 1314 H2NCH2COOH - II v=1 Glycine ... None 0 + 1284 cis-CH2OHCHO v=3 Glycolaldehyde ... None 0 Querying just by frequency isn't particularly effective; a nicer approach is to use both frequency and chemical name. If you can remember that CO 2-1 is approximately @@ -139,30 +139,30 @@ this query works: .. doctest-remote-data:: >>> CO2to1 = Splatalogue.query_lines(1*u.mm, 2*u.mm, chemical_name=" CO ") - >>> CO2to1.pprint(max_width=100) - Species Chemical Name Freq-GHz(rest frame,redshifted) ... E_U (cm^-1) E_U (K) Linelist - ------- --------------- ------------------------------- ... ----------- ---------- -------- - COv=3 Carbon Monoxide 224.2417699 ... 6361.659 9152.9556 CDMS - COv=2 Carbon Monoxide -- ... 4271.3871 6145.5379 CDMS - COv=2 Carbon Monoxide 226.340357 ... 4271.3869 6145.53761 SLAIM - COv=1 Carbon Monoxide -- ... 2154.70101 3100.11628 CDMS - COv=1 Carbon Monoxide 228.43911 ... 2154.70191 3100.11758 SLAIM - COv=0 Carbon Monoxide -- ... 11.53492 16.59608 CDMS - COv=0 Carbon Monoxide -- ... 11.53492 16.59608 JPL - COv=0 Carbon Monoxide 230.538 ... 0.0 0.0 Lovas - COv=0 Carbon Monoxide 230.538 ... 11.53492 16.59608 SLAIM + >>> CO2to1.pprint(max_width=200) + species_id name chemical_name resolved_QNs linelist LovasASTIntensity ... telescope_Lovas_NIST transitionBandColor searchErrorMessage sqlquery requestnumber + ---------- --------------------------------- --------------- ------------ -------- ----------------- ... -------------------- -------------------- ------------------ -------- ------------- + 1343 CO v = 3 Carbon Monoxide 2- 1 CDMS ... datatablelightpurple None 0 + 991 CO v = 2 Carbon Monoxide 2- 1 CDMS ... datatablelightpurple None 0 + 991 CO v = 2 Carbon Monoxide 2- 1 SLAIM ... datatablelightpurple None 0 + 990 CO v = 1 Carbon Monoxide 2- 1 CDMS ... datatablelightpurple None 0 + 990 CO v = 1 Carbon Monoxide 2- 1 SLAIM 0.62 Jy ... datatablelightpurple None 0 + 204 CO v = 0 Carbon Monoxide 2-1 CDMS 70. ... NRAO 11m datatablelightpurple None 0 + 204 CO v = 0 Carbon Monoxide 2-1 JPL ... datatablelightpurple None 0 + 204 CO v = 0 Carbon Monoxide 2-1 Lovas 70. ... NRAO 11m datatablelightpurple None 0 + 204 CO v = 0 Carbon Monoxide 2- 1 SLAIM 70. ... datatablelightpurple None 0 Of course, there's some noise in there: both the vibrationally excited line and a whole lot of different line lists. Start by thinning out the line lists used: .. doctest-remote-data:: - >>> CO2to1 = Splatalogue.query_lines(1*u.mm, 2*u.mm, chemical_name=" CO ",only_NRAO_recommended=True) - >>> CO2to1.pprint(max_width=100) - Species Chemical Name Freq-GHz(rest frame,redshifted) ... E_U (cm^-1) E_U (K) Linelist - ------- --------------- ------------------------------- ... ----------- ---------- -------- - COv=1 Carbon Monoxide -- ... 2154.70101 3100.11628 CDMS - COv=0 Carbon Monoxide -- ... 11.53492 16.59608 CDMS + >>> CO2to1 = Splatalogue.query_lines(1*u.mm, 2*u.mm, chemical_name=" CO ", only_NRAO_recommended=True) + >>> CO2to1.pprint(max_width=200) + species_id name chemical_name resolved_QNs linelist LovasASTIntensity ... telescope_Lovas_NIST transitionBandColor searchErrorMessage sqlquery requestnumber + ---------- --------------------------------- --------------- ------------ -------- ----------------- ... -------------------- -------------------- ------------------ -------- ------------- + 990 CO v = 1 Carbon Monoxide 2- 1 CDMS ... datatablelightpurple None 0 + 204 CO v = 0 Carbon Monoxide 2-1 CDMS 70. ... NRAO 11m datatablelightpurple None 0 Then get rid of the vibrationally excited line by setting an energy upper limit in Kelvin: @@ -171,10 +171,10 @@ Then get rid of the vibrationally excited line by setting an energy upper limit >>> CO2to1 = Splatalogue.query_lines(1*u.mm, 2*u.mm, chemical_name=" CO ", ... only_NRAO_recommended=True, ... energy_max=50, energy_type='eu_k') - >>> CO2to1.pprint(max_width=100) - Species Chemical Name Freq-GHz(rest frame,redshifted) ... E_U (cm^-1) E_U (K) Linelist - ------- --------------- ------------------------------- ... ----------- -------- -------- - COv=0 Carbon Monoxide -- ... 11.53492 16.59608 CDMS + >>> CO2to1.pprint(max_width=200) + species_id name chemical_name resolved_QNs linelist LovasASTIntensity ... telescope_Lovas_NIST transitionBandColor searchErrorMessage sqlquery requestnumber + ---------- --------------------------------- --------------- ------------ -------- ----------------- ... -------------------- -------------------- ------------------ -------- ------------- + 204 CO v = 0 Carbon Monoxide 2-1 CDMS 70. ... NRAO 11m datatablelightpurple None 0 A note on recombination lines ----------------------------- @@ -189,25 +189,25 @@ these symbols (Hα, Hβ, Hγ, Hδ, Hε, Hζ), even though they will show up as .. doctest-remote-data:: >>> ha_result = Splatalogue.query_lines(84*u.GHz, 115*u.GHz, chemical_name='Hα') - >>> ha_result.pprint(max_width=100) - Species Chemical Name Freq-GHz(rest frame,redshifted) ... E_U (K) Linelist - -------- --------------------------- ------------------------------- ... ------- -------- - Hα Hydrogen Recombination Line 85.68839 ... 0.0 Recomb - Hα Hydrogen Recombination Line 92.034434 ... 0.0 Recomb - Hα Hydrogen Recombination Line 99.022952 ... 0.0 Recomb - Hα Hydrogen Recombination Line 106.737357 ... 0.0 Recomb + >>> ha_result.pprint(max_width=200) + species_id name chemical_name resolved_QNs linelist LovasASTIntensity ... source_Lovas_NIST telescope_Lovas_NIST transitionBandColor searchErrorMessage sqlquery requestnumber + ---------- -------- --------------------------- ------------------ -------- ----------------- ... ----------------- -------------------- ------------------- ------------------ -------- ------------- + 1154 Hα Hydrogen Recombination Line H ( 42 ) α Recomb ... datatableskyblue None 0 + 1154 Hα Hydrogen Recombination Line H ( 41 ) α Recomb ... datatableskyblue None 0 + 1154 Hα Hydrogen Recombination Line H ( 40 ) α Recomb ... datatableskyblue None 0 + 1154 Hα Hydrogen Recombination Line H ( 39 ) α Recomb ... datatableskyblue None 0 You could also search by specifying the line list .. doctest-remote-data:: - >>> recomb_result = Splatalogue.query_lines(84*u.GHz, 85*u.GHz, line_lists=['Recomb']) - >>> recomb_result.pprint(max_width=100) - Species Chemical Name Freq-GHz(rest frame,redshifted) ... E_U (K) Linelist - --------- --------------------------- ------------------------------- ... ------- -------- - Hγ Hydrogen Recombination Line 84.914394 ... 0.0 Recomb - Heγ Helium Recombination Line 84.948997 ... 0.0 Recomb - Cγ Carbon Recombination Line 84.956762 ... 0.0 Recomb + >>> recomb_result = Splatalogue.query_lines(84*u.GHz, 85*u.GHz, line_lists=['Recombination']) + >>> recomb_result.pprint(max_width=200) + species_id name chemical_name resolved_QNs linelist LovasASTIntensity ... source_Lovas_NIST telescope_Lovas_NIST transitionBandColor searchErrorMessage sqlquery requestnumber + ---------- --------- --------------------------- ------------------- -------- ----------------- ... ----------------- -------------------- ------------------- ------------------ -------- ------------- + 1156 Hγ Hydrogen Recombination Line H ( 60 ) γ Recomb ... datatableskyblue None 0 + 1162 Heγ Helium Recombination Line He ( 60 ) γ Recomb ... datatableskyblue None 0 + 1166 Cγ Carbon Recombination Line C ( 60 ) γ Recomb ... datatableskyblue None 0 Cleaning Up the Returned Data ----------------------------- @@ -218,48 +218,37 @@ regular basis. For example, if you want data returned preferentially in units of K rather than inverse cm, you're interested in low-energy lines, and you want your data sorted by energy, you can use an approach like this: -(note that as of March 2023, there is an upstream error in which the ``noHFS`` keyword -is not respected; we include it here as a demonstration in the hope that that error will -be fixed) - .. doctest-remote-data:: >>> S = Splatalogue(energy_max=500, - ... energy_type='eu_k',energy_levels=['el4'], - ... line_strengths=['ls4'], - ... only_NRAO_recommended=True, - ... noHFS=True, - ... displayHFS=False) + ... energy_type='eu_k', energy_levels=['Four'], + ... line_strengths=['CDMSJPL']) >>> def trimmed_query(*args,**kwargs): - ... columns = ('Species','Chemical Name','Resolved QNs', - ... 'Freq-GHz(rest frame,redshifted)', - ... 'Meas Freq-GHz(rest frame,redshifted)', - ... 'Log10 (Aij)', - ... 'E_U (K)') + ... columns = ('species_id', 'chemical_name', 'name', 'resolved_QNs', + ... 'orderedfreq', + ... 'aij', + ... 'upper_state_energy_K') ... table = S.query_lines(*args, **kwargs)[columns] - ... table.rename_column('Log10 (Aij)','log10(Aij)') - ... table.rename_column('E_U (K)','EU_K') - ... table.rename_column('Resolved QNs','QNs') - ... table.rename_column('Freq-GHz(rest frame,redshifted)', 'Freq-GHz'), - ... table.rename_column('Meas Freq-GHz(rest frame,redshifted)', 'Meas Freq-GHz'), - ... table.sort('EU_K') + ... table.sort('upper_state_energy_K') ... return table >>> trimmed_query(1*u.GHz,30*u.GHz, ... chemical_name='(H2.*Formaldehyde)|( HDCO )', - ... energy_max=50)[:10].pprint(max_width=100) - Species Chemical Name QNs Freq-GHz Meas Freq-GHz log10(Aij) EU_K - ------- ------------- ------------------- --------- ------------- ---------- -------- - HDCO Formaldehyde 1(1,0)-1(1,1) -- 5.3461416 -8.31616 11.18301 - H2C18O Formaldehyde 1(1,0)-1(1,1),F=1-0 4.3887783 -- -9.0498 15.30206 - H2C18O Formaldehyde 1(1,0)-1(1,1),F=0-1 4.3887957 -- -8.57268 15.30206 - H2C18O Formaldehyde 1(1,0)-1(1,1),F=2-2 4.3887965 -- -8.69765 15.30206 - H2C18O Formaldehyde 1(1,0)-1(1,1) 4.388797 -- -8.57272 15.30206 - H2C18O Formaldehyde 1(1,0)-1(1,1),F=2-1 4.3888012 -- -9.17475 15.30206 - H2C18O Formaldehyde 1(1,0)-1(1,1),F=1-2 4.3888036 -- -8.9529 15.30206 - H2C18O Formaldehyde 1(1,0)-1(1,1),F=1-1 4.3888083 -- -9.1748 15.30206 - H213CO Formaldehyde 1(1,0)-1(1,1) -- 4.5930885 -8.51332 15.34693 - H2CO Formaldehyde 1(1,0)-1(1,1),F=1-2 4.8296665 -- -8.82819 15.39497 - + ... energy_max=50)[:10].pprint(max_width=150) + species_id chemical_name name resolved_QNs orderedfreq aij upper_state_energy_K + ---------- ------------- ---------------------------- ---------------------------- ----------- -------- -------------------- + 109 Formaldehyde HDCO 1( 1, 0)- 1( 1, 1) 5346.142 -8.44112 11.18258 + 109 Formaldehyde HDCO 1( 1, 0)- 1( 1, 1) 5346.1616 -8.31295 11.18287 + 109 Formaldehyde HDCO 1(1,0) - 1(1,1) 5346.1416 -8.31616 11.18301 + 155 Formaldehyde H2C18O 1( 1, 0)- 1( 1, 1) 4388.797 -8.22052 15.30187 + 155 Formaldehyde H2C18O 1( 1, 0)- 1( 1, 1), F= 1- 0 4388.7783 -9.0498 15.30206 + 155 Formaldehyde H2C18O 1( 1, 0)- 1( 1, 1), F= 0- 1 4388.7957 -8.57268 15.30206 + 155 Formaldehyde H2C18O 1( 1, 0)- 1( 1, 1), F= 2- 2 4388.7965 -8.69765 15.30206 + 155 Formaldehyde H2C18O 1(1,0) - 1(1,1) 4388.797 -8.57272 15.30206 + 155 Formaldehyde H2C18O 1( 1, 0)- 1( 1, 1), F= 2- 1 4388.8012 -9.17475 15.30206 + 155 Formaldehyde H2C18O 1( 1, 0)- 1( 1, 1), F= 1- 2 4388.8036 -8.9529 15.30206 + +There are utility functions in `astroquery.splatalogue.utils` that automate +some of the above cleanup. Troubleshooting =============== From c5a6d1e648011fafaf865671876d1377bb544ebe Mon Sep 17 00:00:00 2001 From: "Adam Ginsburg (keflavich)" Date: Sat, 6 Apr 2024 14:54:29 -0400 Subject: [PATCH 29/30] fix template (it turns out to be kind of a useless file but nice as a test...) --- astroquery/splatalogue/templates.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/astroquery/splatalogue/templates.py b/astroquery/splatalogue/templates.py index cf74081b3e..8c72cb665d 100644 --- a/astroquery/splatalogue/templates.py +++ b/astroquery/splatalogue/templates.py @@ -6,6 +6,6 @@ from .core import SplatalogueClass SplatalogueKelvins = SplatalogueClass(energy_max=500, energy_type='eu_k', - energy_levels=['el4'], - line_strengths=['ls4'], + energy_levels=['Four'], + line_strengths=['CDMSJPL'], only_NRAO_recommended=True, noHFS=True) From 9f2c43798c74efa4b996ba6e99c24dfbf02a6d29 Mon Sep 17 00:00:00 2001 From: Adam Ginsburg Date: Sun, 7 Apr 2024 22:25:46 -0400 Subject: [PATCH 30/30] Update docs/splatalogue/splatalogue.rst MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Brigitta Sipőcz --- docs/splatalogue/splatalogue.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/splatalogue/splatalogue.rst b/docs/splatalogue/splatalogue.rst index 97c7cf029e..31985fb83b 100644 --- a/docs/splatalogue/splatalogue.rst +++ b/docs/splatalogue/splatalogue.rst @@ -247,7 +247,7 @@ data sorted by energy, you can use an approach like this: 155 Formaldehyde H2C18O 1( 1, 0)- 1( 1, 1), F= 2- 1 4388.8012 -9.17475 15.30206 155 Formaldehyde H2C18O 1( 1, 0)- 1( 1, 1), F= 1- 2 4388.8036 -8.9529 15.30206 -There are utility functions in `astroquery.splatalogue.utils` that automate +There are utility functions in ``astroquery.splatalogue.utils`` that automate some of the above cleanup. Troubleshooting