### Install Pysolar via pip Source: https://context7.com/pingswept/pysolar/llms.txt The standard command to install the Pysolar library into your Python environment. ```bash pip install pysolar ``` -------------------------------- ### Import Libraries and Setup Source: https://github.com/pingswept/pysolar/blob/master/pysolar/rest2-validation.ipynb Imports necessary libraries like Matplotlib for plotting and NumPy for numerical operations. It also sets up the environment for inline plotting. ```python %matplotlib inline import matplotlib.pyplot as plt import numpy as np ``` -------------------------------- ### Hourly Solar Calculations Source: https://context7.com/pingswept/pysolar/llms.txt This example demonstrates how to calculate solar altitude and azimuth for every hour of a day given latitude, longitude, and a base date. ```APIDOC ## Hourly Solar Calculations ### Description Calculates the solar altitude and azimuth for each hour of a given day. ### Method N/A (Illustrative Python code) ### Endpoint N/A ### Parameters - **latitude** (float) - Required - The latitude of the location. - **longitude** (float) - Required - The longitude of the location. - **base_date** (datetime) - Required - The starting date and time for calculations. ### Request Example ```python import datetime import pysolar latitude = 39.74 longitude = -104.99 base_date = datetime.datetime(2023, 10, 26, 0, 0, 0, tzinfo=datetime.timezone.utc) times = [base_date + datetime.timedelta(hours=h) for h in range(24)] altitudes = [pysolar.get_altitude(latitude, longitude, t) for t in times] azimuths = [pysolar.get_azimuth(latitude, longitude, t) for t in times] for i, (t, alt, azi) in enumerate(zip(times, altitudes, azimuths)): if alt > 0: print(f"{t.strftime('%H:%M')} UTC: Alt={alt:6.2f}°, Azi={azi:6.2f}°") # Switch back to standard math mode pysolar.use_math() ``` ### Response #### Success Response (200) Prints hourly UTC time, altitude, and azimuth if altitude is positive. #### Response Example ``` 08:00 UTC: Alt=15.32°, Azi=105.12° 09:00 UTC: Alt=25.89°, Azi=120.45° ... 16:00 UTC: Alt=20.15°, Azi=250.78° ``` ``` -------------------------------- ### Install Pysolar Validation Dependencies Source: https://github.com/pingswept/pysolar/blob/master/doc/index.md Installs the necessary Python packages and tools required to run the Pysolar validation notebooks and scripts. This includes IPython Notebook, Python 3, Matplotlib, Pandas, SciPy, and pytz. ```bash sudo apt-get install ipython3-notebook python3 python3-matplotlib python3-pandas python3-scipy python3-tz ``` -------------------------------- ### Get Sunrise, Sunset, and Transit Times in Python Source: https://context7.com/pingswept/pysolar/llms.txt Calculates astronomical sunrise, sunset, and solar transit (noon) times for a specified location and date. All returned times are timezone-aware and match the input datetime's timezone. Supports calculating all three, just sunrise/sunset, or individual times. ```python import datetime from pysolar import util # Frankfurt, Germany latitude = 50.111512 longitude = 8.680506 # Create timezone-aware datetime for a specific day # Using UTC timezone day = datetime.datetime(2024, 6, 21, 12, 0, 0, tzinfo=datetime.timezone.utc) # Get all three times sunrise, sunset, transit = util.get_sunrise_sunset_transit(latitude, longitude, day) print(f"Sunrise: {sunrise.strftime('%H:%M:%S %Z')}") print(f"Solar noon: {transit.strftime('%H:%M:%S %Z')}") print(f"Sunset: {sunset.strftime('%H:%M:%S %Z')}") # Get just sunrise and sunset sunrise, sunset = util.get_sunrise_sunset(latitude, longitude, day) print(f"Day length: {(sunset - sunrise).total_seconds() / 3600:.2f} hours") # Individual functions sunrise_time = util.get_sunrise_time(latitude, longitude, day) sunset_time = util.get_sunset_time(latitude, longitude, day) transit_time = util.get_transit_time(latitude, longitude, day) ``` -------------------------------- ### Get Sunrise, Sunset, and Transit Times Source: https://context7.com/pingswept/pysolar/llms.txt Calculates astronomical sunrise, sunset, and solar transit (noon) times for a given location and date. All times are returned in the same timezone as the input datetime. ```APIDOC ## Get Sunrise, Sunset, and Transit Times ### Description Calculates astronomical sunrise, sunset, and solar transit (noon) times for a given location and date. All times are returned in the same timezone as the input datetime. ### Method `util.get_sunrise_sunset_transit(latitude, longitude, date)` `util.get_sunrise_sunset(latitude, longitude, date)` `util.get_sunrise_time(latitude, longitude, date)` `util.get_sunset_time(latitude, longitude, date)` `util.get_transit_time(latitude, longitude, date)` ### Parameters - **latitude** (float) - Required - Latitude in decimal degrees. - **longitude** (float) - Required - Longitude in decimal degrees. - **date** (datetime) - Required - A timezone-aware datetime object representing the day. ### Request Example ```python import datetime from pysolar import util latitude = 50.111512 longitude = 8.680506 day = datetime.datetime(2024, 6, 21, 12, 0, 0, tzinfo=datetime.timezone.utc) sunrise, sunset, transit = util.get_sunrise_sunset_transit(latitude, longitude, day) print(f"Sunrise: {sunrise.strftime('%H:%M:%S %Z')}") print(f"Solar noon: {transit.strftime('%H:%M:%S %Z')}") print(f"Sunset: {sunset.strftime('%H:%M:%S %Z')}") sunrise, sunset = util.get_sunrise_sunset(latitude, longitude, day) print(f"Day length: {(sunset - sunrise).total_seconds() / 3600:.2f} hours") ``` ### Response #### Success Response (200) - **sunrise** (datetime) - The astronomical sunrise time. - **sunset** (datetime) - The astronomical sunset time. - **transit** (datetime) - The solar transit (noon) time. #### Response Example ``` Sunrise: 04:30:15 UTC Solar noon: 12:45:30 UTC Sunset: 20:59:45 UTC Day length: 16.49 hours ``` ``` -------------------------------- ### Get Combined Solar Position Source: https://context7.com/pingswept/pysolar/llms.txt Retrieves both azimuth and altitude in a single efficient function call. ```python import datetime from pysolar.solar import get_position latitude = 42.206 longitude = -71.382 date = datetime.datetime(2007, 2, 18, 15, 13, 1, 130320, tzinfo=datetime.timezone.utc) azimuth, altitude = get_position(latitude, longitude, date) print(f"Azimuth: {azimuth:.2f}°, Altitude: {altitude:.2f}°") ``` -------------------------------- ### Fast Altitude and Azimuth Calculations in Python Source: https://context7.com/pingswept/pysolar/llms.txt Calculates solar altitude and azimuth using simplified, faster methods that omit atmospheric refraction corrections. Useful when speed is prioritized over high precision. Compares results with more precise calculations. ```python import datetime from pysolar.solar import get_altitude_fast, get_azimuth_fast latitude = 42.364908 longitude = -71.112828 date = datetime.datetime(2007, 2, 18, 20, 13, 1, 130320, tzinfo=datetime.timezone.utc) # Fast altitude calculation (less precise) altitude_fast = get_altitude_fast(latitude, longitude, date) print(f"Fast altitude: {altitude_fast:.2f} degrees") # Fast azimuth calculation azimuth_fast = get_azimuth_fast(latitude, longitude, date) print(f"Fast azimuth: {azimuth_fast:.2f} degrees") # Compare with precise calculations from pysolar.solar import get_altitude, get_azimuth altitude_precise = get_altitude(latitude, longitude, date) azimuth_precise = get_azimuth(latitude, longitude, date) print(f"Altitude difference: {abs(altitude_precise - altitude_fast):.4f} degrees") print(f"Azimuth difference: {abs(azimuth_precise - azimuth_fast):.4f} degrees") ``` -------------------------------- ### Simulate Sun Motion Over Time Source: https://context7.com/pingswept/pysolar/llms.txt Calculates solar altitude, azimuth, and radiation over a specified time range. It supports horizon profiling to account for obstructions. ```python import datetime from pysolar import simulate latitude = 42.0 longitude = -70.0 # Define time range start = datetime.datetime(2024, 6, 21, 6, 0, 0, tzinfo=datetime.timezone.utc) end = datetime.datetime(2024, 6, 21, 20, 0, 0, tzinfo=datetime.timezone.utc) step_minutes = 30 # Create a simple horizon profile (360 values, one per degree of azimuth) # Value represents horizon obstruction height (0 = no obstruction) horizon = [0] * 360 # Flat horizon # Run simulation print("Time | Alt (°) | Azi (°) | Rad (W/m²)") print("-" * 55) for time, alt, azi, rad, shade in simulate.simulate_span( latitude, longitude, horizon, start, end, step_minutes ): if alt > 0: print(f"{time.strftime('%Y-%m-%d %H:%M')} | {alt:6.2f} | {azi:7.2f} | {rad:9.2f}") # Generate datetime sequence for dt in simulate.datetime_range(start, end, step_minutes): print(dt) ``` -------------------------------- ### Calculate Air Mass and Optical Depth Source: https://context7.com/pingswept/pysolar/llms.txt Computes atmospheric parameters including air mass ratio, optical depth, and extraterrestrial flux based on solar altitude and day of year. ```python from pysolar import radiation # Air mass ratio (1.0 at zenith, increases as sun gets lower) altitude_90 = 90 # Sun directly overhead altitude_30 = 30 # Sun at 30° elevation altitude_5 = 5 # Sun near horizon am_90 = radiation.get_air_mass_ratio(altitude_90) am_30 = radiation.get_air_mass_ratio(altitude_30) am_5 = radiation.get_air_mass_ratio(altitude_5) print(f"Air mass at 90° altitude: {am_90:.2f}") print(f"Air mass at 30° altitude: {am_30:.2f}") print(f"Air mass at 5° altitude: {am_5:.2f}") # Optical depth varies throughout the year day_summer = 172 # Summer day_winter = 355 # Winter od_summer = radiation.get_optical_depth(day_summer) od_winter = radiation.get_optical_depth(day_winter) print(f"Optical depth (summer): {od_summer:.4f}") print(f"Optical depth (winter): {od_winter:.4f}") # Apparent extraterrestrial flux flux_summer = radiation.get_apparent_extraterrestrial_flux(day_summer) flux_winter = radiation.get_apparent_extraterrestrial_flux(day_winter) print(f"Extraterrestrial flux (summer): {flux_summer:.2f} W/m²") print(f"Extraterrestrial flux (winter): {flux_winter:.2f} W/m²") ``` -------------------------------- ### Import Libraries and Load Data Source: https://github.com/pingswept/pysolar/blob/master/test/validation.ipynb Imports the Pandas library and loads data from a CSV file named 'pysolar_v_usno.csv' into a Pandas DataFrame, setting the 'timestamp' column as the index. ```python import pandas df = pandas.read_csv('pysolar_v_usno.csv', index_col='timestamp') ``` -------------------------------- ### Calculate Hourly Solar Position (Python) Source: https://context7.com/pingswept/pysolar/llms.txt Calculates the solar altitude and azimuth for each hour of a day at a given latitude and longitude. It iterates through 24 hours, retrieves the solar position for each time, and prints the results if the altitude is positive (sun is above the horizon). ```Python import datetime import pysolar latitude = 33.92 # Example latitude longitude = -118.40 # Example longitude base_date = datetime.datetime(2023, 10, 26, 0, 0, 0, tzinfo=datetime.timezone.utc) # Calculate for every hour of the day times = [base_date + datetime.timedelta(hours=h) for h in range(24)] altitudes = [pysolar.get_altitude(latitude, longitude, t) for t in times] azimuths = [pysolar.get_azimuth(latitude, longitude, t) for t in times] # Display results for i, (t, alt, azi) in enumerate(zip(times, altitudes, azimuths)): if alt > 0: print(f"{t.strftime('%H:%M')} UTC: Alt={alt:6.2f}°, Azi={azi:6.2f}°") # Switch back to standard math mode pysolar.use_math() ``` -------------------------------- ### Fast Altitude and Azimuth Calculations Source: https://context7.com/pingswept/pysolar/llms.txt Provides faster but less precise methods for calculating solar altitude and azimuth by skipping atmospheric refraction corrections. ```APIDOC ## Fast Altitude and Azimuth Calculations ### Description Faster but less accurate alternatives for situations where speed is more important than precision. These simplified functions skip atmospheric refraction corrections and use approximate formulas. ### Method `get_altitude_fast(latitude, longitude, date)` `get_azimuth_fast(latitude, longitude, date)` ### Parameters - **latitude** (float) - Required - Latitude in decimal degrees. - **longitude** (float) - Required - Longitude in decimal degrees. - **date** (datetime) - Required - A timezone-aware datetime object. ### Request Example ```python import datetime from pysolar.solar import get_altitude_fast, get_azimuth_fast latitude = 42.364908 longitude = -71.112828 date = datetime.datetime(2007, 2, 18, 20, 13, 1, 130320, tzinfo=datetime.timezone.utc) altitude_fast = get_altitude_fast(latitude, longitude, date) azimuth_fast = get_azimuth_fast(latitude, longitude, date) print(f"Fast altitude: {altitude_fast:.2f} degrees") print(f"Fast azimuth: {azimuth_fast:.2f} degrees") ``` ### Response #### Success Response (200) - **altitude_fast** (float) - The calculated altitude in degrees. - **azimuth_fast** (float) - The calculated azimuth in degrees. #### Response Example ``` Fast altitude: -10.12 degrees Fast azimuth: 180.45 degrees ``` ``` -------------------------------- ### Global Irradiance Under Clear and Overcast Skies in Python Source: https://context7.com/pingswept/pysolar/llms.txt Calculates the global horizontal irradiance (GHI) reaching the Earth's surface under clear sky conditions by combining direct and diffuse radiation. Also provides a function to estimate GHI for overcast conditions. Requires parameters like temperature, pressure, and turbidity for clear sky calculations. ```python import datetime from pysolar import util latitude = 42.206 longitude = -71.382 date = datetime.datetime(2024, 6, 21, 14, 0, 0, tzinfo=datetime.timezone.utc) # Calculate global irradiance under clear sky ghi_clear = util.global_irradiance_clear( latitude, longitude, date, elevation=0, temperature=293.15, # 20°C in Kelvin pressure=101325, # Standard pressure in Pascals TL=1.0, # Linke turbidity factor AM=2.0 # Air mass ) print(f"Global irradiance (clear sky): {ghi_clear:.2f} W/m²") # Calculate for overcast conditions ghi_overcast = util.global_irradiance_overcast(latitude, longitude, date) print(f"Global irradiance (overcast): {ghi_overcast:.2f} W/m²") ``` -------------------------------- ### Perform Julian Day Calculations Source: https://context7.com/pingswept/pysolar/llms.txt Calculates Julian solar and ephemeris days, centuries, and millenniums. Includes utilities for leap seconds and Delta-T corrections. ```python import datetime from pysolar import solartime date = datetime.datetime(2024, 6, 21, 12, 0, 0, tzinfo=datetime.timezone.utc) # Julian solar day (UT1-based) jd = solartime.get_julian_solar_day(date) print(f"Julian Solar Day: {jd:.6f}") # Julian ephemeris day (TT-based) jde = solartime.get_julian_ephemeris_day(date) print(f"Julian Ephemeris Day: {jde:.6f}") # Julian century and millennium (for VSOP calculations) jce = solartime.get_julian_ephemeris_century(jde) jme = solartime.get_julian_ephemeris_millennium(jce) print(f"Julian Ephemeris Century: {jce:.6f}") print(f"Julian Ephemeris Millennium: {jme:.6f}") # Leap seconds and delta-T corrections leap_secs = solartime.get_leap_seconds(date) delta_t = solartime.get_delta_t(date) print(f"Leap seconds (UTC to TAI): {leap_secs} s") print(f"Delta-T (UT1 to TT): {delta_t:.4f} s") ``` -------------------------------- ### Calculate Sun Altitude with Pysolar Source: https://context7.com/pingswept/pysolar/llms.txt Calculates the sun's altitude in degrees for a given location and time. Supports optional parameters for elevation, temperature, and atmospheric pressure. ```python import datetime from pysolar.solar import get_altitude latitude = 42.206 longitude = -71.382 date = datetime.datetime(2007, 2, 18, 15, 13, 1, 130320, tzinfo=datetime.timezone.utc) altitude = get_altitude(latitude, longitude, date) print(f"Sun altitude: {altitude:.2f} degrees") ``` -------------------------------- ### Calculate Direct Solar Radiation Source: https://context7.com/pingswept/pysolar/llms.txt Computes the direct solar irradiation in W/m² based on the sun's altitude. Requires the sun to be above the horizon. ```python import datetime from pysolar.solar import get_altitude from pysolar import radiation latitude = 42.206 longitude = -71.382 date = datetime.datetime(2007, 2, 18, 15, 13, 1, 130320, tzinfo=datetime.timezone.utc) altitude = get_altitude(latitude, longitude, date) if altitude > 0: direct_radiation = radiation.get_radiation_direct(date, altitude) print(f"Direct radiation: {direct_radiation:.2f} W/m²") ``` -------------------------------- ### Run Pysolar Validation Script Source: https://github.com/pingswept/pysolar/blob/master/doc/index.md Executes the `query_usno.py` script to gather data from the US Naval Observatory and validate Pysolar's accuracy. This script is used to compare Pysolar's altitude and azimuth estimations against official data, generating error statistics. ```bash python3 -i query_usno.py usno_data_6259.txt ``` -------------------------------- ### Enable NumPy Vectorized Calculations Source: https://context7.com/pingswept/pysolar/llms.txt Configures Pysolar to use NumPy for efficient batch processing of solar calculations. ```python import datetime import numpy as np import pysolar # Enable NumPy mode pysolar.use_numpy() from pysolar.solar import get_altitude, get_azimuth # Single location, multiple times latitude = 42.206 longitude = -71.382 base_date = datetime.datetime(2024, 6, 21, 0, 0, 0, tzinfo=datetime.timezone.utc) ``` -------------------------------- ### Estimate Clear-Sky Direct Solar Radiation with Pysolar Source: https://github.com/pingswept/pysolar/blob/master/doc/index.md Calculates the direct solar irradiation in watts per square meter using Pysolar's `get_radiation_direct` function. This function accounts for atmospheric scattering but does not return zero at night. It requires the date, and the sun's altitude, which is derived from latitude, longitude, and date. ```python import datetime from pysolar import radiation latitude_deg = 42.206 # positive in the northern hemisphere longitude_deg = -71.382 # negative reckoning west from prime meridian in Greenwich, England date = datetime.datetime(2007, 2, 18, 15, 13, 1, 130320, tzinfo=datetime.timezone.utc) altitude_deg = radiation.get_altitude(latitude_deg, longitude_deg, date) radiation.get_radiation_direct(date, altitude_deg) ``` -------------------------------- ### Calculate Solar Azimuth with Pysolar Source: https://github.com/pingswept/pysolar/blob/master/doc/index.md Calculates the azimuth of the sun, which is the angle relative to north, with positive values indicating east and negative or >180 values indicating west. Requires latitude, longitude, and a datetime object. The result is in degrees. ```Python from pysolar.solar import * import datetime latitude = 42.206 longitude = -71.382 date = datetime.datetime(2007, 2, 18, 15, 13, 1, 130320, tzinfo=datetime.timezone.utc) print(get_azimuth(latitude, longitude, date)) ``` -------------------------------- ### Calculate Broadband Direct Normal Irradiance Source: https://github.com/pingswept/pysolar/blob/master/pysolar/rest2-validation.ipynb Calculates the broadband direct normal irradiance using the pysolar.rest module. This function takes an altitude as input and returns the irradiance value. It also demonstrates calculating optical mass with aerosols for varying altitudes and plotting the results. ```python from pysolar.rest import * get_broadband_direct_normal_irradiance(45.0) altitude = np.linspace(0, 90, 90) #ma = np.array(map(get_optical_mass_aerosol, altitude)) ma = np.array([get_optical_mass_aerosol(alt) for alt in altitude]) plt.plot(altitude, ma) plt.xlabel("altitude [degrees]") plt.ylabel("optical mass, aerosol [kg/m^2?]") ``` -------------------------------- ### Convert Standard Time to Solar Time Source: https://context7.com/pingswept/pysolar/llms.txt Converts UTC time to solar time based on longitude and the equation of time. Also provides the hour angle and equation of time correction. ```python import datetime from pysolar.solar import get_solar_time, get_hour_angle, equation_of_time longitude = -71.382 # Boston, MA date = datetime.datetime(2024, 6, 21, 12, 0, 0, tzinfo=datetime.timezone.utc) # Get solar time in hours solar_time = get_solar_time(longitude, date) print(f"UTC time: 12:00:00") print(f"Solar time: {int(solar_time)}:{int((solar_time % 1) * 60):02d}") # Get hour angle (degrees from solar noon) hour_angle = get_hour_angle(date, longitude) print(f"Hour angle: {hour_angle:.2f}° (0° = solar noon)") # Equation of time correction (minutes) day_of_year = date.timetuple().tm_yday eot = equation_of_time(day_of_year) print(f"Equation of time: {eot:.2f} minutes") ``` -------------------------------- ### Global Irradiance Under Clear Sky Source: https://context7.com/pingswept/pysolar/llms.txt Calculates the global horizontal irradiance under clear sky conditions, combining direct and diffuse radiation components. ```APIDOC ## Global Irradiance Under Clear Sky ### Description Calculates the global horizontal irradiance under clear sky conditions, combining direct and diffuse radiation components. ### Method `util.global_irradiance_clear(latitude, longitude, date, elevation=0, temperature=293.15, pressure=101325, TL=1.0, AM=2.0)` `util.global_irradiance_overcast(latitude, longitude, date)` ### Parameters - **latitude** (float) - Required - Latitude in decimal degrees. - **longitude** (float) - Required - Longitude in decimal degrees. - **date** (datetime) - Required - A timezone-aware datetime object. - **elevation** (float) - Optional - Elevation in meters. Defaults to 0. - **temperature** (float) - Optional - Temperature in Kelvin. Defaults to 293.15 (20°C). - **pressure** (float) - Optional - Pressure in Pascals. Defaults to 101325. - **TL** (float) - Optional - Linke turbidity factor. Defaults to 1.0. - **AM** (float) - Optional - Air mass. Defaults to 2.0. ### Request Example ```python import datetime from pysolar import util latitude = 42.206 longitude = -71.382 date = datetime.datetime(2024, 6, 21, 14, 0, 0, tzinfo=datetime.timezone.utc) ghi_clear = util.global_irradiance_clear(latitude, longitude, date, elevation=0, temperature=293.15, pressure=101325, TL=1.0, AM=2.0) print(f"Global irradiance (clear sky): {ghi_clear:.2f} W/m²") ghi_overcast = util.global_irradiance_overcast(latitude, longitude, date) print(f"Global irradiance (overcast): {ghi_overcast:.2f} W/m²") ``` ### Response #### Success Response (200) - **ghi_clear** (float) - Global horizontal irradiance under clear sky conditions in W/m². - **ghi_overcast** (float) - Global horizontal irradiance under overcast conditions in W/m². #### Response Example ``` Global irradiance (clear sky): 850.75 W/m² Global irradiance (overcast): 200.50 W/m² ``` ``` -------------------------------- ### Extraterrestrial Irradiance Calculation in Python Source: https://context7.com/pingswept/pysolar/llms.txt Calculates the solar radiation intensity outside Earth's atmosphere for a given location and time. It accounts for the variation in the solar constant as Earth orbits the sun. Allows for specifying a custom solar constant value. ```python import datetime from pysolar import util latitude = 42.206 longitude = -71.382 date = datetime.datetime(2024, 6, 21, 12, 0, 0, tzinfo=datetime.timezone.utc) # Default solar constant is 1367 W/m² extraterrestrial = util.extraterrestrial_irrad(latitude, longitude, date) print(f"Extraterrestrial irradiance: {extraterrestrial:.2f} W/m²") # Custom solar constant extraterrestrial_custom = util.extraterrestrial_irrad( latitude, longitude, date, SC=1361.0 # Different solar constant value ) print(f"With custom SC: {extraterrestrial_custom:.2f} W/m²") ``` -------------------------------- ### Calculate Solar Altitude with Pysolar Source: https://github.com/pingswept/pysolar/blob/master/doc/index.md Calculates the angle between the sun and a tangent plane to the Earth at a given location and time. Requires latitude, longitude, and a datetime object. The result is in degrees. ```Python from pysolar.solar import * import datetime latitude = 42.206 longitude = -71.382 date = datetime.datetime(2007, 2, 18, 15, 13, 1, 130320, tzinfo=datetime.timezone.utc) print(get_altitude(latitude, longitude, date)) ``` ```Python latitude = YOUR_LATITUDE_GOES_HERE longitude = YOUR_LONGITUDE_GOES_HERE date = datetime.datetime.now(datetime.timezone.utc) print(get_altitude(latitude, longitude, date)) ``` -------------------------------- ### Calculate Effective Aerosol Wavelength (Low Frequency) Source: https://github.com/pingswept/pysolar/blob/master/pysolar/rest2-validation.ipynb Calculates the effective aerosol wavelength for low-frequency conditions. Similar to the high-frequency calculation, it uses air mass, aerosol optical depth, and wavelength as inputs, and the results are plotted against air masses. ```python air_masses = np.linspace(1, 15, 15) eff_aero_wavelength = np.array([get_effective_aerosol_wavelength("low-frequency", mass, 1.3, 0.6) for mass in air_masses]) plt.plot(air_masses, eff_aero_wavelength) plt.xlabel("optical mass, aerosol [kg/m^2?]") plt.ylabel("low freq. effective aerosol wavelength [um?]") ``` -------------------------------- ### Calculate Sun Azimuth with Pysolar Source: https://context7.com/pingswept/pysolar/llms.txt Calculates the sun's horizontal angle measured clockwise from north. Returns a value between 0 and 360 degrees. ```python import datetime from pysolar.solar import get_azimuth latitude = 42.206 longitude = -71.382 date = datetime.datetime(2007, 2, 18, 15, 13, 1, 130320, tzinfo=datetime.timezone.utc) azimuth = get_azimuth(latitude, longitude, date) print(f"Sun azimuth: {azimuth:.2f} degrees") ``` -------------------------------- ### Calculate and Print Altitude Error Statistics Source: https://github.com/pingswept/pysolar/blob/master/test/validation.ipynb Calculates and prints the mean, standard deviation, minimum, and maximum values for the 'alt_error' column in the DataFrame. ```python print('Mean error: {0} degrees'.format(df.alt_error.mean())) print('Standard deviation: {0} degrees'.format(df.alt_error.std())) print('Minimum error: {0} degrees'.format(df.alt_error.min())) print('Maximum error: {0} degrees'.format(df.alt_error.max())) ``` -------------------------------- ### Calculate and Print Azimuth Error Statistics Source: https://github.com/pingswept/pysolar/blob/master/test/validation.ipynb Calculates and prints the mean, standard deviation, minimum, and maximum values for the 'az_error' column in the DataFrame. ```python print('Mean error: {0} degrees'.format(df.az_error.mean())) print('Standard deviation: {0} degrees'.format(df.az_error.std())) print('Minimum error: {0} degrees'.format(df.az_error.min())) print('Maximum error: {0} degrees'.format(df.az_error.max())) ``` -------------------------------- ### Extraterrestrial Irradiance Source: https://context7.com/pingswept/pysolar/llms.txt Calculates extraterrestrial irradiation (solar radiation outside Earth's atmosphere) for a given location and time. The solar constant varies by approximately ±3% as Earth orbits the sun. ```APIDOC ## Extraterrestrial Irradiance ### Description Calculates extraterrestrial irradiation (solar radiation outside Earth's atmosphere) for a given location and time. The solar constant varies by approximately ±3% as Earth orbits the sun. ### Method `util.extraterrestrial_irrad(latitude, longitude, date, SC=1367.0)` ### Parameters - **latitude** (float) - Required - Latitude in decimal degrees. - **longitude** (float) - Required - Longitude in decimal degrees. - **date** (datetime) - Required - A timezone-aware datetime object. - **SC** (float) - Optional - The solar constant in W/m². Defaults to 1367.0. ### Request Example ```python import datetime from pysolar import util latitude = 42.206 longitude = -71.382 date = datetime.datetime(2024, 6, 21, 12, 0, 0, tzinfo=datetime.timezone.utc) extraterrestrial = util.extraterrestrial_irrad(latitude, longitude, date) print(f"Extraterrestrial irradiance: {extraterrestrial:.2f} W/m²") extraterrestrial_custom = util.extraterrestrial_irrad(latitude, longitude, date, SC=1361.0) print(f"With custom SC: {extraterrestrial_custom:.2f} W/m²") ``` ### Response #### Success Response (200) - **extraterrestrial_irrad** (float) - The calculated extraterrestrial irradiance in W/m². #### Response Example ``` Extraterrestrial irradiance: 1366.50 W/m² With custom SC: 1360.50 W/m² ``` ``` -------------------------------- ### Calculate Effective Aerosol Wavelength (High Frequency) Source: https://github.com/pingswept/pysolar/blob/master/pysolar/rest2-validation.ipynb Calculates the effective aerosol wavelength for high-frequency conditions. It takes air mass, aerosol optical depth, and wavelength as inputs. The results are then plotted against air masses. ```python air_masses = np.linspace(1, 15, 15) eff_aero_wavelength = np.array([get_effective_aerosol_wavelength("high-frequency", mass, 1.3, 0.6) for mass in air_masses]) plt.plot(air_masses, eff_aero_wavelength) plt.xlabel("optical mass, aerosol [kg/m^2?]") plt.ylabel("high freq. effective aerosol wavelength [um?]") ``` -------------------------------- ### Plot Azimuth Error vs. Azimuth Source: https://github.com/pingswept/pysolar/blob/master/test/validation.ipynb Generates a scatter plot of azimuth error against solar azimuth. It sets labels for the x and y axes, a title, and limits the x-axis to 0-360 degrees. ```python az_error_plot = df.plot(x='az1', y='az_error', marker='.', linestyle='', color='#2980B9', figsize=(15,10)) az_error_plot.set_xlabel('Azimuth [degrees]', fontsize=16) az_error_plot.set_ylabel('Error [degrees]', fontsize=16) az_error_plot.set_title('Error in azimuth between USNO and Pysolar', fontsize=16) az_error_plot.set_xlim(0, 360) ``` -------------------------------- ### Plot Altitude Error vs. Altitude Source: https://github.com/pingswept/pysolar/blob/master/test/validation.ipynb Generates a scatter plot of altitude error against solar altitude. It sets labels for the x and y axes and a title for the plot. ```python alt_error_plot = df.plot(x='alt1', y='alt_error', marker='.', linestyle='', color='#2980B9', figsize=(15,10)) alt_error_plot.set_xlabel('Altitude [degrees]', fontsize=16) alt_error_plot.set_ylabel('Error [degrees]', fontsize=16) alt_error_plot.set_title('Error in altitude between USNO and Pysolar', fontsize=16) ``` -------------------------------- ### Plot Error vs. Latitude Source: https://github.com/pingswept/pysolar/blob/master/test/validation.ipynb Generates scatter plots of both altitude error and azimuth error against latitude. It sets axis labels, a title, and limits the x-axis to -90 to 90 degrees. ```python latitude_error_plot = df.plot(kind='scatter', x='latitude', y='alt_error', color='#2980B9', figsize=(15,10)) df.plot(kind='scatter', x='latitude', y='az_error', color='#2980B9', ax=latitude_error_plot) latitude_error_plot.set_xlabel('Latitude [degrees]', fontsize=16) latitude_error_plot.set_ylabel('Error [degrees]', fontsize=16) latitude_error_plot.set_title('Error between USNO and Pysolar as a function of latitude', fontsize=16) latitude_error_plot.set_xlim(-90, 90) ``` -------------------------------- ### Plot Error vs. Longitude Source: https://github.com/pingswept/pysolar/blob/master/test/validation.ipynb Generates scatter plots of both altitude error and azimuth error against longitude. It sets axis labels, a title, and limits the x-axis to 0-360 degrees. ```python longitude_error_plot = df.plot(kind='scatter', x='longitude', y='alt_error', color='#2980B9', figsize=(15,10)) df.plot(kind='scatter', x='longitude', y='az_error', color='#2980B9', ax=longitude_error_plot) longitude_error_plot.set_xlabel('Longitude [degrees]', fontsize=16) longitude_error_plot.set_ylabel('Error [degrees]', fontsize=16) longitude_error_plot.set_title('Error between USNO and Pysolar as a function of longitude', fontsize=16) longitude_error_plot.set_xlim(0, 360) ``` -------------------------------- ### Sun Declination Calculation in Python Source: https://context7.com/pingswept/pysolar/llms.txt Calculates the sun's declination angle, which is the angle between the Earth's equatorial plane and a line connecting the Earth and the sun. This value ranges from approximately +23.45° to -23.45°. Can be calculated using the day of the year or a specific datetime object. ```python import datetime from pysolar.solar import get_declination from pysolar import util # Using day of year (1-365) summer_solstice_day = 172 # Approximately June 21 winter_solstice_day = 355 # Approximately December 21 declination_summer = get_declination(summer_solstice_day) declination_winter = get_declination(winter_solstice_day) print(f"Summer solstice declination: {declination_summer:.2f}°") print(f"Winter solstice declination: {declination_winter:.2f}°") # Using datetime date = datetime.datetime(2024, 6, 21, 12, 0, 0, tzinfo=datetime.timezone.utc) declination = util.declination_degree(date) print(f"Declination on {date.date()}: {declination:.2f}°") ``` -------------------------------- ### Sun Declination Source: https://context7.com/pingswept/pysolar/llms.txt Calculates the angle between Earth's equatorial plane and a line between Earth and the sun. Varies between +23.45° (summer solstice) and -23.45° (winter solstice). ```APIDOC ## Sun Declination ### Description Calculates the angle between Earth's equatorial plane and a line between Earth and the sun. Varies between +23.45° (summer solstice) and -23.45° (winter solstice). ### Method `get_declination(day_of_year)` `util.declination_degree(date)` ### Parameters - **day_of_year** (int) - Required - The day of the year (1-365). - **date** (datetime) - Required - A timezone-aware datetime object. ### Request Example ```python import datetime from pysolar.solar import get_declination from pysolar import util summer_solstice_day = 172 winter_solstice_day = 355 declination_summer = get_declination(summer_solstice_day) declination_winter = get_declination(winter_solstice_day) print(f"Summer solstice declination: {declination_summer:.2f}°") print(f"Winter solstice declination: {declination_winter:.2f}°") date = datetime.datetime(2024, 6, 21, 12, 0, 0, tzinfo=datetime.timezone.utc) declination = util.declination_degree(date) print(f"Declination on {date.date()}: {declination:.2f}°") ``` ### Response #### Success Response (200) - **declination** (float) - The sun's declination angle in degrees. #### Response Example ``` Summer solstice declination: 23.44° Winter solstice declination: -23.44° Declination on 2024-06-21: 23.44° ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.