forked from pypeit/PypeIt-development-suite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_nires_masters
executable file
·98 lines (73 loc) · 2.91 KB
/
build_nires_masters
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
#!/usr/bin/env python3
#
# See top-level LICENSE.rst file for Copyright information
#
# -*- coding: utf-8 -*-
"""
This script builds the NIRES Masters
Execute it with: ./build_cooked
"""
import os
import tarfile
import shutil
import glob
import argparse
import pdb
import numpy as np
def parser(options=None):
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
#parser.add_argument('version', type=str, help='Version number to generate (e.g. 0.91)')
parser.add_argument('--redux_dir', type=str, help='Full path to the REDUX dir; '
'default is REDUX_OUT in current directory')
parser.add_argument('-o', '--output_dir', type=str,
help='Full path to the destination directory for the NIRES masters.'
'Defaults to "NIRES_MASTERS" in the current directory')
parser.add_argument('-f', '--force_copy', help='Copy the files even if they already exist in the destination',
action='store_true', default=False)
return parser.parse_args() if options is None else parser.parse_args(options)
def main():
pargs = parser()
redux_dir = os.path.join(os.getcwd(), 'REDUX_OUT') if pargs.redux_dir is None \
else pargs.redux_dir
# Generate Cooked folder
if pargs.output_dir is not None:
nires_dir = pargs.output_dir
else:
nires_dir = 'NIRES_MASTERS'
if not os.path.isdir(nires_dir):
os.makedirs(nires_dir, exist_ok=True)
# ------------------------------------------------------------------
keck_nires_path = os.path.join(redux_dir, 'keck_nires', 'NIRES', 'Masters')
files_01 = glob.glob(os.path.join(keck_nires_path, '*2_01*'))
# Do it
for ifile in files_01:
cooked_file = os.path.join(nires_dir, os.path.basename(ifile).replace('_2_','_1_'))
copy_me(ifile, cooked_file, pargs.force_copy)
# A few more
for root in ['MasterFlat_A_7_01.fits', 'MasterSlits_A_7_01.fits.gz']:
ifile = os.path.join(keck_nires_path, root)
cooked_file = os.path.join(nires_dir, os.path.basename(ifile).replace('7','1'))
copy_me(ifile, cooked_file, pargs.force_copy)
exit(0)
def copy_me(new_file, cooked_file, force_copy):
"""
Simple script to copy a given file to a new file
First compares that the new_file is newer than the
cooked file (if the latter exists)
Args:
new_file: str
cooked_file: str
Returns:
"""
# Compare date stamp
doit = True
if os.path.exists(cooked_file):
# Time is in seconds total (like MJD)
if os.path.getctime(cooked_file) > os.path.getctime(new_file):
doit = False
if doit or force_copy:
shutil.copy2(new_file, cooked_file)
print("Generated/over-wrote {:s}".format(cooked_file))
if __name__ == '__main__':
# Giddy up
main()