Coverage for python/lsst/sims/skybrightness/skyModel.py : 83%

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
""" Really, just return the input.
Parameters ---------- input : anything
Returns ------- input : anything Just return whatever you sent in. """
""" Make sure values are within min/max """
""" Convert Ra,Dec to Altitude and Azimuth.
Coordinate transformation is killing performance. Just use simple equations to speed it up and ignore abberation, precesion, nutation, nutrition, etc.
Parameters ---------- ra : array_like RA, in radians. dec : array_like Dec, in radians. Must be same length as `ra`. lat : float Latitude of the observatory in radians. lon : float Longitude of the observatory in radians. mjd : float Modified Julian Date.
Returns ------- alt : numpy.array Altitude, same length as `ra` and `dec`. Radians. az : numpy.array Azimuth, same length as `ra` and `dec`. Radians. """
""" Convert alt, az to RA, Dec without taking into account abberation, precesion, diffraction, ect.
Parameters ---------- alt : numpy.array Altitude, same length as `ra` and `dec`. Radians. az : numpy.array Azimuth, same length as `ra` and `dec`. Must be same length as `alt`. Radians. lat : float Latitude of the observatory in radians. lon : float Longitude of the observatory in radians. mjd : float Modified Julian Date.
Returns ------- ra : array_like RA, in radians. dec : array_like Dec, in radians. """
else: if azRelMoon > np.pi: azRelMoon = 2.0 * np.pi - azRelMoon
twilight=True, zodiacal=True, moon=True, airglow=True, lowerAtm=False, upperAtm=False, scatteredStar=False, mergedSpec=True, mags=False, preciseAltAz=False, airmass_limit=2.5): """ Instatiate the SkyModel. This loads all the required template spectra/magnitudes that will be used for interpolation.
Parameters ---------- Observatory : Site object object with attributes lat, lon, elev. But default loads LSST.
twilight : bool (True) Include twilight component (True) zodiacal : bool (True) Include zodiacal light component (True) moon : bool (True) Include scattered moonlight component (True) airglow : bool (True) Include airglow component lowerAtm : bool (False) Include lower atmosphere component. This component is part of `mergedSpec`. upperAtm : bool (False) Include upper atmosphere component. This component is part of `mergedSpec`. scatteredStar : bool (False) Include scattered starlight component. This component is part of `mergedSpec`. mergedSpec : bool (True) Compute the lowerAtm, upperAtm, and scatteredStar simultaneously since they are all functions of only airmass. mags : bool (False) By default, the sky model computes a 17,001 element spectrum. If `mags` is True, the model will return the LSST ugrizy magnitudes (in that order). preciseAltAz : bool (False) If False, use the fast alt, az to ra, dec coordinate transformations that do not take abberation, diffraction, etc into account. Results in errors up to ~1.5 degrees, but an order of magnitude faster than coordinate transforms in sims_utils. airmass_limit : float (2.5) Most of the models are only accurate to airmass 2.5. If set higher, airmass values higher than 2.5 are set to 2.5. """
# set this as a way to track if coords have been set
# Airmass limit.
else:
'upperAtm': self.upperAtm, 'airglow': self.airglow, 'zodiacal': self.zodiacal, 'scatteredStar': self.scatteredStar, 'mergedSpec': self.mergedSpec}
# Check that the merged component isn't being run with other components warnings.warn("Adding component multiple times to the final output spectra.")
'upperAtm': UpperAtm, 'mergedSpec': MergedSpec, 'moon': MoonInterp, 'zodiacal': ZodiacalInterp, 'twilight': TwilightInterp}
# Load up the interpolation objects for each component
# Set up a pyephem observatory object self.telescope = observatory self.Observatory = ephem.Observer() self.Observatory.lat = self.telescope.latitude_rad self.Observatory.lon = self.telescope.longitude_rad self.Observatory.elevation = self.telescope.height else: self.Observatory = observatory
# Note that observing conditions have not been set
airglow=True, lowerAtm=False, upperAtm=False, scatteredStar=False, mergedSpec=True): """ Convience function for turning on/off different sky components. """ self.moon = moon self.lowerAtm = lowerAtm self.twilight = twilight self.zodiacal = zodiacal self.upperAtm = upperAtm self.airglow = airglow self.scatteredStar = scatteredStar self.mergedSpec = mergedSpec
""" Set up an array for all the interpolation points """
'altEclip', 'azEclipRelSun', 'sunAlt', 'azRelSun', 'solarFlux']
filterNames=['u', 'g', 'r', 'i', 'z', 'y']): """ Set the sky parameters by computing the sky conditions on a given MJD and sky location.
lon: Longitude-like (RA or Azimuth). Can be single number, list, or numpy array lat: Latitude-like (Dec or Altitude) mjd: Modified Julian Date for the calculation. Must be single number. degrees: (False) Assumes lon and lat are radians unless degrees=True azAlt: (False) Assume lon, lat are RA, Dec unless azAlt=True solarFlux: solar flux in SFU Between 50 and 310. Default=130. 1 SFU=10^4 Jy. filterNames: list of fitlers to return magnitudes for (if initialized with mags=True). """ # Wrap in array just in case single points were passed else: else: raise ValueError('mjd must be single value.') self.ra, self.dec = _raDecFromAltAz(self.alts, self.azs, ObservationMetaData(mjd=self.mjd, site=self.telescope)) else: self.telescope.latitude_rad, self.telescope.longitude_rad, mjd) else: self.alts, self.azs, pa = _altAzPaFromRaDec(self.ra, self.dec, ObservationMetaData(mjd=self.mjd, site=self.telescope)) else: self.telescope.latitude_rad, self.telescope.longitude_rad, mjd)
# Assume large airmasses are the same as airmass=2.5
# Interpolate the templates to the set paramters
filterNames=['u', 'g', 'r', 'i', 'z', 'y']): """ Set the sky parameters by computing the sky conditions on a given MJD and sky location.
Use if you already have alt az coordinates so you can skip the coordinate conversion. """ # Wrap in array just in case single points were passed if np.size(ra) == 1: ra = np.array([ra]).ravel() dec = np.array([dec]).ravel() alt = np.array(alt).ravel() az = np.array(az).ravel() else: ra = np.array(ra) dec = np.array(dec) alt = np.array(alt) az = np.array(az) self.ra = np.radians(ra) self.dec = np.radians(dec) self.alts = np.radians(alt) self.azs = np.radians(az) else: raise ValueError('mjd must be single value.')
# Assume large airmasses are the same as airmass=2.5
# Interpolate the templates to the set paramters
""" Return the intermediate values that are caluculated by setRaDecMjd and used for interpolation. All of these values are also accesible as class atributes, this is a convience method to grab them all at once and document the formats.
Returns ------- out : dict Dictionary of all the intermediate calculated values that may be of use outside (the key:values in the output dict) ra : numpy.array RA of the interpolation points (radians) dec : np.array Dec of the interpolation points (radians) alts : np.array Altitude (radians) azs : np.array Azimuth of interpolation points (radians) airmass : np.array Airmass values for each point, computed via 1./np.cos(np.pi/2.-self.alts). solarFlux : float The solar flux used (SFU). sunAz : float Azimuth of the sun (radians) sunAlt : float Altitude of the sun (radians) sunRA : float RA of the sun (radians) sunDec : float Dec of the sun (radians) azRelSun : np.array Azimuth of each point relative to the sun (0=same direction as sun) (radians) moonAz : float Azimuth of the moon (radians) moonAlt : float Altitude of the moon (radians) moonRA : float RA of the moon (radians) moonDec : float Dec of the moon (radians). Note, if you want distances moonPhase : float Phase of the moon (0-100) moonSunSep : float Seperation of moon and sun (degrees) azRelMoon : np.array Azimuth of each point relative to teh moon eclipLon : np.array Ecliptic longitude (radians) of each point eclipLat : np.array Ecliptic latitude (radians) of each point sunEclipLon: np.array Ecliptic longitude (radians) of each point with the sun at longitude zero
Note that since the alt and az can be calculated using the fast approximation, if one wants to compute the distance between the the points and the sun or moon, it is probably better to use the ra,dec positions rather than the alt,az positions. """
'moonAz', 'moonAlt', 'sunAlt', 'sunAz', 'azRelSun', 'moonSunSep', 'azRelMoon', 'eclipLon', 'eclipLat', 'moonRA', 'moonDec', 'sunRA', 'sunDec', 'sunEclipLon']
else: result[attribute] = None
""" Setup the points for the interpolation functions. """ # Switch to Dublin Julian Date for pyephem
# Compute airmass the same way as ESO model
# Calc azimuth relative to moon
# Subtract off the sun ecliptic longitude
moonAz=0., sunAlt=-12., sunAz=0., sunEclipLon=0., eclipLon=135., eclipLat=90., degrees=True, solarFlux=130., filterNames=['u', 'g', 'r', 'i', 'z', 'y']): """ Set parameters manually. Note, you can put in unphysical combinations of paramters if you want to (e.g., put a full moon at zenith at sunset). if the alts kwarg is set it will override the airmass kwarg. MoonPhase is percent of moon illuminated (0-100) """
# Convert all values to radians for internal use. self.npix = len(self.filterNames) else:
else: self.airmass = airmass self.alts = np.pi/2.-np.arccos(1./airmass)
# Interpolate the templates to the set paramters
""" Interpolate the template spectra to the set RA, Dec and MJD.
the results are stored as attributes of the class: .wave = the wavelength in nm .spec = array of spectra with units of ergs/s/cm^2/nm """
raise ValueError( 'No parameters have been set. Must run setRaDecMjd or setParams before running interpSky.')
# set up array to hold the resulting spectra for each ra, dec point.
# Rebuild the components dict so things can be turned on/off 'upperAtm': self.upperAtm, 'airglow': self.airglow, 'zodiacal': self.zodiacal, 'scatteredStar': self.scatteredStar, 'mergedSpec': self.mergedSpec}
# Loop over each component and add it to the result. # Make sure the component has something self.spec[self.mask, :] = np.nan return else: warnings.warn('Wavelength arrays of components do not match.')
""" Return the wavelength and spectra. Wavelenth in nm spectra is flambda in ergs/cm^2/s/nm """ raise ValueError('No coordinates set. Use setRaDecMjd, setRaDecAltAzMjd, or setParams methods before calling returnWaveSpec.') raise ValueError('SkyModel set to interpolate magnitudes. Initialize object with mags=False') # Mask out high airmass points # self.spec[self.mask] *= 0
""" Convert the computed spectra to a magnitude using the supplied bandpass, or, if self.mags=True, return the mags in the LSST filters
If mags=True when initialized, return mags returns an structured array with dtype names u,g,r,i,z,y.
bandpasses: optional dictionary with bandpass name keys and bandpass object values.
""" raise ValueError('No coordinates set. Use setRaDecMjd, setRaDecAltAzMjd, or setParams methods before calling returnMags.')
warnings.warn('Ignoring set bandpasses and returning LSST ugrizy.') # Mask out high airmass else: # Check that there is flux in the band, otherwise calcMag fails # Mask out high airmass |