Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def click(event):
global cnt
if event.button == 3:
lon,lat = map(event.xdata, event.ydata, inverse=True)
if opts.osys == 'eq': lon = (360 - lon) % 360
lon *= a.img.deg2rad; lat *= a.img.deg2rad
ra,dec = ephem.hours(lon), ephem.degrees(lat)
x,y,z = a.coord.radec2eq((ra,dec))
flx = h[(x,y,z)]
print '#%d (RA,DEC): (%s, %s), Jy: %f' % (cnt, ra, dec, flx)
cnt += 1
elif event.button==2:
lon,lat = map(event.xdata, event.ydata, inverse=True)
if opts.osys == 'eq': lon = (360 - lon) % 360
lon *= a.img.deg2rad; lat *= a.img.deg2rad
ra,dec = ephem.hours(lon), ephem.degrees(lat)
x,y,z = a.coord.radec2eq((ra,dec))
#flx = h[(x,y,z)]
crd = [mk_arr(c, dtype=np.double) for c in (x,y,z)]
px,wgts = h.crd2px(*crd, **{'interpolate':1})
flx = np.sum(h[px],axis=-1)
print '#%d (RA,DEC): (%s, %s), Jy: %f (4px sum)' % (cnt, ra, dec, flx)
cnt += 1
#
self.pulse_recording.open (self.prefix+filename)
#
# We open the header file as a regular file, write header data,
# then close
hdrf = open(self.prefix+hdrfilename, "w")
hdrf.write("receiver center frequency: "+str(self.frequency)+"\n")
hdrf.write("observing frequency: "+str(self.observing_freq)+"\n")
hdrf.write("DM: "+str(self.dm)+"\n")
hdrf.write("doppler: "+str(self.doppler)+"\n")
hdrf.write("pulse rate: "+str(self.pulse_freq)+"\n")
hdrf.write("pulse sps: "+str(self.pulse_freq*self.folding)+"\n")
hdrf.write("file sps: "+str(self.folder_input_rate)+"\n")
hdrf.write("sidereal: "+str(ephem.hours(sidtime))+"\n")
hdrf.write("bandwidth: "+str(self.u.adc_freq() / self.u.decim_rate())+"\n")
hdrf.write("sample type: short\n")
hdrf.write("sample size: 1\n")
hdrf.close()
#
# If time to write full header info (saves storage this way)
#
if (now - self.continuum_then > 20):
self.sun.compute(self.locality)
enow = ephem.now()
sunset = self.locality.next_setting(self.sun)
sunrise = self.locality.next_rising(self.sun)
sun_insky = "Down"
self.sunstate = "Dn"
if ((sunrise < enow) and (enow < sunset)):
sun_insky = "Up"
self.sunstate = "Up"
self.continuum_then = now
continuum_file.write(str(ephem.hours(sidtime))+" "+flt+" Dn="+str(inter)+",")
continuum_file.write("Ti="+str(integ)+",Fc="+str(fc)+",Bw="+str(bw))
continuum_file.write(",Ga="+str(ga)+",Sun="+str(sun_insky)+"\n")
else:
continuum_file.write(str(ephem.hours(sidtime))+" "+flt+"\n")
continuum_file.close()
return(data)
def request_noisified():
my_obs = observatory_PTF.PTF
# make up an object:
vega = my_obs.create_target(ephem.hours('18:36:56.20'), ephem.degrees('38:46:59.0'), "cepheid") # coordinates of vega
for i in range(10):
mindiff_multiplier = i - 5
if mindiff_multiplier < 1:
mindiff_multiplier = 1
t = generic_observatory.time_series_generator()
time_series = t.generate_time_series(vega, my_obs)
print("mindiff_multiplier should be: ", mindiff_multiplier)
try:
output = my_obs.observe(target=vega, times = time_series, band = "V")
except AssertionError as description:
print("Failed %s times so far, because of %s" % ((i+1), description))
else:
return output
return request_noisified()
def _solartime(observer, sun):
"""Return solar time for given observer and sun"""
# sidereal time == ra (right ascension) is the highest point (noon)
hour_angle = observer.sidereal_time() - sun.ra
return ephem.hours(hour_angle + ephem.hours("12:00")).norm # norm for 24h
def solarTime(utc_dt, lat, lon):
"""Compute local solar time for given (lat, lon)
"""
import ephem
o = ephem.Observer()
o.date = utc_dt
o.lat = str(lat)
o.lon = str(lon)
sun = ephem.Sun()
sun.compute(o)
hour_angle = o.sidereal_time() - sun.ra
rad = str(ephem.hours(hour_angle + ephem.hours('12:00')).norm)
t = datetime.strptime(rad, '%H:%M:%S.%f')
solar_dt = datetime.combine(utc_dt.date(), t.time())
return solar_dt
'''If star is above horizon and sun is below horizon:'''
if (ingress > sunset and egress < sunrise) and (ingress > starrise and egress < starset) or bypassTag:
ingressAlt,ingressDir,egressAlt,egressDir = ingressEgressAltAz(planet,observatory,ingress,egress)
transitInfo = [planet,transitEpoch,duration(planet)/2,'transit',ingressAlt,ingressDir,egressAlt,egressDir]
transits[str(day)].append(transitInfo)
#else: print 'Partial transit'
if calcEclipses and len(eclipseEpochs) != 0:
eclipseEpoch = eclipseEpochs[0]
ingress = eclipseEpoch-duration(planet)/2
egress = eclipseEpoch+duration(planet)/2
''' Calculate positions of host stars'''
observatory.horizon = observatory_minHorizon ## Input format- deg:min:sec (type=str)
star = ephem.FixedBody()
star._ra = ephem.hours(RA(planet))
star._dec = ephem.degrees(dec(planet))
star.compute(observatory)
exoplanetDB[planet]['Constellation'] = ephem.constellation(star)[0]
bypassTag = False
try:
starrise = gd2jd(datestr2list(str(observatory.next_rising(star))))
starset = gd2jd(datestr2list(str(observatory.next_setting(star))))
except ephem.AlwaysUpError:
'''If the star is always up, you don't need starrise and starset to
know that the event should be included further calculations'''
print 'Woo! '+str(planet)+' is always above the horizon.'
bypassTag = True
'''If star is above horizon and sun is below horizon:'''
if (ingress > sunset and egress < sunrise) and (ingress > starrise and egress < starset) or bypassTag:
ingressAlt,ingressDir,egressAlt,egressDir = ingressEgressAltAz(planet,observatory,ingress,egress)
sidtime = self.locality.sidereal_time()
# Pick up localtime, for generating filenames
foo = time.localtime()
# Generate filenames for both data and header file
hitfilename = "%04d%02d%02d%02d.phit" % (foo.tm_year, foo.tm_mon,
foo.tm_mday, foo.tm_hour)
hitf = open(self.prefix+hitfilename, "a")
hitf.write("receiver center frequency: "+str(self.frequency)+"\n")
hitf.write("observing frequency: "+str(self.observing_freq)+"\n")
hitf.write("DM: "+str(self.dm)+"\n")
hitf.write("doppler: "+str(self.doppler)+"\n")
hitf.write("sidereal: "+str(ephem.hours(sidtime))+"\n")
hitf.write("bandwidth: "+str(self.u.adc_freq() / self.u.decim_rate())+"\n")
hitf.write("spectral peaks: "+str(hits)+"\n")
hitf.write("HCM: "+str(hcavg)+" "+str(hcmax)+"\n")
hitf.close()