-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapply-filter.py
executable file
·61 lines (49 loc) · 2.08 KB
/
apply-filter.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
#!/usr/bin/env python3
#
# apply-filter.py -- Integrate spectrum over passband filter function.
#
# Copyright (C) 2017, 2018 Gabriel Szasz <[email protected]>
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.
#
"""Integrate spectrum over passband filter function
usage: apply-filter.py [-h] [FILE]
Integrate spectrum over passband filter function
"""
import pyphot
import numpy as np
import argparse
__version__ = "0.1"
def main():
description = "TBD"
epilog = "TBD"
arg_parser = argparse.ArgumentParser(description=description, epilog=epilog)
arg_parser.add_argument('-v', '--version', action='version', version='%(prog)s ' + __version__)
arg_parser.add_argument("-f", metavar="FILTER", dest='filter', default="GROUND_JOHNSON_V")
arg_parser.add_argument("spectra", metavar="FILE", nargs='*',
help="spectrum data")
args = arg_parser.parse_args()
lib = pyphot.get_library()
f = lib[args.filter]
for spectrum_file in args.spectra:
spectrum_data = np.loadtxt(spectrum_file, unpack=True, dtype='float')
passband_flux = f.get_flux(spectrum_data[0, :], spectrum_data[1, :])
mag = -2.5 * np.log10(passband_flux) - f.Vega_zero_mag
print(mag)
if __name__ == "__main__":
# This code is executed only when apply-filter.py is being run
# directly as a script. Since local variables are allocated much faster
# than global variables, it is a good practice to encapsulate whole initial
# code into the main() function.
main()