Skip to main content
proper timezone designation, show created plot in code.
Source Link

Look at the pysolar docs (http://pysolar.readthedocs.io/en/latest/) under "Estimate of clear sky radiation". The algorithm does not return zeros at night, but instead just plugs those numbers straight in, giving nonsensical values. Filter the results so that if altitude_deg < 0, the radiation is 0. An example just using pysolar, datetime, and pyplot (I don't use pandas, so I can't comment on that) and lists looks like:

import datetime
import matplotlib.pyplot as plt
import pysolar
lat, lon = 39.9075, 116.39723  # Beijing, China
timezone = datetime.timezone(datetime.timedelta(hours=8))  # 0800 UTC
start = datetime.datetime(2018,1,1,8tzinfo=timezone)  # 1 Jan 2018, 0800 UTC

# Calculate radiation every hour for 90 days
nhr = 24*90
dates, altitudes_deg, radiations = list(), list(), list()
for ihr in range(nhr):
    date = start + datetime.timedelta(hours=ihr)
    altitude_deg = pysolar.solar.get_altitude(lat,lon,date)
    if altitude_deg <= 0:
        radiation = 0.
    else:
        radiation = pysolar.radiation.get_radiation_direct(date,altitude_deg)
    dates.append(date)
    altitudes_deg.append(altitude_deg)
    radiations.append(radiation)

days = [ihr/24 for ihr in range(nhr)]
fig, axs = plt.subplots(nrows=2,ncols=1,sharex=True)
axs[0].plot(days,altitudes_deg)
axs[0].set_title('Solar altitude, degrees')
axs[1].plot(days,radiations)
axs[1].set_title('Solar radiation, W/m2')
axs[1].set_xlabel('Days since ' + start.strftime('%Y/%m/%d %H:%M UTC'))
plt.show()

Altitude and radiation plot

Look at the pysolar docs (http://pysolar.readthedocs.io/en/latest/) under "Estimate of clear sky radiation". The algorithm does not return zeros at night, but instead just plugs those numbers straight in, giving nonsensical values. Filter the results so that if altitude_deg < 0, the radiation is 0. An example just using pysolar, datetime, and pyplot (I don't use pandas, so I can't comment on that) and lists looks like:

import datetime
import matplotlib.pyplot as plt
import pysolar
lat, lon = 39.9075, 116.39723  # Beijing, China
start = datetime.datetime(2018,1,1,8)  # 1 Jan 2018, 0800 UTC

# Calculate radiation every hour for 90 days
nhr = 24*90
dates, altitudes_deg, radiations = list(), list(), list()
for ihr in range(nhr):
    date = start + datetime.timedelta(hours=ihr)
    altitude_deg = pysolar.solar.get_altitude(lat,lon,date)
    if altitude_deg <= 0:
        radiation = 0.
    else:
        radiation = pysolar.radiation.get_radiation_direct(date,altitude_deg)
    dates.append(date)
    altitudes_deg.append(altitude_deg)
    radiations.append(radiation)

days = [ihr/24 for ihr in range(nhr)]
fig, axs = plt.subplots(nrows=2,ncols=1,sharex=True)
axs[0].plot(days,altitudes_deg)
axs[0].set_title('Solar altitude, degrees')
axs[1].plot(days,radiations)
axs[1].set_title('Solar radiation, W/m2')
axs[1].set_xlabel('Days since ' + start.strftime('%Y/%m/%d %H:%M UTC'))

Altitude and radiation plot

Look at the pysolar docs (http://pysolar.readthedocs.io/en/latest/) under "Estimate of clear sky radiation". The algorithm does not return zeros at night, but instead just plugs those numbers straight in, giving nonsensical values. Filter the results so that if altitude_deg < 0, the radiation is 0. An example just using pysolar, datetime, and pyplot (I don't use pandas, so I can't comment on that) and lists looks like:

import datetime
import matplotlib.pyplot as plt
import pysolar
lat, lon = 39.9075, 116.39723  # Beijing, China
timezone = datetime.timezone(datetime.timedelta(hours=8))  # 0800 UTC
start = datetime.datetime(2018,1,1,tzinfo=timezone)  # 1 Jan 2018

# Calculate radiation every hour for 90 days
nhr = 24*90
dates, altitudes_deg, radiations = list(), list(), list()
for ihr in range(nhr):
    date = start + datetime.timedelta(hours=ihr)
    altitude_deg = pysolar.solar.get_altitude(lat,lon,date)
    if altitude_deg <= 0:
        radiation = 0.
    else:
        radiation = pysolar.radiation.get_radiation_direct(date,altitude_deg)
    dates.append(date)
    altitudes_deg.append(altitude_deg)
    radiations.append(radiation)

days = [ihr/24 for ihr in range(nhr)]
fig, axs = plt.subplots(nrows=2,ncols=1,sharex=True)
axs[0].plot(days,altitudes_deg)
axs[0].set_title('Solar altitude, degrees')
axs[1].plot(days,radiations)
axs[1].set_title('Solar radiation, W/m2')
axs[1].set_xlabel('Days since ' + start.strftime('%Y/%m/%d %H:%M UTC'))
plt.show()

Altitude and radiation plot

Source Link
Jareth Holt
  • 1.4k
  • 7
  • 8

Look at the pysolar docs (http://pysolar.readthedocs.io/en/latest/) under "Estimate of clear sky radiation". The algorithm does not return zeros at night, but instead just plugs those numbers straight in, giving nonsensical values. Filter the results so that if altitude_deg < 0, the radiation is 0. An example just using pysolar, datetime, and pyplot (I don't use pandas, so I can't comment on that) and lists looks like:

import datetime
import matplotlib.pyplot as plt
import pysolar
lat, lon = 39.9075, 116.39723  # Beijing, China
start = datetime.datetime(2018,1,1,8)  # 1 Jan 2018, 0800 UTC

# Calculate radiation every hour for 90 days
nhr = 24*90
dates, altitudes_deg, radiations = list(), list(), list()
for ihr in range(nhr):
    date = start + datetime.timedelta(hours=ihr)
    altitude_deg = pysolar.solar.get_altitude(lat,lon,date)
    if altitude_deg <= 0:
        radiation = 0.
    else:
        radiation = pysolar.radiation.get_radiation_direct(date,altitude_deg)
    dates.append(date)
    altitudes_deg.append(altitude_deg)
    radiations.append(radiation)

days = [ihr/24 for ihr in range(nhr)]
fig, axs = plt.subplots(nrows=2,ncols=1,sharex=True)
axs[0].plot(days,altitudes_deg)
axs[0].set_title('Solar altitude, degrees')
axs[1].plot(days,radiations)
axs[1].set_title('Solar radiation, W/m2')
axs[1].set_xlabel('Days since ' + start.strftime('%Y/%m/%d %H:%M UTC'))

Altitude and radiation plot