sxs 2024.0.2__tar.gz → 2024.0.4__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.
- {sxs-2024.0.2 → sxs-2024.0.4}/CITATION.cff +2 -2
- {sxs-2024.0.2 → sxs-2024.0.4}/PKG-INFO +1 -1
- sxs-2024.0.4/sxs/__version__.py +1 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/utilities/__init__.py +1 -0
- sxs-2024.0.4/sxs/utilities/inspire.py +153 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/waveforms/format_handlers/spectre_cce_v1.py +2 -2
- sxs-2024.0.2/sxs/__version__.py +0 -1
- sxs-2024.0.2/sxs/utilities/references/inspire.py +0 -229
- {sxs-2024.0.2 → sxs-2024.0.4}/.codecov.yml +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/.github/dependabot.yml +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/.github/scripts/parse_bump_rule.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/.github/workflows/build.yml +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/.github/workflows/pr_rtd_link.yml +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/.gitignore +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/.readthedocs.yaml +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/LICENSE +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/README.md +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/docs/api/catalog.md +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/docs/api/horizons.md +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/docs/api/load.md +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/docs/api/metadata.md +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/docs/api/simulation.md +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/docs/api/simulations.md +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/docs/api/time_series.md +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/docs/api/waveforms.md +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/docs/html/main.html +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/docs/images/favicon.ico +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/docs/index.md +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/docs/javascript/mathjax.js +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/docs/julia.md +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/docs/mathematica.md +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/docs/stylesheets/extra.css +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/docs/tutorials/00-Introduction.ipynb +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/docs/tutorials/01-Simulations_and_Metadata.ipynb +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/docs/tutorials/02-Simulation.ipynb +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/docs/tutorials/03-Horizons.ipynb +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/docs/tutorials/04-Waveforms.ipynb +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/docs/tutorials/05-PreprocessingForFFTs.ipynb +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/mkdocs.yml +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/pyproject.toml +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/__init__.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/caltechdata/__init__.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/caltechdata/catalog.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/caltechdata/login.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/catalog/__init__.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/catalog/catalog.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/catalog/create.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/catalog/description.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/handlers.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/horizons/__init__.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/horizons/spec_horizons_h5.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/horizons/xor_multishuffle_bzip2.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/julia/GWFrames.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/julia/__init__.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/juliapkg.json +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/metadata/__init__.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/metadata/metadata.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/simulations/__init__.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/simulations/simulation.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/simulations/simulations.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/time_series.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/utilities/bitwise.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/utilities/decimation/__init__.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/utilities/decimation/greedy_spline.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/utilities/decimation/linear_bisection.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/utilities/decimation/peak_greed.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/utilities/decimation/suppression.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/utilities/dicts.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/utilities/downloads.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/utilities/files.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/utilities/formats.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/utilities/lvcnr/__init__.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/utilities/lvcnr/comparisons.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/utilities/lvcnr/conversion.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/utilities/lvcnr/dataset.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/utilities/lvcnr/horizons.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/utilities/lvcnr/metadata.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/utilities/lvcnr/waveform_amp_phase.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/utilities/lvcnr/waveforms.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/utilities/monotonicity.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/utilities/pretty_print.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/utilities/references/__init__.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/utilities/references/ads.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/utilities/references/arxiv.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/utilities/references/fairchild_report.py +0 -0
- {sxs-2024.0.2/sxs/utilities → sxs-2024.0.4/sxs/utilities/references}/inspire.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/utilities/references/journal_abbreviations.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/utilities/references/references.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/utilities/select.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/utilities/smooth_functions.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/utilities/sxs_directories.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/utilities/sxs_identifiers.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/utilities/url.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/waveforms/__init__.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/waveforms/alignment.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/waveforms/format_handlers/__init__.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/waveforms/format_handlers/lvc.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/waveforms/format_handlers/nrar.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/waveforms/format_handlers/rotating_paired_diff_multishuffle_bzip2.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/waveforms/format_handlers/rotating_paired_xor_multishuffle_bzip2.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/waveforms/memory.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/waveforms/mode_utilities.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/waveforms/transformations.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/waveforms/waveform_grid.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/waveforms/waveform_mixin.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/waveforms/waveform_modes.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/waveforms/waveform_signal.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/zenodo/__init__.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/zenodo/api/__init__.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/zenodo/api/deposit.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/zenodo/api/login.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/zenodo/api/records.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/zenodo/catalog.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/zenodo/creators.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/zenodo/simannex.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/sxs/zenodo/surrogatemodeling.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/tests/__init__.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/tests/conftest.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/tests/test_catalog.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/tests/test_horizons.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/tests/test_julia.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/tests/test_loader.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/tests/test_metadata.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/tests/test_simulation.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/tests/test_time_series.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/tests/test_transformations.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/tests/test_utilities.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/tests/test_waveform_rotations.py +0 -0
- {sxs-2024.0.2 → sxs-2024.0.4}/tests/test_waveforms.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: sxs
|
|
3
|
-
Version: 2024.0.
|
|
3
|
+
Version: 2024.0.4
|
|
4
4
|
Summary: Interface to data produced by the Simulating eXtreme Spacetimes collaboration
|
|
5
5
|
Project-URL: Homepage, https://github.com/sxs-collaboration/sxs
|
|
6
6
|
Project-URL: Documentation, https://sxs.readthedocs.io/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "2024.0.4"
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"""Search the INSPIRE database
|
|
2
|
+
|
|
3
|
+
Documentation can be found here: <https://github.com/inspirehep/rest-api-doc>
|
|
4
|
+
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import warnings
|
|
8
|
+
|
|
9
|
+
api_url = "https://inspirehep.net/api/{record_type}"
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def inspire2doi(inspire_bibtex_key, raise_exceptions=False):
|
|
13
|
+
try:
|
|
14
|
+
result = query(inspire_bibtex_key, fields="dois.value,arxiv_eprints")
|
|
15
|
+
except KeyboardInterrupt:
|
|
16
|
+
raise
|
|
17
|
+
except Exception as e:
|
|
18
|
+
warnings.warn(f"Error querying for INSPIRE key {inspire_bibtex_key}")
|
|
19
|
+
if raise_exceptions:
|
|
20
|
+
raise e
|
|
21
|
+
else:
|
|
22
|
+
if not result:
|
|
23
|
+
warnings.warn(f"No entry found for INSPIRE key {inspire_bibtex_key}")
|
|
24
|
+
if raise_exceptions:
|
|
25
|
+
raise ValueError(f"No entry found for INSPIRE key {inspire_bibtex_key}")
|
|
26
|
+
else:
|
|
27
|
+
try:
|
|
28
|
+
return result[0]["metadata"]["dois"][0]["value"]
|
|
29
|
+
except Exception as e:
|
|
30
|
+
# DOI not present; INSPIRE only has an arXiv number, so we'll convert to an arXiv DOI
|
|
31
|
+
try:
|
|
32
|
+
eprint_value = result[0]["metadata"]["arxiv_eprints"][0]["value"]
|
|
33
|
+
# https://info-arxiv-org.proxy.library.cornell.edu/help/arxiv_identifier.html
|
|
34
|
+
# says that identifiers starting with 9107 to 0703 need their category included
|
|
35
|
+
if eprint_value.startswith("9") or int(eprint_value[:4])<704:
|
|
36
|
+
category = result[0]["metadata"]["arxiv_eprints"][0]["categories"][0]
|
|
37
|
+
return f"10.48550/arXiv.{category}/{eprint_value}"
|
|
38
|
+
else:
|
|
39
|
+
return f"10.48550/arXiv.{eprint_value}"
|
|
40
|
+
except Exception as e:
|
|
41
|
+
warnings.warn(f"Unexpected result format for INSPIRE key {inspire_bibtex_key}: \n{result}")
|
|
42
|
+
if raise_exceptions:
|
|
43
|
+
raise e
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def query(
|
|
47
|
+
query,
|
|
48
|
+
sort="mostrecent",
|
|
49
|
+
page=1,
|
|
50
|
+
size=1000,
|
|
51
|
+
fields=None,
|
|
52
|
+
page_limit=10,
|
|
53
|
+
record_type="literature"
|
|
54
|
+
):
|
|
55
|
+
"""Fetch records from the INSPIRE API.
|
|
56
|
+
|
|
57
|
+
Parameters
|
|
58
|
+
----------
|
|
59
|
+
query : str
|
|
60
|
+
The search query. For details, see
|
|
61
|
+
https://github.com/inspirehep/rest-api-doc/tree/master#search-query
|
|
62
|
+
fields : str, optional
|
|
63
|
+
The fields to retrieve from INSPIRE. This can be a
|
|
64
|
+
comma-separated list of field names. For example, to
|
|
65
|
+
retrieve the list of DOIs: "dois.value". Other options at
|
|
66
|
+
https://inspire-schemas.readthedocs.io/en/latest/schemas/elements/reference.html
|
|
67
|
+
Note that other fields will also be returned for each record,
|
|
68
|
+
even when you just ask for one — including "id", "links",
|
|
69
|
+
"metadata", "created", and "updated". The default value of
|
|
70
|
+
None will return all fields.
|
|
71
|
+
sort : str, optional
|
|
72
|
+
The sorting order. Default is "mostrecent".
|
|
73
|
+
size : int, optional
|
|
74
|
+
The number of records per page. Default is 1000.
|
|
75
|
+
page : int, optional
|
|
76
|
+
The starting page number. Default is 1.
|
|
77
|
+
page_limit : int, optional
|
|
78
|
+
Optional limit to the number of pages to collect.
|
|
79
|
+
record_type : str, optional
|
|
80
|
+
The type of record to fetch (e.g., "literature"). Default is
|
|
81
|
+
"literature". Other options can be found here:
|
|
82
|
+
https://github.com/inspirehep/rest-api-doc/tree/master#obtaining-a-record
|
|
83
|
+
|
|
84
|
+
Returns
|
|
85
|
+
-------
|
|
86
|
+
list
|
|
87
|
+
The JSON response from the API.
|
|
88
|
+
|
|
89
|
+
Raises
|
|
90
|
+
------
|
|
91
|
+
requests.exceptions.HTTPError :
|
|
92
|
+
If the HTTP request to INSPIRE failed
|
|
93
|
+
|
|
94
|
+
"""
|
|
95
|
+
import sys
|
|
96
|
+
import requests
|
|
97
|
+
from requests.adapters import HTTPAdapter
|
|
98
|
+
from urllib3.util.retry import Retry
|
|
99
|
+
|
|
100
|
+
session = requests.Session()
|
|
101
|
+
collected_results = []
|
|
102
|
+
|
|
103
|
+
## Retry automatically on certain types of errors
|
|
104
|
+
retry = Retry(
|
|
105
|
+
total=10,
|
|
106
|
+
backoff_factor=0.1,
|
|
107
|
+
status_forcelist=[
|
|
108
|
+
413, # Request Entity Too Large
|
|
109
|
+
429, # Too Many Requests
|
|
110
|
+
500, # Internal Server Error
|
|
111
|
+
502, # Bad Gateway
|
|
112
|
+
503, # Service Unavailable
|
|
113
|
+
504, # Gateway Timeout
|
|
114
|
+
],
|
|
115
|
+
)
|
|
116
|
+
adapter = HTTPAdapter(max_retries=retry)
|
|
117
|
+
session.mount("https://", adapter)
|
|
118
|
+
|
|
119
|
+
url = api_url.format(record_type=record_type)
|
|
120
|
+
params = {
|
|
121
|
+
"q": query,
|
|
122
|
+
"sort": sort,
|
|
123
|
+
"size": size,
|
|
124
|
+
"page": page,
|
|
125
|
+
}
|
|
126
|
+
if fields:
|
|
127
|
+
params["fields"] = fields
|
|
128
|
+
|
|
129
|
+
while params["page"] - page <= page_limit:
|
|
130
|
+
response = session.get(url, params=params)
|
|
131
|
+
if response.status_code != 200:
|
|
132
|
+
print(f"An error occurred when trying to access <{api_url}>.", file=sys.stderr)
|
|
133
|
+
try:
|
|
134
|
+
print(response.json(), file=sys.stderr)
|
|
135
|
+
except:
|
|
136
|
+
pass
|
|
137
|
+
response.raise_for_status()
|
|
138
|
+
raise RuntimeError() # Will only happen if the response was not strictly an error
|
|
139
|
+
|
|
140
|
+
try:
|
|
141
|
+
json_response = response.json()
|
|
142
|
+
except ValueError:
|
|
143
|
+
print(f"Response from {url} does not contain valid JSON; returning early.")
|
|
144
|
+
return collected_results
|
|
145
|
+
|
|
146
|
+
new_hits = json_response.get("hits", {}).get("hits", [])
|
|
147
|
+
if not new_hits:
|
|
148
|
+
break
|
|
149
|
+
collected_results.extend(new_hits)
|
|
150
|
+
|
|
151
|
+
params["page"] += 1
|
|
152
|
+
|
|
153
|
+
return collected_results
|
|
@@ -98,9 +98,9 @@ def load(file_name, **kwargs):
|
|
|
98
98
|
if (match:=regex.match(legend_entry)):
|
|
99
99
|
ell, m = int(match[2]), int(match[3])
|
|
100
100
|
if match[1] == "Real":
|
|
101
|
-
data[:, spherical.Yindex(ell, m)] += h5[:, i][indices]
|
|
101
|
+
data[:, spherical.Yindex(ell, m, ell_min=ell_min)] += h5[:, i][indices]
|
|
102
102
|
elif match[1] == "Imag":
|
|
103
|
-
data[:, spherical.Yindex(ell, m)] += 1j * h5[:, i][indices]
|
|
103
|
+
data[:, spherical.Yindex(ell, m, ell_min=ell_min)] += 1j * h5[:, i][indices]
|
|
104
104
|
else:
|
|
105
105
|
raise ValueError(f"Unrecognized legend entry '{legend_entry}'")
|
|
106
106
|
|
sxs-2024.0.2/sxs/__version__.py
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "2024.0.2"
|
|
@@ -1,229 +0,0 @@
|
|
|
1
|
-
"""Search the INSPIRE database
|
|
2
|
-
|
|
3
|
-
Documentation can be found here: <https://inspirehep.net/info/hep/api>
|
|
4
|
-
|
|
5
|
-
"""
|
|
6
|
-
|
|
7
|
-
from functools import lru_cache
|
|
8
|
-
|
|
9
|
-
api_url = "https://inspirehep.net/search"
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
@lru_cache()
|
|
13
|
-
def query(pattern, output_format='recjson', output_tags=None, records_in_groups_of=None, jump_to_records=None):
|
|
14
|
-
"""Search the INSPIRE database
|
|
15
|
-
|
|
16
|
-
API documentation: <https://inspirehep.net/info/hep/api>
|
|
17
|
-
Search documentation: <https://inspirehep.net/info/hep/search-tips>
|
|
18
|
-
|
|
19
|
-
Parameters
|
|
20
|
-
----------
|
|
21
|
-
pattern : str
|
|
22
|
-
This is the query in the Inspire search syntax. All search features and
|
|
23
|
-
operators familiar from the Inspire web interface and documented in the
|
|
24
|
-
online help are supported and complex queries are possible. Documentation
|
|
25
|
-
here: <https://inspirehep.net/info/hep/search-tips>.
|
|
26
|
-
output_format : str, optional [defaults to 'recjson']
|
|
27
|
-
The format of the response sent back to the client. There are two choices,
|
|
28
|
-
'xm' for (MARC-)XML or 'recjson' for JSON. The XML response format is
|
|
29
|
-
MARCXML or fragments thereof when individual fields are selected via the
|
|
30
|
-
output_tags parameter
|
|
31
|
-
output_tags : str, optional [defaults to None]
|
|
32
|
-
If present, this selects (filter) specific tags from the response. If
|
|
33
|
-
output_format is 'xm', this option takes a comma separated list of MARC
|
|
34
|
-
tags; valid MARC tags for Inspire records can be found here
|
|
35
|
-
<https://twiki.cern.ch/twiki/bin/view/Inspire/DevelopmentRecordMarkup>. If
|
|
36
|
-
output_format is 'recjson', this is similar to selecting MARC tags, however
|
|
37
|
-
by name instead of numerical value. In addition the JSON response can
|
|
38
|
-
contain derived or dynamically calculated values which are not available in
|
|
39
|
-
MARC. If this argument is None, the default output will be returned, which
|
|
40
|
-
generally includes all available information for each record.
|
|
41
|
-
records_in_groups_of : int, optional [defaults to None]
|
|
42
|
-
If present, this parameter specifies the number of records per chunk for
|
|
43
|
-
long responses. Note that the default setting is 25 records per chunk. The
|
|
44
|
-
maximum number is 250.
|
|
45
|
-
jump_to_records : int, optional [defaults to None]
|
|
46
|
-
Long responses are split into several chunks. To access subsequent chunks
|
|
47
|
-
specify the record offset with this parameter.
|
|
48
|
-
|
|
49
|
-
Returns
|
|
50
|
-
-------
|
|
51
|
-
json : list or dict
|
|
52
|
-
Usually, this will be a list of the results from the query, even if there
|
|
53
|
-
is only one. Each result will be a dictionary mapping the requested
|
|
54
|
-
'output_tags' to their corresponding values.
|
|
55
|
-
|
|
56
|
-
Raises
|
|
57
|
-
------
|
|
58
|
-
requests.exceptions.HTTPError :
|
|
59
|
-
If the HTTP request to INSPIRE failed for any reason
|
|
60
|
-
|
|
61
|
-
"""
|
|
62
|
-
import sys
|
|
63
|
-
import requests
|
|
64
|
-
|
|
65
|
-
params = {
|
|
66
|
-
'p': pattern,
|
|
67
|
-
'of': output_format,
|
|
68
|
-
}
|
|
69
|
-
if output_tags is not None:
|
|
70
|
-
params['ot'] = output_tags
|
|
71
|
-
if records_in_groups_of is not None:
|
|
72
|
-
params['rg'] = records_in_groups_of
|
|
73
|
-
if jump_to_records is not None:
|
|
74
|
-
params['jrec'] = jump_to_records
|
|
75
|
-
|
|
76
|
-
r = requests.get(api_url, params=params)
|
|
77
|
-
if r.status_code != 200:
|
|
78
|
-
print('An error occurred when trying to access <{0}>.'.format(api_url), file=sys.stderr)
|
|
79
|
-
try:
|
|
80
|
-
print(r.json(), file=sys.stderr)
|
|
81
|
-
except:
|
|
82
|
-
pass
|
|
83
|
-
r.raise_for_status()
|
|
84
|
-
raise RuntimeError() # Will only happen if the response was not strictly an error
|
|
85
|
-
return r.json()
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
def extract_bibtex_key(system_control_numbers):
|
|
89
|
-
"""Get bibtex key from 'system_control_numbers' field
|
|
90
|
-
|
|
91
|
-
Unfortunately, this seems to be the only way to get the bibtex key. I have
|
|
92
|
-
seen suggestions around the github issues for inspirehep/invenio that this
|
|
93
|
-
should always be present
|
|
94
|
-
|
|
95
|
-
"""
|
|
96
|
-
if isinstance(system_control_numbers, dict):
|
|
97
|
-
system_control_numbers = [system_control_numbers,]
|
|
98
|
-
bibtex_keys = [number.get('value', '') for number in system_control_numbers
|
|
99
|
-
if number.get('institute', '') in ['INSPIRETeX', 'SPIRESTeX']]
|
|
100
|
-
bibtex_keys = [key for key in bibtex_keys if key]
|
|
101
|
-
if not bibtex_keys:
|
|
102
|
-
return ''
|
|
103
|
-
return bibtex_keys[0]
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
def extract_doi(doi):
|
|
107
|
-
"""Ensure that 'doi' is a single string
|
|
108
|
-
|
|
109
|
-
Occasionally, INSPIRE returns a list of identical DOIs. This just extracts the
|
|
110
|
-
first element if it is such a list, or returns the input otherwise.
|
|
111
|
-
|
|
112
|
-
"""
|
|
113
|
-
if isinstance(doi, list) and len(doi)>0:
|
|
114
|
-
return doi[0]
|
|
115
|
-
return doi
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
def extract_doi_url(doi):
|
|
119
|
-
"""Ensure that 'doi' is a single string
|
|
120
|
-
|
|
121
|
-
Occasionally, INSPIRE returns a list of identical DOIs. This just extracts the
|
|
122
|
-
first element if it is such a list, or returns the input otherwise.
|
|
123
|
-
|
|
124
|
-
"""
|
|
125
|
-
doi = extract_doi(doi)
|
|
126
|
-
if doi:
|
|
127
|
-
return 'https://dx.doi.org/' + doi
|
|
128
|
-
else:
|
|
129
|
-
return doi
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
def extract_arxiv_url(system_control_numbers):
|
|
133
|
-
"""Extract any arxiv URLs from the system_control_number field
|
|
134
|
-
|
|
135
|
-
"""
|
|
136
|
-
if isinstance(system_control_numbers, dict):
|
|
137
|
-
system_control_numbers = [system_control_numbers,]
|
|
138
|
-
arxiv_urls = [
|
|
139
|
-
number['value'].replace('oai:arXiv.org:', 'https://arxiv.org/abs/')
|
|
140
|
-
for number in system_control_numbers if number.get('institute', '') == 'arXiv' and 'value' in number
|
|
141
|
-
]
|
|
142
|
-
if not arxiv_urls:
|
|
143
|
-
return ''
|
|
144
|
-
return arxiv_urls[0]
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
def map_bibtex_keys_to_doi(bibtex_keys):
|
|
148
|
-
"""Map a list of INSPIRE bibtex keys to DOIs
|
|
149
|
-
|
|
150
|
-
This function queries the INSPIRE database, searching for each of the input
|
|
151
|
-
bibtex keys, and extracting the corresponding DOIs (if present on INSPIRE).
|
|
152
|
-
|
|
153
|
-
Parameter
|
|
154
|
-
---------
|
|
155
|
-
bibtex_keys : str, or list of str
|
|
156
|
-
Each string should be precisely one bibtex key from INSPIRE. Note that any
|
|
157
|
-
bibtex keys that are not found by INSPIRE are simply ignored.
|
|
158
|
-
|
|
159
|
-
Returns
|
|
160
|
-
-------
|
|
161
|
-
key_to_doi : dict
|
|
162
|
-
The output is a dictionary mapping each input bibtex key itself to the
|
|
163
|
-
corresponding DOI. These are raw DOIs; to get a URL, just append the DOI
|
|
164
|
-
to 'https://dx.doi.org/', which will resolve to the appropriate web page
|
|
165
|
-
for that DOI. Note that any record that is found by its bibtex key but
|
|
166
|
-
does not have a DOI will simply be absent from this dictionary.
|
|
167
|
-
|
|
168
|
-
Raises
|
|
169
|
-
------
|
|
170
|
-
requests.exceptions.HTTPError
|
|
171
|
-
If the HTTP request to INSPIRE failed for any reason.
|
|
172
|
-
|
|
173
|
-
"""
|
|
174
|
-
if not isinstance(bibtex_keys, list):
|
|
175
|
-
bibtex_keys = [bibtex_keys,]
|
|
176
|
-
pattern = 'find texkey ' + ' or texkey '.join(bibtex_keys)
|
|
177
|
-
output_tags = 'system_control_number,doi'
|
|
178
|
-
results = query(pattern, output_tags=output_tags)
|
|
179
|
-
mapping = {
|
|
180
|
-
bibtex_key: doi
|
|
181
|
-
for result in results
|
|
182
|
-
for bibtex_key in [extract_bibtex_key(result['system_control_number']),]
|
|
183
|
-
for doi in [extract_doi(result['doi']),]
|
|
184
|
-
if bibtex_key and doi
|
|
185
|
-
}
|
|
186
|
-
return mapping
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
def map_bibtex_keys_to_identifiers(bibtex_keys):
|
|
190
|
-
"""Map a list of INSPIRE bibtex keys to DOIs, arxiv numbers, or URLs
|
|
191
|
-
|
|
192
|
-
This function queries the INSPIRE database, searching for each of the input
|
|
193
|
-
bibtex keys, and extracting the corresponding DOIs (if present on INSPIRE).
|
|
194
|
-
Failing that
|
|
195
|
-
|
|
196
|
-
Parameter
|
|
197
|
-
---------
|
|
198
|
-
bibtex_keys : str, or list of str
|
|
199
|
-
Each string should be precisely one bibtex key from INSPIRE. Note that any
|
|
200
|
-
bibtex keys that are not found by INSPIRE are simply ignored.
|
|
201
|
-
|
|
202
|
-
Returns
|
|
203
|
-
-------
|
|
204
|
-
key_to_identifier : dict
|
|
205
|
-
The output is a dictionary mapping each input bibtex key itself to the
|
|
206
|
-
corresponding DOI URL, arxiv URL, or other URL.
|
|
207
|
-
|
|
208
|
-
Raises
|
|
209
|
-
------
|
|
210
|
-
requests.exceptions.HTTPError
|
|
211
|
-
If the HTTP request to INSPIRE failed for any reason.
|
|
212
|
-
|
|
213
|
-
"""
|
|
214
|
-
if not bibtex_keys:
|
|
215
|
-
return {}
|
|
216
|
-
if not isinstance(bibtex_keys, list):
|
|
217
|
-
bibtex_keys = [bibtex_keys,]
|
|
218
|
-
pattern = 'find texkey ' + ' or texkey '.join(bibtex_keys)
|
|
219
|
-
output_tags = 'system_control_number,doi'
|
|
220
|
-
results = query(pattern, output_tags=output_tags)
|
|
221
|
-
mapping = {
|
|
222
|
-
bibtex_key: (doi if doi else arxiv)
|
|
223
|
-
for result in results
|
|
224
|
-
for bibtex_key in [extract_bibtex_key(result['system_control_number']),]
|
|
225
|
-
for doi in [extract_doi_url(result['doi']),]
|
|
226
|
-
for arxiv in [extract_arxiv_url(result['system_control_number']),]
|
|
227
|
-
if bibtex_key and (bool(doi) or bool(arxiv))
|
|
228
|
-
}
|
|
229
|
-
return mapping
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|