Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
lbary_ltopo = 1.0 + res['frac'][0]
bcvel_baryc = ( lbary_ltopo - 1.0 ) * 2.99792458E5
print "\t\tBarycentric velocity:", bcvel_baryc
res = jplephem.pulse_delay(ra/15.0, dec, int(mjd), mjd%1, 1, 0.0)
mbjd = mjd + res['delay'][0] / (3600.0 * 24.0)
gobs = ephem.Observer()
gobs.name = h[0].header['TELESCOP']
gobs.lat = rad(latitude) # lat/long in decimal degrees
gobs.long = rad(longitude)
timeT = h[0].header['UTC-OBS'].split(':')
if len(timeT[0]) == 1:
gobs.date = h[0].header['DATE-OBS'][:10] + ' 0' + h[0].header['UTC-OBS']
else:
gobs.date = h[0].header['DATE-OBS'][:10] + ' ' + h[0].header['UTC-OBS']
mephem = ephem.Moon()
mephem.compute(gobs)
Mcoo = jplephem.object_track("Moon", int(mjd), float(mjd%1), 1, 0.0)
Mp = jplephem.barycentric_object_track("Moon", int(mjd), float(mjd%1), 1, 0.0)
Sp = jplephem.barycentric_object_track("Sun", int(mjd), float(mjd%1), 1, 0.0)
res = jplephem.object_doppler("Moon", int(mjd), mjd%1, 1, 0.0)
lunation,moon_state,moonsep,moonvel = GLOBALutils.get_lunar_props(ephem,gobs,Mcoo,Mp,Sp,res,ra,dec)
refvel = bcvel_baryc + moonvel
print '\t\tRadial Velocity of sacttered moonlight:',refvel
#moon_alts.update({fsim:mephem.alt})
#moon_ills.update({fsim:lunation})
print '\t\tExtraction:'
if mode == 'so':
sci_fits = dirout + fsim.split('/')[-1][:-4]+'spec.fits.S'
Mho = str(int(HHOUR))
if len(Mho)<2:
Mho = '0'+Mho
mins = (HHOUR - int(Mho))*60.
Mmi = str(int(mins))
if len(Mmi)<2:
Mmi = '0'+Mmi
segs = (mins - int(Mmi))*60.
if segs<10:
Mse = '0'+str(segs)[:5]
else:
Mse = str(segs)[:6]
gobs.date = str(DDATE[:4]) + '-' + str(DDATE[4:6]) + '-' + str(DDATE[6:]) + ' ' + Mho + ':' + Mmi +':' +Mse
mephem = ephem.Moon()
mephem.compute(gobs)
Mcoo = jplephem.object_track("Moon", int(mjd), float(mjd%1), 1, 0.0)
Mp = jplephem.barycentric_object_track("Moon", int(mjd), float(mjd%1), 1, 0.0)
Sp = jplephem.barycentric_object_track("Sun", int(mjd), float(mjd%1), 1, 0.0)
res = jplephem.object_doppler("Moon", int(mjd), mjd%1, 1, 0.0)
lunation,moon_state,moonsep,moonvel = GLOBALutils.get_lunar_props(ephem,gobs,Mcoo,Mp,Sp,res,ra,dec)
refvel = bcvel_baryc + moonvel
print '\t\tRadial Velocity of sacttered moonlight:',refvel
sorted_indices = np.argsort( np.abs( np.array(ThAr_ref_dates) - mjd ) )
sorted_indices_FP = np.argsort( np.abs( np.array(ThFP_ref_dates) - mjd ) )
print '\t\tExtraction:'
# optimally and simply extract spectra
sci_fits_ob = dirout + fsim.split('/')[-1][:-8]+'spec.ob.fits.S'
sci_fits_co = dirout + fsim.split('/')[-1][:-8]+'spec.co.fits.S'
self.tel.site.elevation = self.altitude.to(u.meter).value
## Do calculations using ephem
RADEC_string = ','.join(self.coordinate_from_header.to_string('hmsdms', sep=':').split())
TargetObject = ephem.readdb("Target,f|M|F7,{},2.02,2000".format(RADEC_string))
TargetObject.compute(self.tel.site)
self.target_alt = TargetObject.alt * 180./ephem.pi * u.deg
self.target_az = TargetObject.az * 180./ephem.pi * u.deg
self.logger.debug(" Target Alt, Az = {0:.1f}, {1:.1f}".format(\
self.target_alt.to(u.deg).value,\
self.target_az.to(u.deg).value))
self.target_zenith_angle = 90.*u.deg - self.target_alt
self.airmass = 1.0/math.cos(self.target_zenith_angle.to(u.radian).value)*(1.0 - 0.0012*(1.0/(math.cos(self.target_zenith_angle.to(u.radian).value)**2 - 1.0)))
self.logger.debug(" Target airmass (calculated) = {0:.2f}".format(\
self.airmass))
## Calculate Moon Position and Illumination
TheMoon = ephem.Moon()
TheMoon.compute(self.tel.site)
self.moon_phase = TheMoon.phase
self.moon_sep = ephem.separation(TargetObject, TheMoon)
self.moon_sep = self.moon_sep * 180./ephem.pi * u.deg
self.moon_alt = TheMoon.alt * 180./ephem.pi * u.deg
if self.moon_alt > 0:
self.logger.debug(" A {0:.0f} percent illuminated Moon is {1:.0f} deg from target.".format(\
self.moon_phase,\
self.moon_sep.to(u.deg).value))
else:
self.logger.debug(" A {0:.0f} percent illuminated Moon is down.".format(\
self.moon_phase))
else:
self.target_alt = None
self.target_az = None
self.moon_phase = None
res = jplephem.pulse_delay(ra/15.0, dec, int(mjd), mjd%1, 1, 0.0)
mbjd = mjd + res['delay'][0] / (3600.0 * 24.0)
# Moon Phase Calculations
gobs = ephem.Observer()
gobs.name='Clay_Mag_2'
gobs.lat=rad(latitude) # lat/long in decimal degrees
gobs.long=rad(longitude)
DDATE = h[0].header['UT-DATE']
HHOUR = h[0].header['UT-TIME']
Mho = HHOUR[:2]
Mmi = HHOUR[3:5]
Mse = HHOUR[6:]
gobs.date = str(DDATE[:4]) + '-' + str(DDATE[5:6]) + '-' + str(DDATE[7:]) + ' ' + Mho + ':' + Mmi +':' +Mse
mephem = ephem.Moon()
mephem.compute(gobs)
Mcoo = jplephem.object_track("Moon", int(mjd), float(mjd%1), 1, 0.0)
Mp = jplephem.barycentric_object_track("Moon", int(mjd), float(mjd%1), 1, 0.0)
Sp = jplephem.barycentric_object_track("Sun", int(mjd), float(mjd%1), 1, 0.0)
res = jplephem.object_doppler("Moon", int(mjd), mjd%1, 1, 0.0)
lunation,moon_state,moonsep,moonvel = GLOBALutils.get_lunar_props(ephem,gobs,Mcoo,Mp,Sp,res,ra,dec)
refvel = bcvel_baryc + moonvel
print '\t\tRadial Velocity of sacttered moonlight:',refvel
sorted_indices = np.argsort( np.abs( np.array(thar_dates) - mjd ) )
# optimally and simply extract spectra
sci_fits = dirout + 'PFS_' + h[0].header['UT-DATE'] + '_' + h[0].header['UT-TIME'] +'.'+ obname +'.spec.fits'
sci_fits_simple = dirout + 'PFS_' + h[0].header['UT-DATE'] + '_' + h[0].header['UT-TIME'] +'.'+ obname +'.spec.simple.fits'
P_fits = dirout + 'P_' + h[0].header['UT-DATE'] + '_' + h[0].header['UT-TIME'] +'.'+ obname +'.fits'
riseset = {}
# Find sunrise and sunset:
riseset['sun'] = find_rise_set(observer, ephem.Sun())
# Now find the full moon closest to the date,
# which may be the next full moon or the previous one.
lastfull = ephem.previous_full_moon(observer.date)
nextfull = ephem.next_full_moon(observer.date)
now = ephem.now()
if now - lastfull > nextfull - now:
observer.date = nextfull
else:
observer.date = lastfull
riseset['full moon'] = find_rise_set(observer, ephem.Moon())
return riseset
import ephem
import pytz
from widgets.prototypes import WidgetPrototype
from widgets.utils import stringdecorator
TIMEZONE = pytz.timezone('Europe/London')
EPHEM_BODIES = [
ephem.Sun(),
ephem.Moon(),
ephem.Mercury(),
ephem.Venus(),
ephem.Mars(),
ephem.Jupiter(),
ephem.Saturn(),
# ephem.Uranus(),
# ephem.Neptune(),
]
class EphemBodies(WidgetPrototype):
def __init__(
self,
longitude: float,
latitude: float,
super().__init__()
self.observer = observer
print("AnalemmaWindow: observer at %.1f %.1f" % (observer.lat,
observer.lon))
self.year = year
self.lunar = lunar
self.special_dates = None
self.drawing_area = None
self.width = 0
self.height = 0
# Even if we're actually showing the moon, call the object self.sun.
if self.lunar:
self.sun = ephem.Moon()
else:
self.sun = ephem.Sun()
self.sinusoidal = False
self.sun_color = (1, 1, 0)
self.backside_color = (1, .7, 0)
self.text_color = (1, 1, 0)
if background:
self.background_color = background
else:
self.background_color = (0, 0, .6, 1)
self.special_dot_size = 5
def update_moon(t, Site):
Moon = ephem.Moon()
Site.date = t
Moon.compute(Site)
X, Y = AltAz2XY(Moon.alt, Moon.az)
r = Moon.size / 3600 * np.pi / 180 * 2
return X, Y, r, Moon.alt
:param date_time: datetime object of current time
:return: -
"""
# Translate time stamp into UTC. In debug mode compute the moon position for a fixed time
# (as defined in configuration.py).
if self.debug:
# Alternative date, used for first tests of auto-alignment:
t = self.configuration.ephemeris_fixed_datetime
dt = datetime.datetime(t[0], t[1], t[2], t[3], t[4], t[5])
self.location_time.date = self.local_time_to_utc(dt)
else:
self.location_time.date = self.local_time_to_utc(date_time)
# Compute the ephemeris using PyEphem.
self.moon = ephem.Moon(self.location_time)
s = ephem.Sun(self.location_time)
self.ra = self.moon.ra
self.de = self.moon.dec
self.radius = self.moon.radius
self.diameter = self.moon.radius * 2.
self.sun_ra = s.ra
self.sun_de = s.dec
# Compute the distance between sun and moon in the sky.
self.elongation = acos(
sin(self.de) * sin(self.sun_de) + cos(self.de) * cos(self.sun_de) * cos(
self.sun_ra - self.ra))
# Compute the position angles of the point on the moon limb pointing at the sun,
# and of the North pole of the sunlit moon phase.
self.pos_angle_sun = self.sun_direction()
def get_next_new_moon(self, mycity, delay, args = None) :
"""
Return the date and time of the next new moon
@param city: the city wher calculate the event.
@param delay: the delay (in seconds) to the event.
@param args: an optional argument.
@returns: the next new moon daytime or None
"""
if abs(delay) >= 86400*28:
return None
m = ephem.Moon()
today = datetime.datetime.today() - datetime.timedelta(seconds=delay+30)
mycity.date = today
m.compute(mycity)
moon_date = ephem.localtime(ephem.next_new_moon(mycity.date))
return moon_date + datetime.timedelta(seconds=delay)