def _setupPointGrid(self): """ Setup the points for the interpolation functions. """ # Switch to Dublin Julian Date for pyephem self.Observatory.date = mjd2djd(self.mjd) sun = ephem.Sun() sun.compute(self.Observatory) self.sunAlt = sun.alt self.sunAz = sun.az self.sunRA = sun.ra self.sunDec = sun.dec # Compute airmass the same way as ESO model self.airmass = 1./np.cos(np.pi/2.-self.alts) self.points['airmass'] = self.airmass self.points['nightTimes'] = 2 self.points['alt'] = self.alts self.points['az'] = self.azs if self.twilight: self.points['sunAlt'] = self.sunAlt self.azRelSun = wrapRA(self.azs - self.sunAz) self.points['azRelSun'] = self.azRelSun if self.moon: moon = ephem.Moon() moon.compute(self.Observatory) self.moonPhase = moon.phase self.moonAlt = moon.alt self.moonAz = moon.az self.moonRA = moon.ra self.moonDec = moon.dec # Calc azimuth relative to moon self.azRelMoon = calcAzRelMoon(self.azs, self.moonAz) self.moonTargSep = haversine(self.azs, self.alts, self.moonAz, self.moonAlt) self.points['moonAltitude'] += np.degrees(self.moonAlt) self.points['azRelMoon'] += self.azRelMoon self.moonSunSep = self.moonPhase/100.*180. self.points['moonSunSep'] += self.moonSunSep if self.zodiacal: self.eclipLon = np.zeros(self.npts) self.eclipLat = np.zeros(self.npts) for i, temp in enumerate(self.ra): eclip = ephem.Ecliptic(ephem.Equatorial(self.ra[i], self.dec[i], epoch='2000')) self.eclipLon[i] += eclip.lon self.eclipLat[i] += eclip.lat # Subtract off the sun ecliptic longitude sunEclip = ephem.Ecliptic(sun) self.sunEclipLon = sunEclip.lon self.points['altEclip'] += self.eclipLat self.points['azEclipRelSun'] += wrapRA(self.eclipLon - self.sunEclipLon) self.mask = np.where((self.airmass > self.airmassLimit) | (self.airmass < 1.))[0] self.goodPix = np.where((self.airmass <= self.airmassLimit) & (self.airmass >= 1.))[0]
def setParams(self, airmass=1.,azs=90., alts=None, moonPhase=31.67, moonAlt=45., moonAz=0., sunAlt=-12., sunAz=0., sunEclipLon=0., eclipLon=135., eclipLat=90., degrees=True, solarFlux=130.): """ Set paramters 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. if degrees: convertFunc = np.radians else: convertFunc = justReturn self.solarFlux=solarFlux self.sunAlt = convertFunc(sunAlt) self.moonPhase = moonPhase self.moonAlt = convertFunc(moonAlt) self.moonAz = convertFunc(moonAz) self.eclipLon = convertFunc(eclipLon) self.eclipLat = convertFunc(eclipLat) self.sunEclipLon = convertFunc(sunEclipLon) self.azs = convertFunc(azs) if alts is not None: self.airmass = 1./np.cos(np.pi/2.-convertFunc(alts)) self.alts = convertFunc(alts) else: self.airmass = airmass self.alts = np.pi/2.-np.arccos(1./airmass) self.moonTargSep = haversine(azs, alts, moonAz, self.moonAlt) self.npts = np.size(airmass) self._initPoints() self.points['airmass'] = self.airmass self.points['nightTimes'] = 2 self.points['alt'] = self.alts self.points['az'] = self.azs self.azRelMoon = wrapRA(self.azs - self.moonAz) over = np.where(self.azRelMoon > np.pi) self.azRelMoon[over] = 2.*np.pi - self.azRelMoon[over] self.points['moonAltitude'] += np.degrees(self.moonAlt) self.points['azRelMoon'] = self.azRelMoon self.points['moonSunSep'] += self.moonPhase/100.*180. self.eclipLon = convertFunc(eclipLon) self.eclipLat = convertFunc(eclipLat) self.sunEclipLon = convertFunc(sunEclipLon) self.points['altEclip'] += self.eclipLat self.points['azEclipRelSun'] += wrapRA(self.eclipLon - self.sunEclipLon) self.sunAz = convertFunc(sunAz) self.points['sunAlt'] = self.sunAlt self.points['azRelSun'] = wrapRA(self.azs - self.sunAz) self.points['solarFlux'] = solarFlux
def calcAzRelMoon(azs, moonAz): azRelMoon = wrapRA(azs - moonAz) if isinstance(azs, np.ndarray): over = np.where(azRelMoon > np.pi) azRelMoon[over] = 2. * np.pi - azRelMoon[over] else: if azRelMoon > np.pi: azRelMoon = 2.0 * np.pi - azRelMoon return azRelMoon
def setParams(self, airmass=1., azs=90., alts=None, moonPhase=31.67, moonAlt=45., 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.filterNames = filterNames if self.mags: self.npix = len(self.filterNames) if degrees: convertFunc = np.radians else: convertFunc = justReturn self.solarFlux = solarFlux self.sunAlt = convertFunc(sunAlt) self.moonPhase = moonPhase self.moonAlt = convertFunc(moonAlt) self.moonAz = convertFunc(moonAz) self.eclipLon = convertFunc(eclipLon) self.eclipLat = convertFunc(eclipLat) self.sunEclipLon = convertFunc(sunEclipLon) self.azs = convertFunc(azs) if alts is not None: self.airmass = 1. / np.cos(np.pi / 2. - convertFunc(alts)) self.alts = convertFunc(alts) else: self.airmass = airmass self.alts = np.pi / 2. - np.arccos(1. / airmass) self.moonTargSep = haversine(self.azs, self.alts, moonAz, self.moonAlt) self.npts = np.size(self.airmass) self._initPoints() self.points['airmass'] = self.airmass self.points['nightTimes'] = 2 self.points['alt'] = self.alts self.points['az'] = self.azs self.azRelMoon = calcAzRelMoon(self.azs, self.moonAz) self.points['moonAltitude'] += np.degrees(self.moonAlt) self.points['azRelMoon'] = self.azRelMoon self.points['moonSunSep'] += self.moonPhase / 100. * 180. self.eclipLon = convertFunc(eclipLon) self.eclipLat = convertFunc(eclipLat) self.sunEclipLon = convertFunc(sunEclipLon) self.points['altEclip'] += self.eclipLat self.points['azEclipRelSun'] += wrapRA(self.eclipLon - self.sunEclipLon) self.sunAz = convertFunc(sunAz) self.points['sunAlt'] = self.sunAlt self.points['azRelSun'] = wrapRA(self.azs - self.sunAz) self.points['solarFlux'] = solarFlux self.paramsSet = True self.mask = np.where((self.airmass > self.airmassLimit) | (self.airmass < 1.))[0] self.goodPix = np.where((self.airmass <= self.airmassLimit) & (self.airmass >= 1.))[0] # Interpolate the templates to the set paramters self._interpSky()
def _setupPointGrid(self): """ Setup the points for the interpolation functions. """ # Switch to Dublin Julian Date for pyephem self.Observatory.date = mjd2djd(self.mjd) sun = ephem.Sun() sun.compute(self.Observatory) self.sunAlt = sun.alt self.sunAz = sun.az self.sunRA = sun.ra self.sunDec = sun.dec # Compute airmass the same way as ESO model self.airmass = 1. / np.cos(np.pi / 2. - self.alts) self.points['airmass'] = self.airmass self.points['nightTimes'] = 2 self.points['alt'] = self.alts self.points['az'] = self.azs if self.twilight: self.points['sunAlt'] = self.sunAlt self.azRelSun = wrapRA(self.azs - self.sunAz) self.points['azRelSun'] = self.azRelSun if self.moon: moon = ephem.Moon() moon.compute(self.Observatory) self.moonPhase = moon.phase self.moonAlt = moon.alt self.moonAz = moon.az self.moonRA = moon.ra self.moonDec = moon.dec # Calc azimuth relative to moon self.azRelMoon = calcAzRelMoon(self.azs, self.moonAz) self.moonTargSep = haversine(self.azs, self.alts, self.moonAz, self.moonAlt) self.points['moonAltitude'] += np.degrees(self.moonAlt) self.points['azRelMoon'] += self.azRelMoon self.moonSunSep = self.moonPhase / 100. * 180. self.points['moonSunSep'] += self.moonSunSep if self.zodiacal: self.eclipLon = np.zeros(self.npts) self.eclipLat = np.zeros(self.npts) for i, temp in enumerate(self.ra): eclip = ephem.Ecliptic( ephem.Equatorial(self.ra[i], self.dec[i], epoch='2000')) self.eclipLon[i] += eclip.lon self.eclipLat[i] += eclip.lat # Subtract off the sun ecliptic longitude sunEclip = ephem.Ecliptic(sun) self.sunEclipLon = sunEclip.lon self.points['altEclip'] += self.eclipLat self.points['azEclipRelSun'] += wrapRA(self.eclipLon - self.sunEclipLon) self.mask = np.where((self.airmass > self.airmassLimit) | (self.airmass < 1.))[0] self.goodPix = np.where((self.airmass <= self.airmassLimit) & (self.airmass >= 1.))[0]
def setParams(self, airmass=1., azs=90., alts=None, moonPhase=31.67, moonAlt=45., moonAz=0., sunAlt=-12., sunAz=0., sunEclipLon=0., eclipLon=135., eclipLat=90., degrees=True, solarFlux=130.): """ Set paramters 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. if degrees: convertFunc = np.radians else: convertFunc = justReturn self.solarFlux = solarFlux self.sunAlt = convertFunc(sunAlt) self.moonPhase = moonPhase self.moonAlt = convertFunc(moonAlt) self.moonAz = convertFunc(moonAz) self.eclipLon = convertFunc(eclipLon) self.eclipLat = convertFunc(eclipLat) self.sunEclipLon = convertFunc(sunEclipLon) self.azs = convertFunc(azs) if alts is not None: self.airmass = 1. / np.cos(np.pi / 2. - convertFunc(alts)) self.alts = convertFunc(alts) else: self.airmass = airmass self.alts = np.pi / 2. - np.arccos(1. / airmass) self.moonTargSep = haversine(azs, alts, moonAz, self.moonAlt) self.npts = np.size(airmass) self._initPoints() self.points['airmass'] = self.airmass self.points['nightTimes'] = 2 self.points['alt'] = self.alts self.points['az'] = self.azs self.azRelMoon = wrapRA(self.azs - self.moonAz) over = np.where(self.azRelMoon > np.pi) self.azRelMoon[over] = 2. * np.pi - self.azRelMoon[over] self.points['moonAltitude'] += np.degrees(self.moonAlt) self.points['azRelMoon'] = self.azRelMoon self.points['moonSunSep'] += self.moonPhase / 100. * 180. self.eclipLon = convertFunc(eclipLon) self.eclipLat = convertFunc(eclipLat) self.sunEclipLon = convertFunc(sunEclipLon) self.points['altEclip'] += self.eclipLat self.points['azEclipRelSun'] += wrapRA(self.eclipLon - self.sunEclipLon) self.sunAz = convertFunc(sunAz) self.points['sunAlt'] = self.sunAlt self.points['azRelSun'] = wrapRA(self.azs - self.sunAz) self.points['solarFlux'] = solarFlux
def setRaDecMjd(self, lon, lat, mjd, degrees=False, azAlt=False, solarFlux=130.): """ Set the sky parameters by computing the sky conditions on a given MJD and sky location. Ra and Dec in raidans or degrees. input ra, dec or az,alt w/ altAz=True solarFlux: solar flux in s.f.u. Between 50 and 310. """ # Wrap in array just in case single points were passed if not type(lon).__module__ == np.__name__: if np.size(lon) == 1: lon = np.array([lon]) lat = np.array([lat]) else: lon = np.array(lon) lat = np.array(lat) if degrees: self.ra = np.radians(lon) self.dec = np.radians(lat) else: self.ra = lon self.dec = lat self.mjd = mjd if azAlt: self.azs = self.ra.copy() self.alts = self.dec.copy() self.ra, self.dec = _raDecFromAltAz(self.alts, self.azs, self.Observatory.lon, self.Observatory.lat, self.mjd) else: self.alts, self.azs, pa = _altAzPaFromRaDec( self.ra, self.dec, self.Observatory.lon, self.Observatory.lat, self.mjd) self.npts = self.ra.size self._initPoints() self.solarFlux = solarFlux self.points['solarFlux'] = self.solarFlux # Switch to Dublin Julian Date for pyephem self.Observatory.date = mjd2djd(self.mjd) sun = ephem.Sun() sun.compute(self.Observatory) self.sunAlt = sun.alt self.sunAz = sun.az # Compute airmass the same way as ESO model self.airmass = 1. / np.cos(np.pi / 2. - self.alts) self.points['airmass'] = self.airmass self.points['nightTimes'] = 2 self.points['alt'] = self.alts self.points['az'] = self.azs if self.twilight: self.points['sunAlt'] = self.sunAlt self.points['azRelSun'] = wrapRA(self.azs - self.sunAz) if self.moon: moon = ephem.Moon() moon.compute(self.Observatory) self.moonPhase = moon.phase self.moonAlt = moon.alt self.moonAz = moon.az # Calc azimuth relative to moon self.azRelMoon = wrapRA(self.azs - self.moonAz) over = np.where(self.azRelMoon > np.pi) self.azRelMoon[over] = 2. * np.pi - self.azRelMoon[over] self.points['moonAltitude'] += np.degrees(self.moonAlt) self.points['azRelMoon'] += self.azRelMoon self.points['moonSunSep'] += self.moonPhase / 100. * 180. if self.zodiacal: self.eclipLon = np.zeros(self.npts) self.eclipLat = np.zeros(self.npts) for i, temp in enumerate(self.ra): eclip = ephem.Ecliptic( ephem.Equatorial(self.ra[i], self.dec[i], epoch='2000')) self.eclipLon[i] += eclip.lon self.eclipLat[i] += eclip.lat # Subtract off the sun ecliptic longitude sunEclip = ephem.Ecliptic(sun) self.sunEclipLon = sunEclip.lon self.points['altEclip'] += self.eclipLat self.points['azEclipRelSun'] += wrapRA(self.eclipLon - self.sunEclipLon)
left = np.searchsorted(data['mjd'], umjd) right = np.searchsorted(data['mjd'], umjd, side='right') altaz = np.zeros(data.size, dtype=zip(['alt', 'az'], [float] * 2)) moonAlt = np.zeros(data.size, dtype=float) print 'computing alts and azs' for j, (le, ri, mjd) in enumerate(zip(left, right, umjd)): Observatory.date = mjd2djd(mjd) sun.compute(Observatory) alt, az, pa = altAzPaFromRaDec(data['ra'][le:ri], data['dec'][le:ri], telescope.lon, telescope.lat, mjd) az = wrapRA(az - sun.az) altaz['alt'][le:ri] += alt altaz['az'][le:ri] += az moon.compute(Observatory) moonAlt[le:ri] += moon.alt print 'making maps' good = np.where(moonAlt < 0) magMap[:, i] = healbin(altaz['az'][good], altaz['alt'][good], data['sky'][good], nside=nside, reduceFunc=np.median) rmsMap[:, i] = healbin(altaz['az'][good], altaz['alt'][good], data['sky'][good],
def setParams(self, airmass=1., azs=90., alts=None, moonPhase=31.67, moonAlt=45., 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.filterNames = filterNames if self.mags: self.npix = len(self.filterNames) if degrees: convertFunc = np.radians else: convertFunc = justReturn self.solarFlux = solarFlux self.sunAlt = convertFunc(sunAlt) self.moonPhase = moonPhase self.moonAlt = convertFunc(moonAlt) self.moonAz = convertFunc(moonAz) self.eclipLon = convertFunc(eclipLon) self.eclipLat = convertFunc(eclipLat) self.sunEclipLon = convertFunc(sunEclipLon) self.azs = convertFunc(azs) if alts is not None: self.airmass = 1./np.cos(np.pi/2.-convertFunc(alts)) self.alts = convertFunc(alts) else: self.airmass = airmass self.alts = np.pi/2.-np.arccos(1./airmass) self.moonTargSep = haversine(self.azs, self.alts, moonAz, self.moonAlt) self.npts = np.size(self.airmass) self._initPoints() self.points['airmass'] = self.airmass self.points['nightTimes'] = 2 self.points['alt'] = self.alts self.points['az'] = self.azs self.azRelMoon = calcAzRelMoon(self.azs, self.moonAz) self.points['moonAltitude'] += np.degrees(self.moonAlt) self.points['azRelMoon'] = self.azRelMoon self.points['moonSunSep'] += self.moonPhase/100.*180. self.eclipLon = convertFunc(eclipLon) self.eclipLat = convertFunc(eclipLat) self.sunEclipLon = convertFunc(sunEclipLon) self.points['altEclip'] += self.eclipLat self.points['azEclipRelSun'] += wrapRA(self.eclipLon - self.sunEclipLon) self.sunAz = convertFunc(sunAz) self.points['sunAlt'] = self.sunAlt self.points['azRelSun'] = wrapRA(self.azs - self.sunAz) self.points['solarFlux'] = solarFlux self.paramsSet = True self.mask = np.where((self.airmass > self.airmassLimit) | (self.airmass < 1.))[0] self.goodPix = np.where((self.airmass <= self.airmassLimit) & (self.airmass >= 1.))[0] # Interpolate the templates to the set paramters if self.goodPix.size > 0: self._interpSky() else: warnings.warn('No points in interpolation range')
right = np.searchsorted(data['mjd'], umjd, side='right') altaz = np.zeros(data.size, dtype=zip(['alt','az'], [float]*2)) moonAlt = np.zeros(data.size, dtype=float) print 'computing alts and azs' for j, (le, ri, mjd) in enumerate(zip(left,right,umjd)): Observatory.date = mjd2djd(mjd) sun.compute(Observatory) obs_metadata = ObservationMetaData(pointingRA=np.degrees(sun.ra), pointingDec=np.degrees(sun.dec), rotSkyPos=np.degrees(0), mjd=mjd) alt, az, pa = _altAzPaFromRaDec(data['ra'][le:ri], data['dec'][le:ri], obs_metadata) az = wrapRA(az - sun.az) altaz['alt'][le:ri] += alt altaz['az'][le:ri] += az moon.compute(Observatory) moonAlt[le:ri] += moon.alt print 'making maps' good = np.where(moonAlt < 0) magMap[:,i] = _healbin(altaz['az'][good],altaz['alt'][good], data['sky'][good], nside=nside, reduceFunc=np.median) rmsMap[:,i] = _healbin(altaz['az'][good],altaz['alt'][good],data['sky'][good], nside=nside, reduceFunc=robustRMS) print 'saving maps' np.savez('TwilightMaps/twiMaps_%s.npz' % filterName, magMap=magMap, rmsMap=rmsMap, sunAlts=sunAlts)
def setRaDecMjd(self,lon,lat,mjd,degrees=False,azAlt=False,solarFlux=130.): """ Set the sky parameters by computing the sky conditions on a given MJD and sky location. Ra and Dec in raidans or degrees. input ra, dec or az,alt w/ altAz=True solarFlux: solar flux in s.f.u. Between 50 and 310. """ # Wrap in array just in case single points were passed if not type(lon).__module__ == np.__name__ : if np.size(lon) == 1: lon = np.array([lon]) lat = np.array([lat]) else: lon = np.array(lon) lat = np.array(lat) if degrees: self.ra = np.radians(lon) self.dec = np.radians(lat) else: self.ra = lon self.dec = lat self.mjd = mjd if azAlt: self.azs = self.ra.copy() self.alts = self.dec.copy() self.ra,self.dec = _raDecFromAltAz(self.alts,self.azs, self.Observatory.lon, self.Observatory.lat, self.mjd) else: self.alts,self.azs,pa = _altAzPaFromRaDec(self.ra, self.dec, self.Observatory.lon, self.Observatory.lat, self.mjd) self.npts = self.ra.size self._initPoints() self.solarFlux = solarFlux self.points['solarFlux'] = self.solarFlux # Switch to Dublin Julian Date for pyephem self.Observatory.date = mjd2djd(self.mjd) sun = ephem.Sun() sun.compute(self.Observatory) self.sunAlt = sun.alt self.sunAz = sun.az # Compute airmass the same way as ESO model self.airmass = 1./np.cos(np.pi/2.-self.alts) self.points['airmass'] = self.airmass self.points['nightTimes'] = 2 self.points['alt'] = self.alts self.points['az'] = self.azs if self.twilight: self.points['sunAlt'] = self.sunAlt self.points['azRelSun'] = wrapRA(self.azs - self.sunAz) if self.moon: moon = ephem.Moon() moon.compute(self.Observatory) self.moonPhase = moon.phase self.moonAlt = moon.alt self.moonAz = moon.az # Calc azimuth relative to moon self.azRelMoon = wrapRA(self.azs - self.moonAz) over = np.where(self.azRelMoon > np.pi) self.azRelMoon[over] = 2.*np.pi - self.azRelMoon[over] self.points['moonAltitude'] += np.degrees(self.moonAlt) self.points['azRelMoon'] += self.azRelMoon self.points['moonSunSep'] += self.moonPhase/100.*180. if self.zodiacal: self.eclipLon = np.zeros(self.npts) self.eclipLat = np.zeros(self.npts) for i,temp in enumerate(self.ra): eclip = ephem.Ecliptic(ephem.Equatorial(self.ra[i],self.dec[i], epoch='2000')) self.eclipLon[i] += eclip.lon self.eclipLat[i] += eclip.lat # Subtract off the sun ecliptic longitude sunEclip = ephem.Ecliptic(sun) self.sunEclipLon = sunEclip.lon self.points['altEclip'] += self.eclipLat self.points['azEclipRelSun'] += wrapRA(self.eclipLon - self.sunEclipLon)