sxs 2024.0.10__py3-none-any.whl → 2024.0.11__py3-none-any.whl

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/__init__.py CHANGED
@@ -43,8 +43,9 @@ astronomical_unit = 149_597_870_700.0 # m
43
43
  parsec_in_meters = 3.0856775814913672789139379577965e16 # m
44
44
 
45
45
  # The value of the solar mass parameter G*M_sun is known to higher accuracy than either of its
46
- # factors. The value here is taken from the publication "2021 Selected Astronomical Constants",
47
- # which can be found at <https://asa.hmnao.com/static/files/2021/Astronomical_Constants_2021.pdf>.
46
+ # factors. The value here is taken from the IAU Division I Working Group's publication on
47
+ # "Numerical Standards for Fundamental Astronomy"
48
+ # <https://iau-a3.gitlab.io/NSFA/NSFA_cbe.html#GMS2012>.
48
49
  # In the TDB (Barycentric Dynamical Time) time scale — which seems to be the more relevant one and
49
50
  # looks like the more standard one for LIGO — we have
50
51
  solar_mass_parameter = 1.32712440041e20 # m^3/s^2
sxs/__version__.py CHANGED
@@ -1 +1 @@
1
- __version__ = "2024.0.10"
1
+ __version__ = "2024.0.11"
@@ -0,0 +1,147 @@
1
+ from pathlib import Path
2
+ from .. import sxs_id, Metadata, sxs_directory
3
+ from ..utilities import sxs_identifier_re
4
+ from ..zenodo import path_to_invenio as p2i
5
+
6
+ def file_upload_allowed(file, directory_listing):
7
+ """Return True if the file should be uploaded
8
+
9
+ A file should be uploaded if
10
+ * it is named "metadata.json" or "Horizons.h5"
11
+ * it is named "Strain_*.json" or "ExtraWaveforms.json" and the corresponding
12
+ ".h5" file is in the directory listing
13
+ * it is named "Strain_*.h5" or "ExtraWaveforms.h5" and the corresponding
14
+ ".json" file is in the directory listing
15
+
16
+ """
17
+ # Check `file.name` to ignore the directory
18
+ if file.name in ["metadata.json", "Horizons.h5"]:
19
+ return True
20
+ if file.name.startswith("Strain_") or file.name.startswith("ExtraWaveforms"):
21
+ # Ensure that both `.h5` and `.json` exist for all such files
22
+ if file.suffix == ".json":
23
+ return file.with_suffix(".h5") in directory_listing
24
+ elif file.suffix == ".h5":
25
+ return file.with_suffix(".json") in directory_listing
26
+ else:
27
+ return False
28
+ return False
29
+
30
+
31
+ def files_to_upload(directory, annex_dir="."):
32
+ """Return a list of files to upload
33
+
34
+ The files to upload are those that are in the directory listing
35
+ and pass the `file_upload_allowed` function.
36
+
37
+ """
38
+ full_directory = annex_dir / Path(directory)
39
+ files = []
40
+ for lev in full_directory.resolve().glob("Lev*"):
41
+ directory_listing = list(lev.iterdir())
42
+ files.extend([
43
+ file for file in directory_listing
44
+ if file_upload_allowed(file, directory_listing)
45
+ ])
46
+ return sorted(files, key=lambda x: str(x).lower())
47
+
48
+
49
+ def extract_id_from_common_metadata(file, annex_dir):
50
+ """Extract the SXS ID from a common-metadata.txt file
51
+
52
+ If the ID doesn't exist, return the directory path, relative to
53
+ the `annex_dir`.
54
+ """
55
+ file = Path(file)
56
+ annex_dir = Path(annex_dir)
57
+ key = str(file.resolve().parent.relative_to(annex_dir.resolve()))
58
+ with file.open("r") as f:
59
+ for line in f.readlines():
60
+ line = line.strip()
61
+ if "alternative-names" in line:
62
+ if (m := sxs_identifier_re.search(line)):
63
+ key = m["sxs_identifier"]
64
+ break
65
+ return key
66
+
67
+
68
+ def local_simulations(annex_dir):
69
+ """
70
+ Walk the annex directory to find and process all simulations
71
+
72
+ For each `common-metadata.txt` file found:
73
+ - Ensures that at least one directory starting with "Lev"
74
+ exists; if not, the process is skipped.
75
+ - Defines a key for the metadata, which is either:
76
+ - The SXS ID contained in that file's "alternative-names"
77
+ field, if present.
78
+ - The directory path relative to `annex_dir`.
79
+ - Chooses the highest "Lev" directory and extracts the
80
+ metadata.
81
+ - Finds all files to upload in the directory; if none are
82
+ found, the process is skipped.
83
+ - Adds the "files" dictionary to the metadata, pointing to
84
+ each file that would be uploaded if the simulation were
85
+ published.
86
+
87
+ Args:
88
+ annex_dir (str or Path): The path to the annex directory to be
89
+ processed.
90
+
91
+ Returns:
92
+ dict: A dictionary containing the processed simulations
93
+ metadata.
94
+ """
95
+ from os import walk
96
+
97
+ simulations = {}
98
+ annex_dir = Path(annex_dir).resolve()
99
+
100
+ # The `walk` method can be made *much* faster than the `glob` method
101
+ for dirpath, dirnames, filenames in walk(annex_dir, topdown=True):
102
+ dirpath = Path(dirpath)
103
+
104
+ # Ignore hidden directories
105
+ if dirpath.name.startswith("."):
106
+ dirnames[:] = []
107
+ continue
108
+
109
+ if "common-metadata.txt" in filenames:
110
+ if not any(d.startswith("Lev") for d in dirnames):
111
+ continue
112
+
113
+ key = extract_id_from_common_metadata(dirpath / "common-metadata.txt", annex_dir)
114
+
115
+ # Find the highest Lev directory and extract the metadata
116
+ highest_lev = sorted(
117
+ [d for d in dirnames if d.startswith("Lev")]
118
+ )[-1]
119
+ metadata = Metadata.load(dirpath / highest_lev / "metadata")
120
+
121
+ metadata["files"] = {
122
+ p2i(file.relative_to(dirpath)): {"link": str(file)}
123
+ for file in files_to_upload(dirpath, annex_dir)
124
+ }
125
+
126
+ simulations[key] = metadata
127
+
128
+ dirnames[:] = [] # Don't keep looking for common-metadata.txt files under this directory
129
+
130
+ return simulations
131
+
132
+
133
+ def write_local_simulations(annex_dir):
134
+ """Write the local simulations to a file for use when loading `Simulations`
135
+
136
+ Args:
137
+ annex_dir (str or Path): The path to the annex directory to be
138
+ processed.
139
+
140
+ Returns:
141
+ None
142
+ """
143
+ from json import dump
144
+
145
+ simulations = local_simulations(annex_dir)
146
+ with open(sxs_directory("cache") / "local_simulations.json", "w") as f:
147
+ dump(simulations, f, indent=2, separators=(",", ": "), ensure_ascii=True)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: sxs
3
- Version: 2024.0.10
3
+ Version: 2024.0.11
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/
@@ -1,5 +1,5 @@
1
- sxs/__init__.py,sha256=51_F8xiD6cdE2kIq9dPyHxNQVsp4oCvtR1wQQQ0VS2A,2577
2
- sxs/__version__.py,sha256=HO2uZQyvoVBeimxjf5paV_MvgXvaiQQkNFP85H526HY,26
1
+ sxs/__init__.py,sha256=cZJ3qp5EjO2QSJaajRVJX4xYBvReEHBoG1lNeFpBJfU,2579
2
+ sxs/__version__.py,sha256=Xd7nz7DPZis9Vq-2REnlFOQdwBBtH_mJhRJ6B6Q_dEA,26
3
3
  sxs/handlers.py,sha256=zm1NQTeyM2idXzcmL24YXjnRVn2PBEa72LQQUUMHgOM,16667
