def SimulateSpan(latitude_deg, longitude_deg, start_utc_datetime, end_utc_datetime, step_minutes, elevation=0, temperature_celsius=25, pressure_millibars=1013.25): '''Simulate the motion of the sun over a time span and location of your choosing. The start and end points are set by datetime objects, which can be created with the standard Python datetime module like this: import datetime start = datetime.datetime(2008, 12, 23, 23, 14, 0) ''' time_list = BuildTimeList(start_utc_datetime, end_utc_datetime, step_minutes) angles_list = [(time, solar.GetAltitude(latitude_deg, longitude_deg, time, elevation, temperature_celsius, pressure_millibars), solar.GetAzimuth(latitude_deg, longitude_deg, time, elevation)) for time in time_list] power_list = [(time, alt, az, radiation.GetRadiationDirect(time, alt)) for (time, alt, az) in angles_list] print power_list
def solarelevation_function_clear(latitude_deg, longitude_deg, utc_datetime,temperature_celsius = 25, pressure_millibars = 1013.25, elevation = elevation_default): """Equation calculates Solar elevation function for clear sky type. Parameters ---------- latitude_deg : float latitude in decimal degree. A geographical term denoting the north/south angular location of a place on a sphere. longitude_deg : float longitude in decimal degree. Longitude shows your location in an east-west direction,relative to the Greenwich meridian. utc_datetime : date_object utc_datetime. UTC DateTime is for Universal Time ( i.e. like a GMT+0 ) temperature_celsius : float Temperature is a physical property of a system that underlies the common notions of hot and cold. pressure_millibars : float pressure_millibars elevation : float The elevation of a geographic location is its height above a fixed reference point, often the mean sea level. Returns ------- SOLALTC : float Solar elevation function clear sky References ---------- .. [1] S. Younes, R.Claywell and el al,"Quality control of solar radiation data: present status and proposed new approaches", energy 30 (2005), pp 1533 - 1549. """ altitude = solar.GetAltitude(latitude_deg, longitude_deg,utc_datetime, elevation, temperature_celsius,pressure_millibars) return (0.038175 + (1.5458 * (math.sin(altitude))) + ((-0.59980) * (0.5 * (1 - math.cos(2 * (altitude))))))
def direct_underclear(latitude_deg, longitude_deg, utc_datetime, temperature_celsius = 25, pressure_millibars = 1013.25, TY = TY_default, AM = AM_default, TL = TL_default,elevation = elevation_default): """Equation calculates direct radiation under clear sky conditions. Parameters ---------- latitude_deg : float latitude in decimal degree. A geographical term denoting the north/south angular location of a place on a sphere. longitude_deg : float longitude in decimal degree. Longitude shows your location in an east-west direction,relative to the Greenwich meridian. utc_datetime : date_object utc_datetime. UTC DateTime is for Universal Time ( i.e. like a GMT+0 ) temperature_celsius : float Temperature is a physical property of a system that underlies the common notions of hot and cold. pressure_millibars : float pressure_millibars TY : float Total number of days in a year. eg. 365 days per year,(no leap days) AM : float Air mass. An Air Mass is a measure of how far light travels through the Earth's atmosphere. One air mass, or AM1, is the thickness of the Earth's atmosphere. Air mass zero (AM0) describes solar irradiance in space, where it is unaffected by the atmosphere. The power density of AM1 light is about 1,000 W/m^2 TL : float Linke turbidity factor elevation : float The elevation of a geographic location is its height above a fixed reference point, often the mean sea level. Returns ------- DIRC : float Direct Irradiation under clear References ---------- .. [1] S. Younes, R.Claywell and el al,"Quality control of solar radiation data: present status and proposed new approaches", energy 30 (2005), pp 1533 - 1549. """ KD = mean_earth_sun_distance(utc_datetime) DEC = declination_degree(utc_datetime,TY) DIRC = (1367 * KD * math.exp(-0.8662 * (AM) * (TL) * (DEC) ) * math.sin(solar.GetAltitude(latitude_deg,longitude_deg, utc_datetime,elevation , temperature_celsius , pressure_millibars ))) return DIRC
def ComparePysolarToUSNO(datum): alt = solar.GetAltitude(float(datum.latitude), float(datum.longitude), datum.timestamp, datum.elevation) pysolar_alt = (90.0 - alt) az = solar.GetAzimuth(float(datum.latitude), float(datum.longitude), datum.timestamp, datum.elevation) pysolar_az = (180.0 - az) % 360.0 # print pysolar_alt # print pysolar_az pysolar = Ephemeris(datum.timestamp, datum.latitude, datum.longitude, datum.elevation, pysolar_az, pysolar_alt) c = EphemerisComparison('pysolar', pysolar, 'usno', datum) return c
def calculateSolarAngles(self,timeDatetimeFormat): # solar altitude, sometimes called solar angle self.solarAltitudeDegrees=solar.GetAltitude(self.latitudeFloatingPoint,self.longitudeFloatingPoint,timeDatetimeFormat) self.solarAltitudeRadians=math.radians(self.solarAltitudeDegrees) # azimuth: west is -90 degrees, north is -180 degrees, east is -270 degrees self.solarAzimuthDegrees=solar.GetAzimuth(self.latitudeFloatingPoint,self.longitudeFloatingPoint,timeDatetimeFormat) self.solarAzimuthRadians=0.0-math.radians(self.solarAzimuthDegrees) # solarAzimuthRadiansConverted: north is 0, east is 0.5 pi, south is pi, west is 1.5 pi if self.solarAzimuthRadians < math.pi: self.solarAzimuthRadiansConverted=self.solarAzimuthRadians+math.pi else: self.solarAzimuthRadiansConverted=self.solarAzimuthRadians-math.pi if self.reduceRunTime: self.solarCritAngle=self.horizontanFromList(self.solarAzimuthRadiansConverted) else: self.solarCritAngle=horizontan(self.extendedDem,self.solarAzimuthRadiansConverted)
def addSunPaths(im, latitude_deg, longitude_deg, horizon, d): pix = im.load() alt_zero = getAltitudeZero() az_zero = getAzimuthZero() for m in range(24 * 60): alt = solar.GetAltitude(latitude_deg, longitude_deg, d + dt.timedelta(minutes=m)) az = solar.GetAzimuth(latitude_deg, longitude_deg, d + dt.timedelta(minutes=m)) x = az_zero + int(az * 1944.0 / 360.0) y = alt_zero - int(alt_zero * sin(radians(alt))) if y < horizon[x]: pix[x % 1944, y] = (255, 193, 37) return im
def global_irradiance_overcast(latitude_deg, longitude_deg, utc_datetime, elevation = elevation_default, temperature_celsius = 25, pressure_millibars = 1013.25): """Calculated Global is used to compare to the Diffuse under overcast conditions. Under overcast skies, global and diffuse are expected to be equal due to the absence of the beam component. Parameters ---------- latitude_deg : float latitude in decimal degree. A geographical term denoting the north/south angular location of a place on a sphere. longitude_deg : float longitude in decimal degree. Longitude shows your location in an east-west direction,relative to the Greenwich meridian. utc_datetime : date_object utc_datetime. UTC DateTime is for Universal Time ( i.e. like a GMT+0 ) elevation : float The elevation of a geographic location is its height above a fixed reference point, often the mean sea level. temperature_celsius : float Temperature is a physical property of a system that underlies the common notions of hot and cold. pressure_millibars : float pressure_millibars Returns ------- ghioc : float Global Irradiation under overcast sky References ---------- .. [1] S. Younes, R.Claywell and el al, "Quality control of solar radiation data: present status and proposed new approaches", energy 30 (2005), pp 1533 - 1549. """ ghioc = (572 * (solar.GetAltitude(latitude_deg, longitude_deg, utc_datetime, elevation , temperature_celsius , pressure_millibars ))) return ghioc
def solarelevation_function_overcast(latitude_deg, longitude_deg, utc_datetime, elevation = elevation_default, temperature_celsius = 25, pressure_millibars = 1013.25): """ The function calculates solar elevation function for overcast sky type. This associated hourly overcast radiation model is based on the estimation of the overcast sky transmittance with the sun directly overhead combined with the application of an over sky elavation function to estimate the overcast day global irradiation value at any solar elevation. Parameters ---------- latitude_deg : float latitude in decimal degree. A geographical term denoting the north/south angular location of a place on a sphere. longitude_deg : float longitude in decimal degree. Longitude shows your location in an east-west direction,relative to the Greenwich meridian. utc_datetime : date_object utc_datetime. UTC DateTime is for Universal Time ( i.e. like a GMT+0 ) elevation : float The elevation of a geographic location is its height above a fixed reference point, often the mean sea level. temperature_celsius : float Temperature is a physical property of a system that underlies the common notions of hot and cold. pressure_millibars : float pressure_millibars Returns ------- SOLALTO : float Solar elevation function overcast References ---------- .. [1] Prof. Peter Tregenza,"Solar radiation and daylight models", p.89. .. [2] Also accessible through Google Books: http://tinyurl.com/5kdbwu Tariq Muneer, "Solar Radiation and Daylight Models, Second Edition: For the Energy Efficient Design of Buildings" """ altitude = solar.GetAltitude(latitude_deg, longitude_deg,utc_datetime, elevation, temperature_celsius,pressure_millibars) return ((-0.0067133) + (0.78600 * (math.sin(altitude)))) + (0.22401 * (0.5 * (1 - math.cos(2 * altitude))))
def diffuse_underovercast(latitude_deg, longitude_deg, utc_datetime, elevation = elevation_default, temperature_celsius = 25, pressure_millibars = 1013.25,TL=TL_default): """Function calculates the diffuse radiation under overcast conditions. Parameters ---------- latitude_deg : float latitude in decimal degree. A geographical term denoting the north/south angular location of a place on a sphere. longitude_deg : float longitude in decimal degree. Longitude shows your location in an east-west direction,relative to the Greenwich meridian. utc_datetime : date_object utc_datetime. UTC DateTime is for Universal Time ( i.e. like a GMT+0 ) elevation : float The elevation of a geographic location is its height above a fixed reference point, often the mean sea level. temperature_celsius : float Temperature is a physical property of a system that underlies the common notions of hot and cold. pressure_millibars : float pressure_millibars TL : float Linke turbidity factor Returns ------- DIFOC : float Diffuse Irradiation under overcast References ---------- .. [1] S. Younes, R.Claywell and el al,"Quality control of solar radiation data: present status and proposed new approaches", energy 30 (2005), pp 1533 - 1549. """ DT = ((-21.657) + (41.752 * (TL)) + (0.51905 * (TL) * (TL))) DIFOC = ((mean_earth_sun_distance(utc_datetime) )*(DT)*(solar.GetAltitude(latitude_deg,longitude_deg, utc_datetime, elevation, temperature_celsius, pressure_millibars))) return DIFOC
def from_time_and_location(self, lat, long, datetimestring, view_z, view_a): """Sets the user-defined geometry to a given view zenith and azimuth, and a solar zenith and azimuth calculated from the lat, long and date given. Uses the PySolar module for the calculations. Arguments: * ``lat`` -- The latitude of the location (0-90 degrees) * ``long`` -- The longitude of the location * ``datetimestring`` -- Any string that can be parsed to produce a date/time object. All that is really needed is a time - eg. "14:53" * ``view_z`` -- The view zenith angle * ``view_a`` -- The view azimuth angle """ # Try and import the PySolar module, if it fails give an error message try: import solar except: raise ExecutionError( "To set the geometry from a time and location you must have the PySolar module installed.\nTo install this, run 'pip install pysolar' at the command line." ) dt = dateutil.parser.parse(datetimestring, dayfirst=True) self.solar_z = solar.GetAltitude(lat, long, dt) az = solar.GetAzimuth(lat, long, dt) if az < 0: self.solar_a = abs(az) + 180 else: self.solar_a = abs(az - 180) self.solar_a = self.solar_a % 360 self.day = dt.day self.month = dt.month self.view_z = view_z self.view_a = view_a
def ShadeTest(): latitude_deg = 42.364908 longitude_deg = -71.112828 width = 100 height = 200 area = width * height d = datetime.datetime.utcnow() thirty_minutes = datetime.timedelta(hours=0.5) times = [] powers = [] shade_x = [] shade_y = [] shaded_powers = [] for i in range(48): timestamp = d.ctime() altitude_deg = solar.GetAltitude(latitude_deg, longitude_deg, d) azimuth_deg = solar.GetAzimuth(latitude_deg, longitude_deg, d) power = radiation.GetRadiationDirect(d, altitude_deg) xs = shade.GetXShade(width, 120, azimuth_deg) ys = shade.GetYShade(height, 120, altitude_deg) shaded_area = xs * ys shaded_percentage = shaded_area / area if (altitude_deg > 0): times.append(float(d.hour) + (float(d.minute) / 60) - 5) # - 5 to adjust to EST powers.append(power) shade_x.append(xs) shade_y.append(ys) shaded_powers.append(power * (1 - shaded_percentage)) #print timestamp, "UTC", altitude_deg, azimuth_deg, power d = d + thirty_minutes print times print powers print shade_x pylab.plot( times, shaded_powers, times, powers ) # plot ends up with a line across it because x values wrap around pylab.show() # could fix that with sort function below