pylamda 0.1.0__tar.gz → 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pylamda-0.1.0 → pylamda-0.2.0}/PKG-INFO +9 -6
- {pylamda-0.1.0 → pylamda-0.2.0}/README.md +6 -4
- {pylamda-0.1.0 → pylamda-0.2.0}/pyproject.toml +7 -5
- {pylamda-0.1.0 → pylamda-0.2.0}/src/pylamda/__init__.py +15 -2
- {pylamda-0.1.0 → pylamda-0.2.0}/src/pylamda/bib.py +350 -51
- {pylamda-0.1.0 → pylamda-0.2.0}/src/pylamda/catalogue.py +195 -18
- {pylamda-0.1.0 → pylamda-0.2.0}/src/pylamda/cli.py +304 -83
- pylamda-0.2.0/src/pylamda/combine.py +705 -0
- {pylamda-0.1.0 → pylamda-0.2.0}/src/pylamda/compare.py +102 -59
- pylamda-0.2.0/src/pylamda/data/database_refs.bib +275 -0
- {pylamda-0.1.0 → pylamda-0.2.0}/src/pylamda/data/references.bib +342 -0
- {pylamda-0.1.0 → pylamda-0.2.0}/src/pylamda/data/references.json +1342 -52
- {pylamda-0.1.0 → pylamda-0.2.0}/src/pylamda/fix.py +119 -44
- {pylamda-0.1.0 → pylamda-0.2.0}/src/pylamda/issues.py +27 -1
- {pylamda-0.1.0 → pylamda-0.2.0}/src/pylamda/model.py +45 -2
- {pylamda-0.1.0 → pylamda-0.2.0}/src/pylamda/reader.py +245 -29
- {pylamda-0.1.0 → pylamda-0.2.0}/src/pylamda/references.py +83 -1
- {pylamda-0.1.0 → pylamda-0.2.0}/src/pylamda/refsearch.py +175 -56
- {pylamda-0.1.0 → pylamda-0.2.0}/src/pylamda/verify.py +159 -75
- {pylamda-0.1.0 → pylamda-0.2.0}/src/pylamda/writer.py +28 -5
- pylamda-0.1.0/src/pylamda/combine.py +0 -318
- pylamda-0.1.0/src/pylamda/data/database_refs.bib +0 -55
- {pylamda-0.1.0 → pylamda-0.2.0}/LICENSE +0 -0
- {pylamda-0.1.0 → pylamda-0.2.0}/src/pylamda/__main__.py +0 -0
- {pylamda-0.1.0 → pylamda-0.2.0}/src/pylamda/formula.py +0 -0
- {pylamda-0.1.0 → pylamda-0.2.0}/src/pylamda/py.typed +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pylamda
|
|
3
|
-
Version: 0.
|
|
4
|
-
Summary: Work with and work on molecular
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Work with and work on molecular line data in the LAMDA format.
|
|
5
5
|
License-Expression: MIT
|
|
6
6
|
License-File: LICENSE
|
|
7
7
|
Keywords: LAMDA,RADEX,EMAA,NLTE,collision rates,Einstein A,molecular data,astrophysics
|
|
@@ -29,6 +29,7 @@ Requires-Dist: ruff (>=0.6) ; extra == "dev"
|
|
|
29
29
|
Requires-Dist: sphinx (>=8.2) ; extra == "dev"
|
|
30
30
|
Requires-Dist: sphinx-copybutton (>=0.5) ; extra == "dev"
|
|
31
31
|
Requires-Dist: sphinx-rtd-theme (>=3.0) ; extra == "dev"
|
|
32
|
+
Project-URL: Changelog, https://github.com/chrab/pylamda/blob/main/CHANGELOG.md
|
|
32
33
|
Project-URL: Documentation, https://pylamda.readthedocs.io/
|
|
33
34
|
Project-URL: Issues, https://github.com/chrab/pylamda/issues
|
|
34
35
|
Project-URL: Repository, https://github.com/chrab/pylamda
|
|
@@ -36,8 +37,12 @@ Description-Content-Type: text/markdown
|
|
|
36
37
|
|
|
37
38
|
# pylamda
|
|
38
39
|
|
|
39
|
-
[](https://pypi.org/project/pylamda/)
|
|
41
|
+
[](https://github.com/chrab/pylamda/actions/workflows/tests.yml)
|
|
42
|
+
[](https://pypi.org/project/pylamda/)
|
|
43
|
+
[](https://pylamda.readthedocs.io/)
|
|
44
|
+
[](https://github.com/chrab/pylamda/tree/python-coverage-comment-action-data)
|
|
45
|
+
[](https://github.com/chrab/pylamda/blob/main/LICENSE)
|
|
41
46
|
|
|
42
47
|
Python toolkit for working with and on files in the LAMDA format (the
|
|
43
48
|
[Leiden Atomic and Molecular Database](https://home.strw.leidenuniv.nl/~moldata/)).
|
|
@@ -80,5 +85,3 @@ pip install ".[plot]" # with matplotlib
|
|
|
80
85
|
pip install -e ".[dev]" # development: tests, ruff, Sphinx
|
|
81
86
|
```
|
|
82
87
|
|
|
83
|
-
Python ≥ 3.11. License: MIT.
|
|
84
|
-
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
# pylamda
|
|
2
2
|
|
|
3
|
-
[](https://pypi.org/project/pylamda/)
|
|
4
|
+
[](https://github.com/chrab/pylamda/actions/workflows/tests.yml)
|
|
5
|
+
[](https://pypi.org/project/pylamda/)
|
|
6
|
+
[](https://pylamda.readthedocs.io/)
|
|
7
|
+
[](https://github.com/chrab/pylamda/tree/python-coverage-comment-action-data)
|
|
8
|
+
[](https://github.com/chrab/pylamda/blob/main/LICENSE)
|
|
5
9
|
|
|
6
10
|
Python toolkit for working with and on files in the LAMDA format (the
|
|
7
11
|
[Leiden Atomic and Molecular Database](https://home.strw.leidenuniv.nl/~moldata/)).
|
|
@@ -43,5 +47,3 @@ pip install . # numpy and requests
|
|
|
43
47
|
pip install ".[plot]" # with matplotlib
|
|
44
48
|
pip install -e ".[dev]" # development: tests, ruff, Sphinx
|
|
45
49
|
```
|
|
46
|
-
|
|
47
|
-
Python ≥ 3.11. License: MIT.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "pylamda"
|
|
3
|
-
version = "0.
|
|
4
|
-
description = "Work with and work on molecular
|
|
3
|
+
version = "0.2.0"
|
|
4
|
+
description = "Work with and work on molecular line data in the LAMDA format."
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
license = "MIT"
|
|
7
7
|
license-files = ["LICENSE"]
|
|
@@ -25,6 +25,7 @@ dependencies = ["numpy>=1.26", "requests>=2.31"]
|
|
|
25
25
|
Documentation = "https://pylamda.readthedocs.io/"
|
|
26
26
|
Repository = "https://github.com/chrab/pylamda"
|
|
27
27
|
Issues = "https://github.com/chrab/pylamda/issues"
|
|
28
|
+
Changelog = "https://github.com/chrab/pylamda/blob/main/CHANGELOG.md"
|
|
28
29
|
|
|
29
30
|
[project.optional-dependencies]
|
|
30
31
|
plot = ["matplotlib>=3.8"]
|
|
@@ -45,13 +46,14 @@ dev = [
|
|
|
45
46
|
[project.scripts]
|
|
46
47
|
pylamda = "pylamda.cli:main"
|
|
47
48
|
|
|
48
|
-
[tool.poetry]
|
|
49
|
-
packages = [{ include = "pylamda", from = "src" }]
|
|
50
|
-
|
|
51
49
|
[build-system]
|
|
52
50
|
requires = ["poetry-core>=2.0.0,<3.0.0"]
|
|
53
51
|
build-backend = "poetry.core.masonry.api"
|
|
54
52
|
|
|
53
|
+
[tool.poetry]
|
|
54
|
+
# cspell:ignore pylamda
|
|
55
|
+
packages = [{ include = "pylamda", from = "src" }]
|
|
56
|
+
|
|
55
57
|
[tool.ruff]
|
|
56
58
|
line-length = 120
|
|
57
59
|
target-version = "py311"
|
|
@@ -15,10 +15,19 @@ reported as issues, never silently interpreted.
|
|
|
15
15
|
from importlib.metadata import PackageNotFoundError, version
|
|
16
16
|
|
|
17
17
|
from .bib import BibEntry, BibResult, bibtex, collect_references
|
|
18
|
-
from .combine import
|
|
18
|
+
from .combine import (
|
|
19
|
+
AddedPartner,
|
|
20
|
+
CombineError,
|
|
21
|
+
DroppedPartner,
|
|
22
|
+
ScaledPartner,
|
|
23
|
+
add_partner,
|
|
24
|
+
drop_partner,
|
|
25
|
+
patch_scale_partner,
|
|
26
|
+
scale_partner,
|
|
27
|
+
)
|
|
19
28
|
from .compare import LamdaDiff, LevelMatch, PartnerDiff, compare, critical_density, match_levels
|
|
20
29
|
from .fix import FixError, FixRecord, add_reference, fix, patch
|
|
21
|
-
from .issues import CODES, SEVERITIES, Issue, LamdaReadError
|
|
30
|
+
from .issues import CODES, SEVERITIES, Issue, LamdaReadError, NotLamdaError
|
|
22
31
|
from .model import (
|
|
23
32
|
PARTNER_IDS,
|
|
24
33
|
PARTNERS,
|
|
@@ -61,6 +70,8 @@ __all__ = [
|
|
|
61
70
|
"LamdaData",
|
|
62
71
|
"LamdaDiff",
|
|
63
72
|
"LamdaReadError",
|
|
73
|
+
"NotLamdaError",
|
|
74
|
+
"ScaledPartner",
|
|
64
75
|
"SourceMap",
|
|
65
76
|
"__version__",
|
|
66
77
|
"add_partner",
|
|
@@ -76,6 +87,8 @@ __all__ = [
|
|
|
76
87
|
"partner_name",
|
|
77
88
|
"patch",
|
|
78
89
|
"read",
|
|
90
|
+
"patch_scale_partner",
|
|
91
|
+
"scale_partner",
|
|
79
92
|
"split_partner_line",
|
|
80
93
|
"verify",
|
|
81
94
|
"write",
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
(doi.org).
|
|
13
13
|
4. Identifiers that are not resolved (or offline) give a ``@misc`` entry with the
|
|
14
14
|
identifier and a note saying what the reference is for.
|
|
15
|
-
5. The main papers of LAMDA and
|
|
15
|
+
5. The main papers of LAMDA, EMAA, CHIANTI, CDMS and JPL are added from
|
|
16
|
+
``pylamda/data/database_refs.bib``.
|
|
16
17
|
|
|
17
18
|
References given only as free text ("Flower (2001)") are not guessed: they are listed
|
|
18
19
|
in :attr:`BibResult.free_text`.
|
|
@@ -31,10 +32,10 @@ from dataclasses import dataclass, field, replace
|
|
|
31
32
|
from importlib.resources import files
|
|
32
33
|
from pathlib import Path
|
|
33
34
|
|
|
34
|
-
from .catalogue import load_catalogue
|
|
35
|
-
from .model import LamdaData
|
|
35
|
+
from .catalogue import load_catalogue, reference_segments
|
|
36
|
+
from .model import PYLAMDA_NOTE, LamdaData
|
|
36
37
|
from .reader import read
|
|
37
|
-
from .references import find_identifiers
|
|
38
|
+
from .references import file_reference_text, find_identifiers, level_reference_text, line_reference_text
|
|
38
39
|
|
|
39
40
|
#: Base URL of the SciX API (the same API as ADS).
|
|
40
41
|
SCIX_API = "https://api.scixplorer.org/v1"
|
|
@@ -51,6 +52,40 @@ EMAA_ACKNOWLEDGEMENT = (
|
|
|
51
52
|
"(https://dx.doi.org/10.17178/EMAA). EMAA is supported by the Observatoire des Sciences de l'Univers "
|
|
52
53
|
"de Grenoble (OSUG) (https://ror.org/03vte9x46)."
|
|
53
54
|
)
|
|
55
|
+
#: Keys added if a file names CDMS: the CDMS papers (decided 2026-11-28).
|
|
56
|
+
CDMS_KEYS: tuple[str, ...] = ("Muller2001", "Muller2005", "Endres2016")
|
|
57
|
+
#: What CDMS asks for besides the citation of its papers.
|
|
58
|
+
CDMS_REQUEST = "CDMS: cite the CDMS papers and the original papers of the data of each molecule."
|
|
59
|
+
#: Keys added if a file names JPL: the JPL catalogue paper (decided 2026-11-28).
|
|
60
|
+
JPL_KEYS: tuple[str, ...] = ("Pickett1998",)
|
|
61
|
+
#: Key of the first CHIANTI paper, cited for every CHIANTI version
|
|
62
|
+
#: (https://www.chiantidatabase.org/referencing.html).
|
|
63
|
+
CHIANTI_FIRST = "Dere1997"
|
|
64
|
+
#: CHIANTI version -> key of its paper. A version is the major number, or "7.1".
|
|
65
|
+
CHIANTI_VERSIONS: dict[str, str] = {
|
|
66
|
+
"1": "Dere1997",
|
|
67
|
+
"2": "Landi1999",
|
|
68
|
+
"3": "Dere2001",
|
|
69
|
+
"4": "Young2003",
|
|
70
|
+
"5": "Landi2006",
|
|
71
|
+
"6": "Dere2009",
|
|
72
|
+
"7": "Landi2012",
|
|
73
|
+
"7.1": "Landi2013",
|
|
74
|
+
"8": "DelZanna2015",
|
|
75
|
+
"9": "Dere2019",
|
|
76
|
+
"10": "DelZanna2021",
|
|
77
|
+
"11": "Dufresne2024",
|
|
78
|
+
}
|
|
79
|
+
#: The acknowledgement CHIANTI asks for (https://www.chiantidatabase.org/referencing.html).
|
|
80
|
+
CHIANTI_ACKNOWLEDGEMENT = (
|
|
81
|
+
"CHIANTI is a collaborative project involving George Mason University, the University of Michigan (USA), "
|
|
82
|
+
"University of Cambridge (UK) and NASA Goddard Space Flight Center (USA)."
|
|
83
|
+
)
|
|
84
|
+
#: What CHIANTI asks for besides the citation.
|
|
85
|
+
CHIANTI_REQUEST = (
|
|
86
|
+
"CHIANTI asks to cite the first CHIANTI paper (Dere et al. 1997) and the paper of the version used, "
|
|
87
|
+
"and, for detailed work on a data set, the papers of the original atomic data."
|
|
88
|
+
)
|
|
54
89
|
#: What LAMDA asks for besides the citation (https://home.strw.leidenuniv.nl/~moldata/).
|
|
55
90
|
LAMDA_REQUEST = (
|
|
56
91
|
"LAMDA asks to mention the date when the database was accessed, and to cite the original papers "
|
|
@@ -62,8 +97,19 @@ _DATABASE_NOTES = {
|
|
|
62
97
|
"vanderTak2020": "LAMDA database (2020 status review)",
|
|
63
98
|
"Faure2025": "EMAA database",
|
|
64
99
|
"EMAA": "EMAA database (dataset DOI)",
|
|
100
|
+
CHIANTI_FIRST: "CHIANTI database (first paper)",
|
|
101
|
+
"Muller2001": "CDMS database",
|
|
102
|
+
"Muller2005": "CDMS database",
|
|
103
|
+
"Endres2016": "CDMS database",
|
|
104
|
+
"Pickett1998": "JPL database",
|
|
105
|
+
}
|
|
106
|
+
_ROLE_TEXT = {
|
|
107
|
+
"dataset": "dataset",
|
|
108
|
+
"file": "the whole file (line 1)",
|
|
109
|
+
"levels": "levels and radiative data",
|
|
110
|
+
"lines": "radiative transitions",
|
|
111
|
+
"comments": "named in a comment",
|
|
65
112
|
}
|
|
66
|
-
_ROLE_TEXT = {"dataset": "dataset", "levels": "levels and radiative data", "comments": "named in a comment"}
|
|
67
113
|
_SEARCH_CHUNK = 900 # characters of a SciX query (the limit is 1000)
|
|
68
114
|
_EXPORT_CHUNK = 200 # bibcodes per SciX export request
|
|
69
115
|
|
|
@@ -84,9 +130,10 @@ class Reference:
|
|
|
84
130
|
molecule : str
|
|
85
131
|
The molecule of the file.
|
|
86
132
|
role : str
|
|
87
|
-
``"dataset"`` (dataset DOI), ``"levels"`` (
|
|
88
|
-
|
|
89
|
-
|
|
133
|
+
``"dataset"`` (dataset DOI), ``"file"`` (line 1), ``"levels"`` (line 2, the NLEV
|
|
134
|
+
line and the comment lines around it), ``"lines"`` (the NLIN line and the comment
|
|
135
|
+
lines around it), ``"collisions"`` (partner line) or ``"comments"`` (a comment
|
|
136
|
+
line, line 2 or the notes; only with an identifier).
|
|
90
137
|
partner : str or None
|
|
91
138
|
The partner (by ID) for ``"collisions"``.
|
|
92
139
|
text : str
|
|
@@ -121,28 +168,102 @@ def collect_references(data: LamdaData) -> list[Reference]:
|
|
|
121
168
|
Returns
|
|
122
169
|
-------
|
|
123
170
|
list of Reference
|
|
124
|
-
Dataset DOI,
|
|
125
|
-
|
|
171
|
+
Dataset DOI, file reference (line 1, if it holds an identifier or looks like a
|
|
172
|
+
reference), level reference, line reference and partner references (with or
|
|
173
|
+
without identifiers), then the comment lines, line 2 and notes that hold an
|
|
174
|
+
identifier. The level reference is line 2 (if it looks like a reference) and the
|
|
175
|
+
NLEV line with the comment lines around it
|
|
176
|
+
(:func:`~pylamda.references.level_reference_text`); the line reference is the
|
|
177
|
+
NLIN line with the comment lines around it
|
|
178
|
+
(:func:`~pylamda.references.line_reference_text`).
|
|
126
179
|
"""
|
|
127
180
|
path = data.source_map.path if data.source_map else None
|
|
128
181
|
mol = data.molecule
|
|
129
182
|
refs = []
|
|
130
183
|
if data.dataset_doi:
|
|
131
184
|
refs.append(Reference(path, mol, "dataset", None, data.dataset_doi, [f"doi:{data.dataset_doi}"]))
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
refs.append(Reference(path, mol, "
|
|
185
|
+
whole = file_reference_text(data)
|
|
186
|
+
if whole:
|
|
187
|
+
refs.append(Reference(path, mol, "file", None, whole, find_identifiers(whole)))
|
|
188
|
+
levels, where = level_reference_text(data) # line 2 if it looks like a reference, the NLEV line
|
|
189
|
+
if levels:
|
|
190
|
+
refs.append(Reference(path, mol, "levels", None, levels, find_identifiers(levels)))
|
|
191
|
+
lines = line_reference_text(data) # the NLIN line
|
|
192
|
+
if lines:
|
|
193
|
+
refs.append(Reference(path, mol, "lines", None, lines, find_identifiers(lines)))
|
|
135
194
|
for c in data.collisions:
|
|
136
195
|
if c.reference.strip():
|
|
137
196
|
text = c.reference.strip()
|
|
138
197
|
refs.append(Reference(path, mol, "collisions", c.label, text, find_identifiers(text)))
|
|
198
|
+
line1 = data.source_map.raw[0] if data.source_map is not None and data.source_map.raw else None
|
|
139
199
|
for text in _comment_texts(data):
|
|
200
|
+
if whole and text == line1: # line 1 is the file reference already
|
|
201
|
+
continue
|
|
140
202
|
ids = find_identifiers(text)
|
|
141
|
-
if ids:
|
|
203
|
+
if ids and not (where == "line 2" and text == data.title): # line 2 is the level reference already
|
|
142
204
|
refs.append(Reference(path, mol, "comments", None, text.strip().lstrip("!").strip(), ids))
|
|
143
205
|
return refs
|
|
144
206
|
|
|
145
207
|
|
|
208
|
+
@dataclass(frozen=True)
|
|
209
|
+
class Paper:
|
|
210
|
+
"""One cited paper of a reference text (:func:`reference_papers`).
|
|
211
|
+
|
|
212
|
+
Attributes
|
|
213
|
+
----------
|
|
214
|
+
reference : Reference
|
|
215
|
+
The reference text it is part of (role ``"file"``, ``"levels"``, ``"lines"`` or
|
|
216
|
+
``"collisions"``).
|
|
217
|
+
block : int or None
|
|
218
|
+
For ``"collisions"``: the index of the collision block.
|
|
219
|
+
segment : str
|
|
220
|
+
The text of the paper, without identifiers.
|
|
221
|
+
has_id : bool
|
|
222
|
+
Whether an identifier names the paper.
|
|
223
|
+
index, count : int
|
|
224
|
+
Its number in the reference text (from 1) and the number of papers there.
|
|
225
|
+
"""
|
|
226
|
+
|
|
227
|
+
reference: Reference
|
|
228
|
+
block: int | None
|
|
229
|
+
segment: str
|
|
230
|
+
has_id: bool
|
|
231
|
+
index: int
|
|
232
|
+
count: int
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
def reference_papers(data: LamdaData) -> list[Paper]:
|
|
236
|
+
"""The cited papers of a data set: the one rule of F03, ``bib``, ``bib --search`` and ``fix``.
|
|
237
|
+
|
|
238
|
+
The file reference (line 1), the level reference, the line reference and each partner
|
|
239
|
+
reference are split into papers by :func:`~pylamda.catalogue.reference_segments`;
|
|
240
|
+
database notes are left out. For the levels, identifiers in comment lines, line 2,
|
|
241
|
+
the notes and the dataset DOI also count; the lines need their own identifiers.
|
|
242
|
+
|
|
243
|
+
Parameters
|
|
244
|
+
----------
|
|
245
|
+
data : LamdaData
|
|
246
|
+
The data.
|
|
247
|
+
|
|
248
|
+
Returns
|
|
249
|
+
-------
|
|
250
|
+
list of Paper
|
|
251
|
+
File, levels, then the partners in block order.
|
|
252
|
+
"""
|
|
253
|
+
refs = collect_references(data)
|
|
254
|
+
level_ids = [i for r in refs if r.role in ("comments", "dataset") for i in r.identifiers]
|
|
255
|
+
blocks = iter([b for b, c in enumerate(data.collisions) if c.reference.strip()])
|
|
256
|
+
out = []
|
|
257
|
+
for ref in refs:
|
|
258
|
+
if ref.role not in ("file", "levels", "lines", "collisions"):
|
|
259
|
+
continue
|
|
260
|
+
block = next(blocks) if ref.role == "collisions" else None
|
|
261
|
+
parts = reference_segments(ref.text, level_ids if ref.role == "levels" else None)
|
|
262
|
+
for k, (seg, has_id) in enumerate(parts, 1):
|
|
263
|
+
out.append(Paper(ref, block, seg, has_id, k, len(parts)))
|
|
264
|
+
return out
|
|
265
|
+
|
|
266
|
+
|
|
146
267
|
def _comment_texts(data: LamdaData) -> list[str]:
|
|
147
268
|
"""Line 2 (title), the notes and the comment lines of the file (not the partner lines)."""
|
|
148
269
|
texts = [data.title, *data.notes]
|
|
@@ -150,8 +271,127 @@ def _comment_texts(data: LamdaData) -> list[str]:
|
|
|
150
271
|
if smap is not None:
|
|
151
272
|
notes_from = smap.notes or len(smap.raw) + 1
|
|
152
273
|
texts += [line for i, line in enumerate(smap.raw, 1) if i < notes_from and line.lstrip().startswith("!")]
|
|
153
|
-
|
|
154
|
-
|
|
274
|
+
return [t for t in texts if t and t.strip() and not PYLAMDA_NOTE.match(t)] # not pylamda's own notes
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
_CHIANTI = re.compile(r"\bCHIANTI\b", re.I)
|
|
278
|
+
# "CHIANTI 11.0.2", "CHIANTI v8", "CHIANTI version 7.1", "CHIANTI database v10"
|
|
279
|
+
_CHIANTI_VERSION = re.compile(
|
|
280
|
+
r"\bCHIANTI\b['\"]?(?:\s+(?:atomic\s+)?database)?[\s,:]*(?:v(?:ersion)?\.?\s*)?(\d{1,2})(?:\.(\d+))?(?![\d.]*\d{3})",
|
|
281
|
+
re.I,
|
|
282
|
+
)
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
def chianti_versions(data: LamdaData) -> list[str] | None:
|
|
286
|
+
"""The CHIANTI versions a data set names (keys of :data:`CHIANTI_VERSIONS`).
|
|
287
|
+
|
|
288
|
+
Parameters
|
|
289
|
+
----------
|
|
290
|
+
data : LamdaData
|
|
291
|
+
The data.
|
|
292
|
+
|
|
293
|
+
Returns
|
|
294
|
+
-------
|
|
295
|
+
list of str or None
|
|
296
|
+
None if the data set does not name CHIANTI; else the versions found, in the order
|
|
297
|
+
found (empty if no version is given).
|
|
298
|
+
"""
|
|
299
|
+
texts = [
|
|
300
|
+
data.level_reference,
|
|
301
|
+
data.line_reference,
|
|
302
|
+
data.source,
|
|
303
|
+
*(c.reference for c in data.collisions),
|
|
304
|
+
*_comment_texts(data),
|
|
305
|
+
]
|
|
306
|
+
texts = [t for t in texts if t]
|
|
307
|
+
if not any(_CHIANTI.search(t) for t in texts):
|
|
308
|
+
return None
|
|
309
|
+
out: list[str] = []
|
|
310
|
+
for t in texts:
|
|
311
|
+
for m in _CHIANTI_VERSION.finditer(t):
|
|
312
|
+
major, minor = m.group(1), m.group(2)
|
|
313
|
+
version = "7.1" if major == "7" and minor == "1" else major.lstrip("0")
|
|
314
|
+
if version in CHIANTI_VERSIONS and version not in out:
|
|
315
|
+
out.append(version)
|
|
316
|
+
return out
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
#: Databases that a ``!SOURCE:`` line names first, as astrolinedata writes it
|
|
320
|
+
#: (``!SOURCE: CHIANTI 11.0.2, ion ne_3, ...``, ``!SOURCE: LAMDA https://...``).
|
|
321
|
+
SOURCE_DATABASES: tuple[str, ...] = ("LAMDA", "EMAA", "CHIANTI", "CDMS", "JPL", "BASECOL", "HITRAN", "ExoMol", "NIST")
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
def source_database(data: LamdaData) -> str | None:
|
|
325
|
+
"""The database a data set comes from, if the file says so.
|
|
326
|
+
|
|
327
|
+
The first word of the ``!SOURCE:`` line if it is one of :data:`SOURCE_DATABASES`, or
|
|
328
|
+
``"EMAA"`` for an EMAA dataset DOI (``10.17178/EMAA...``). A file without such a
|
|
329
|
+
sign (most LAMDA files) gives None: its origin is not known.
|
|
330
|
+
|
|
331
|
+
Parameters
|
|
332
|
+
----------
|
|
333
|
+
data : LamdaData
|
|
334
|
+
The data.
|
|
335
|
+
|
|
336
|
+
Returns
|
|
337
|
+
-------
|
|
338
|
+
str or None
|
|
339
|
+
The database (spelt as in :data:`SOURCE_DATABASES`), or None.
|
|
340
|
+
"""
|
|
341
|
+
m = re.match(r"\s*([A-Za-z]+)\b", data.source or "")
|
|
342
|
+
if m:
|
|
343
|
+
name = {d.lower(): d for d in SOURCE_DATABASES}.get(m.group(1).lower())
|
|
344
|
+
if name:
|
|
345
|
+
return name
|
|
346
|
+
if (data.dataset_doi or "").upper().startswith("10.17178/EMAA"):
|
|
347
|
+
return "EMAA"
|
|
348
|
+
return None
|
|
349
|
+
|
|
350
|
+
|
|
351
|
+
def is_cdms(data: LamdaData) -> bool:
|
|
352
|
+
"""Whether a data set names CDMS (the Cologne Database for Molecular Spectroscopy).
|
|
353
|
+
|
|
354
|
+
Parameters
|
|
355
|
+
----------
|
|
356
|
+
data : LamdaData
|
|
357
|
+
The data.
|
|
358
|
+
|
|
359
|
+
Returns
|
|
360
|
+
-------
|
|
361
|
+
bool
|
|
362
|
+
True if "CDMS" (or a CDMS link) is in one of its texts.
|
|
363
|
+
"""
|
|
364
|
+
texts = [
|
|
365
|
+
data.level_reference,
|
|
366
|
+
data.line_reference,
|
|
367
|
+
data.source,
|
|
368
|
+
*(c.reference for c in data.collisions),
|
|
369
|
+
*_comment_texts(data),
|
|
370
|
+
]
|
|
371
|
+
return any(re.search(r"\bCDMS\b|cdms\.astro\.uni-koeln\.de", t or "", re.I) for t in texts)
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
def is_jpl(data: LamdaData) -> bool:
|
|
375
|
+
"""Whether a data set names the JPL catalogue (JPL Molecular Spectroscopy).
|
|
376
|
+
|
|
377
|
+
Parameters
|
|
378
|
+
----------
|
|
379
|
+
data : LamdaData
|
|
380
|
+
The data.
|
|
381
|
+
|
|
382
|
+
Returns
|
|
383
|
+
-------
|
|
384
|
+
bool
|
|
385
|
+
True if "JPL" (or a link to ``spec.jpl.nasa.gov``) is in one of its texts.
|
|
386
|
+
"""
|
|
387
|
+
texts = [
|
|
388
|
+
data.level_reference,
|
|
389
|
+
data.line_reference,
|
|
390
|
+
data.source,
|
|
391
|
+
*(c.reference for c in data.collisions),
|
|
392
|
+
*_comment_texts(data),
|
|
393
|
+
]
|
|
394
|
+
return any(re.search(r"\bJPL\b|spec\.jpl\.nasa\.gov", t or "", re.I) for t in texts)
|
|
155
395
|
|
|
156
396
|
|
|
157
397
|
def is_emaa(data: LamdaData) -> bool:
|
|
@@ -169,7 +409,13 @@ def is_emaa(data: LamdaData) -> bool:
|
|
|
169
409
|
"""
|
|
170
410
|
if (data.dataset_doi or "").upper().startswith("10.17178/EMAA"):
|
|
171
411
|
return True
|
|
172
|
-
texts = [
|
|
412
|
+
texts = [
|
|
413
|
+
data.level_reference,
|
|
414
|
+
data.line_reference,
|
|
415
|
+
data.source,
|
|
416
|
+
*(c.reference for c in data.collisions),
|
|
417
|
+
*_comment_texts(data),
|
|
418
|
+
]
|
|
173
419
|
return any(re.search(r"\bEMAA\b", t or "") for t in texts)
|
|
174
420
|
|
|
175
421
|
|
|
@@ -508,8 +754,18 @@ class BibResult:
|
|
|
508
754
|
What could not be resolved, and why.
|
|
509
755
|
keys : dict of str to str
|
|
510
756
|
Identifier -> key of every entry (for ``keys`` in the next run).
|
|
757
|
+
lamda : bool
|
|
758
|
+
Whether the LAMDA papers are added: a file comes from LAMDA or its origin is not
|
|
759
|
+
known (:func:`source_database`). False only if every file names another database.
|
|
511
760
|
emaa : bool
|
|
512
761
|
Whether a file comes from EMAA (the export then holds EMAA's acknowledgement).
|
|
762
|
+
cdms : bool
|
|
763
|
+
Whether a file names CDMS.
|
|
764
|
+
jpl : bool
|
|
765
|
+
Whether a file names JPL.
|
|
766
|
+
chianti : list of str or None
|
|
767
|
+
None if no file names CHIANTI; else the CHIANTI versions named (the export then
|
|
768
|
+
holds CHIANTI's request and acknowledgement).
|
|
513
769
|
n_files : int
|
|
514
770
|
Number of data sets.
|
|
515
771
|
"""
|
|
@@ -518,7 +774,11 @@ class BibResult:
|
|
|
518
774
|
free_text: list[Reference] = field(default_factory=list)
|
|
519
775
|
warnings: list[str] = field(default_factory=list)
|
|
520
776
|
keys: dict[str, str] = field(default_factory=dict)
|
|
777
|
+
lamda: bool = True
|
|
521
778
|
emaa: bool = False
|
|
779
|
+
cdms: bool = False
|
|
780
|
+
jpl: bool = False
|
|
781
|
+
chianti: list[str] | None = None
|
|
522
782
|
n_files: int = 0
|
|
523
783
|
|
|
524
784
|
def text(self) -> str:
|
|
@@ -532,6 +792,11 @@ class BibResult:
|
|
|
532
792
|
head.append(f"% {LAMDA_REQUEST}")
|
|
533
793
|
if self.emaa:
|
|
534
794
|
head.append(f"% EMAA asks for this acknowledgement: {EMAA_ACKNOWLEDGEMENT}")
|
|
795
|
+
if self.cdms:
|
|
796
|
+
head.append(f"% {CDMS_REQUEST}")
|
|
797
|
+
if self.chianti is not None:
|
|
798
|
+
head.append(f"% {CHIANTI_REQUEST}")
|
|
799
|
+
head.append(f"% CHIANTI asks for this acknowledgement: {CHIANTI_ACKNOWLEDGEMENT}")
|
|
535
800
|
parts = ["\n".join(head)]
|
|
536
801
|
for e in self.entries:
|
|
537
802
|
note = f"{e.note} (pylamda reference catalogue)" if e.source == "catalogue" else e.note
|
|
@@ -566,33 +831,32 @@ class _Work:
|
|
|
566
831
|
return "; ".join(f"{mol}: {', '.join(uses)}" for mol, uses in self.uses.items())
|
|
567
832
|
|
|
568
833
|
|
|
569
|
-
def _from_catalogue(
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
if
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
return unresolved
|
|
834
|
+
def _from_catalogue(cat, data: LamdaData, fname: str | None, paper: Paper, works: dict, result: BibResult) -> bool:
|
|
835
|
+
"""Add a free-text paper if the catalogue knows it; return whether it does."""
|
|
836
|
+
ref, seg = paper.reference, paper.segment
|
|
837
|
+
hit = cat.find(seg, molecule=data.molecule, file=fname, role=ref.role, partner=ref.partner)
|
|
838
|
+
if hit is not None and hit.status == "skip": # reviewed: not a reference, no entry
|
|
839
|
+
return True
|
|
840
|
+
if hit is None or hit.key is None:
|
|
841
|
+
return False
|
|
842
|
+
ident = f"bibcode:{hit.bibcode}"
|
|
843
|
+
w = works.get(ident)
|
|
844
|
+
if w is None:
|
|
845
|
+
ids = [ident] + ([f"doi:{hit.doi}"] if hit.doi else [])
|
|
846
|
+
w = works[ident] = _Work(
|
|
847
|
+
ids, seg, bibcode=hit.bibcode, bibtex=cat.bibtex.get(hit.key), source="catalogue", catalogue_key=hit.key
|
|
848
|
+
)
|
|
849
|
+
w.add_use(data.molecule, ref.use)
|
|
850
|
+
if hit.match == "text":
|
|
851
|
+
result.warnings.append(
|
|
852
|
+
f"{fname or data.molecule}: {seg!r} found in the reference catalogue by its text only "
|
|
853
|
+
f"({hit.key}, cited there for another molecule): check it"
|
|
854
|
+
)
|
|
855
|
+
return True
|
|
592
856
|
|
|
593
857
|
|
|
594
858
|
def database_entries() -> dict[str, str]:
|
|
595
|
-
"""The shipped BibTeX entries of the LAMDA
|
|
859
|
+
"""The shipped BibTeX entries of the database papers (LAMDA, EMAA, CHIANTI, CDMS, JPL), by key.
|
|
596
860
|
|
|
597
861
|
Returns
|
|
598
862
|
-------
|
|
@@ -626,8 +890,11 @@ def bibtex(
|
|
|
626
890
|
token : str or None, optional
|
|
627
891
|
SciX API token; default: :func:`scix_token` (environment, token file).
|
|
628
892
|
database_refs : bool, optional
|
|
629
|
-
Add the main papers of LAMDA (
|
|
630
|
-
|
|
893
|
+
Add the main papers of LAMDA (unless every file comes from another database, by its
|
|
894
|
+
``!SOURCE:`` line or an EMAA dataset DOI: :func:`source_database`), EMAA (if a
|
|
895
|
+
file comes from EMAA) and
|
|
896
|
+
CHIANTI (if a file names CHIANTI: the first paper and the paper of each version
|
|
897
|
+
named), CDMS (if a file names CDMS) and JPL (if a file names JPL). Default: True.
|
|
631
898
|
keys : dict of str to str or None, optional
|
|
632
899
|
Identifier -> key from an earlier run, to keep keys stable.
|
|
633
900
|
cache : bool, str or os.PathLike, optional
|
|
@@ -653,18 +920,37 @@ def bibtex(
|
|
|
653
920
|
If SciX rejects the token.
|
|
654
921
|
"""
|
|
655
922
|
datas = [s if isinstance(s, LamdaData) else read(s) for s in sources]
|
|
656
|
-
result = BibResult(
|
|
923
|
+
result = BibResult(
|
|
924
|
+
n_files=len(datas),
|
|
925
|
+
lamda=not datas or any(source_database(d) in (None, "LAMDA") for d in datas), # if in doubt: LAMDA
|
|
926
|
+
emaa=any(is_emaa(d) for d in datas),
|
|
927
|
+
cdms=any(is_cdms(d) for d in datas),
|
|
928
|
+
jpl=any(is_jpl(d) for d in datas),
|
|
929
|
+
)
|
|
930
|
+
for d in datas:
|
|
931
|
+
versions = chianti_versions(d)
|
|
932
|
+
if versions is None:
|
|
933
|
+
continue
|
|
934
|
+
result.chianti = [*(result.chianti or []), *(v for v in versions if v not in (result.chianti or []))]
|
|
935
|
+
if not versions:
|
|
936
|
+
where = d.source_map.path if d.source_map else d.molecule
|
|
937
|
+
result.warnings.append(
|
|
938
|
+
f"{where}: CHIANTI without a version; cite the paper of the version used "
|
|
939
|
+
"(https://www.chiantidatabase.org/referencing.html)"
|
|
940
|
+
)
|
|
657
941
|
|
|
658
942
|
works: dict[str, _Work] = {}
|
|
659
943
|
cat = load_catalogue() if catalogue else None
|
|
660
944
|
for d in datas:
|
|
661
945
|
fname = Path(d.source_map.path).name if d.source_map else None
|
|
946
|
+
free: dict[int, tuple[Reference, list[str]]] = {} # papers without identifier, not in the catalogue
|
|
947
|
+
for p in reference_papers(d):
|
|
948
|
+
if not p.has_id and not (cat and _from_catalogue(cat, d, fname, p, works, result)):
|
|
949
|
+
free.setdefault(id(p.reference), (p.reference, []))[1].append(p.segment)
|
|
950
|
+
for ref, segs in free.values():
|
|
951
|
+
text = "; ".join(segs)
|
|
952
|
+
result.free_text.append(ref if text == ref.text else replace(ref, text=text))
|
|
662
953
|
for ref in collect_references(d):
|
|
663
|
-
if not ref.identifiers and ref.role in ("levels", "collisions"):
|
|
664
|
-
unresolved = _from_catalogue(cat, d, fname, ref, works, result) if cat else [ref.text]
|
|
665
|
-
if unresolved:
|
|
666
|
-
text = "; ".join(unresolved)
|
|
667
|
-
result.free_text.append(ref if text == ref.text else replace(ref, text=text))
|
|
668
954
|
for ident in ref.identifiers:
|
|
669
955
|
w = works.setdefault(ident, _Work([ident], identifier_context(ref.text, ident)))
|
|
670
956
|
w.add_use(d.molecule, ref.use)
|
|
@@ -712,10 +998,23 @@ def bibtex(
|
|
|
712
998
|
used_keys: set[str] = set()
|
|
713
999
|
if database_refs:
|
|
714
1000
|
db = database_entries()
|
|
715
|
-
wanted = [
|
|
1001
|
+
wanted = [
|
|
1002
|
+
*(LAMDA_KEYS if result.lamda else ()),
|
|
1003
|
+
*(EMAA_KEYS if result.emaa else ()),
|
|
1004
|
+
*(CDMS_KEYS if result.cdms else ()),
|
|
1005
|
+
*(JPL_KEYS if result.jpl else ()),
|
|
1006
|
+
]
|
|
1007
|
+
if result.chianti is not None:
|
|
1008
|
+
for key in (CHIANTI_FIRST, *(CHIANTI_VERSIONS[v] for v in result.chianti)):
|
|
1009
|
+
if key not in wanted:
|
|
1010
|
+
wanted.append(key)
|
|
716
1011
|
db_ids: dict[str, BibEntry] = {}
|
|
717
1012
|
for key in wanted:
|
|
718
|
-
|
|
1013
|
+
version = next((v for v, k in CHIANTI_VERSIONS.items() if k == key and v in (result.chianti or [])), None)
|
|
1014
|
+
note = f"CHIANTI database, version {version}" if version else _DATABASE_NOTES.get(key, "database")
|
|
1015
|
+
if version and key == CHIANTI_FIRST:
|
|
1016
|
+
note = f"{_DATABASE_NOTES[key]}; version {version}"
|
|
1017
|
+
e = BibEntry(key, db[key], "database", note=note)
|
|
719
1018
|
doi = entry_field(db[key], "doi")
|
|
720
1019
|
adsurl = entry_field(db[key], "adsurl") or ""
|
|
721
1020
|
for ident in (f"doi:{doi}" if doi else None, f"bibcode:{adsurl[len(SCIX_ABS) :]}" if adsurl else None):
|