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 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 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