Coverage for python/lsst/sims/skybrightness/twilightFunc.py : 19%

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 numpy as np
3__all__ = ['twilightFunc', 'zenithTwilight', 'simpleTwi']
6def simpleTwi(xdata, *args):
7 """
8 Fit a simple slope and constant to many healpixels
10 xdata should have keys:
11 sunAlt
12 hpid
14 args:
15 0: slope
16 1:hpid: magnitudes
17 hpid+1:2*hpid: constant offsets
18 """
20 args = np.array(args)
21 hpmax = np.max(xdata['hpid'])
22 result = args[xdata['hpid']+1]*np.exp(xdata['sunAlt'] * args[0]) + args[xdata['hpid']+2+hpmax]
23 return result
26def twilightFunc(xdata, *args, amCut=1.0):
27 """
28 xdata: numpy array with columns 'alt', 'az', 'sunAlt' all in radians.
29 az should be relative to the sun (i.e., sun is at az zero.
31 based on what I've seen, here's my guess for how to fit the twilight:
32 args[0] = ratio of (zenith twilight flux at sunAlt = -12) and dark sky zenith flux
33 args[1] = decay slope for all pixels (mags/radian)
34 args[2] = airmass term for hemisphere away from the sun. (factor to multiply max brightness at zenith by)
35 args[3] = az term for hemisphere towards sun
36 args[4] = zenith dark sky flux
37 args[5:] = zenith dark sky times constant (optionall)
39 amCut : float (1.0)
40 The airmass cut to apply to use only the away from sun fit. Was set to 1.1
41 previously for not very clear reasons.
43 """
45 args = np.array(args)
46 az = xdata['azRelSun']
47 airmass = xdata['airmass']
48 sunAlt = xdata['sunAlt']
49 flux = np.zeros(az.size, dtype=float)
50 away = np.where((airmass <= amCut) | ((az >= np.pi/2) & (az <= 3.*np.pi/2)))
51 towards = np.where((airmass > amCut) & ((az < np.pi/2) | (az > 3.*np.pi/2)))
53 flux = args[0]*args[4]*10.**(args[1]*(sunAlt+np.radians(12.))+args[2]*(airmass-1.))
54 flux[towards] *= 10.**(args[3]*np.cos(az[towards])*(airmass[towards]-1.))
56 # This let's one fit the dark sky background simultaneously.
57 # It assumes the dark sky is a function of airmass only. Forced to be args[4] at zenith.
58 if np.size(args) >= 6:
59 flux[away] += args[4]*np.exp(args[5:][xdata['hpid'][away]]*(airmass[away]-1.))
60 flux[towards] += args[4]*np.exp(args[5:][xdata['hpid'][towards]]*(airmass[towards]-1.))
62 return flux
65def zenithTwilight(alpha, *args):
66 """
67 The flux at zenith as a linear combination of a twilight component and a constant:
68 alpha = sun altitude (radians)
69 args[0] = ratio of (zenith twilight flux at sunAlt = -12) and dark sky zenith flux
70 args[1] = decay slope for all pixels (mags/radian)
71 args[2] = airmass term for hemisphere away from the sun. (factor to multiply max brightness at zenith by)
72 args[3] = az term for hemisphere towards sun
73 args[4] = zenith dark sky flux
74 """
76 flux = args[0]*args[4]*10.**(args[1]*(alpha+np.radians(12.))) + args[4]
77 return flux