def get_moon_sep(time1,time2,ra,dec): obs = observer.Observer('saao') obs2 = ephem.Observer() obs2.lat = obs.site_info.latitude if obs.site_info.longitude[0] == '-': obs2.lon = obs.site_info.longitude[1:] else: obs2.lon = '-'+obs.site_info.longitude date = time1 obs2.date = str(date) m = ephem.Moon(obs2) rasep = np.sqrt((ra - m.ra*180./np.pi)**2) decsep = np.sqrt((dec - m.dec*180/np.pi)**2) if rasep > 180: rasep = 360 - rasep if decsep > 180: decsep = 360 - decsep moonsep = np.sqrt( (rasep)**2 + (decsep)**2 ) return moonsep
def GetTransitsInNight(ra,dec,P,t0,dur,date='today',tel='saao',maxAM=2.0,obname='test',out=10.): if date == 'today': refdate = datetime.datetime.utcnow() if refdate.hour < 11: refdate -= datetime.timedelta(days=1) sy,sm,ss = str(refdate.year),str(refdate.month),str(refdate.day) date = sy+'-'+sm+'-'+ss else: cos = date.split('-') refdate = datetime.datetime(int(cos[0]),int(cos[1]),int(cos[2]),13,0,0) obs = observer.Observer(tel) obs.almanac(date.replace('-','/')) nra,ndec = coordsDeg_to_coords(ra,dec) target = obs.target(obname, nra, ndec) vis = is_visible(target,obs,date,maxAM=maxAM,tel=tel) if vis: jd1,jd2 = get_time_up(target,obs,date,maxAM=maxAM,tel=tel) if jd2 > jd1: intransit, transits = get_transits(P,t0,dur,jd1,jd2,delt=out) if intransit: return transits else: return [] return []
def setUp(self): self._observer = observer.Observer() self._observer.position = np.array((0., 0., 0.)) self._observer.direction = np.array((1., 0., 0.)) self._tested = normalized_world.NormalizedWorld(self._observer)
import sl_osc_receive, observer obs = observer.Observer() osc = sl_osc_receive.SlOscReceive(54321,obs) try: while True: pass except KeyboardInterrupt : osc.terminate()
import observer obs = observer.Observer('subaru') hudf = obs.target('HUDF', '3 32 39.0', '-27 47 29.1') ms1054 = obs.target('MS1054', '10 56 59.99', '-03 37 36.0') cl1256 = obs.target('CL1256', '12 55 33.76', '01 04 3.72') obs.almanac('2010/01/12') obs.airmass(hudf, ms1054, cl1256) observer.plots.plot_airmass(obs, None)
def make_plot2(refdate, ra, dec, t0, per, dur, obname, dest='./'): sy,sm,sd = str(refdate.year),str(refdate.month),str(refdate.day) date = sy+'-'+sm+'-'+sd if refdate.month < 10: sm = '0'+sm if refdate.day < 10: sd = '0'+sd fig, ax = subplots(1,figsize=(20,6)) fig.autofmt_xdate() obs = observer.Observer('saao') obs.almanac(date.replace('-','/')) tw1 = obs.almanac_data.evening_twilight_12().datetime()#.strftime('%Y-%m-%d %H:%M:%S') tw2 = obs.almanac_data.evening_twilight_18().datetime()#.strftime('%Y-%m-%d %H:%M:%S') tw3 = obs.almanac_data.morning_twilight_18().datetime()#.strftime('%Y-%m-%d %H:%M:%S') tw4 = obs.almanac_data.morning_twilight_12().datetime()#.strftime('%Y-%m-%d %H:%M:%S') ts1 = obs.almanac_data.sunset().datetime()#.strftime('%Y-%m-%d %H:%M:%S') ts2 = obs.almanac_data.sunrise().datetime()#.strftime('%Y-%m-%d %H:%M:%S') x1 = pd.to_datetime(np.array([ts1, tw1])) x2 = pd.to_datetime(np.array([tw1, tw2])) x3 = pd.to_datetime(np.array([tw2, tw3])) x4 = pd.to_datetime(np.array([tw3, tw4])) x5 = pd.to_datetime(np.array([tw4, ts2])) y1 = np.array([0,0]) y2 = np.array([90,90]) pos = 95 if True: obs = observer.Observer('saao') obs.almanac(date.replace('-','/')) nra,ndec = coordsDeg_to_coords(ra,dec) target = obs.target(obname, nra, ndec) obs.airmass(target) AM = np.array(obs.airmass_data[0].airmass) ALT = 0.5*np.pi - np.arccos(1./AM) ALT = 180.*ALT/np.pi utc = obs.airmass_data[0].utc reft = [] pdt = [] for t in utc: reft.append(get_mjd(t.datetime())) pdt.append(t.datetime()) reft,pdt = np.array(reft),pd.to_datetime(np.array(pdt)) II = np.where(ALT>10)[0] plot(pdt[II],ALT[II],'r') if True: t0 = t0 - 2400000.5 phase = (reft-t0)/per phase = phase - phase.astype('int') IT1 = np.where( (phase > 1 - 0.5*dur/per)) [0] IT2 = np.where( (phase < 0.5*dur/per))[0] IT = np.hstack((IT1,IT2)) if len(IT)>0: plot(pdt[IT],ALT[IT],'r',linewidth='4.') IT = np.where((phase > 0.5 - 0.5*dur/per) & (phase < 0.5 + 0.5*dur/per))[0] if len(IT)>0: plot(pdt[IT],ALT[IT],'g',linewidth='4.') moonsep = get_moon_sep(pdt[II[0]], pdt[II[-1]],ra, dec) text(pdt[II][0], pos, 'Moon: '+str(np.around(moonsep))+' deg', color="black") rng = pd.date_range(ts1, ts2, freq='15min') altitudes = get_moon_elev(obs,rng) I = np.where(altitudes>0)[0] if len(I)>0: plot(rng[I],altitudes[I],'y-') moon_state, moon_ill = get_moon_ill(obs,rng[int(0.5*len(rng))]) text(ts1, 100, moon_state + ' moon, ' + str(int(np.around(moon_ill*100)))+' %') fill_between(x1, y1, y2, where=y2 >= y1, facecolor='lightblue', interpolate=True) fill_between(x2, y1, y2, where=y2 >= y1, facecolor='blue', interpolate=True) fill_between(x3, y1, y2, where=y2 >= y1, facecolor='darkblue', interpolate=True) fill_between(x4, y1, y2, where=y2 >= y1, facecolor='blue', interpolate=True) fill_between(x5, y1, y2, where=y2 >= y1, facecolor='lightblue', interpolate=True) axhline(30., color='k',linestyle='--') xlim(x1[0],x5[-1]) ylim(0,90) ylabel('Altitude') xfmt = mdates.DateFormatter('%d-%m %H:%M') ax.xaxis.set_major_formatter(xfmt) fname = dest+'/futuretransit_'+str(refdate).split()[0]+'_'+obname+'.png' savefig(fname,bbox_inches='tight',format='png') return fname.split('/')[-1]
# print self.sensor.readTemp() temperature = self.sensor.readTemp() self.broadcast(value = temperature,timestamp = time.time()) time.sleep(self.interval) def stop(self): self.stop_event.set() if __name__ == '__main__': aSensor = tempSensor() aTempPoller = sensorPoller(aSensor,interval=10) #register default observer with the poller firstobserver = observer.Observer(aTempPoller.observable) aTempPoller.start() do_exit = False while do_exit == False: try: # sleep some time time.sleep(0.1) except KeyboardInterrupt: # Ctrl+C was hit - exit program do_exit = True # stop all running thread aTempPoller.stop()
def init(command=None): args = configure_cmdline(command) if command is None: command = args.command single = args.single configure_logging() logging.debug("Starting sdnalyzer.") configuration = None config_file_path = "/etc/sdnalytics/sdnalytics.json" if not os.path.isfile(config_file_path): print "Run sdn-ctl setup before executing sdn-observe or sdn-analyze" #"Copy sdnalyzer.default.json to " + config_file_path + " and adapt the file according to your setup. Then start this program again." return with open(config_file_path) as config_file: configuration = json.loads(config_file.read()) if "connectionString" not in configuration: raise Exception( "No connection string configured in sdnalyzer.json.") store.start(configuration["connectionString"]) if "api" in configuration: if "port" in configuration["api"]: api_port = int(configuration["api"]["port"]) if "username" in configuration["api"]: api_username = configuration["api"]["username"] if "password" in configuration["api"]: api_password = configuration["api"]["password"] if command == "observe" or command == "analyze": command += "r" if command == "setup": store.init() print "Successfully setup the database. You can now use sdn-analyze and sdn-observe monitor your network." elif command == "reset": store.drop() store.init() print "Successfully reset the database. All previously gathered data has been discarded." elif command == "observer": program_state = start_api(command, api_username, api_password, api_port + 1) import observer poll_interval = 30 if "pollInterval" in configuration: poll_interval = int(configuration["pollInterval"]) if "controller" in configuration: if "host" in configuration["controller"]: controller_host = configuration["controller"]["host"] if "port" in configuration["controller"]: controller_port = configuration["controller"]["port"] program_state.instance = observer.Observer(controller_host, controller_port) program_state.instance.observe(single, poll_interval, program_state) elif command == "analyzer": program_state = start_api(command, api_username, api_password, api_port + 2) import analyzer program_state.instance = analyzer.Analyzer() program_state.instance.analyze(single, program_state) elif command == "adhoc": import adhoc adhoc.run() else: logging.error("Invalid command {}.".format(command)) logging.debug("Shut down.")
def factory(screen_width, screen_height): return Engine(world.World(), observer.Observer(), screen_width, screen_height)
def setUp(self): _observer = observer.Observer() self._tested = virtualscreen.VirtualScreen(_observer)
# Copyright © 2018 Stanislav Hnatiuk. All rights reserved. # !/usr/bin/env python3 import sys from PyQt5.QtWidgets import QApplication import mainWindow import observer if __name__ == '__main__': app = QApplication(sys.argv) core = observer.Observer() ex = mainWindow.MainWindow(core) sys.exit(app.exec())