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

1# 

2# LSST Data Management System 

3# Copyright 2008, 2009, 2010 LSST Corporation. 

4# 

5# This product includes software developed by the 

6# LSST Project (http://www.lsst.org/). 

7# 

8# This program is free software: you can redistribute it and/or modify 

9# it under the terms of the GNU General Public License as published by 

10# the Free Software Foundation, either version 3 of the License, or 

11# (at your option) any later version. 

12# 

13# This program is distributed in the hope that it will be useful, 

14# but WITHOUT ANY WARRANTY; without even the implied warranty of 

15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

16# GNU General Public License for more details. 

17# 

18# You should have received a copy of the LSST License Statement and 

19# the GNU General Public License along with this program. If not, 

20# see <http://www.lsstcorp.org/LegalNotices/>. 

21# 

22import sys 

23import os 

24import collections 

25 

26from astropy.io import fits 

27import numpy as np 

28 

29import lsst.afw.image as afwImage 

30import lsst.daf.base as dafBase 

31 

32TsField = collections.namedtuple("TsField", "photoCalib gain dateAvg exptime airmass") 

33 

34 

35def converttsField(infile, filt, exptime=53.907456): 

36 """Extract data from a tsField table 

37 

38 @param[in] infile path to tsField FITS file 

39 @param[in] filt index of filter in tsField FILTERS metadata entry 

40 @param[in] exptime exposure time (sec) 

41 

42 @return a dict with the following entries: 

43 - photoCalib: an lsst.afw.PhotoCalib 

44 - gain: gain as a float 

45 - dateAvg: date of exposure at middle of exposure, as an lsst.daf.base.DateTime 

46 - exptime: exposure time (sec) 

47 - airmass: airmass 

48 """ 

49 with fits.open(infile) as ptr: 

50 if ptr[0].header['NFIELDS'] != 1: 50 ↛ 51line 50 didn't jump to line 51, because the condition on line 50 was never true

51 print("INVALID TSFIELD FILE") 

52 sys.exit(1) 

53 filts = ptr[0].header['FILTERS'].split() 

54 idx = filts.index(filt) 

55 

56 mjdTaiStart = ptr[1].data.field('mjd')[0][idx] # MJD(TAI) when row 0 was read 

57 airmass = ptr[1].data.field("airmass")[0][idx] 

58 

59 gain = float(ptr[1].data.field('gain')[0][idx]) # comes out as numpy.float32 

60 aa = ptr[1].data.field('aa')[0][idx] # f0 = 10**(-0.4*aa) counts/second 

61 aaErr = ptr[1].data.field('aaErr')[0][idx] 

62 

63 # Conversions 

64 dateAvg = dafBase.DateTime(mjdTaiStart + 0.5 * exptime / 3600 / 24) 

65 fluxMag0 = 10**(-0.4 * aa) * exptime 

66 dfluxMag0 = fluxMag0 * 0.4 * np.log(10.0) * aaErr 

67 

68 photoCalib = afwImage.makePhotoCalibFromCalibZeroPoint(fluxMag0, dfluxMag0) 

69 

70 return TsField( 

71 photoCalib=photoCalib, 

72 gain=gain, 

73 dateAvg=dateAvg, 

74 exptime=exptime, 

75 airmass=airmass, 

76 ) 

77 

78 

79if __name__ == '__main__': 79 ↛ 80line 79 didn't jump to line 80, because the condition on line 79 was never true

80 infile = sys.argv[1] 

81 filt = sys.argv[2] 

82 if not os.path.isfile(infile): 

83 sys.exit(1) 

84 

85 converttsField(infile, filt)