Spaces:
Runtime error
Runtime error
Commit
·
692f707
1
Parent(s):
7b08294
add extraction of magnitudes and fluxes in multiple apertures
Browse files- temps/archive.py +54 -11
temps/archive.py
CHANGED
@@ -20,9 +20,11 @@ class archive():
|
|
20 |
convert_colors=True,
|
21 |
extinction_corr=True,
|
22 |
only_zspec=True,
|
|
|
23 |
target_test='specz', flags_kept=[3,3.1,3.4,3.5,4]):
|
24 |
|
25 |
self.aperture = aperture
|
|
|
26 |
self.flags_kept=flags_kept
|
27 |
|
28 |
|
@@ -62,6 +64,7 @@ class archive():
|
|
62 |
|
63 |
|
64 |
self._set_training_data(cat,
|
|
|
65 |
only_zspec=only_zspec,
|
66 |
extinction_corr=extinction_corr,
|
67 |
convert_colors=convert_colors)
|
@@ -72,18 +75,51 @@ class archive():
|
|
72 |
|
73 |
|
74 |
def _extract_fluxes(self,catalogue):
|
75 |
-
|
76 |
-
|
|
|
|
|
|
|
|
|
77 |
|
78 |
f = catalogue[columns_f].values
|
79 |
ferr = catalogue[columns_ferr].values
|
80 |
return f, ferr
|
81 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
def _to_colors(self, flux, fluxerr):
|
83 |
""" Convert fluxes to colors"""
|
84 |
-
color = flux[:,:-1] / flux[:,1:]
|
85 |
|
86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
return color,color_err
|
88 |
|
89 |
def _set_combiend_target(self, catalogue):
|
@@ -100,13 +136,20 @@ class archive():
|
|
100 |
|
101 |
return catalogue
|
102 |
|
103 |
-
def _correct_extinction(self,catalogue, f):
|
104 |
"""Corrects for extinction"""
|
105 |
ext_correction_cols = [f'EB_V_corr_FLUX_{x}' for x in ['G','R','I','Z','Y','J','H']]
|
106 |
-
|
|
|
|
|
|
|
|
|
107 |
|
108 |
f = f * ext_correction
|
109 |
-
|
|
|
|
|
|
|
110 |
|
111 |
def _select_only_zspec(self,catalogue,cat_flag=None):
|
112 |
"""Selects only galaxies with spectroscopic redshift"""
|
@@ -166,9 +209,9 @@ class archive():
|
|
166 |
return catalogue_valid
|
167 |
|
168 |
|
169 |
-
def _set_training_data(self,catalogue, only_zspec=True, extinction_corr=True, convert_colors=True):
|
170 |
|
171 |
-
cat_da = self._exclude_only_zspec(
|
172 |
target_z_train_DA = cat_da['photo_z_L15'].values
|
173 |
|
174 |
|
@@ -181,7 +224,7 @@ class archive():
|
|
181 |
|
182 |
self.cat_train=catalogue
|
183 |
f, ferr = self._extract_fluxes(catalogue)
|
184 |
-
|
185 |
f_DA, ferr_DA = self._extract_fluxes(cat_da)
|
186 |
idx = np.random.randint(0, len(f_DA), len(f))
|
187 |
f_DA, ferr_DA = f_DA[idx], ferr_DA[idx]
|
@@ -191,7 +234,7 @@ class archive():
|
|
191 |
|
192 |
if extinction_corr==True:
|
193 |
f = self._correct_extinction(catalogue,f)
|
194 |
-
|
195 |
if convert_colors==True:
|
196 |
col, colerr = self._to_colors(f, ferr)
|
197 |
col_DA, colerr_DA = self._to_colors(f_DA, ferr_DA)
|
|
|
20 |
convert_colors=True,
|
21 |
extinction_corr=True,
|
22 |
only_zspec=True,
|
23 |
+
all_apertures=False,
|
24 |
target_test='specz', flags_kept=[3,3.1,3.4,3.5,4]):
|
25 |
|
26 |
self.aperture = aperture
|
27 |
+
self.all_apertures=all_apertures
|
28 |
self.flags_kept=flags_kept
|
29 |
|
30 |
|
|
|
64 |
|
65 |
|
66 |
self._set_training_data(cat,
|
67 |
+
cat_test,
|
68 |
only_zspec=only_zspec,
|
69 |
extinction_corr=extinction_corr,
|
70 |
convert_colors=convert_colors)
|
|
|
75 |
|
76 |
|
77 |
def _extract_fluxes(self,catalogue):
|
78 |
+
if self.all_apertures:
|
79 |
+
columns_f = [f'FLUX_{x}_{a}' for a in [1,2,3] for x in ['G','R','I','Z','Y','J','H']]
|
80 |
+
columns_ferr = [f'FLUXERR_{x}_{a}' for a in [1,2,3] for x in ['G','R','I','Z','Y','J','H'] ]
|
81 |
+
else:
|
82 |
+
columns_f = [f'FLUX_{x}_{self.aperture}' for x in ['G','R','I','Z','Y','J','H']]
|
83 |
+
columns_ferr = [f'FLUXERR_{x}_{self.aperture}' for x in ['G','R','I','Z','Y','J','H']]
|
84 |
|
85 |
f = catalogue[columns_f].values
|
86 |
ferr = catalogue[columns_ferr].values
|
87 |
return f, ferr
|
88 |
|
89 |
+
def _extract_magnitudes(self,catalogue):
|
90 |
+
if self.all_apertures:
|
91 |
+
columns_m = [f'MAG_{x}_{a}' for a in [1,2,3] for x in ['G','R','I','Z','Y','J','H']]
|
92 |
+
columns_merr = [f'MAGERR_{x}_{a}' for a in [1,2,3] for x in ['G','R','I','Z','Y','J','H'] ]
|
93 |
+
else:
|
94 |
+
columns_m = [f'MAG_{x}_{self.aperture}' for x in ['G','R','I','Z','Y','J','H']]
|
95 |
+
columns_merr = [f'MAGERR_{x}_{self.aperture}' for x in ['G','R','I','Z','Y','J','H']]
|
96 |
+
|
97 |
+
m = catalogue[columns_m].values
|
98 |
+
merr = catalogue[columns_merr].values
|
99 |
+
return m, merr
|
100 |
+
|
101 |
def _to_colors(self, flux, fluxerr):
|
102 |
""" Convert fluxes to colors"""
|
|
|
103 |
|
104 |
+
if self.all_apertures:
|
105 |
+
|
106 |
+
for a in range(3):
|
107 |
+
lim1 = 7*a
|
108 |
+
lim2 = 7*(a+1)
|
109 |
+
c = flux[:,lim1:(lim2-1)] / flux[:,(lim1+1):lim2]
|
110 |
+
cerr = np.sqrt((fluxerr[:,lim1:(lim2-1)]/ flux[:,(lim1+1):lim2])**2 + (flux[:,lim1:(lim2-1)] / flux[:,(lim1+1):lim2]**2)**2 * fluxerr[:,(lim1+1):lim2]**2)
|
111 |
+
|
112 |
+
if a==0:
|
113 |
+
color = c
|
114 |
+
color_err = cerr
|
115 |
+
else:
|
116 |
+
color = np.concatenate((color,c),axis=1)
|
117 |
+
color_err = np.concatenate((color_err,cerr),axis=1)
|
118 |
+
|
119 |
+
else:
|
120 |
+
color = flux[:,:-1] / flux[:,1:]
|
121 |
+
|
122 |
+
color_err = np.sqrt((fluxerr[:,:-1]/ flux[:,1:])**2 + (flux[:,:-1] / flux[:,1:]**2)**2 * fluxerr[:,1:]**2)
|
123 |
return color,color_err
|
124 |
|
125 |
def _set_combiend_target(self, catalogue):
|
|
|
136 |
|
137 |
return catalogue
|
138 |
|
139 |
+
def _correct_extinction(self,catalogue, f, return_ext_corr=False):
|
140 |
"""Corrects for extinction"""
|
141 |
ext_correction_cols = [f'EB_V_corr_FLUX_{x}' for x in ['G','R','I','Z','Y','J','H']]
|
142 |
+
if self.all_apertures:
|
143 |
+
ext_correction = catalogue[ext_correction_cols].values
|
144 |
+
ext_correction = np.concatenate((ext_correction,ext_correction,ext_correction),axis=1)
|
145 |
+
else:
|
146 |
+
ext_correction = catalogue[ext_correction_cols].values
|
147 |
|
148 |
f = f * ext_correction
|
149 |
+
if return_ext_corr:
|
150 |
+
return f, ext_correction
|
151 |
+
else:
|
152 |
+
return f
|
153 |
|
154 |
def _select_only_zspec(self,catalogue,cat_flag=None):
|
155 |
"""Selects only galaxies with spectroscopic redshift"""
|
|
|
209 |
return catalogue_valid
|
210 |
|
211 |
|
212 |
+
def _set_training_data(self,catalogue, catalogue_da, only_zspec=True, extinction_corr=True, convert_colors=True):
|
213 |
|
214 |
+
cat_da = self._exclude_only_zspec(catalogue_da)
|
215 |
target_z_train_DA = cat_da['photo_z_L15'].values
|
216 |
|
217 |
|
|
|
224 |
|
225 |
self.cat_train=catalogue
|
226 |
f, ferr = self._extract_fluxes(catalogue)
|
227 |
+
|
228 |
f_DA, ferr_DA = self._extract_fluxes(cat_da)
|
229 |
idx = np.random.randint(0, len(f_DA), len(f))
|
230 |
f_DA, ferr_DA = f_DA[idx], ferr_DA[idx]
|
|
|
234 |
|
235 |
if extinction_corr==True:
|
236 |
f = self._correct_extinction(catalogue,f)
|
237 |
+
|
238 |
if convert_colors==True:
|
239 |
col, colerr = self._to_colors(f, ferr)
|
240 |
col_DA, colerr_DA = self._to_colors(f_DA, ferr_DA)
|