<s> import os <EOL> import sys <EOL> import serial <EOL> import re <EOL> from datetime import datetime as dt <EOL> from datetime import timedelta as tdelta <EOL> import time <EOL> import argparse <EOL> import logging <EOL> import logging . handlers <EOL> import numpy as np <EOL> import astropy . units as u <EOL> from astropy . time import Time <EOL> from astropy . coordinates import EarthLocation <EOL> from astroplan import Observer <EOL> import pymongo <EOL> from panoptes . utils . config import load_config <EOL> from panoptes . utils . database import PanMongo <EOL> from panoptes . utils . PID import PID <EOL> from panoptes . weather . weather_station import WeatherStation <EOL> def movingaverage ( interval , window_size ) : <EOL> window = np . ones ( int ( window_size ) ) / float ( window_size ) <EOL> return np . convolve ( interval , window , '<STR_LIT>' ) <EOL> class AAGCloudSensor ( WeatherStation ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , serial_address = None ) : <EOL> super ( ) . __init__ ( ) <EOL> logger = logging . getLogger ( '<STR_LIT>' ) <EOL> if len ( logger . handlers ) == <NUM_LIT:0> : <EOL> logger . setLevel ( logging . DEBUG ) <EOL> LogConsoleHandler = logging . StreamHandler ( ) <EOL> LogConsoleHandler . setLevel ( logging . INFO ) <EOL> LogFormat = logging . Formatter ( '<STR_LIT>' ) <EOL> LogConsoleHandler . setFormatter ( LogFormat ) <EOL> logger . addHandler ( LogConsoleHandler ) <EOL> LogFilePath = os . path . join ( '<STR_LIT:/>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> if not os . path . exists ( LogFilePath ) : <EOL> os . mkdir ( LogFilePath ) <EOL> now = dt . utcnow ( ) <EOL> LogFileName = now . strftime ( '<STR_LIT>' ) <EOL> LogFile = os . path . join ( LogFilePath , LogFileName ) <EOL> LogFileHandler = logging . handlers . TimedRotatingFileHandler ( LogFile , <EOL> when = '<STR_LIT>' , interval = <NUM_LIT:1> , utc = True ) <EOL> LogFileHandler . setLevel ( logging . DEBUG ) <EOL> LogFileHandler . setFormatter ( LogFormat ) <EOL> logger . addHandler ( LogFileHandler ) <EOL> self . logger = logger <EOL> self . cfg = load_config ( ) [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> if not serial_address : <EOL> serial_address = self . cfg . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if self . logger : <EOL> self . logger . debug ( '<STR_LIT>' . format ( serial_address ) ) <EOL> if serial_address : <EOL> if self . logger : <EOL> self . logger . info ( '<STR_LIT>' ) <EOL> try : <EOL> self . AAG = serial . Serial ( serial_address , <NUM_LIT> , timeout = <NUM_LIT:2> ) <EOL> self . logger . info ( "<STR_LIT>" . format ( serial_address ) ) <EOL> except OSError as e : <EOL> self . logger . error ( '<STR_LIT>' ) <EOL> self . logger . error ( '<STR_LIT>' . format ( e . errno ) ) <EOL> self . logger . error ( '<STR_LIT>' . format ( e . strerror ) ) <EOL> self . AAG = None <EOL> except : <EOL> self . logger . error ( "<STR_LIT>" ) <EOL> self . AAG = None <EOL> else : <EOL> self . AAG = None <EOL> self . last_update = None <EOL> self . safe = None <EOL> self . ambient_temp = None <EOL> self . sky_temp = None <EOL> self . wind_speed = None <EOL> self . internal_voltage = None <EOL> self . LDR_resistance = None <EOL> self . rain_sensor_temp = None <EOL> self . PWM = None <EOL> self . errors = None <EOL> self . switch = None <EOL> self . safe_dict = None <EOL> self . hibernate = <NUM_LIT> <EOL> if '<STR_LIT>' in self . cfg : <EOL> self . heater_cfg = self . cfg [ '<STR_LIT>' ] <EOL> else : <EOL> self . heater_cfg = { <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : <NUM_LIT:6> , <EOL> '<STR_LIT>' : <NUM_LIT:20> , <EOL> '<STR_LIT>' : <NUM_LIT:4> , <EOL> '<STR_LIT>' : <NUM_LIT:10> , <EOL> '<STR_LIT>' : <NUM_LIT:10> , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> } <EOL> self . heater_PID = PID ( Kp = <NUM_LIT> , Ki = <NUM_LIT> , Kd = <NUM_LIT> , <EOL> max_age = <NUM_LIT> , <EOL> output_limits = [ self . heater_cfg [ '<STR_LIT>' ] , <NUM_LIT:100> ] ) <EOL> self . impulse_heating = None <EOL> self . impulse_start = None <EOL> self . commands = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> self . expects = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> self . delays = { <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> } <EOL> if self . AAG : <EOL> result = self . query ( '<STR_LIT>' ) <EOL> if result : <EOL> self . name = result [ <NUM_LIT:0> ] . strip ( ) <EOL> if self . logger : <EOL> self . logger . info ( '<STR_LIT>' . format ( self . name ) ) <EOL> else : <EOL> self . name = '<STR_LIT>' <EOL> if self . logger : <EOL> self . logger . warning ( '<STR_LIT>' ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> result = self . query ( '<STR_LIT>' ) <EOL> if result : <EOL> self . firmware_version = result [ <NUM_LIT:0> ] . strip ( ) <EOL> if self . logger : <EOL> self . logger . info ( '<STR_LIT>' . format ( self . firmware_version ) ) <EOL> else : <EOL> self . firmware_version = '<STR_LIT>' <EOL> if self . logger : <EOL> self . logger . warning ( '<STR_LIT>' ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> result = self . query ( '<STR_LIT>' ) <EOL> if result : <EOL> self . serial_number = result [ <NUM_LIT:0> ] . strip ( ) <EOL> if self . logger : <EOL> self . logger . info ( '<STR_LIT>' . format ( self . serial_number ) ) <EOL> else : <EOL> self . serial_number = '<STR_LIT>' <EOL> if self . logger : <EOL> self . logger . warning ( '<STR_LIT>' ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> def send ( self , send , delay = <NUM_LIT> ) : <EOL> found_command = False <EOL> for cmd in self . commands . keys ( ) : <EOL> if re . match ( cmd , send ) : <EOL> if self . logger : <EOL> self . logger . debug ( '<STR_LIT>' . format ( self . commands [ cmd ] ) ) <EOL> found_command = True <EOL> break <EOL> if not found_command : <EOL> if self . logger : <EOL> self . logger . warning ( '<STR_LIT>' . format ( send ) ) <EOL> return None <EOL> if self . logger : <EOL> self . logger . debug ( '<STR_LIT>' ) <EOL> cleared = self . AAG . read ( self . AAG . inWaiting ( ) ) <EOL> if len ( cleared ) > <NUM_LIT:0> : <EOL> if self . logger : <EOL> self . logger . debug ( '<STR_LIT>' . format ( cleared . decode ( '<STR_LIT:utf-8>' ) ) ) <EOL> self . AAG . write ( send . encode ( '<STR_LIT:utf-8>' ) ) <EOL> time . sleep ( delay ) <EOL> response = self . AAG . read ( self . AAG . inWaiting ( ) ) . decode ( '<STR_LIT:utf-8>' ) <EOL> if self . logger : <EOL> self . logger . debug ( '<STR_LIT>' . format ( response ) ) <EOL> ResponseMatch = re . match ( '<STR_LIT>' , response ) <EOL> if ResponseMatch : <EOL> result = ResponseMatch . group ( <NUM_LIT:1> ) <EOL> else : <EOL> result = response <EOL> return result <EOL> def query ( self , send , maxtries = <NUM_LIT:5> ) : <EOL> found_command = False <EOL> for cmd in self . commands . keys ( ) : <EOL> if re . match ( cmd , send ) : <EOL> if self . logger : <EOL> self . logger . debug ( '<STR_LIT>' . format ( self . commands [ cmd ] ) ) <EOL> found_command = True <EOL> break <EOL> if not found_command : <EOL> if self . logger : <EOL> self . logger . warning ( '<STR_LIT>' . format ( send ) ) <EOL> return None <EOL> if cmd in self . delays . keys ( ) : <EOL> delay = self . delays [ cmd ] <EOL> else : <EOL> delay = <NUM_LIT> <EOL> expect = self . expects [ cmd ] <EOL> count = <NUM_LIT:0> <EOL> result = None <EOL> while not result and ( count <= maxtries ) : <EOL> count += <NUM_LIT:1> <EOL> result = self . send ( send , delay = delay ) <EOL> MatchExpect = re . match ( expect , result ) <EOL> if not MatchExpect : <EOL> if self . logger : <EOL> self . logger . debug ( '<STR_LIT>' . format ( expect , result ) ) <EOL> result = None <EOL> time . sleep ( self . hibernate ) <EOL> else : <EOL> if self . logger : <EOL> self . logger . debug ( '<STR_LIT>' . format ( expect , result ) ) <EOL> result = MatchExpect . groups ( ) <EOL> return result <EOL> def get_ambient_temperature ( self , n = <NUM_LIT:5> ) : <EOL> '''<STR_LIT>''' <EOL> if self . logger : <EOL> self . logger . info ( '<STR_LIT>' ) <EOL> values = [ ] <EOL> for i in range ( <NUM_LIT:0> , n ) : <EOL> try : <EOL> value = float ( self . query ( '<STR_LIT>' ) [ <NUM_LIT:0> ] ) / <NUM_LIT> <EOL> except : <EOL> pass <EOL> else : <EOL> if self . logger : <EOL> self . logger . debug ( '<STR_LIT>' . format ( value ) ) <EOL> values . append ( value ) <EOL> if len ( values ) >= n - <NUM_LIT:1> : <EOL> self . ambient_temp = np . median ( values ) * u . Celsius <EOL> if self . logger : <EOL> self . logger . info ( '<STR_LIT>' . format ( self . ambient_temp ) ) <EOL> else : <EOL> self . ambient_temp = None <EOL> if self . logger : <EOL> self . logger . info ( '<STR_LIT>' ) <EOL> return self . ambient_temp <EOL> def get_sky_temperature ( self , n = <NUM_LIT:9> ) : <EOL> '''<STR_LIT>''' <EOL> if self . logger : <EOL> self . logger . info ( '<STR_LIT>' ) <EOL> values = [ ] <EOL> for i in range ( <NUM_LIT:0> , n ) : <EOL> try : <EOL> value = float ( self . query ( '<STR_LIT>' ) [ <NUM_LIT:0> ] ) / <NUM_LIT> <EOL> except : <EOL> pass <EOL> else : <EOL> if self . logger : <EOL> self . logger . debug ( '<STR_LIT>' . format ( value ) ) <EOL> values . append ( value ) <EOL> if len ( values ) >= n - <NUM_LIT:1> : <EOL> self . sky_temp = np . median ( values ) * u . Celsius <EOL> if self . logger : <EOL> self . logger . info ( '<STR_LIT>' . format ( self . sky_temp ) ) <EOL> else : <EOL> self . sky_temp = None <EOL> if self . logger : <EOL> self . logger . info ( '<STR_LIT>' ) <EOL> return self . sky_temp <EOL> def get_values ( self , n = <NUM_LIT:5> ) : <EOL> '''<STR_LIT>''' <EOL> if self . logger : <EOL> self . logger . info ( '<STR_LIT>' ) <EOL> ZenerConstant = <NUM_LIT:3> <EOL> LDRPullupResistance = <NUM_LIT> <EOL> RainPullUpResistance = <NUM_LIT:1> <EOL> RainResAt25 = <NUM_LIT:1> <EOL> RainBeta = <NUM_LIT> <EOL> ABSZERO = <NUM_LIT> <EOL> internal_voltages = [ ] <EOL> LDR_resistances = [ ] <EOL> rain_sensor_temps = [ ] <EOL> for i in range ( <NUM_LIT:0> , n ) : <EOL> responses = self . query ( '<STR_LIT>' ) <EOL> try : <EOL> internal_voltage = <NUM_LIT> * ZenerConstant / float ( responses [ <NUM_LIT:0> ] ) <EOL> internal_voltages . append ( internal_voltage ) <EOL> LDR_resistance = LDRPullupResistance / ( ( <NUM_LIT> / float ( responses [ <NUM_LIT:1> ] ) ) - <NUM_LIT:1.> ) <EOL> LDR_resistances . append ( LDR_resistance ) <EOL> r = np . log ( RainPullUpResistance / ( ( <NUM_LIT> / float ( responses [ <NUM_LIT:2> ] ) ) - <NUM_LIT:1.> ) / RainResAt25 ) <EOL> rain_sensor_temp = <NUM_LIT:1.> / ( r / RainBeta + <NUM_LIT:1.> / ( ABSZERO + <NUM_LIT> ) ) - ABSZERO <EOL> rain_sensor_temps . append ( rain_sensor_temp ) <EOL> except : <EOL> pass <EOL> if len ( internal_voltages ) >= n - <NUM_LIT:1> : <EOL> self . internal_voltage = np . median ( internal_voltages ) * u . volt <EOL> if self . logger : <EOL> self . logger . info ( '<STR_LIT>' . format ( self . internal_voltage ) ) <EOL> else : <EOL> self . internal_voltage = None <EOL> if self . logger : <EOL> self . logger . info ( '<STR_LIT>' ) <EOL> if len ( LDR_resistances ) >= n - <NUM_LIT:1> : <EOL> self . LDR_resistance = np . median ( LDR_resistances ) * u . kohm <EOL> if self . logger : <EOL> self . logger . info ( '<STR_LIT>' . format ( self . LDR_resistance ) ) <EOL> else : <EOL> self . LDR_resistance = None <EOL> if self . logger : <EOL> self . logger . info ( '<STR_LIT>' ) <EOL> if len ( rain_sensor_temps ) >= n - <NUM_LIT:1> : <EOL> self . rain_sensor_temp = np . median ( rain_sensor_temps ) * u . Celsius <EOL> if self . logger : <EOL> self . logger . info ( '<STR_LIT>' . format ( self . rain_sensor_temp ) ) <EOL> else : <EOL> self . rain_sensor_temp = None <EOL> if self . logger : <EOL> self . logger . info ( '<STR_LIT>' ) <EOL> return ( self . internal_voltage , self . LDR_resistance , self . rain_sensor_temp ) <EOL> def get_rain_frequency ( self , n = <NUM_LIT:5> ) : <EOL> '''<STR_LIT>''' <EOL> if self . logger : <EOL> self . logger . info ( '<STR_LIT>' ) <EOL> values = [ ] <EOL> for i in range ( <NUM_LIT:0> , n ) : <EOL> try : <EOL> value = float ( self . query ( '<STR_LIT>' ) [ <NUM_LIT:0> ] ) * <NUM_LIT> / <NUM_LIT> <EOL> if self . logger : <EOL> self . logger . debug ( '<STR_LIT>' . format ( value ) ) <EOL> values . append ( value ) <EOL> except : <EOL> pass <EOL> if len ( values ) >= n - <NUM_LIT:1> : <EOL> self . rain_frequency = np . median ( values ) <EOL> if self . logger : <EOL> self . logger . info ( '<STR_LIT>' . format ( self . rain_frequency ) ) <EOL> else : <EOL> self . rain_frequency = None <EOL> if self . logger : <EOL> self . logger . info ( '<STR_LIT>' ) <EOL> return self . rain_frequency <EOL> def get_PWM ( self ) : <EOL> '''<STR_LIT>''' <EOL> if self . logger : <EOL> self . logger . info ( '<STR_LIT>' ) <EOL> try : <EOL> value = self . query ( '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> self . PWM = float ( value ) * <NUM_LIT> / <NUM_LIT> <EOL> if self . logger : <EOL> self . logger . info ( '<STR_LIT>' . format ( self . PWM ) ) <EOL> except : <EOL> self . PWM = None <EOL> if self . logger : <EOL> self . logger . info ( '<STR_LIT>' ) <EOL> return self . PWM <EOL> def set_PWM ( self , percent , ntries = <NUM_LIT:15> ) : <EOL> '''<STR_LIT:U+0020>''' <EOL> count = <NUM_LIT:0> <EOL> success = False <EOL> if percent < <NUM_LIT:0.> : <EOL> percent = <NUM_LIT:0.> <EOL> if percent > <NUM_LIT> : <EOL> percent = <NUM_LIT> <EOL> while not success and count <= ntries : <EOL> if self . logger : <EOL> self . logger . info ( '<STR_LIT>' . format ( percent ) ) <EOL> send_digital = int ( <NUM_LIT> * float ( percent ) / <NUM_LIT> ) <EOL> send_string = '<STR_LIT>' . format ( send_digital ) <EOL> result = self . query ( send_string ) <EOL> count += <NUM_LIT:1> <EOL> if result : <EOL> self . PWM = float ( result [ <NUM_LIT:0> ] ) * <NUM_LIT> / <NUM_LIT> <EOL> if abs ( self . PWM - percent ) > <NUM_LIT> : <EOL> if self . logger : <EOL> self . logger . warning ( '<STR_LIT>' ) <EOL> time . sleep ( <NUM_LIT:2> ) <EOL> else : <EOL> success = True <EOL> if self . logger : <EOL> self . logger . info ( '<STR_LIT>' . format ( self . PWM ) ) <EOL> def get_errors ( self ) : <EOL> '''<STR_LIT>''' <EOL> if self . logger : <EOL> self . logger . info ( '<STR_LIT>' ) <EOL> response = self . query ( '<STR_LIT>' ) <EOL> if response : <EOL> self . errors = { '<STR_LIT>' : str ( int ( response [ <NUM_LIT:0> ] ) ) , <EOL> '<STR_LIT>' : str ( int ( response [ <NUM_LIT:1> ] ) ) , <EOL> '<STR_LIT>' : str ( int ( response [ <NUM_LIT:2> ] ) ) , <EOL> '<STR_LIT>' : str ( int ( response [ <NUM_LIT:3> ] ) ) } <EOL> if self . logger : <EOL> self . logger . info ( "<STR_LIT>" . format ( <EOL> self . errors [ '<STR_LIT>' ] , <EOL> self . errors [ '<STR_LIT>' ] , <EOL> self . errors [ '<STR_LIT>' ] , <EOL> self . errors [ '<STR_LIT>' ] , <EOL> ) ) <EOL> else : <EOL> self . errors = { '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None } <EOL> return self . errors <EOL> def get_switch ( self , maxtries = <NUM_LIT:3> ) : <EOL> '''<STR_LIT>''' <EOL> if self . logger : <EOL> self . logger . info ( '<STR_LIT>' ) <EOL> self . switch = None <EOL> tries = <NUM_LIT:0> <EOL> status = None <EOL> while not status : <EOL> tries += <NUM_LIT:1> <EOL> response = self . send ( '<STR_LIT>' ) <EOL> if re . match ( '<STR_LIT>' , response ) : <EOL> status = '<STR_LIT>' <EOL> elif re . match ( '<STR_LIT>' , response ) : <EOL> status = '<STR_LIT>' <EOL> else : <EOL> status = None <EOL> if not status and tries >= maxtries : <EOL> status = '<STR_LIT>' <EOL> self . switch = status <EOL> if self . logger : <EOL> self . logger . info ( '<STR_LIT>' . format ( self . switch ) ) <EOL> return self . switch <EOL> def wind_speed_enabled ( self ) : <EOL> '''<STR_LIT>''' <EOL> if self . logger : <EOL> self . logger . debug ( '<STR_LIT>' ) <EOL> try : <EOL> enabled = bool ( self . query ( '<STR_LIT>' ) [ <NUM_LIT:0> ] ) <EOL> if enabled : <EOL> if self . logger : <EOL> self . logger . debug ( '<STR_LIT>' ) <EOL> else : <EOL> if self . logger : <EOL> self . logger . debug ( '<STR_LIT>' ) <EOL> except : <EOL> enabled = None <EOL> return enabled <EOL> def get_wind_speed ( self , n = <NUM_LIT:3> ) : <EOL> '''<STR_LIT>''' <EOL> if self . logger : <EOL> self . logger . info ( '<STR_LIT>' ) <EOL> if self . wind_speed_enabled ( ) : <EOL> values = [ ] <EOL> for i in range ( <NUM_LIT:0> , n ) : <EOL> result = self . query ( '<STR_LIT>' ) <EOL> if result : <EOL> value = float ( result [ <NUM_LIT:0> ] ) <EOL> if self . logger : <EOL> self . logger . debug ( '<STR_LIT>' . format ( value ) ) <EOL> values . append ( value ) <EOL> if len ( values ) >= <NUM_LIT:3> : <EOL> self . wind_speed = np . median ( values ) * u . km / u . hr <EOL> if self . logger : <EOL> self . logger . info ( '<STR_LIT>' . format ( self . wind_speed ) ) <EOL> else : <EOL> self . wind_speed = None <EOL> else : <EOL> self . wind_speed = None <EOL> return self . wind_speed <EOL> def update_weather ( self , update_mongo = True ) : <EOL> '''<STR_LIT:U+0020>''' <EOL> data = { } <EOL> data [ '<STR_LIT>' ] = self . name <EOL> data [ '<STR_LIT>' ] = self . firmware_version <EOL> data [ '<STR_LIT>' ] = self . serial_number <EOL> if self . get_sky_temperature ( ) : <EOL> data [ '<STR_LIT>' ] = self . sky_temp . value <EOL> if self . get_ambient_temperature ( ) : <EOL> data [ '<STR_LIT>' ] = self . ambient_temp . value <EOL> self . get_values ( ) <EOL> if self . internal_voltage : <EOL> data [ '<STR_LIT>' ] = self . internal_voltage . value <EOL> if self . LDR_resistance : <EOL> data [ '<STR_LIT>' ] = self . LDR_resistance . value <EOL> if self . rain_sensor_temp : <EOL> data [ '<STR_LIT>' ] = self . rain_sensor_temp . value <EOL> if self . get_rain_frequency ( ) : <EOL> data [ '<STR_LIT>' ] = self . rain_frequency <EOL> if self . get_PWM ( ) : <EOL> data [ '<STR_LIT>' ] = self . PWM <EOL> if self . get_errors ( ) : <EOL> data [ '<STR_LIT>' ] = self . errors <EOL> if self . get_wind_speed ( ) : <EOL> data [ '<STR_LIT>' ] = self . wind_speed . value <EOL> self . safe_dict = make_safety_decision ( self . cfg , logger = self . logger ) <EOL> data [ '<STR_LIT>' ] = self . safe_dict [ '<STR_LIT>' ] <EOL> data [ '<STR_LIT>' ] = self . safe_dict [ '<STR_LIT>' ] <EOL> data [ '<STR_LIT>' ] = self . safe_dict [ '<STR_LIT>' ] <EOL> data [ '<STR_LIT>' ] = self . safe_dict [ '<STR_LIT>' ] <EOL> data [ '<STR_LIT>' ] = self . safe_dict [ '<STR_LIT>' ] <EOL> if update_mongo : <EOL> try : <EOL> db = PanMongo ( ) <EOL> if self . logger : <EOL> self . logger . info ( '<STR_LIT>' ) <EOL> db . insert_current ( '<STR_LIT>' , data ) <EOL> if self . logger : <EOL> self . logger . info ( '<STR_LIT>' ) <EOL> except : <EOL> if self . logger : <EOL> self . logger . warning ( '<STR_LIT>' ) <EOL> else : <EOL> print ( '<STR_LIT>' . format ( '<STR_LIT>' , <EOL> dt . utcnow ( ) . strftime ( '<STR_LIT>' ) ) ) <EOL> for key in [ '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> if key in data . keys ( ) : <EOL> print ( '<STR_LIT>' . format ( key , data [ key ] ) ) <EOL> else : <EOL> print ( '<STR_LIT>' . format ( key , '<STR_LIT>' ) ) <EOL> print ( '<STR_LIT>' ) <EOL> return self . safe <EOL> def AAG_heater_algorithm ( self , target , last_entry ) : <EOL> '''<STR_LIT>''' <EOL> deltaT = last_entry [ '<STR_LIT>' ] - target <EOL> scaling = <NUM_LIT:0.5> <EOL> if deltaT > <NUM_LIT> : <EOL> deltaPWM = - <NUM_LIT> * scaling <EOL> elif deltaT > <NUM_LIT> : <EOL> deltaPWM = - <NUM_LIT:20> * scaling <EOL> elif deltaT > <NUM_LIT> : <EOL> deltaPWM = - <NUM_LIT:10> * scaling <EOL> elif deltaT > <NUM_LIT> : <EOL> deltaPWM = - <NUM_LIT:6> * scaling <EOL> elif deltaT > <NUM_LIT:1.> : <EOL> deltaPWM = - <NUM_LIT:4> * scaling <EOL> elif deltaT > <NUM_LIT:0.5> : <EOL> deltaPWM = - <NUM_LIT:2> * scaling <EOL> elif deltaT > <NUM_LIT> : <EOL> deltaPWM = - <NUM_LIT:1> * scaling <EOL> elif deltaT < - <NUM_LIT> : <EOL> deltaPWM = <NUM_LIT:1> * scaling <EOL> elif deltaT < - <NUM_LIT:0.5> : <EOL> deltaPWM = <NUM_LIT:2> * scaling <EOL> elif deltaT < - <NUM_LIT:1.> : <EOL> deltaPWM = <NUM_LIT:4> * scaling <EOL> elif deltaT < - <NUM_LIT> : <EOL> deltaPWM = <NUM_LIT:6> * scaling <EOL> elif deltaT < - <NUM_LIT> : <EOL> deltaPWM = <NUM_LIT:10> * scaling <EOL> elif deltaT < - <NUM_LIT> : <EOL> deltaPWM = <NUM_LIT:20> * scaling <EOL> elif deltaT < - <NUM_LIT> : <EOL> deltaPWM = <NUM_LIT> * scaling <EOL> return int ( deltaPWM ) <EOL> def calculate_and_set_PWM ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . logger . info ( '<STR_LIT>' ) <EOL> now = dt . utcnow ( ) <EOL> start = now - tdelta ( <NUM_LIT:0> , int ( self . heater_cfg [ '<STR_LIT>' ] ) ) <EOL> db = PanMongo ( ) <EOL> entries = [ x for x in db . weather . find ( { '<STR_LIT:date>' : { '<STR_LIT>' : start , '<STR_LIT>' : now } } ) <EOL> ] <EOL> self . logger . info ( '<STR_LIT>' . format ( <EOL> len ( entries ) , int ( self . heater_cfg [ '<STR_LIT>' ] ) , <EOL> ) ) <EOL> last_entry = [ x for x in db . current . find ( { "<STR_LIT:type>" : "<STR_LIT>" } ) <EOL> ] [ <NUM_LIT:0> ] [ '<STR_LIT:data>' ] <EOL> rain_history = [ x [ '<STR_LIT:data>' ] [ '<STR_LIT>' ] <EOL> for x <EOL> in entries <EOL> if '<STR_LIT>' in x [ '<STR_LIT:data>' ] . keys ( ) <EOL> ] <EOL> if '<STR_LIT>' not in last_entry . keys ( ) : <EOL> self . logger . warning ( '<STR_LIT>' ) <EOL> elif '<STR_LIT>' not in last_entry . keys ( ) : <EOL> self . logger . warning ( '<STR_LIT>' ) <EOL> else : <EOL> if len ( rain_history ) > <NUM_LIT:3> and not np . any ( rain_history ) : <EOL> self . logger . info ( '<STR_LIT>' ) <EOL> if self . impulse_heating : <EOL> impulse_time = ( now - self . impulse_start ) . total_seconds ( ) <EOL> if impulse_time > float ( self . heater_cfg [ '<STR_LIT>' ] ) : <EOL> self . logger . info ( '<STR_LIT>' . format ( <EOL> float ( self . heater_cfg [ '<STR_LIT>' ] ) <EOL> ) ) <EOL> self . impulse_heating = False <EOL> self . impulse_start = None <EOL> else : <EOL> self . logger . info ( '<STR_LIT>' . format ( <EOL> impulse_time ) ) <EOL> else : <EOL> self . logger . info ( '<STR_LIT>' ) <EOL> self . impulse_start = now <EOL> self . impulse_heating = True <EOL> else : <EOL> self . logger . info ( '<STR_LIT>' ) <EOL> self . impulse_heating = False <EOL> self . impulse_start = None <EOL> if self . impulse_heating : <EOL> target_temp = float ( last_entry [ '<STR_LIT>' ] ) + float ( self . heater_cfg [ '<STR_LIT>' ] ) <EOL> if last_entry [ '<STR_LIT>' ] < target_temp : <EOL> self . logger . info ( '<STR_LIT>' ) <EOL> self . set_PWM ( <NUM_LIT:100> ) <EOL> else : <EOL> new_PWM = AAG_heater_algorithm ( target_temp , last_entry ) <EOL> self . logger . info ( '<STR_LIT>' . format ( new_PWM ) ) <EOL> self . set_PWM ( new_PWM ) <EOL> else : <EOL> if last_entry [ '<STR_LIT>' ] < self . heater_cfg [ '<STR_LIT>' ] : <EOL> deltaT = self . heater_cfg [ '<STR_LIT>' ] <EOL> elif last_entry [ '<STR_LIT>' ] > self . heater_cfg [ '<STR_LIT>' ] : <EOL> deltaT = self . heater_cfg [ '<STR_LIT>' ] <EOL> else : <EOL> frac = ( last_entry [ '<STR_LIT>' ] - self . heater_cfg [ '<STR_LIT>' ] ) / ( self . heater_cfg [ '<STR_LIT>' ] - self . heater_cfg [ '<STR_LIT>' ] ) <EOL> deltaT = self . heater_cfg [ '<STR_LIT>' ] + frac * ( self . heater_cfg [ '<STR_LIT>' ] - self . heater_cfg [ '<STR_LIT>' ] ) <EOL> target_temp = last_entry [ '<STR_LIT>' ] + deltaT <EOL> new_PWM = int ( self . heater_PID . recalculate ( last_entry [ '<STR_LIT>' ] , <EOL> new_set_point = target_temp ) ) <EOL> self . logger . debug ( '<STR_LIT>' . format ( self . heater_PID . last_interval ) ) <EOL> self . logger . info ( '<STR_LIT>' . format ( <EOL> target_temp , last_entry [ '<STR_LIT>' ] , <EOL> new_PWM , self . heater_PID . Kp * self . heater_PID . Pval , <EOL> self . heater_PID . Ki * self . heater_PID . Ival , <EOL> len ( self . heater_PID . history ) , <EOL> self . heater_PID . Kd * self . heater_PID . Dval , <EOL> ) ) <EOL> self . set_PWM ( new_PWM ) <EOL> def make_safety_decision ( cfg , logger = None ) : <EOL> '''<STR_LIT>''' <EOL> if logger : <EOL> logger . info ( '<STR_LIT>' ) <EOL> if '<STR_LIT>' in cfg . keys ( ) : <EOL> threshold_cloudy = cfg [ '<STR_LIT>' ] <EOL> else : <EOL> if logger : <EOL> logger . warning ( '<STR_LIT>' ) <EOL> threshold_cloudy = - <NUM_LIT:20> <EOL> if '<STR_LIT>' in cfg . keys ( ) : <EOL> threshold_very_cloudy = cfg [ '<STR_LIT>' ] <EOL> else : <EOL> if logger : <EOL> logger . warning ( '<STR_LIT>' ) <EOL> threshold_very_cloudy = - <NUM_LIT:15> <EOL> if '<STR_LIT>' in cfg . keys ( ) : <EOL> threshold_windy = cfg [ '<STR_LIT>' ] <EOL> else : <EOL> if logger : <EOL> logger . warning ( '<STR_LIT>' ) <EOL> threshold_windy = <NUM_LIT:20> <EOL> if '<STR_LIT>' in cfg . keys ( ) : <EOL> threshold_very_windy = cfg [ '<STR_LIT>' ] <EOL> else : <EOL> if logger : <EOL> logger . warning ( '<STR_LIT>' ) <EOL> threshold_very_windy = <NUM_LIT:30> <EOL> if '<STR_LIT>' in cfg . keys ( ) : <EOL> threshold_gusty = cfg [ '<STR_LIT>' ] <EOL> else : <EOL> if logger : <EOL> logger . warning ( '<STR_LIT>' ) <EOL> threshold_gusty = <NUM_LIT> <EOL> if '<STR_LIT>' in cfg . keys ( ) : <EOL> threshold_very_gusty = cfg [ '<STR_LIT>' ] <EOL> else : <EOL> if logger : <EOL> logger . warning ( '<STR_LIT>' ) <EOL> threshold_very_gusty = <NUM_LIT:50> <EOL> if '<STR_LIT>' in cfg . keys ( ) : <EOL> threshold_rain = cfg [ '<STR_LIT>' ] <EOL> else : <EOL> if logger : <EOL> logger . warning ( '<STR_LIT>' ) <EOL> threshold_rain = <NUM_LIT> <EOL> if '<STR_LIT>' in cfg . keys ( ) : <EOL> safety_delay = cfg [ '<STR_LIT>' ] <EOL> else : <EOL> if logger : <EOL> logger . warning ( '<STR_LIT>' ) <EOL> safety_delay = <NUM_LIT> <EOL> end = dt . utcnow ( ) <EOL> start = end - tdelta ( <NUM_LIT:0> , int ( safety_delay * <NUM_LIT> ) ) <EOL> db = PanMongo ( ) <EOL> entries = [ x for x in db . weather . find ( { '<STR_LIT:date>' : { '<STR_LIT>' : start , '<STR_LIT>' : end } } ) ] <EOL> if logger : <EOL> logger . info ( '<STR_LIT>' . format ( len ( entries ) , safety_delay ) ) <EOL> sky_diff = [ x [ '<STR_LIT:data>' ] [ '<STR_LIT>' ] - x [ '<STR_LIT:data>' ] [ '<STR_LIT>' ] <EOL> for x in entries <EOL> if '<STR_LIT>' in x [ '<STR_LIT:data>' ] . keys ( ) and '<STR_LIT>' in x [ '<STR_LIT:data>' ] . keys ( ) ] <EOL> if len ( sky_diff ) == <NUM_LIT:0> : <EOL> if logger : <EOL> logger . info ( '<STR_LIT>' ) <EOL> sky_safe = False <EOL> cloud_condition = '<STR_LIT>' <EOL> else : <EOL> if max ( sky_diff ) > threshold_very_cloudy : <EOL> if logger : <EOL> logger . info ( '<STR_LIT>' <EOL> '<STR_LIT>' . format ( safety_delay , max ( sky_diff ) ) ) <EOL> sky_safe = False <EOL> else : <EOL> sky_safe = True <EOL> if sky_diff [ - <NUM_LIT:1> ] > threshold_very_cloudy : <EOL> cloud_condition = '<STR_LIT>' <EOL> elif sky_diff [ - <NUM_LIT:1> ] > threshold_cloudy : <EOL> cloud_condition = '<STR_LIT>' <EOL> else : <EOL> cloud_condition = '<STR_LIT>' <EOL> if logger : <EOL> logger . info ( '<STR_LIT>' . format ( cloud_condition , sky_diff [ - <NUM_LIT:1> ] ) ) <EOL> wind_speed = [ x [ '<STR_LIT:data>' ] [ '<STR_LIT>' ] <EOL> for x in entries <EOL> if '<STR_LIT>' in x [ '<STR_LIT:data>' ] . keys ( ) ] <EOL> if len ( wind_speed ) == <NUM_LIT:0> : <EOL> if logger : <EOL> logger . info ( '<STR_LIT>' ) <EOL> wind_safe = False <EOL> gust_safe = False <EOL> wind_condition = '<STR_LIT>' <EOL> gust_condition = '<STR_LIT>' <EOL> else : <EOL> typical_data_interval = ( end - min ( [ x [ '<STR_LIT:date>' ] for x in entries ] ) ) . total_seconds ( ) / len ( entries ) <EOL> mavg_count = int ( np . ceil ( <NUM_LIT> / typical_data_interval ) ) <EOL> wind_mavg = movingaverage ( wind_speed , mavg_count ) <EOL> if max ( wind_mavg ) > threshold_very_windy : <EOL> if logger : <EOL> logger . info ( '<STR_LIT>' <EOL> '<STR_LIT>' . format ( safety_delay , max ( wind_mavg ) ) ) <EOL> wind_safe = False <EOL> else : <EOL> wind_safe = True <EOL> if wind_mavg [ - <NUM_LIT:1> ] > threshold_very_windy : <EOL> wind_condition = '<STR_LIT>' <EOL> elif wind_mavg [ - <NUM_LIT:1> ] > threshold_windy : <EOL> wind_condition = '<STR_LIT>' <EOL> else : <EOL> wind_condition = '<STR_LIT>' <EOL> if logger : <EOL> logger . info ( '<STR_LIT>' . format ( wind_condition , wind_mavg [ - <NUM_LIT:1> ] ) ) <EOL> if max ( wind_speed ) > threshold_very_gusty : <EOL> if logger : <EOL> logger . info ( '<STR_LIT>' <EOL> '<STR_LIT>' . format ( safety_delay , max ( wind_speed ) ) ) <EOL> gust_safe = False <EOL> else : <EOL> gust_safe = True <EOL> if wind_speed [ - <NUM_LIT:1> ] > threshold_very_gusty : <EOL> gust_condition = '<STR_LIT>' <EOL> elif wind_speed [ - <NUM_LIT:1> ] > threshold_windy : <EOL> gust_condition = '<STR_LIT>' <EOL> else : <EOL> gust_condition = '<STR_LIT>' <EOL> if logger : <EOL> logger . info ( '<STR_LIT>' . format ( gust_condition , wind_speed [ - <NUM_LIT:1> ] ) ) <EOL> rf_value = [ x [ '<STR_LIT:data>' ] [ '<STR_LIT>' ] <EOL> for x in entries <EOL> if '<STR_LIT>' in x [ '<STR_LIT:data>' ] . keys ( ) ] <EOL> if len ( rf_value ) == <NUM_LIT:0> : <EOL> rain_safe = False <EOL> rain_condition = '<STR_LIT>' <EOL> else : <EOL> if min ( rf_value ) < threshold_rain : <EOL> if logger : <EOL> logger . info ( '<STR_LIT>' . format ( safety_delay ) ) <EOL> rain_safe = False <EOL> else : <EOL> rain_safe = True <EOL> if rf_value [ - <NUM_LIT:1> ] < threshold_rain : <EOL> rain_condition = '<STR_LIT>' <EOL> else : <EOL> rain_condition = '<STR_LIT>' <EOL> if logger : <EOL> logger . info ( '<STR_LIT>' . format ( rain_condition ) ) <EOL> safe = sky_safe & wind_safe & gust_safe & rain_safe <EOL> translator = { True : '<STR_LIT>' , False : '<STR_LIT>' } <EOL> if logger : <EOL> logger . info ( '<STR_LIT>' . format ( translator [ safe ] ) ) <EOL> safe_dict = { '<STR_LIT>' : safe , <EOL> '<STR_LIT>' : cloud_condition , <EOL> '<STR_LIT>' : wind_condition , <EOL> '<STR_LIT>' : gust_condition , <EOL> '<STR_LIT>' : rain_condition } <EOL> return safe_dict <EOL> def plot_weather ( date_string ) : <EOL> import matplotlib as mpl <EOL> mpl . use ( '<STR_LIT>' ) <EOL> from matplotlib import pyplot as plt <EOL> from matplotlib . dates import HourLocator , MinuteLocator , DateFormatter <EOL> plt . ioff ( ) <EOL> dpi = <NUM_LIT:100> <EOL> plt . figure ( figsize = ( <NUM_LIT:16> , <NUM_LIT:9> ) , dpi = dpi ) <EOL> hours = HourLocator ( byhour = range ( <NUM_LIT> ) , interval = <NUM_LIT:1> ) <EOL> hours_fmt = DateFormatter ( '<STR_LIT>' ) <EOL> mins = MinuteLocator ( range ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:15> ) ) <EOL> mins_fmt = DateFormatter ( '<STR_LIT>' ) <EOL> if not date_string : <EOL> today = True <EOL> date = dt . utcnow ( ) <EOL> date_string = date . strftime ( '<STR_LIT>' ) <EOL> else : <EOL> today = False <EOL> date = dt . strptime ( '<STR_LIT>' . format ( date_string ) , '<STR_LIT>' ) <EOL> start = dt ( date . year , date . month , date . day , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> end = dt ( date . year , date . month , date . day , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:0> ) <EOL> cfg = load_config ( ) [ '<STR_LIT:location>' ] <EOL> loc = EarthLocation ( <EOL> lat = cfg [ '<STR_LIT>' ] , <EOL> lon = cfg [ '<STR_LIT>' ] , <EOL> height = cfg [ '<STR_LIT>' ] , <EOL> ) <EOL> obs = Observer ( location = loc , name = '<STR_LIT>' , timezone = cfg [ '<STR_LIT>' ] ) <EOL> sunset = obs . sun_set_time ( Time ( start ) , which = '<STR_LIT>' ) . datetime <EOL> evening_civil_twilight = obs . twilight_evening_civil ( Time ( start ) , which = '<STR_LIT>' ) . datetime <EOL> evening_nautical_twilight = obs . twilight_evening_nautical ( Time ( start ) , which = '<STR_LIT>' ) . datetime <EOL> evening_astronomical_twilight = obs . twilight_evening_astronomical ( Time ( start ) , which = '<STR_LIT>' ) . datetime <EOL> morning_astronomical_twilight = obs . twilight_morning_astronomical ( Time ( start ) , which = '<STR_LIT>' ) . datetime <EOL> morning_nautical_twilight = obs . twilight_morning_nautical ( Time ( start ) , which = '<STR_LIT>' ) . datetime <EOL> morning_civil_twilight = obs . twilight_morning_civil ( Time ( start ) , which = '<STR_LIT>' ) . datetime <EOL> sunrise = obs . sun_rise_time ( Time ( start ) , which = '<STR_LIT>' ) . datetime <EOL> print ( '<STR_LIT>' . format ( Time ( start ) ) ) <EOL> print ( obs . is_night ( Time ( start ) ) ) <EOL> print ( '<STR_LIT>' . format ( sunset ) ) <EOL> print ( '<STR_LIT>' . format ( evening_civil_twilight ) ) <EOL> print ( '<STR_LIT>' . format ( evening_nautical_twilight ) ) <EOL> print ( '<STR_LIT>' . format ( evening_astronomical_twilight ) ) <EOL> print ( '<STR_LIT>' . format ( morning_astronomical_twilight ) ) <EOL> print ( '<STR_LIT>' . format ( morning_nautical_twilight ) ) <EOL> print ( '<STR_LIT>' . format ( morning_civil_twilight ) ) <EOL> plot_positions = [ ( [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ) , <EOL> ( [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ) , <EOL> ( [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ) , <EOL> ( [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ) , <EOL> ( [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ) , <EOL> ( [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ) , <EOL> ] <EOL> db = PanMongo ( ) <EOL> entries = [ x for x in db . weather . find ( { '<STR_LIT:date>' : { '<STR_LIT>' : start , '<STR_LIT>' : end } } ) . sort ( [ ( '<STR_LIT:date>' , pymongo . ASCENDING ) ] ) ] <EOL> if today : <EOL> current_values = [ x for x in db . current . find ( { "<STR_LIT:type>" : "<STR_LIT>" } ) ] [ <NUM_LIT:0> ] <EOL> else : <EOL> current_values = None <EOL> print ( '<STR_LIT>' ) <EOL> t_axes = plt . axes ( plot_positions [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] ) <EOL> if today : <EOL> time_title = date <EOL> else : <EOL> time_title = end <EOL> plt . title ( '<STR_LIT>' . format ( date_string , time_title . strftime ( '<STR_LIT>' ) ) ) <EOL> amb_temp = [ x [ '<STR_LIT:data>' ] [ '<STR_LIT>' ] <EOL> for x in entries <EOL> if '<STR_LIT>' in x [ '<STR_LIT:data>' ] . keys ( ) ] <EOL> time = [ x [ '<STR_LIT:date>' ] for x in entries <EOL> if '<STR_LIT>' in x [ '<STR_LIT:data>' ] . keys ( ) ] <EOL> t_axes . plot_date ( time , amb_temp , '<STR_LIT>' , <EOL> markersize = <NUM_LIT:2> , markeredgewidth = <NUM_LIT:0> , <EOL> drawstyle = "<STR_LIT:default>" ) <EOL> try : <EOL> max_temp = max ( amb_temp ) <EOL> min_temp = min ( amb_temp ) <EOL> label_time = end - tdelta ( <NUM_LIT:0> , <NUM_LIT:7> * <NUM_LIT> * <NUM_LIT> ) <EOL> label_temp = <NUM_LIT> <EOL> t_axes . annotate ( '<STR_LIT>' . format ( <EOL> min_temp , max_temp ) , <EOL> xy = ( label_time , max_temp ) , <EOL> xytext = ( label_time , label_temp ) , <EOL> size = <NUM_LIT:16> , <EOL> ) <EOL> except : <EOL> pass <EOL> plt . ylabel ( "<STR_LIT>" ) <EOL> plt . grid ( which = '<STR_LIT>' , color = '<STR_LIT:k>' ) <EOL> plt . yticks ( range ( - <NUM_LIT:100> , <NUM_LIT:100> , <NUM_LIT:10> ) ) <EOL> plt . xlim ( start , end ) <EOL> plt . ylim ( - <NUM_LIT:5> , <NUM_LIT> ) <EOL> t_axes . xaxis . set_major_locator ( hours ) <EOL> t_axes . xaxis . set_major_formatter ( hours_fmt ) <EOL> if obs . is_night ( Time ( start ) ) : <EOL> plt . axvspan ( start , morning_astronomical_twilight , ymin = <NUM_LIT:0> , ymax = <NUM_LIT:1> , color = '<STR_LIT>' , alpha = <NUM_LIT:0.5> ) <EOL> plt . axvspan ( morning_astronomical_twilight , morning_nautical_twilight , ymin = <NUM_LIT:0> , ymax = <NUM_LIT:1> , color = '<STR_LIT>' , alpha = <NUM_LIT> ) <EOL> plt . axvspan ( morning_nautical_twilight , morning_civil_twilight , ymin = <NUM_LIT:0> , ymax = <NUM_LIT:1> , color = '<STR_LIT>' , alpha = <NUM_LIT> ) <EOL> plt . axvspan ( morning_civil_twilight , sunrise , ymin = <NUM_LIT:0> , ymax = <NUM_LIT:1> , color = '<STR_LIT>' , alpha = <NUM_LIT:0.1> ) <EOL> plt . axvspan ( sunset , evening_civil_twilight , ymin = <NUM_LIT:0> , ymax = <NUM_LIT:1> , color = '<STR_LIT>' , alpha = <NUM_LIT:0.1> ) <EOL> plt . axvspan ( evening_civil_twilight , evening_nautical_twilight , ymin = <NUM_LIT:0> , ymax = <NUM_LIT:1> , color = '<STR_LIT>' , alpha = <NUM_LIT> ) <EOL> plt . axvspan ( evening_nautical_twilight , evening_astronomical_twilight , ymin = <NUM_LIT:0> , ymax = <NUM_LIT:1> , color = '<STR_LIT>' , alpha = <NUM_LIT> ) <EOL> plt . axvspan ( evening_astronomical_twilight , end , ymin = <NUM_LIT:0> , ymax = <NUM_LIT:1> , color = '<STR_LIT>' , alpha = <NUM_LIT:0.5> ) <EOL> else : <EOL> plt . axvspan ( sunset , evening_civil_twilight , ymin = <NUM_LIT:0> , ymax = <NUM_LIT:1> , color = '<STR_LIT>' , alpha = <NUM_LIT:0.1> ) <EOL> plt . axvspan ( evening_civil_twilight , evening_nautical_twilight , ymin = <NUM_LIT:0> , ymax = <NUM_LIT:1> , color = '<STR_LIT>' , alpha = <NUM_LIT> ) <EOL> plt . axvspan ( evening_nautical_twilight , evening_astronomical_twilight , ymin = <NUM_LIT:0> , ymax = <NUM_LIT:1> , color = '<STR_LIT>' , alpha = <NUM_LIT> ) <EOL> plt . axvspan ( evening_astronomical_twilight , morning_astronomical_twilight , <EOL> ymin = <NUM_LIT:0> , ymax = <NUM_LIT:1> , color = '<STR_LIT>' , alpha = <NUM_LIT:0.5> ) <EOL> plt . axvspan ( morning_astronomical_twilight , morning_nautical_twilight , ymin = <NUM_LIT:0> , ymax = <NUM_LIT:1> , color = '<STR_LIT>' , alpha = <NUM_LIT> ) <EOL> plt . axvspan ( morning_nautical_twilight , morning_civil_twilight , ymin = <NUM_LIT:0> , ymax = <NUM_LIT:1> , color = '<STR_LIT>' , alpha = <NUM_LIT> ) <EOL> plt . axvspan ( morning_civil_twilight , sunrise , ymin = <NUM_LIT:0> , ymax = <NUM_LIT:1> , color = '<STR_LIT>' , alpha = <NUM_LIT:0.1> ) <EOL> tlh_axes = plt . axes ( plot_positions [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] ) <EOL> plt . title ( '<STR_LIT>' ) <EOL> tlh_axes . plot_date ( time , amb_temp , '<STR_LIT>' , <EOL> markersize = <NUM_LIT:4> , markeredgewidth = <NUM_LIT:0> , <EOL> drawstyle = "<STR_LIT:default>" ) <EOL> try : <EOL> current_amb_temp = current_values [ '<STR_LIT:data>' ] [ '<STR_LIT>' ] <EOL> current_time = current_values [ '<STR_LIT:date>' ] <EOL> label_time = current_time - tdelta ( <NUM_LIT:0> , <NUM_LIT:30> * <NUM_LIT> ) <EOL> label_temp = <NUM_LIT> <EOL> tlh_axes . annotate ( '<STR_LIT>' . format ( current_amb_temp ) , <EOL> xy = ( current_time , current_amb_temp ) , <EOL> xytext = ( label_time , label_temp ) , <EOL> size = <NUM_LIT:16> , <EOL> ) <EOL> except : <EOL> pass <EOL> plt . grid ( which = '<STR_LIT>' , color = '<STR_LIT:k>' ) <EOL> plt . yticks ( range ( - <NUM_LIT:100> , <NUM_LIT:100> , <NUM_LIT:10> ) ) <EOL> tlh_axes . xaxis . set_major_locator ( mins ) <EOL> tlh_axes . xaxis . set_major_formatter ( mins_fmt ) <EOL> tlh_axes . yaxis . set_ticklabels ( [ ] ) <EOL> plt . xlim ( date - tdelta ( <NUM_LIT:0> , <NUM_LIT> * <NUM_LIT> ) , date + tdelta ( <NUM_LIT:0> , <NUM_LIT:5> * <NUM_LIT> ) ) <EOL> plt . ylim ( - <NUM_LIT:5> , <NUM_LIT> ) <EOL> print ( '<STR_LIT>' ) <EOL> td_axes = plt . axes ( plot_positions [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] ) <EOL> temp_diff = [ x [ '<STR_LIT:data>' ] [ '<STR_LIT>' ] - x [ '<STR_LIT:data>' ] [ '<STR_LIT>' ] <EOL> for x in entries <EOL> if '<STR_LIT>' in x [ '<STR_LIT:data>' ] . keys ( ) and '<STR_LIT>' in x [ '<STR_LIT:data>' ] . keys ( ) and '<STR_LIT>' in x [ '<STR_LIT:data>' ] . keys ( ) ] <EOL> time = [ x [ '<STR_LIT:date>' ] for x in entries <EOL> if '<STR_LIT>' in x [ '<STR_LIT:data>' ] . keys ( ) and '<STR_LIT>' in x [ '<STR_LIT:data>' ] . keys ( ) and '<STR_LIT>' in x [ '<STR_LIT:data>' ] . keys ( ) ] <EOL> sky_condition = [ x [ '<STR_LIT:data>' ] [ '<STR_LIT>' ] <EOL> for x in entries <EOL> if '<STR_LIT>' in x [ '<STR_LIT:data>' ] . keys ( ) and '<STR_LIT>' in x [ '<STR_LIT:data>' ] . keys ( ) and '<STR_LIT>' in x [ '<STR_LIT:data>' ] . keys ( ) ] <EOL> td_axes . plot_date ( time , temp_diff , '<STR_LIT>' , label = '<STR_LIT>' , <EOL> markersize = <NUM_LIT:2> , markeredgewidth = <NUM_LIT:0> , <EOL> drawstyle = "<STR_LIT:default>" ) <EOL> td_axes . fill_between ( time , - <NUM_LIT> , temp_diff , where = np . array ( sky_condition ) == '<STR_LIT>' , <EOL> color = '<STR_LIT>' , alpha = <NUM_LIT:0.5> ) <EOL> td_axes . fill_between ( time , - <NUM_LIT> , temp_diff , where = np . array ( sky_condition ) == '<STR_LIT>' , <EOL> color = '<STR_LIT>' , alpha = <NUM_LIT:0.5> ) <EOL> td_axes . fill_between ( time , - <NUM_LIT> , temp_diff , where = np . array ( sky_condition ) == '<STR_LIT>' , <EOL> color = '<STR_LIT>' , alpha = <NUM_LIT:0.5> ) <EOL> plt . ylabel ( "<STR_LIT>" ) <EOL> plt . grid ( which = '<STR_LIT>' , color = '<STR_LIT:k>' ) <EOL> plt . yticks ( range ( - <NUM_LIT:100> , <NUM_LIT:100> , <NUM_LIT:10> ) ) <EOL> plt . xlim ( start , end ) <EOL> plt . ylim ( - <NUM_LIT> , <NUM_LIT:10> ) <EOL> td_axes . xaxis . set_major_locator ( hours ) <EOL> td_axes . xaxis . set_major_formatter ( hours_fmt ) <EOL> td_axes . xaxis . set_ticklabels ( [ ] ) <EOL> tdlh_axes = plt . axes ( plot_positions [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] ) <EOL> tdlh_axes . plot_date ( time , temp_diff , '<STR_LIT>' , label = '<STR_LIT>' , <EOL> markersize = <NUM_LIT:4> , markeredgewidth = <NUM_LIT:0> , <EOL> drawstyle = "<STR_LIT:default>" ) <EOL> tdlh_axes . fill_between ( time , - <NUM_LIT> , temp_diff , where = np . array ( sky_condition ) == '<STR_LIT>' , <EOL> color = '<STR_LIT>' , alpha = <NUM_LIT:0.5> ) <EOL> tdlh_axes . fill_between ( time , - <NUM_LIT> , temp_diff , where = np . array ( sky_condition ) == '<STR_LIT>' , <EOL> color = '<STR_LIT>' , alpha = <NUM_LIT:0.5> ) <EOL> tdlh_axes . fill_between ( time , - <NUM_LIT> , temp_diff , where = np . array ( sky_condition ) == '<STR_LIT>' , <EOL> color = '<STR_LIT>' , alpha = <NUM_LIT:0.5> ) <EOL> plt . grid ( which = '<STR_LIT>' , color = '<STR_LIT:k>' ) <EOL> plt . yticks ( range ( - <NUM_LIT:100> , <NUM_LIT:100> , <NUM_LIT:10> ) ) <EOL> plt . xlim ( date - tdelta ( <NUM_LIT:0> , <NUM_LIT> * <NUM_LIT> ) , date + tdelta ( <NUM_LIT:0> , <NUM_LIT:5> * <NUM_LIT> ) ) <EOL> plt . ylim ( - <NUM_LIT> , <NUM_LIT:10> ) <EOL> tdlh_axes . xaxis . set_major_locator ( mins ) <EOL> tdlh_axes . xaxis . set_major_formatter ( mins_fmt ) <EOL> tdlh_axes . xaxis . set_ticklabels ( [ ] ) <EOL> tdlh_axes . yaxis . set_ticklabels ( [ ] ) <EOL> print ( '<STR_LIT>' ) <EOL> w_axes = plt . axes ( plot_positions [ <NUM_LIT:2> ] [ <NUM_LIT:0> ] ) <EOL> wind_speed = [ x [ '<STR_LIT:data>' ] [ '<STR_LIT>' ] <EOL> for x in entries <EOL> if '<STR_LIT>' in x [ '<STR_LIT:data>' ] . keys ( ) and <EOL> '<STR_LIT>' in x [ '<STR_LIT:data>' ] . keys ( ) and <EOL> '<STR_LIT>' in x [ '<STR_LIT:data>' ] . keys ( ) ] <EOL> wind_mavg = movingaverage ( wind_speed , <NUM_LIT:10> ) <EOL> trans = { '<STR_LIT>' : <NUM_LIT:0> , '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : <NUM_LIT:10> , '<STR_LIT>' : <NUM_LIT:10> } <EOL> wind_condition = [ trans [ x [ '<STR_LIT:data>' ] [ '<STR_LIT>' ] ] + trans [ x [ '<STR_LIT:data>' ] [ '<STR_LIT>' ] ] <EOL> for x in entries <EOL> if '<STR_LIT>' in x [ '<STR_LIT:data>' ] . keys ( ) and <EOL> '<STR_LIT>' in x [ '<STR_LIT:data>' ] . keys ( ) and <EOL> '<STR_LIT>' in x [ '<STR_LIT:data>' ] . keys ( ) ] <EOL> time = [ x [ '<STR_LIT:date>' ] for x in entries <EOL> if '<STR_LIT>' in x [ '<STR_LIT:data>' ] . keys ( ) and <EOL> '<STR_LIT>' in x [ '<STR_LIT:data>' ] . keys ( ) and <EOL> '<STR_LIT>' in x [ '<STR_LIT:data>' ] . keys ( ) ] <EOL> w_axes . plot_date ( time , wind_speed , '<STR_LIT>' , alpha = <NUM_LIT:0.5> , <EOL> markersize = <NUM_LIT:2> , markeredgewidth = <NUM_LIT:0> , <EOL> drawstyle = "<STR_LIT:default>" ) <EOL> w_axes . plot_date ( time , wind_mavg , '<STR_LIT>' , <EOL> label = '<STR_LIT>' , <EOL> markersize = <NUM_LIT:3> , markeredgewidth = <NUM_LIT:0> , <EOL> linewidth = <NUM_LIT:3> , alpha = <NUM_LIT:0.5> , <EOL> drawstyle = "<STR_LIT:default>" ) <EOL> w_axes . plot_date ( [ start , end ] , [ <NUM_LIT:0> , <NUM_LIT:0> ] , '<STR_LIT>' , ms = <NUM_LIT:1> ) <EOL> w_axes . fill_between ( time , - <NUM_LIT:5> , wind_speed , <EOL> where = np . array ( wind_condition ) == <NUM_LIT:0> , <EOL> color = '<STR_LIT>' , alpha = <NUM_LIT:0.5> ) <EOL> w_axes . fill_between ( time , - <NUM_LIT:5> , wind_speed , <EOL> where = ( np . array ( wind_condition ) > <NUM_LIT:0> ) & ( np . array ( wind_condition ) < <NUM_LIT:10> ) , <EOL> color = '<STR_LIT>' , alpha = <NUM_LIT:0.5> ) <EOL> w_axes . fill_between ( time , - <NUM_LIT:5> , wind_speed , <EOL> where = np . array ( wind_condition ) > <NUM_LIT:10> , <EOL> color = '<STR_LIT>' , alpha = <NUM_LIT:0.5> ) <EOL> try : <EOL> max_wind = max ( wind_speed ) <EOL> label_time = end - tdelta ( <NUM_LIT:0> , <NUM_LIT:6> * <NUM_LIT> * <NUM_LIT> ) <EOL> label_wind = <NUM_LIT> <EOL> w_axes . annotate ( '<STR_LIT>' . format ( max_wind ) , <EOL> xy = ( label_time , max_wind ) , <EOL> xytext = ( label_time , label_wind ) , <EOL> size = <NUM_LIT:16> , <EOL> ) <EOL> except : <EOL> pass <EOL> plt . ylabel ( "<STR_LIT>" ) <EOL> plt . grid ( which = '<STR_LIT>' , color = '<STR_LIT:k>' ) <EOL> plt . yticks ( range ( - <NUM_LIT:100> , <NUM_LIT:100> , <NUM_LIT:10> ) ) <EOL> plt . xlim ( start , end ) <EOL> wind_max = max ( [ <NUM_LIT> , np . ceil ( max ( wind_speed ) / <NUM_LIT> ) * <NUM_LIT> ] ) <EOL> plt . ylim ( <NUM_LIT:0> , <NUM_LIT> ) <EOL> w_axes . xaxis . set_major_locator ( hours ) <EOL> w_axes . xaxis . set_major_formatter ( hours_fmt ) <EOL> w_axes . xaxis . set_ticklabels ( [ ] ) <EOL> wlh_axes = plt . axes ( plot_positions [ <NUM_LIT:2> ] [ <NUM_LIT:1> ] ) <EOL> wlh_axes . plot_date ( time , wind_speed , '<STR_LIT>' , alpha = <NUM_LIT> , <EOL> markersize = <NUM_LIT:4> , markeredgewidth = <NUM_LIT:0> , <EOL> drawstyle = "<STR_LIT:default>" ) <EOL> wlh_axes . plot_date ( time , wind_mavg , '<STR_LIT>' , <EOL> label = '<STR_LIT>' , <EOL> markersize = <NUM_LIT:2> , markeredgewidth = <NUM_LIT:0> , <EOL> linewidth = <NUM_LIT:3> , alpha = <NUM_LIT:0.5> , <EOL> drawstyle = "<STR_LIT:default>" ) <EOL> wlh_axes . plot_date ( [ start , end ] , [ <NUM_LIT:0> , <NUM_LIT:0> ] , '<STR_LIT>' , ms = <NUM_LIT:1> ) <EOL> wlh_axes . fill_between ( time , - <NUM_LIT:5> , wind_speed , <EOL> where = np . array ( wind_condition ) == <NUM_LIT:0> , <EOL> color = '<STR_LIT>' , alpha = <NUM_LIT:0.5> ) <EOL> wlh_axes . fill_between ( time , - <NUM_LIT:5> , wind_speed , <EOL> where = ( np . array ( wind_condition ) > <NUM_LIT:0> ) & ( np . array ( wind_condition ) < <NUM_LIT:10> ) , <EOL> color = '<STR_LIT>' , alpha = <NUM_LIT:0.5> ) <EOL> wlh_axes . fill_between ( time , - <NUM_LIT:5> , wind_speed , <EOL> where = np . array ( wind_condition ) > <NUM_LIT:10> , <EOL> color = '<STR_LIT>' , alpha = <NUM_LIT:0.5> ) <EOL> try : <EOL> current_wind = current_values [ '<STR_LIT:data>' ] [ '<STR_LIT>' ] <EOL> current_time = current_values [ '<STR_LIT:date>' ] <EOL> label_time = current_time - tdelta ( <NUM_LIT:0> , <NUM_LIT:30> * <NUM_LIT> ) <EOL> label_wind = <NUM_LIT> <EOL> wlh_axes . annotate ( '<STR_LIT>' . format ( current_wind ) , <EOL> xy = ( current_time , current_wind ) , <EOL> xytext = ( label_time , label_wind ) , <EOL> size = <NUM_LIT:16> , <EOL> ) <EOL> except : <EOL> pass <EOL> plt . grid ( which = '<STR_LIT>' , color = '<STR_LIT:k>' ) <EOL> plt . yticks ( range ( - <NUM_LIT:100> , <NUM_LIT:100> , <NUM_LIT:10> ) ) <EOL> plt . xlim ( date - tdelta ( <NUM_LIT:0> , <NUM_LIT> * <NUM_LIT> ) , date + tdelta ( <NUM_LIT:0> , <NUM_LIT:5> * <NUM_LIT> ) ) <EOL> wind_max = max ( [ <NUM_LIT> , np . ceil ( max ( wind_speed ) / <NUM_LIT> ) * <NUM_LIT> ] ) <EOL> plt . ylim ( <NUM_LIT:0> , <NUM_LIT> ) <EOL> wlh_axes . xaxis . set_major_locator ( mins ) <EOL> wlh_axes . xaxis . set_major_formatter ( mins_fmt ) <EOL> wlh_axes . xaxis . set_ticklabels ( [ ] ) <EOL> wlh_axes . yaxis . set_ticklabels ( [ ] ) <EOL> print ( '<STR_LIT>' ) <EOL> rf_axes = plt . axes ( plot_positions [ <NUM_LIT:3> ] [ <NUM_LIT:0> ] ) <EOL> rf_value = [ x [ '<STR_LIT:data>' ] [ '<STR_LIT>' ] <EOL> for x in entries <EOL> if '<STR_LIT>' in x [ '<STR_LIT:data>' ] . keys ( ) and <EOL> '<STR_LIT>' in x [ '<STR_LIT:data>' ] . keys ( ) ] <EOL> rain_condition = [ x [ '<STR_LIT:data>' ] [ '<STR_LIT>' ] <EOL> for x in entries <EOL> if '<STR_LIT>' in x [ '<STR_LIT:data>' ] . keys ( ) and <EOL> '<STR_LIT>' in x [ '<STR_LIT:data>' ] . keys ( ) ] <EOL> time = [ x [ '<STR_LIT:date>' ] for x in entries <EOL> if '<STR_LIT>' in x [ '<STR_LIT:data>' ] . keys ( ) and <EOL> '<STR_LIT>' in x [ '<STR_LIT:data>' ] . keys ( ) ] <EOL> rf_axes . plot_date ( time , rf_value , '<STR_LIT>' , label = '<STR_LIT>' , <EOL> markersize = <NUM_LIT:2> , markeredgewidth = <NUM_LIT:0> , <EOL> drawstyle = "<STR_LIT:default>" ) <EOL> rf_axes . fill_between ( time , <NUM_LIT:0> , rf_value , where = np . array ( rain_condition ) == '<STR_LIT>' , <EOL> color = '<STR_LIT>' , alpha = <NUM_LIT:0.5> ) <EOL> rf_axes . fill_between ( time , <NUM_LIT:0> , rf_value , where = np . array ( rain_condition ) == '<STR_LIT>' , <EOL> color = '<STR_LIT>' , alpha = <NUM_LIT:0.5> ) <EOL> plt . ylabel ( "<STR_LIT>" ) <EOL> plt . grid ( which = '<STR_LIT>' , color = '<STR_LIT:k>' ) <EOL> plt . ylim ( <NUM_LIT> , <NUM_LIT> ) <EOL> plt . xlim ( start , end ) <EOL> rf_axes . xaxis . set_major_locator ( hours ) <EOL> rf_axes . xaxis . set_major_formatter ( hours_fmt ) <EOL> rf_axes . xaxis . set_ticklabels ( [ ] ) <EOL> rf_axes . yaxis . set_ticklabels ( [ ] ) <EOL> rflh_axes = plt . axes ( plot_positions [ <NUM_LIT:3> ] [ <NUM_LIT:1> ] ) <EOL> rflh_axes . plot_date ( time , rf_value , '<STR_LIT>' , label = '<STR_LIT>' , <EOL> markersize = <NUM_LIT:4> , markeredgewidth = <NUM_LIT:0> , <EOL> drawstyle = "<STR_LIT:default>" ) <EOL> rflh_axes . fill_between ( time , <NUM_LIT:0> , rf_value , where = np . array ( rain_condition ) == '<STR_LIT>' , <EOL> color = '<STR_LIT>' , alpha = <NUM_LIT:0.5> ) <EOL> rflh_axes . fill_between ( time , <NUM_LIT:0> , rf_value , where = np . array ( rain_condition ) == '<STR_LIT>' , <EOL> color = '<STR_LIT>' , alpha = <NUM_LIT:0.5> ) <EOL> plt . grid ( which = '<STR_LIT>' , color = '<STR_LIT:k>' ) <EOL> plt . ylim ( <NUM_LIT> , <NUM_LIT> ) <EOL> plt . xlim ( date - tdelta ( <NUM_LIT:0> , <NUM_LIT> * <NUM_LIT> ) , date + tdelta ( <NUM_LIT:0> , <NUM_LIT:5> * <NUM_LIT> ) ) <EOL> rflh_axes . xaxis . set_major_locator ( mins ) <EOL> rflh_axes . xaxis . set_major_formatter ( mins_fmt ) <EOL> rflh_axes . xaxis . set_ticklabels ( [ ] ) <EOL> rflh_axes . yaxis . set_ticklabels ( [ ] ) <EOL> print ( '<STR_LIT>' ) <EOL> safe_axes = plt . axes ( plot_positions [ <NUM_LIT:4> ] [ <NUM_LIT:0> ] ) <EOL> safe_value = [ int ( x [ '<STR_LIT:data>' ] [ '<STR_LIT>' ] ) <EOL> for x in entries <EOL> if '<STR_LIT>' in x [ '<STR_LIT:data>' ] . keys ( ) ] <EOL> safe_time = [ x [ '<STR_LIT:date>' ] for x in entries <EOL> if '<STR_LIT>' in x [ '<STR_LIT:data>' ] . keys ( ) ] <EOL> safe_axes . plot_date ( safe_time , safe_value , '<STR_LIT>' , <EOL> markersize = <NUM_LIT:2> , markeredgewidth = <NUM_LIT:0> , <EOL> drawstyle = "<STR_LIT:default>" ) <EOL> safe_axes . fill_between ( safe_time , - <NUM_LIT:1> , safe_value , where = np . array ( safe_value ) == <NUM_LIT:1> , <EOL> color = '<STR_LIT>' , alpha = <NUM_LIT:0.5> ) <EOL> safe_axes . fill_between ( safe_time , - <NUM_LIT:1> , safe_value , where = np . array ( safe_value ) == <NUM_LIT:0> , <EOL> color = '<STR_LIT>' , alpha = <NUM_LIT:0.5> ) <EOL> plt . ylabel ( "<STR_LIT>" ) <EOL> plt . xlim ( start , end ) <EOL> plt . ylim ( - <NUM_LIT:0.1> , <NUM_LIT> ) <EOL> plt . yticks ( [ <NUM_LIT:0> , <NUM_LIT:1> ] ) <EOL> plt . grid ( which = '<STR_LIT>' , color = '<STR_LIT:k>' ) <EOL> safe_axes . xaxis . set_major_locator ( hours ) <EOL> safe_axes . xaxis . set_major_formatter ( hours_fmt ) <EOL> safe_axes . xaxis . set_ticklabels ( [ ] ) <EOL> safe_axes . yaxis . set_ticklabels ( [ ] ) <EOL> safelh_axes = plt . axes ( plot_positions [ <NUM_LIT:4> ] [ <NUM_LIT:1> ] ) <EOL> safelh_axes . plot_date ( safe_time , safe_value , '<STR_LIT>' , <EOL> markersize = <NUM_LIT:4> , markeredgewidth = <NUM_LIT:0> , <EOL> drawstyle = "<STR_LIT:default>" ) <EOL> safelh_axes . fill_between ( safe_time , - <NUM_LIT:1> , safe_value , where = np . array ( safe_value ) == <NUM_LIT:1> , <EOL> color = '<STR_LIT>' , alpha = <NUM_LIT:0.5> ) <EOL> safelh_axes . fill_between ( safe_time , - <NUM_LIT:1> , safe_value , where = np . array ( safe_value ) == <NUM_LIT:0> , <EOL> color = '<STR_LIT>' , alpha = <NUM_LIT:0.5> ) <EOL> plt . ylim ( - <NUM_LIT:0.1> , <NUM_LIT> ) <EOL> plt . yticks ( [ <NUM_LIT:0> , <NUM_LIT:1> ] ) <EOL> plt . grid ( which = '<STR_LIT>' , color = '<STR_LIT:k>' ) <EOL> plt . xlim ( date - tdelta ( <NUM_LIT:0> , <NUM_LIT> * <NUM_LIT> ) , date + tdelta ( <NUM_LIT:0> , <NUM_LIT:5> * <NUM_LIT> ) ) <EOL> safelh_axes . xaxis . set_major_locator ( mins ) <EOL> safelh_axes . xaxis . set_major_formatter ( mins_fmt ) <EOL> safelh_axes . xaxis . set_ticklabels ( [ ] ) <EOL> safelh_axes . yaxis . set_ticklabels ( [ ] ) <EOL> print ( '<STR_LIT>' ) <EOL> pwm_axes = plt . axes ( plot_positions [ <NUM_LIT:5> ] [ <NUM_LIT:0> ] ) <EOL> plt . ylabel ( "<STR_LIT>" ) <EOL> plt . ylim ( - <NUM_LIT:5> , <NUM_LIT> ) <EOL> plt . yticks ( [ <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:50> , <NUM_LIT> , <NUM_LIT:100> ] ) <EOL> plt . xlim ( start , end ) <EOL> plt . grid ( which = '<STR_LIT>' , color = '<STR_LIT:k>' ) <EOL> rst_axes = pwm_axes . twinx ( ) <EOL> plt . ylim ( - <NUM_LIT:1> , <NUM_LIT> ) <EOL> plt . xlim ( start , end ) <EOL> pwm_value = [ x [ '<STR_LIT:data>' ] [ '<STR_LIT>' ] <EOL> for x in entries <EOL> if '<STR_LIT>' in x [ '<STR_LIT:data>' ] . keys ( ) and <EOL> '<STR_LIT>' in x [ '<STR_LIT:data>' ] . keys ( ) and <EOL> '<STR_LIT>' in x [ '<STR_LIT:data>' ] . keys ( ) ] <EOL> rst_delta = [ x [ '<STR_LIT:data>' ] [ '<STR_LIT>' ] - x [ '<STR_LIT:data>' ] [ '<STR_LIT>' ] <EOL> for x in entries <EOL> if '<STR_LIT>' in x [ '<STR_LIT:data>' ] . keys ( ) and <EOL> '<STR_LIT>' in x [ '<STR_LIT:data>' ] . keys ( ) and <EOL> '<STR_LIT>' in x [ '<STR_LIT:data>' ] . keys ( ) ] <EOL> time = [ x [ '<STR_LIT:date>' ] for x in entries <EOL> if '<STR_LIT>' in x [ '<STR_LIT:data>' ] . keys ( ) and <EOL> '<STR_LIT>' in x [ '<STR_LIT:data>' ] . keys ( ) and <EOL> '<STR_LIT>' in x [ '<STR_LIT:data>' ] . keys ( ) ] <EOL> rst_axes . plot_date ( time , rst_delta , '<STR_LIT>' , alpha = <NUM_LIT:0.5> , <EOL> label = '<STR_LIT>' , <EOL> markersize = <NUM_LIT:2> , markeredgewidth = <NUM_LIT:0> , <EOL> drawstyle = "<STR_LIT:default>" ) <EOL> pwm_axes . plot_date ( time , pwm_value , '<STR_LIT>' , label = '<STR_LIT>' , <EOL> markersize = <NUM_LIT:2> , markeredgewidth = <NUM_LIT:0> , <EOL> drawstyle = "<STR_LIT:default>" ) <EOL> pwm_axes . xaxis . set_major_locator ( hours ) <EOL> pwm_axes . xaxis . set_major_formatter ( hours_fmt ) <EOL> pwmlh_axes = plt . axes ( plot_positions [ <NUM_LIT:5> ] [ <NUM_LIT:1> ] ) <EOL> plt . ylim ( - <NUM_LIT:5> , <NUM_LIT> ) <EOL> plt . yticks ( [ <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:50> , <NUM_LIT> , <NUM_LIT:100> ] ) <EOL> plt . xlim ( date - tdelta ( <NUM_LIT:0> , <NUM_LIT> * <NUM_LIT> ) , date + tdelta ( <NUM_LIT:0> , <NUM_LIT:5> * <NUM_LIT> ) ) <EOL> plt . grid ( which = '<STR_LIT>' , color = '<STR_LIT:k>' ) <EOL> rstlh_axes = pwmlh_axes . twinx ( ) <EOL> plt . ylim ( - <NUM_LIT:1> , <NUM_LIT> ) <EOL> plt . xlim ( date - tdelta ( <NUM_LIT:0> , <NUM_LIT> * <NUM_LIT> ) , date + tdelta ( <NUM_LIT:0> , <NUM_LIT:5> * <NUM_LIT> ) ) <EOL> rstlh_axes . plot_date ( time , rst_delta , '<STR_LIT>' , alpha = <NUM_LIT:0.5> , <EOL> label = '<STR_LIT>' , <EOL> markersize = <NUM_LIT:4> , markeredgewidth = <NUM_LIT:0> , <EOL> drawstyle = "<STR_LIT:default>" ) <EOL> rstlh_axes . xaxis . set_ticklabels ( [ ] ) <EOL> rstlh_axes . yaxis . set_ticklabels ( [ ] ) <EOL> pwmlh_axes . plot_date ( time , pwm_value , '<STR_LIT>' , label = '<STR_LIT>' , <EOL> markersize = <NUM_LIT:4> , markeredgewidth = <NUM_LIT:0> , <EOL> drawstyle = "<STR_LIT:default>" ) <EOL> pwmlh_axes . xaxis . set_major_locator ( mins ) <EOL> pwmlh_axes . xaxis . set_major_formatter ( mins_fmt ) <EOL> pwmlh_axes . yaxis . set_ticklabels ( [ ] ) <EOL> plot_filename = '<STR_LIT>' . format ( date_string ) <EOL> plot_file = os . path . expanduser ( '<STR_LIT>' . format ( plot_filename ) ) <EOL> print ( '<STR_LIT>' . format ( plot_file ) ) <EOL> plt . savefig ( plot_file , dpi = dpi , bbox_inches = '<STR_LIT>' , pad_inches = <NUM_LIT> ) <EOL> today_name = '<STR_LIT>' <EOL> if os . path . exists ( today_name ) : <EOL> os . remove ( today_name ) <EOL> os . symlink ( plot_file , today_name ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> parser = argparse . ArgumentParser ( <EOL> description = "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , "<STR_LIT>" , <EOL> action = "<STR_LIT:store_true>" , dest = "<STR_LIT>" , <EOL> default = False , help = "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , "<STR_LIT>" , <EOL> action = "<STR_LIT:store_true>" , dest = "<STR_LIT>" , <EOL> default = False , help = "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , "<STR_LIT>" , <EOL> action = "<STR_LIT:store_true>" , dest = "<STR_LIT>" , <EOL> default = False , help = "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , <EOL> action = "<STR_LIT>" , dest = "<STR_LIT>" , <EOL> default = True , help = "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , <EOL> type = str , dest = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , "<STR_LIT>" , <EOL> type = float , dest = "<STR_LIT>" , <EOL> default = <NUM_LIT> , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , "<STR_LIT>" , <EOL> type = str , dest = "<STR_LIT:date>" , <EOL> default = None , <EOL> help = "<STR_LIT>" ) <EOL> args = parser . parse_args ( ) <EOL> if not args . plot : <EOL> AAG = AAGCloudSensor ( serial_address = args . device ) <EOL> if AAG . AAG is not None : <EOL> if args . one : <EOL> AAG . update_weather ( update_mongo = args . mongo ) <EOL> else : <EOL> now = dt . utcnow ( ) <EOL> while True : <EOL> last = now <EOL> now = dt . utcnow ( ) <EOL> loop_duration = ( now - last ) . total_seconds ( ) / <NUM_LIT> <EOL> AAG . update_weather ( update_mongo = args . mongo ) <EOL> AAG . calculate_and_set_PWM ( ) <EOL> AAG . logger . info ( '<STR_LIT>' . format ( args . interval ) ) <EOL> AAG . logger . info ( '<STR_LIT>' ) <EOL> time . sleep ( args . interval ) <EOL> else : <EOL> AAG . logger . warning ( "<STR_LIT>" ) <EOL> print ( "<STR_LIT>" ) <EOL> else : <EOL> plot_weather ( args . date ) </s>
