def apparent_planet_pos(planet_name, tdb, site): '''Return the topocentric apparent position (ra, dec) tuple of a planet at a particular time, from a particular site. Thin wrapper for SLA_RDPLAN. ''' latitude = site['latitude'] longitude = site['longitude'] # TODO: Raise an error if an invalid body is provided. planet = dict(mercury=1, venus=2, moon=3, mars=4, jupiter=5, saturn=6, uranus=7, neptune=8, pluto=9, sun=0) (app_ra_rads, app_dec_rads, diameter_rads) = sla.sla_rdplan(tdb, planet[planet_name], longitude.in_radians(), latitude.in_radians()) app_ra = Angle(radians=app_ra_rads) app_dec = Angle(radians=app_dec_rads) diameter = Angle(radians=diameter_rads) return (app_ra, app_dec, diameter)
def calcPos(self, mjd, config): """Calculate the moon's ecliptic lon/lat and geocentric RA/Dec, for the given MJD(s).""" self.mjd = numpy.copy(mjd) self.ra = numpy.zeros(len(mjd), 'float') self.dec = numpy.zeros(len(mjd), 'float') for i in range(len(mjd)): # Calculate moon's position. ra_RAD, dec_RAD, diam = slalib.sla_rdplan(mjd[i], 3, config['longitude']*_deg2rad, config['latitude']*_deg2rad) self.ra[i] = ra_RAD * _rad2deg self.dec[i] = dec_RAD * _rad2deg # Calculate the lunar phase. eclon = numpy.zeros(len(mjd), 'float') eclat = numpy.zeros(len(mjd), 'float') for i in range(len(mjd)): eclon[i], eclat[i] = slalib.sla_eqecl(self.ra[i]*_deg2rad, self.dec[i]*_deg2rad, self.mjd[i]) # Calculate the solar longitude. sun = Sun() lon_sun = sun.getLon(self.mjd)*_deg2rad # Calculate the solar elongation of the Moon. solarelong = numpy.arccos(numpy.cos((lon_sun - eclon)) * numpy.cos(eclat)) # Calculate the phase of the moon. This is the 0-180 degrees phase. self.phase = 180.0 - solarelong*_rad2deg # Calculate the illumination of the Moon. This is between 0 - 100, and is what Opsim calls 'moonPhase'. self.illum = ( 1 + numpy.cos(self.phase*_deg2rad) )/2.0 * 100.0 return
def calcPos(self, mjd, config): """Calculate the moon's ecliptic lon/lat and geocentric RA/Dec, for the given MJD(s).""" self.mjd = numpy.copy(mjd) self.ra = numpy.zeros(len(mjd), 'float') self.dec = numpy.zeros(len(mjd), 'float') for i in range(len(mjd)): # Calculate moon's position. ra_RAD, dec_RAD, diam = slalib.sla_rdplan( mjd[i], 3, config['longitude'] * _deg2rad, config['latitude'] * _deg2rad) self.ra[i] = ra_RAD * _rad2deg self.dec[i] = dec_RAD * _rad2deg # Calculate the lunar phase. eclon = numpy.zeros(len(mjd), 'float') eclat = numpy.zeros(len(mjd), 'float') for i in range(len(mjd)): eclon[i], eclat[i] = slalib.sla_eqecl(self.ra[i] * _deg2rad, self.dec[i] * _deg2rad, self.mjd[i]) # Calculate the solar longitude. sun = Sun() lon_sun = sun.getLon(self.mjd) * _deg2rad # Calculate the solar elongation of the Moon. solarelong = numpy.arccos( numpy.cos((lon_sun - eclon)) * numpy.cos(eclat)) # Calculate the phase of the moon. This is the 0-180 degrees phase. self.phase = 180.0 - solarelong * _rad2deg # Calculate the illumination of the Moon. This is between 0 - 100, and is what Opsim calls 'moonPhase'. self.illum = (1 + numpy.cos(self.phase * _deg2rad)) / 2.0 * 100.0 return
def test_HJD_to_JD(): event = _create_event() parallax_model = ['None', 1664.51] parallax = microlparallax.MLParallaxes(event, parallax_model) JD = 2455000 MJD = JD- 2400000.5 Sun_angles = slalib.sla_rdplan(MJD,99,0,0) HJD = JD - parallax.AU/parallax.speed_of_light*(np.sin(Sun_angles[1])*np.sin(event.dec*np.pi/180)+ np.cos(Sun_angles[1])*np.cos(event.dec*np.pi/180)* np.cos(event.ra*np.pi/180-Sun_angles[0])) jd = parallax.HJD_to_JD([HJD]) np.allclose(jd,JD)
def findNightDuration(mjd): ctio_lat = -30.16527778 ctio_lon = -70.8125 ctio_height = 2215. degToRad = 2. * np.pi / 360. lat = ctio_lat * degToRad lon = ctio_lon * degToRad height = ctio_height imjd = np.int(mjd) start_mjd = imjd - 6. / 24. # before sunset at CTIO sunset = "" sunrise = "" # check every minute for i in np.arange(0, 1., 1. / (24. * 60)): mjd = start_mjd + i gmst = slalib.sla_gmst(mjd) eqEquinoxes = slalib.sla_eqeqx(mjd) lst = gmst + eqEquinoxes + lon sunra, sundec, diam = slalib.sla_rdplan(mjd, 0, lon, lat) sunha = lst - sunra sinAltRad = np.sin(lat)*np.sin(sundec) + \ np.cos(lat)*np.cos(sundec)*np.cos(sunha) altRad = np.arcsin(sinAltRad) zenithDist = 90 * degToRad - altRad twilight = 100. * 2 * np.pi / 360. if zenithDist <= twilight: bright = True else: bright = False if sunset == "" and bright == False: sunset = mjd if sunset != "" and sunrise == "" and bright == True: sunrise = mjd duration = sunrise - sunset return duration, sunset, sunrise
def getSolarPosition(self, mjd, eastLongitude, latitude, lst): ra, dec, diam = slalib.sla_rdplan(mjd, 0, eastLongitude, latitude) ha = lst - ra zd = self.zenithDistance(ha, dec, latitude) return ra, dec, zd