|
5 | 5 | import getpass |
6 | 6 | import numpy as np |
7 | 7 |
|
| 8 | +from .logging import log_stdout, log_verbose |
| 9 | + |
8 | 10 | version = "1.2.0" |
9 | 11 |
|
10 | 12 | lambda0 = [3726.18, 4101.73, 4340.46, 4363.21, 4861.32, 4958.91, 5006.84] |
11 | 13 | line_type = ['Oxy2', 'Balmer', 'Balmer', 'Single', 'Balmer', 'Single', 'Single'] |
12 | 14 | line_name = ['OII_3727', 'HDELTA', 'HGAMMA', 'OIII_4363', 'HBETA', 'OIII_4958', |
13 | 15 | 'OIII_5007'] |
14 | 16 |
|
15 | | -line_name_short = {"OII": line_name[0], "4363": line_name[3], |
16 | | - "HB": line_name[4], "OIII": line_name[-1], |
17 | | - "HG": line_name[2], "HD": line_name[1]} |
| 17 | +line_name_short = { |
| 18 | + "OII": line_name[0], |
| 19 | + "4363": line_name[3], |
| 20 | + "HB": line_name[4], |
| 21 | + "OIII": line_name[-1], |
| 22 | + "HG": line_name[2], |
| 23 | + "HD": line_name[1] |
| 24 | +} |
18 | 25 |
|
19 | | -fitting_lines_dict = {"lambda0": lambda0, "line_type": line_type, "line_name": line_name} |
| 26 | +fitting_lines_dict = { |
| 27 | + "lambda0": lambda0, |
| 28 | + "line_type": line_type, |
| 29 | + "line_name": line_name |
| 30 | +} |
20 | 31 |
|
21 | 32 | all_lambda0 = [lambda0[0]] + [3728.91] + lambda0[1:] |
22 | 33 | all_line_name = ['OII_3726', 'OII_3729'] + line_name[1:] |
|
40 | 51 | k_dict = dict(zip(line_name, k_values)) |
41 | 52 |
|
42 | 53 |
|
43 | | -def exclude_outliers(objno): |
| 54 | +def exclude_outliers(objno, verbose=False, log=None): |
44 | 55 | """ |
45 | 56 | Exclude spectra that are identified as outliers. |
46 | 57 |
|
47 | 58 | Generally this is because the spectra have very high S/N on the continuum. |
48 | 59 |
|
49 | 60 | :param objno: list or numpy array of eight-digit identifier |
| 61 | + :param verbose: bool to write verbose message to stdout. Default: file only |
| 62 | + :param log: LogClass or logging object |
50 | 63 |
|
51 | | - :return: |
52 | | - flag: numpy array of zeros and ones |
| 64 | + :return flag: numpy array of zeros and ones |
53 | 65 | """ |
54 | 66 |
|
| 67 | + if log is None: |
| 68 | + log = log_stdout() |
| 69 | + |
| 70 | + log_verbose(log, "starting ...", verbose=verbose) |
| 71 | + |
55 | 72 | flag = np.zeros(len(objno), dtype=int) |
56 | | - bad_data = np.array(['32007727', '32101412', '42006031', '32035286', '14023705']) |
| 73 | + bad_data = np.array(['32007727', '32101412', '42006031', |
| 74 | + '32035286', '14023705']) |
57 | 75 | for ii in range(len(bad_data)): |
58 | | - idx = [xx for xx in range(len(objno)) if bad_data[ii] in str(objno[xx])] |
| 76 | + idx = [xx for xx in range(len(objno)) if |
| 77 | + bad_data[ii] in str(objno[xx])] |
59 | 78 | flag[idx] = 1 |
60 | 79 |
|
| 80 | + log_verbose(log, "finished.", verbose=verbose) |
61 | 81 | return flag |
62 | 82 |
|
63 | 83 |
|
64 | | -def dir_date(folder_name, path_init='', year=False): |
| 84 | +def dir_date(folder_name, path_init='', year=False, verbose=False, log=None): |
65 | 85 | """ |
66 | 86 | Purpose: |
67 | 87 | This function finds and returns the path to a directory named after the |
68 | 88 | current date (MMDDYYYY). If the directory doesn't exist yet, it creates |
69 | 89 | a new directory named after the current date in the provided folder_name |
70 | 90 | directory. |
71 | 91 |
|
72 | | - From https://github.com/rafia37/Evolution-of-Galaxies/blob/master/general.py |
| 92 | + From https://github.com/rafia37/Evolution-of-Galaxies/blob/master/general.py |
| 93 | +
|
| 94 | + Usage: |
| 95 | + fitspath = dir_date(folder_name, path_init='', year=True) |
73 | 96 |
|
74 | 97 | :param folder_name: str containing directory for date subdirectory will be in |
75 | 98 | :param path_init: root path. Default: empty string |
76 | 99 | :param year: Indicate whether to include year in date folder. Default: False |
| 100 | + :param verbose: bool to write verbose message to stdout. Default: file only |
| 101 | + :param log: LogClass or logging object |
77 | 102 |
|
78 | | - :return: fitspath: Full path to the date directory |
79 | | -
|
80 | | - Usage: |
81 | | - fitspath = dir_date(folder_name, path_init='', year=True) |
| 103 | + :return fitspath: Full path to the date directory |
82 | 104 | """ |
83 | 105 |
|
| 106 | + if log is None: |
| 107 | + log = log_stdout() |
| 108 | + |
| 109 | + log_verbose(log, "starting ...", verbose=verbose) |
| 110 | + |
84 | 111 | today = date.today() |
85 | 112 |
|
86 | | - list_path = [path_init, folder_name, "%02i%02i" % (today.month, today.day), ''] |
| 113 | + list_path = [path_init, folder_name, |
| 114 | + f"{today.month:02d}{today.day:02d}", ''] |
87 | 115 | if year: |
88 | | - list_path[-2] = "%i" % today.year + list_path[-2] |
| 116 | + list_path[-2] = f"{today.year:d}" + list_path[-2] |
89 | 117 |
|
90 | 118 | fitspath = os.path.join(*list_path) |
91 | 119 | try: |
92 | 120 | os.mkdir(fitspath) |
93 | 121 | except FileExistsError: |
94 | | - print("Path already exists : ", fitspath) |
| 122 | + log.warning(f"Path already exists : {fitspath}") |
95 | 123 |
|
| 124 | + log_verbose(log, "finished.", verbose=verbose) |
96 | 125 | return fitspath |
97 | 126 |
|
98 | 127 |
|
99 | | -def get_user(username=None): |
| 128 | +def get_user(username=None, verbose=False, log=None): |
| 129 | + |
| 130 | + if log is None: |
| 131 | + log = log_stdout() |
| 132 | + |
| 133 | + log_verbose(log, "starting ...", verbose=verbose) |
100 | 134 |
|
101 | | - if isinstance(username, type(None)): |
| 135 | + if username is None: |
102 | 136 | username = getpass.getuser() |
103 | 137 |
|
104 | 138 | if username in fitspath_dict.keys(): |
105 | 139 | fitspath = fitspath_dict[username] |
106 | 140 | else: |
| 141 | + log.warning("Incorrect username input") |
107 | 142 | raise ValueError("Incorrect username input") |
108 | 143 |
|
| 144 | + log_verbose(log, "finished.", verbose=verbose) |
109 | 145 | return fitspath |
0 commit comments