4
4
  sxs/juliapkg.json,sha256=higH1UDu30K_PN6-o7lAz0j1xjgYEiCCYBAc-Iaw1Iw,178
5
5
  sxs/time_series.py,sha256=OKaLg8tFyrtKcef7900ri-a0C6A8wKxA68KovZXvH6I,41081
@@ -18,6 +18,7 @@ sxs/julia/__init__.py,sha256=uSLP_xfU-GZG7IO5vs0TEkCR4LH8aBYMF-852wDY3kI,3490
18
18
  sxs/metadata/__init__.py,sha256=KCvJ9Cf1WhIZp-z28UzarKcmUAzV2BOv2gqKiorILjo,149
19
19
  sxs/metadata/metadata.py,sha256=y6X7LcsJKiZFjBPTwRHGtsT2uHf2s0r0OG_EGjD27pE,27663
20
20
  sxs/simulations/__init__.py,sha256=sl-sDI5N2A03lAfzMig8Jm_Beri_v65qjlIOeGGX9XM,72
21
+ sxs/simulations/local.py,sha256=pibf9uED--w6OMI6tPq8aKmI1y89CIQph40Zmq4yjNE,5127
21
22
  sxs/simulations/simulation.py,sha256=BSqUCoiptbY_obC0fKrTACfwiFnvgHRibHLEx-H4_Rk,33915
22
23
  sxs/simulations/simulations.py,sha256=s20HdjEIcoG3vsgJcC4CwjfhICVwKWNABOYYucPEfSs,17108
23
24
  sxs/utilities/__init__.py,sha256=KTtsBKblP02t20anSzV_7tucRUw_bFObY5my5ZuJEBU,4793
@@ -78,7 +79,7 @@ sxs/zenodo/api/__init__.py,sha256=EM_eh4Q8R5E0vIfMhyIR1IYFfOBu6vA0UTasgX9gHys,21
78
79
  sxs/zenodo/api/deposit.py,sha256=J4RGvGjh0cEOrN4bBZWEDcPAhNscqB2fzLlvRZ5HTHM,36948
79
80
  sxs/zenodo/api/login.py,sha256=Yz0ytgi81_5BpDzhrS0WPMXlvU2qUaCK8yn8zxfEbko,18007
80
81
  sxs/zenodo/api/records.py,sha256=nKkhoHZ95CTztHF9Zzaug5p7IiUCJG4Em1i-l-WqH6U,3689
81
- sxs-2024.0.10.dist-info/METADATA,sha256=5ZHOyiVzpdCcK67xfRxisfJKSbMf1XPEUkveai25Qk8,9245
82
- sxs-2024.0.10.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
83
- sxs-2024.0.10.dist-info/licenses/LICENSE,sha256=ptVOd5m7LDM5ZF0x32cxb8c2Nd5NDmAhy6DX7xt_7VA,1080
84
- sxs-2024.0.10.dist-info/RECORD,,
82
+ sxs-2024.0.11.dist-info/METADATA,sha256=L0BUBgb5iCjiD0YZYsnYYXQpcjQZy9gP9GB6sOcY2EE,9245
83
+ sxs-2024.0.11.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
84
+ sxs-2024.0.11.dist-info/licenses/LICENSE,sha256=ptVOd5m7LDM5ZF0x32cxb8c2Nd5NDmAhy6DX7xt_7VA,1080
85
+ sxs-2024.0.11.dist-info/RECORD,,