@@ -45,7 +45,7 @@ class ObsCondition(Degrader):
4545 uses the same arguments as LSSTErrorModel (from PhotErr).
4646 The following arguments, if supplied, may contain either
4747 a single number (as in the case of LSSTErrorModel), or a path:
48- [m5, nVisYr, airmass, gamma, msky, theta, km, tvis]
48+ [m5, nVisYr, airmass, gamma, msky, theta, km, tvis, EBV ]
4949 For the following keys:
5050 [m5, nVisYr, gamma, msky, theta, km]
5151 numbers/paths for specific bands must be passed.
@@ -121,6 +121,7 @@ def __init__(self, args, comm=None):
121121 "theta" ,
122122 "km" ,
123123 "tvis" ,
124+ "EBV" ,
124125 ]
125126
126127 # validate input parameters
@@ -165,10 +166,12 @@ def _validate_obs_config(self):
165166
166167 # Check if extra keys are passed
167168 # get lsst_error_model keys
168- lsst_error_model_keys = [ field . name for field in fields (LsstErrorParams )]
169+ lsst_error_model_keys = list (LsstErrorParams . __dataclass_fields__ . keys ())
169170 if len (set (self .config ["map_dict" ].keys ()) - set (lsst_error_model_keys )) != 0 :
170171 extra_keys = set (self .config ["map_dict" ].keys ()) - set (lsst_error_model_keys )
171- raise ValueError ("Extra keywords are passed to the configuration: \n " + str (extra_keys ))
172+ # now we added EBV, which is not in LsstErrorParams:
173+ if extra_keys != {"EBV" }:
174+ raise ValueError ("Extra keywords are passed to the configuration: \n " + str (extra_keys ))
172175
173176 # Check data type for the keys:
174177 # Note that LSSTErrorModel checks
@@ -189,7 +192,7 @@ def _validate_obs_config(self):
189192 elif key in self .obs_cond_keys :
190193
191194 # band-independent keys:
192- if key in ["airmass" , "tvis" ]:
195+ if key in ["airmass" , "tvis" , "EBV" ]:
193196
194197 # check if the input is a string or number
195198 if not (
@@ -261,7 +264,7 @@ def _get_maps(self):
261264 for key in self .config ["map_dict" ]:
262265 if key in self .obs_cond_keys :
263266 # band-independent keys:
264- if key in ["airmass" , "tvis" ]:
267+ if key in ["airmass" , "tvis" , "EBV" ]:
265268 if isinstance (self .config ["map_dict" ][key ], str ):
266269 maps [key ] = hp .read_map (self .config ["map_dict" ][key ])[pixels ]
267270 elif isinstance (self .config ["map_dict" ][key ], float ):
@@ -304,9 +307,10 @@ def get_pixel_conditions(self, pixel: int) -> dict:
304307 # For keys that may contain the survey condition maps
305308 if key in self .obs_cond_keys :
306309 # band-independent keys:
307- if key in ["airmass" , "tvis" ]:
308- obs_conditions [key ] = float (self .maps [key ][ind ])
309- # band-dependent keys:
310+ if key in ["airmass" , "tvis" , "EBV" ]:
311+ if key != "EBV" :# exclude EBV because it is not in LsstErrorModel
312+ obs_conditions [key ] = float (self .maps [key ][ind ])
313+ # band-dependent keys
310314 else :
311315 obs_conditions [key ] = {}
312316 for band in (self .maps [key ]).keys ():
@@ -333,6 +337,45 @@ def assign_pixels(self, catalog: pd.DataFrame) -> pd.DataFrame:
333337 catalog = pd .concat ([catalog , assigned_pix ], axis = 1 )
334338
335339 return catalog
340+
341+ # this is milky way extinction, should be added before other observing conditions is applied
342+ def apply_galactic_extinction (self , pixel : int , pixel_cat : pd .DataFrame ) -> pd .DataFrame :
343+ """
344+ MW extinction reddening of the magnitudes
345+ """
346+ # set the A_lamba/E(B-V) values for the six LSST filters
347+ band_a_ebv = {
348+ "u" :4.81 ,
349+ "g" :3.64 ,
350+ "r" :2.70 ,
351+ "i" :2.06 ,
352+ "z" :1.58 ,
353+ "y" :1.31 ,
354+ }
355+
356+ # find the corresponding ebv for the pixel
357+ ind = self .maps ["pixels" ]== pixel
358+ ebvvec = self .maps ["EBV" ][ind ]
359+
360+ if "renameDict" in self .maps .keys ():
361+ bands = self .maps ["renameDict" ]
362+ elif "renameDict" not in self .maps .keys ():
363+ bands = {
364+ "u" :"u" ,
365+ "g" :"g" ,
366+ "r" :"r" ,
367+ "i" :"i" ,
368+ "z" :"z" ,
369+ "y" :"y" ,
370+ }
371+
372+ for b in bands .keys ():
373+ key = bands [b ]
374+ # update pixel_cat to the reddened magnitudes
375+ pixel_cat [key ] = (pixel_cat [key ].copy ())+ ebvvec * band_a_ebv [b ]
376+
377+ return pixel_cat
378+
336379
337380 def run (self ):
338381 """
@@ -356,12 +399,17 @@ def run(self):
356399 # assign each galaxy to a pixel
357400 print ("Assigning pixels." )
358401 catalog = self .assign_pixels (catalog )
359-
402+
360403 # loop over each pixel
361404 pixel_cat_list = []
362405 for pixel , pixel_cat in catalog .groupby ("pixel" ):
363406 # get the observing conditions for this pixel
364407 obs_conditions = self .get_pixel_conditions (pixel )
408+
409+ # apply MW extinction if supplied,
410+ # replace the Mag column with reddened magnitudes:
411+ if "EBV" in self .maps .keys ():
412+ pixel_cat = self .apply_galactic_extinction (pixel , pixel_cat )
365413
366414 # creating the error model for this pixel
367415 errorModel = LsstErrorModel (** obs_conditions )
@@ -402,4 +450,4 @@ def __repr__(self):
402450
403451 printMsg += str (self .config ["map_dict" ])
404452
405- return printMsg
453+ return printMsg
0 commit comments