-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdb_json_indexing.py
37 lines (32 loc) · 1.13 KB
/
db_json_indexing.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
# %% -*- encoding: utf-8 -*-
'''
@File : db_json_indexing.py
@Time : 2023/11/27
@Author : Mingyu Li
@Contact : [email protected]
'''
# %%
import h5py
import pandas as pd
from tqdm import tqdm
import json
indexing = []
with h5py.File('db_filter.hdf5', 'r') as f:
for telescope in tqdm(f.keys()):
data = f[telescope]
for instrument in data.keys():
# sorting the bands by wavelength
bands = list(data[instrument].keys())
wavelength = [data[instrument][band].attrs['w_pivot'] for band in bands]
ddff = pd.DataFrame({"w":wavelength, "f":bands})
ddff.sort_values(by=['w'], inplace=True)
bands = ddff['f'].values
# indexing the bands
indexing.append({
"value":f"{telescope}/{instrument}",
"label":f"{telescope}/{instrument}",
"dialog":True,
"children":[{"value":f"{telescope}/{band}.dat", "label":band.split('.')[-1], "checked":False} for band in bands]})
# Save to json
with open('./static/filters/indexing.json', 'w') as outfile:
json.dump(indexing, outfile)