-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
98 additions
and
23 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# %% -*- 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 instrument in tqdm(f.keys()): | ||
|
||
# sorting the bands by wavelength | ||
bands = list(f[instrument].keys()) | ||
wavelength = [f[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":instrument, | ||
"label":instrument, | ||
"dialog":True, | ||
"children":[{"value":f"{instrument}.{band}", "label":band, "checked":False} for band in bands]}) | ||
|
||
# Save to json | ||
with open('indexing.json', 'w') as outfile: | ||
json.dump(indexing, outfile) |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# %% -*- encoding: utf-8 -*- | ||
''' | ||
@File : store_db2hdf5.py | ||
@Time : 2023/11/27 | ||
@Author : Mingyu Li | ||
@Contact : [email protected] | ||
''' | ||
|
||
# %% | ||
import os | ||
import h5py | ||
import pandas as pd | ||
from glob import glob | ||
from tqdm import tqdm | ||
from pyphot import Filter | ||
|
||
# Get all instrument names | ||
instruments = sorted(os.listdir("filters")) | ||
|
||
# Write to hdf5 | ||
with h5py.File("db_filter.hdf5", "w") as f: | ||
for instrument in tqdm(instruments): | ||
f.create_group(instrument) | ||
files = glob("filters/"+instrument+"/*.dat") | ||
for file in files: | ||
band = file.split("/")[-1][:-4] | ||
df = pd.read_csv(file, header=None, delim_whitespace=True, names=['wavelength', 'transmission'], comment='#').apply(pd.to_numeric, errors='ignore') | ||
f[instrument].create_dataset(band, data=df) | ||
fil = Filter(df['wavelength'], df['transmission'], name=band, dtype='photon', unit='Angstrom') | ||
f[instrument][band].attrs['w_pivot'] = fil.lpivot.value | ||
f[instrument][band].attrs['w_min'] = fil.lmin | ||
f[instrument][band].attrs['w_max'] = fil.lmax | ||
f[instrument][band].attrs['w_width'] = fil.width.value | ||
# %% |