def shading_losses(H, C, data): # Calculate solar radiation: i_s = np.argsort(H.gamma) horizon = interp1d(H.gamma[i_s], H.alpha[i_s], kind='linear', bounds_error=False, fill_value=0) Q_unsh, Q_sh = [], [] Q_m_unsh, Q_m_sh = np.arange(12), np.arange(12) #data.set_time(t) print('\n Calculating daily shading losses:', end=' ') for n in range(1, 366): S = th.solar_day(n, H.L, C) D = data.day_data(n) day = D['time'][0].date() g_sh = np.copy(D['g']) for i in range(len(g_sh)): if (pi / 2 - S.theta_z[i]) <= horizon(S.gamma_s[i]): g_sh[i] = D['g_d'][i] q_unshaded = S.G_T_HDKR(D['g'], D['g_d']) # W/m2 on the collector surface q_shaded = S.G_T_HDKR(g_sh, D['g_d']) W_to_MJ = 60.0 / 1000000 Q_unsh.append(((np.sum(q_unshaded) * W_to_MJ), day.month)) #date())) # Day total radation in MJ Q_sh.append(((np.sum(q_shaded) * W_to_MJ), day.month)) # Day total radation in MJ # Print out n as update... if day.day == 1: print('\n %s: %s' % (calendar.month_abbr[day.month], day.day), end=' ') else: print(day.day, end=' ') sys.stdout.flush() # Final report of shading losses: print('\n\n Monthly totals for shading losses:') for m in range(12): Q_m_unsh[m] = sum(q[0] for q in Q_unsh if q[1] == m + 1) Q_m_sh[m] = sum(q[0] for q in Q_sh if q[1] == m + 1) loss = 100.0 * (Q_m_unsh[m] - Q_m_sh[m]) / Q_m_unsh[m] print(' %s: %0.1f MJ - %0.1f MJ = %0.1f%% loss' % (calendar.month_abbr[m + 1], Q_m_unsh[m], Q_m_sh[m], loss)) fig2 = plt.figure(2) ax2 = fig2.add_axes([0.1, 0.1, 0.8, 0.8]) plot_losses(ax2, Q_m_unsh, Q_m_sh) plt.draw()
def plot_sunpath(ax, L, C): '''Plot sun path for given location, L, and collector, C''' ax.set_theta_zero_location('S') ax.set_theta_direction( 'counterclockwise') # Looking up at the sky, West is right ax.set_thetagrids([0, 45, 90, 135, 180, 225, 270, 315], ['S', 'SE', 'E', 'NE', 'N', 'NW', 'W', 'SW']) n_sum = date(2011, 6, 21).timetuple()[-2] # n for summer solstice n_win = date(2011, 12, 21).timetuple()[-2] # n for winter solstice n_range = np.rint(np.arange(n_sum, n_win, (n_win - n_sum - 0.1) / 6.0)) t_range = np.array(range(600, 1801, 100)) #[600,700,800,900,1200,1500,1800]) t_range = np.array([ datetime(2000, 1, 1) + timedelta(hours=h) for h in [6, 7, 8, 9, 12, 15, 18] ]) print(t_range) t_gamma, t_theta = [], [] for n in n_range: # Plot lines for each month between solstices sday = th.solar_day(n, L, C) if n == n_range[0]: summer = sday elif n == n_range[-1]: winter = sday ax.plot(sday.gamma_s, np.rad2deg(sday.theta_z), 'orange') t_gamma.append(sday.gamma_s[np.searchsorted(sday.time, t_range)]) #print(t_gamma) t_theta.append(sday.theta_z[np.searchsorted(sday.time, t_range)]) #t_gamma.append(sday.gamma_s[sday.i(t_range)]) #t_theta.append(sday.theta_z[sday.i(t_range)]) f_i = interp1d(winter.gamma_s, np.rad2deg(winter.theta_z), kind='linear', bounds_error=False, fill_value=0) f_e = extrap1d(f_i) ax.fill_between(summer.gamma_s, np.rad2deg(summer.theta_z), f_e(summer.gamma_s), facecolor='yellow', alpha=0.5) t_gamma = np.array(t_gamma) t_theta = np.array(t_theta) for t in range(len(t_range)): # Plot lines for each hour of the day x = np.array([t_gamma[n, t] for n in range(len(n_range))]) y = np.array([t_theta[n, t] for n in range(len(n_range))]) print(x, y) ax.plot(x, np.rad2deg(y), 'orange') ax.set_rmax(90)
def shading_losses(H, C, data): # Calculate solar radiation: i_s = np.argsort(H.gamma) horizon = interp1d(H.gamma[i_s], H.alpha[i_s], kind="linear", bounds_error=False, fill_value=0) Q_unsh, Q_sh = [], [] Q_m_unsh, Q_m_sh = np.arange(12), np.arange(12) # data.set_time(t) print("\n Calculating daily shading losses:", end=" ") for n in range(1, 366): S = th.solar_day(n, H.L, C) D = data.day_data(n) day = D["time"][0].date() g_sh = np.copy(D["g"]) for i in range(len(g_sh)): if (pi / 2 - S.theta_z[i]) <= horizon(S.gamma_s[i]): g_sh[i] = D["g_d"][i] q_unshaded = S.G_T_HDKR(D["g"], D["g_d"]) # W/m2 on the collector surface q_shaded = S.G_T_HDKR(g_sh, D["g_d"]) W_to_MJ = 60.0 / 1000000 Q_unsh.append(((np.sum(q_unshaded) * W_to_MJ), day.month)) # date())) # Day total radation in MJ Q_sh.append(((np.sum(q_shaded) * W_to_MJ), day.month)) # Day total radation in MJ # Print out n as update... if day.day == 1: print("\n %s: %s" % (calendar.month_abbr[day.month], day.day), end=" ") else: print(day.day, end=" ") sys.stdout.flush() # Final report of shading losses: print("\n\n Monthly totals for shading losses:") for m in range(12): Q_m_unsh[m] = sum(q[0] for q in Q_unsh if q[1] == m + 1) Q_m_sh[m] = sum(q[0] for q in Q_sh if q[1] == m + 1) loss = 100.0 * (Q_m_unsh[m] - Q_m_sh[m]) / Q_m_unsh[m] print(" %s: %0.1f MJ - %0.1f MJ = %0.1f%% loss" % (calendar.month_abbr[m + 1], Q_m_unsh[m], Q_m_sh[m], loss)) fig2 = plt.figure(2) ax2 = fig2.add_axes([0.1, 0.1, 0.8, 0.8]) plot_losses(ax2, Q_m_unsh, Q_m_sh) plt.draw()
def plot_sunpath(ax, L, C): """Plot sun path for given location, L, and collector, C""" ax.set_theta_zero_location("S") ax.set_theta_direction("counterclockwise") # Looking up at the sky, West is right ax.set_thetagrids([0, 45, 90, 135, 180, 225, 270, 315], ["S", "SE", "E", "NE", "N", "NW", "W", "SW"]) n_sum = date(2011, 6, 21).timetuple()[-2] # n for summer solstice n_win = date(2011, 12, 21).timetuple()[-2] # n for winter solstice n_range = np.rint(np.arange(n_sum, n_win, (n_win - n_sum - 0.1) / 6.0)) t_range = np.array(range(600, 1801, 100)) # [600,700,800,900,1200,1500,1800]) t_range = np.array([datetime(2000, 1, 1) + timedelta(hours=h) for h in [6, 7, 8, 9, 12, 15, 18]]) print(t_range) t_gamma, t_theta = [], [] for n in n_range: # Plot lines for each month between solstices sday = th.solar_day(n, L, C) if n == n_range[0]: summer = sday elif n == n_range[-1]: winter = sday ax.plot(sday.gamma_s, np.rad2deg(sday.theta_z), "orange") t_gamma.append(sday.gamma_s[np.searchsorted(sday.time, t_range)]) # print(t_gamma) t_theta.append(sday.theta_z[np.searchsorted(sday.time, t_range)]) # t_gamma.append(sday.gamma_s[sday.i(t_range)]) # t_theta.append(sday.theta_z[sday.i(t_range)]) f_i = interp1d(winter.gamma_s, np.rad2deg(winter.theta_z), kind="linear", bounds_error=False, fill_value=0) f_e = extrap1d(f_i) ax.fill_between(summer.gamma_s, np.rad2deg(summer.theta_z), f_e(summer.gamma_s), facecolor="yellow", alpha=0.5) t_gamma = np.array(t_gamma) t_theta = np.array(t_theta) for t in range(len(t_range)): # Plot lines for each hour of the day x = np.array([t_gamma[n, t] for n in range(len(n_range))]) y = np.array([t_theta[n, t] for n in range(len(n_range))]) print(x, y) ax.plot(x, np.rad2deg(y), "orange") ax.set_rmax(90)