-
-
Notifications
You must be signed in to change notification settings - Fork 424
Support CDMS all species option; fix format for CDMS linelist reading; fix CDMS quantum numbers parsing #3302
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
e7e71ea
de4038b
34bd35b
dbba11a
ebda867
361e73b
a912cf2
c94ad8d
a4e5711
3de0ebd
559991b
7e56491
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,7 +32,7 @@ class CDMSClass(BaseQuery): | |
| SERVER = conf.server | ||
| CLASSIC_URL = conf.classic_server | ||
| TIMEOUT = conf.timeout | ||
| MALFORMATTED_MOLECULE_LIST = ['017506 NH3-wHFS', '028582 H2NC', '058501 H2C2S', '064527 HC3HCN'] | ||
| MALFORMATTED_MOLECULE_LIST = ['017506 NH3-wHFS', '028528 H2NC', '058501 H2C2S', '064527 HC3HCN'] | ||
|
|
||
| def query_lines_async(self, min_frequency, max_frequency, *, | ||
| min_strength=-500, molecule='All', | ||
|
|
@@ -278,40 +278,48 @@ def _parse_result(self, response, *, verbose=False): | |
| 'F3l': 83, | ||
| 'name': 89} | ||
|
|
||
| result = ascii.read(text, header_start=None, data_start=0, | ||
| comment=r'THIS|^\s{12,14}\d{4,6}.*', | ||
| names=list(starts.keys()), | ||
| col_starts=list(starts.values()), | ||
| format='fixed_width', fast_reader=False) | ||
|
|
||
| result['FREQ'].unit = u.MHz | ||
| result['ERR'].unit = u.MHz | ||
|
|
||
| result['MOLWT'] = [int(x/1e3) for x in result['TAG']] | ||
| result['Lab'] = result['MOLWT'] < 0 | ||
| result['MOLWT'] = np.abs(result['MOLWT']) | ||
| result['MOLWT'].unit = u.Da | ||
|
|
||
| fix_keys = ['GUP'] | ||
| for suf in 'ul': | ||
| for qn in ('J', 'v', 'K', 'F1', 'F2', 'F3'): | ||
| qnind = qn+suf | ||
| fix_keys.append(qnind) | ||
| for key in fix_keys: | ||
| if not np.issubdtype(result[key].dtype, np.integer): | ||
| intcol = np.array(list(map(parse_letternumber, result[key])), | ||
| dtype=int) | ||
| result[key] = intcol | ||
|
|
||
| # if there is a crash at this step, something went wrong with the query | ||
| # and the _last_query_temperature was not set. This shouldn't ever | ||
| # happen, but, well, I anticipate it will. | ||
| if self._last_query_temperature == 0: | ||
| result.rename_column('LGINT', 'LGAIJ') | ||
| result['LGAIJ'].unit = u.s**-1 | ||
| else: | ||
| result['LGINT'].unit = u.nm**2 * u.MHz | ||
| result['ELO'].unit = u.cm**(-1) | ||
| try: | ||
| result = ascii.read(text, header_start=None, data_start=0, | ||
| comment=r'THIS|^\s{12,14}\d{4,6}.*', | ||
| names=list(starts.keys()), | ||
| col_starts=list(starts.values()), | ||
| format='fixed_width', fast_reader=False) | ||
|
|
||
| result['FREQ'].unit = u.MHz | ||
| result['ERR'].unit = u.MHz | ||
|
|
||
| result['MOLWT'] = [int(x/1e3) for x in result['TAG']] | ||
| result['Lab'] = result['MOLWT'] < 0 | ||
| result['MOLWT'] = np.abs(result['MOLWT']) | ||
| result['MOLWT'].unit = u.Da | ||
|
|
||
| fix_keys = ['GUP'] | ||
| for suf in 'ul': | ||
| for qn in ('J', 'v', 'K', 'F1', 'F2', 'F3'): | ||
| qnind = qn+suf | ||
| fix_keys.append(qnind) | ||
| for key in fix_keys: | ||
| if not np.issubdtype(result[key].dtype, np.integer): | ||
| intcol = np.array(list(map(parse_letternumber, result[key])), | ||
| dtype=int) | ||
| result[key] = intcol | ||
|
|
||
| # if there is a crash at this step, something went wrong with the query | ||
| # and the _last_query_temperature was not set. This shouldn't ever | ||
| # happen, but, well, I anticipate it will. | ||
| if self._last_query_temperature == 0: | ||
| result.rename_column('LGINT', 'LGAIJ') | ||
| result['LGAIJ'].unit = u.s**-1 | ||
| else: | ||
| result['LGINT'].unit = u.nm**2 * u.MHz | ||
| result['ELO'].unit = u.cm**(-1) | ||
| except ValueError as ex: | ||
| # Give users a more helpful exception when parsing fails | ||
| original_message = str(ex) | ||
| new_message = ("Failed to parse CDMS response. This may be caused by a malformed search return. " | ||
| "You can check this by running `CDMS.get_molecule('<id>')` instead; if it works, the " | ||
| "problem is caused by the CDMS search interface and cannot be worked around.") | ||
| raise ValueError(new_message) from ex | ||
|
|
||
| return result | ||
|
|
||
|
|
@@ -421,25 +429,24 @@ def get_molecule(self, molecule_id, *, cache=True, return_response=False): | |
| timeout=self.TIMEOUT, cache=cache) | ||
| if return_response: | ||
| return response | ||
| result = self._parse_cat(response) | ||
| result = self._parse_cat(response.text) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shall we raise_for_status prior to this? Or maybe can we even upstream that raise for status and do it inside
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, just adding the raise_for_status here for now. Doing it in request is an idea, but then it changes the behavior of |
||
|
|
||
| species_table = self.get_species_table() | ||
| result.meta = dict(species_table.loc[int(molecule_id)]) | ||
|
|
||
| return result | ||
|
|
||
| def _parse_cat(self, response, *, verbose=False): | ||
| def _parse_cat(self, text, *, verbose=False): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick, but maybe call it text_response :)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this function works on any |
||
| """ | ||
| Parse a catalog response into an `~astropy.table.Table` | ||
|
|
||
| See details in _parse_response; this is a very similar function, | ||
| but the catalog responses have a slightly different format. | ||
| """ | ||
|
|
||
| if 'Zero lines were found' in response.text: | ||
| raise EmptyResponseError(f"Response was empty; message was '{response.text}'.") | ||
| if 'Zero lines were found' in text: | ||
| raise EmptyResponseError(f"Response was empty; message was '{text}'.") | ||
|
|
||
| text = response.text | ||
|
|
||
| # notes about the format | ||
| # [F13.4, 2F8.4, I2, F10.4, I3, I7, I4, 12I2]: FREQ, ERR, LGINT, DR, ELO, GUP, TAG, QNFMT, QN noqa | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.