How to use the sun.sun function in sun

To help you get started, we’ve selected a few sun examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ToninoTarsi / swpi / service.py View on Github external
def run(self):
        #try:
        #shutdown_hour_before_sunset
        time.sleep(300)
        if ( self.cfg.set_system_time_from_ntp_server_at_startup ):
            while (  not globalvars.TimeSetFromNTP ) :
                time.sleep(60)
        if ( self.cfg.shutdown_hour_before_sunset.upper() != "NONE" ):
            s=sun.sun(lat=self.cfg.location_latitude,long=self.cfg.location_longitude)
            sh = float(self.cfg.shutdown_hour_before_sunset)
            h = math.floor(sh)
            m = math.floor( ( sh-h) * 60 )
            sunset = s.sunset()
            time_todo = datetime.timedelta(hours=sunset.hour-h, minutes=sunset.minute-m, seconds=sunset.second)
            time_now = datetime.timedelta(hours=datetime.datetime.now().hour, minutes=datetime.datetime.now().minute, seconds=datetime.datetime.now().second)
 
            seconds_todo = (time_todo - time_now  ).total_seconds()
  
            if (seconds_todo < 0  ) : seconds_todo = seconds_todo + 86400                    
            
            log("SunHalter: System will Halt in %s seconds" % str(seconds_todo))
            time.sleep(seconds_todo)
            systemHalt()
#        except:
github ToninoTarsi / swpi / cameraPI.py View on Github external
def __init__(self, cfg):
		self.cfg = cfg
		self.god=sun.sun(lat=cfg.location_latitude,long=cfg.location_longitude)
github ToninoTarsi / swpi / camera.py View on Github external
def __init__(self, cfg):
		self.finalresolution = cfg.cameradivicefinalresolution
		self.finalresolutionX = cfg.cameradivicefinalresolutionX
		self.finalresolutionY = cfg.cameradivicefinalresolutionY
		self.cfg = cfg
		self.bCaturing = 0
		self.god=sun.sun(lat=cfg.location_latitude,long=cfg.location_longitude)
		
#		self.CameraWatchDog = CameraWatchDogClass(cfg)
#		if len(self.detectCameras()) > 0 :
#			log("Starting camera Watch Dog")
#			self.CameraWatchDog.run()
		
		if ( self.cfg.use_camera_resetter ):
			GPIO.setwarnings(False)
			GPIO.setmode(GPIO.BCM)
			GPIO.setup(self.__PIN_RESET, GPIO.OUT) 
			if cfg.camera_resetter_normaly_on :
				GPIO.output(self.__PIN_RESET, True)
			else:
				GPIO.output(self.__PIN_RESET, False)
github ToninoTarsi / swpi / sun.py View on Github external
vary     = tan(rad(obliq/2))*tan(rad(obliq/2))
  Seqcent  = sin(rad(Manom))*(1.914602-Jcent*(0.004817+0.000014*Jcent))+sin(rad(2*Manom))*(0.019993-0.000101*Jcent)+sin(rad(3*Manom))*0.000289
  Struelong= Mlong+Seqcent
  Sapplong = Struelong-0.00569-0.00478*sin(rad(125.04-1934.136*Jcent))
  declination = deg(asin(sin(rad(obliq))*sin(rad(Sapplong))))
  
  eqtime   = 4*deg(vary*sin(2*rad(Mlong))-2*Eccent*sin(rad(Manom))+4*Eccent*vary*sin(rad(Manom))*cos(2*rad(Mlong))-0.5*vary*vary*sin(4*rad(Mlong))-1.25*Eccent*Eccent*sin(2*rad(Manom)))

  hourangle= deg(acos(cos(rad(90.833))/(cos(rad(latitude))*cos(rad(declination)))-tan(rad(latitude))*tan(rad(declination))))

  self.solarnoon_t=(720-4*longitude-eqtime+timezone*60)/1440
  self.sunrise_t  =self.solarnoon_t-hourangle*4/1440
  self.sunset_t   =self.solarnoon_t+hourangle*4/1440

if __name__ == "__main__":
 s=sun(lat=43.351983,long=12.743187)
 print(datetime.today())
 print(s.sunrise(),s.solarnoon(),s.sunset())
 
 print s.daylight()
github ToninoTarsi / swpi / webcam.py View on Github external
self.caprureresolutionY = cfg.webcamdevice1captureresolutionY
			self.finalresolutionX = cfg.webcamdevice1finalresolutionX
			self.finalresolutionY = cfg.webcamdevice1finalresolutionY
		elif (deviceNumber == 2):
			self.device = cfg.webcamDevice2
			self.captureresolution = cfg.webcamdevice2captureresolution 
			self.finalresolution = cfg.webcamdevice2finalresolution
			self.caprureresolutionX = cfg.webcamdevice2captureresolutionX
			self.caprureresolutionY = cfg.webcamdevice2captureresolutionY
			self.finalresolutionX = cfg.webcamdevice2finalresolutionX
			self.finalresolutionY = cfg.webcamdevice2finalresolutionY
		else:
			log( "ERROR Only 2 webcams are allowed in this version of the software"	)
			
		self.cfg = cfg
		self.god=sun.sun(lat=cfg.location_latitude,long=cfg.location_longitude)