def test_Location_SolarDepression(): c = Location(("Heidelberg", "Germany", 49.412, -8.71, "Europe/Berlin")) c.solar_depression = 'nautical' assert c.solar_depression == 12 c.solar_depression = 18 assert c.solar_depression == 18
def CalcAstralDayTime(Date,Time,Latitude,Longitude): """ Calcule la position du soleil pour l'heure donnée. :param Date: Date UTC :param Time: Heure UTC :param Latitude: Latitude :param Longitude: Longitude :return: D pour Day, U pour Dusk/crépuscule, N pour Night/Nuit, A pour Aube/Dawn """ from astral import Location l = Location() l.solar_depression= 'nautical' l.latitude = Latitude l.longitude = Longitude s = l.sun(date=Date, local=False) # print(Date,Time,Latitude,Longitude,s,) Result = '?' Inter=( {'d': 'sunrise', 'f': 'sunset' , 'r': 'D'} , {'d': 'sunset' , 'f': 'dusk' , 'r': 'U'} , {'d': 'dusk' , 'f': 'dawn' , 'r': 'N'} , {'d': 'dawn' , 'f': 'sunrise', 'r': 'A'} ) for I in Inter: if s[I['d']].time()<s[I['f']].time() and (Time>=s[I['d']].time() and Time<=s[I['f']].time() ) : Result=I['r'] elif s[I['d']].time() > s[I['f']].time() and (Time >= s[I['d']].time() or Time <= s[I['f']].time()): Result = I['r'] # Changement de jour entre les 2 parties de l'intervalle return Result
def get_sun_times(dt=datetime.datetime.now()): loc = Location() loc.name = 'Melbourne' loc.region = 'Oceania' loc.latitude = -37.787027 loc.longitude = 145.110013 loc.timezone = 'Australia/Melbourne' loc.elevation = 75 loc.solar_depression = 'civil' resp = {} for k, v in loc.sun(dt).items(): resp[k] = arrow.get(v).timestamp return resp
def calc_sunset_times(stops_df, latitude, longitude, timezone, date_col = 'date'): """ Calculates the sunset times for all unique dates in stops_df using the provided latitude and longitude using the given timezone. INPUTS ======= stops_df: A pandas DataFrame that contains stops observations. latitude: An object that can be converted to a float that represents the latitude longitude: An object that can be converted to a float that represents the longitude timezone: A string indicating the timezone to calculate the times in. For a list of accepted arguments for timezone, use the follow code: from pytz import all_timezones for timezone in all_timezones: print(timezone) date_col: A string indicating the date column on stops_df. By default assumes it is 'date'. RETURNS ======== A pandas DataFrame in which each row contains information about a date, with column 'sunset' representing sunset time, 'dusk' representing dusk time, 'sunset_minutes' representing sunset time in minutes, and 'dusk_minutes' representing dusk time in minutes. """ l = Location() l.solar_depression = 'civil' l.latitude = float(latitude) l.longitude = float(longitude) l.timezone = timezone l.elevation = 0 unique_dates = list(stops_df[date_col].unique()) sunset = [l.sun(pd.Timestamp(date), local = True)['sunset'].time() for date in unique_dates] dusk = [l.sun(pd.Timestamp(date), local = True)['dusk'].time() for date in unique_dates] sunset_minutes = [time.hour * 60 + time.minute for time in sunset] dusk_minutes = [time.hour * 60 + time.minute for time in dusk] sunset_times = pd.DataFrame(zip(unique_dates, sunset, dusk, sunset_minutes, dusk_minutes)) sunset_times.columns = ['date', 'sunset', 'dusk', 'sunset_minute', 'dusk_minute'] return sunset_times
#input files: weather_irradiation = 'input/weather/solarirradiation_twenthe.csv' weather_timebaseDataset = 3600 #in seconds per interval #Simulation: #number of days to simulate and skipping of initial days. Simulation starts at Sunday January 1. numDays = 5 # number of days startDay = 180 # Initial day numHouses = 30 #Select the geographic location. Refer to the Astral plugin to see available locations (or give a lon+lat) # Use e.g. https://www.latlong.net/ from astral import Location location = Location() location.solar_depression = 'civil' location.latitude = 52.239095 location.longitude = 6.857018 location.timezone = 'Europe/Amsterdam' location.elevation = 0 #Select the devices in the neighbourhood #Devices #Scale overall consumption: consumptionFactor = 1.0 #consumption was a bit too high # Penetration of emerging technology in percentages # all values must be between 0-100 # These indicate what percentage of the houses has a certain device
# create a new diel event table table_name = 'ev_' + in_name[3:] eventTable = arcpy.CreateTable_management(diveDir, table_name, evTemplate) # field list f_names = [ 'ptt', 'fromlocation', 'tolocation', 'diel', 'moon', 'startdate', 'enddate' ] with arcpy.da.InsertCursor(eventTable, f_names) as iCur: rows = [] # define diel events for first day loc = Location(('loc', '', locs[0][1][1], locs[0][1][0], 'US/Pacific', 0)) # pass in as a tuple loc.solar_depression = 'civil' loc_day = startDate # as datetime sun = loc.sun(loc_day) moon = loc.moon_phase(loc_day) events = { 1: sun['dawn'].replace(tzinfo=None), 2: sun['sunrise'].replace(tzinfo=None), 3: sun['sunset'].replace(tzinfo=None), 4: sun['dusk'].replace(tzinfo=None) } diel_name = {1: 'Night', 2: 'Dawn', 3: 'Day', 4: 'Dusk'} per = 3 # first timevalue (deploy) will always be sometime before sunset, RIGHT? seg = 0 cur_hour = startDate.hour # integer endDate = datetime.datetime.combine(startDate.date(), datetime.time(cur_hour + 1))
#!/usr/bin/env python import datetime from astral import Astral, Location import pytz def dt2min(dt): return dt.hour * 60 + dt.minute loc = Location(("Santa Clara", "California", 37.21, -121.58, "US/Pacific", 22)) loc.solar_depression = 'civil' oneday = datetime.timedelta(days=1) soy = datetime.date(2016, 1, 1) for i in (range(1, 366)): sun = loc.sun(date=soy, local=True) print("{{ 0x{0:X}, 0x{1:X} }},".format(dt2min(sun['sunrise']), dt2min(sun['sunset']))) soy = soy + oneday