-
Notifications
You must be signed in to change notification settings - Fork 2
/
builddc0.py
executable file
·177 lines (146 loc) · 6.06 KB
/
builddc0.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/usr/bin/env python
# Get a listings of the files in each dataset
# see get-dc0-file-lists.sh
# NERSC
ENDPOINT = "c9dc477a-3db5-4946-874d-a5dc7efcabcf"
DOMAIN = "g-9fdb0b.6b7bd8.0ec8"
import json
from pytablewriter import MarkdownTableWriter
splits = ["01", "02", "04", "08", "16", "32"]
missions = {
"chlat": {
"fullname": "Chilean Large Aperture Telescope",
"splits": splits,
"bands": ["025", "040", "090", "150", "230", "280"],
},
"spsat": {
"fullname": "South Pole Small Aperture Telescope",
"splits": splits,
"bands": ["025", "040", "085", "095", "145", "155", "230", "280"],
},
"splat": {
"fullname": "South Pole Large Aperture Telescope",
"splits": splits,
"bands": ["020", "025", "040", "090", "150", "230", "280"],
},
}
components = {
"0001": "unlensed primary CMB",
"0010": "lensing perturbation",
"0100": "extragalactic+galactic+dipole",
"1000": "atmosphere+noise",
"1111": "CMB+galactic+extragalactic+atmosphere+noise",
}
# from https://stackoverflow.com/questions/1094841/get-human-readable-version-of-file-size
def sizeof_fmt(num, suffix="B"):
for unit in ["", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi"]:
if abs(num) < 1024.0:
return f"{num:3.1f} {unit}{suffix}"
num /= 1024.0
return f"{num:.1f} Yi{suffix}"
def get_datatype(fname):
# for _map02 files
datatype = "Map: filter+bin iqu map"
if "_map02" in fname:
component = components[fname[-9:-5]]
datatype = f"{datatype}; {component}"
elif "_map03" in fname:
datatype = "Map: tp depth"
elif "_mat02" in fname:
datatype = "Matrix: white noise covariance"
return datatype
def write_dataset(mission, split, band, n_files, data_size, file_table_rows):
dset_table_header = ["File Name", "Datatype", "Size"]
writer = MarkdownTableWriter(
headers=dset_table_header, value_matrix=file_table_rows, margin=1
)
dset_text = f"""---
title: "CMB-S4 DC0 {mission.upper()} Split{split} {band}GHz"
author: "CMB-S4 Collaboration"
description: "CMB-S4 DC0 {mission.upper()} Split{split} {band}GHz"
date_created: "2023-12-07"
seo:
type: Dataset
---
[Back to release](./dc0.html#datasets)
# Dataset: CMB-S4 DC0 {mission.upper()} Split{split} {band}GHz
- Telescope: {missions[mission]["fullname"]} ({mission.upper()})
- Split: `{split}`
- Frequency Band (GHz): `{band}`
See [data access](./dc0.html#data-access) on the DC0 page.
Access the data through the Globus web interface: [![Download via Globus](images/globus-logo.png)](https://app.globus.org/file-manager?origin_id={ENDPOINT}&origin_path=%2Fdatareleases%2Fdc0%2Fmission%2F{mission}%2Fsplit{split}%2F{band}%2F)
Download the [file manifest](https://{DOMAIN}.data.globus.org/datareleases/dc0/mission/{mission}/split{split}/{band}/manifest.json) for the exact file sizes and checksums.
## Files
- Number of files: {n_files}
- Total size: {data_size}
- [JSON format file manifest](https://{DOMAIN}.data.globus.org/datareleases/dc0/mission/{mission}/split{split}/{band}/manifest.json)
"""
with open(f"dc0-{mission}-split{split}-{band}.md", "w") as f:
f.write(dset_text)
f.write(writer.dumps())
# dc0-chlat-split$split-$band.json
# Rows for data release page
# | [Link](dc0-chlat-split01-025.html) | CHLAT | `01` | `025` | `2` | 3.8 GiB |
dc0_dsets_table_header = [
"Link",
"Telescope",
"Split",
"Frequency Band (GHz)",
"Number of Files",
"Total Size",
]
dc0_dsets_table_data = []
for mission in missions:
for split in missions[mission]["splits"]:
for band in missions[mission]["bands"]:
dset_table_data = []
# load file list
with open(f"dc0-{mission}-split{split}-{band}.json") as f:
file_data = json.load(f)
file_list = file_data["DATA"]
# loop over files, build file table info for dataset
# remove manifest from list
# total up bytes in dataset
total_bytes = 0
n_files = len(file_list) - 1
for file_entry in file_list:
fname = file_entry["name"]
if not fname == "manifest.json":
total_bytes += file_entry["size"]
fsize = sizeof_fmt(file_entry["size"])
ftype = get_datatype(fname)
flink = f"[`{fname}`](https://{DOMAIN}.data.globus.org/datareleases/dc0/mission/{mission}/split{split}/{band}/{fname})"
dset_table_data.append([flink, ftype, fsize])
dset_size = sizeof_fmt(total_bytes)
write_dataset(mission, split, band, n_files, dset_size, dset_table_data)
dset_url = f"[Link](dc0-{mission}-split{split}-{band}.html)"
dc0_dsets_table_data.append(
[
dset_url,
f"{mission.upper()}",
f"`{split}`",
f"`{band}`",
f"`{n_files}`",
dset_size,
]
)
writer = MarkdownTableWriter(
headers=dc0_dsets_table_header, value_matrix=dc0_dsets_table_data, margin=1
)
with open("dc0-dset-table.md", "w") as f:
f.write(writer.dumps())
with open("dc0-sidebar.yml", "w") as f:
f.write(" - title: CMB-S4 Data Challenge 0 (DC0)\n")
f.write(" output: web\n")
f.write(" folderitems:\n")
f.write(" - title: Data Challenge 0 Release Page\n")
f.write(' url: "dc0.html"\n')
f.write(" output: web\n")
for mission in missions:
for split in missions[mission]["splits"]:
for band in missions[mission]["bands"]:
title = f" - title: DC0 {mission.upper()} Split{split} {band}\n"
title = title.replace("Split01", "Full mission")
f.write(title)
f.write(f' url: "dc0-{mission}-split{split}-{band}.html"\n')
f.write(f" output: web\n")