Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1import astropy.units as u 

2import numpy as np 

3from lsst.pipe.base import Struct, Task 

4from lsst.verify import Measurement, Datum 

5from lsst.pex.config import Config, Field 

6from lsst.faro.utils.stellar_locus import stellarLocusResid, calcQuartileClippedStats 

7from lsst.faro.utils.matcher import make_matched_photom 

8from lsst.faro.utils.extinction_corr import extinction_corr 

9 

10__all__ = ("WPerpTaskConfig", "WPerpTask") 

11 

12 

13class WPerpTaskConfig(Config): 

14 # These are cuts to apply to the r-band only: 

15 bright_rmag_cut = Field(doc="Bright limit of catalog entries to include", 

16 dtype=float, default=17.0) 

17 faint_rmag_cut = Field(doc="Faint limit of catalog entries to include", 

18 dtype=float, default=23.0) 

19 

20 

21class WPerpTask(Task): 

22 ConfigClass = WPerpTaskConfig 

23 _DefaultName = "WPerpTask" 

24 

25 def run(self, catalogs, photo_calibs, metric_name, vIds): 

26 self.log.info(f"Measuring {metric_name}") 

27 bands = set([f['band'] for f in vIds]) 

28 

29 if ('g' in bands) & ('r' in bands) & ('i' in bands): 

30 rgicat_all = make_matched_photom(vIds, catalogs, photo_calibs) 

31 magcut = ((rgicat_all['base_PsfFlux_mag_r'] < self.config.faint_rmag_cut) 

32 & (rgicat_all['base_PsfFlux_mag_r'] > self.config.bright_rmag_cut)) 

33 rgicat = rgicat_all[magcut] 

34 ext_vals = extinction_corr(rgicat, bands) 

35 

36 wPerp = self.calc_wPerp(rgicat, ext_vals, metric_name) 

37 return wPerp 

38 else: 

39 return Struct(measurement=Measurement(metric_name, np.nan*u.mmag)) 

40 

41 def calc_wPerp(self, phot, extinction_vals, metric_name): 

42 p1, p2, p1coeffs, p2coeffs = stellarLocusResid(phot['base_PsfFlux_mag_g']-extinction_vals['A_g'], 

43 phot['base_PsfFlux_mag_r']-extinction_vals['A_r'], 

44 phot['base_PsfFlux_mag_i']-extinction_vals['A_i']) 

45 

46 if np.size(p2) > 2: 

47 p2_rms = calcQuartileClippedStats(p2).rms*u.mag 

48 extras = {'p1_coeffs': Datum(p1coeffs*u.Unit(''), label='p1_coefficients', 

49 description='p1 coeffs from wPerp fit'), 

50 'p2_coeffs': Datum(p2coeffs*u.Unit(''), label='p2_coefficients', 

51 description='p2_coeffs from wPerp fit')} 

52 

53 return Struct(measurement=Measurement(metric_name, p2_rms.to(u.mmag), extras=extras)) 

54 else: 

55 return Struct(measurement=Measurement(metric_name, np.nan*u.mmag))