Skip to content

Commit ae442e0

Browse files
committed
Add solar position test data and refactor time and angle calculations
1 parent 6887c61 commit ae442e0

File tree

11 files changed

+259
-141
lines changed

11 files changed

+259
-141
lines changed

data/meta.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"spa-test-data-1": {
3+
"latitude": 39.743,
4+
"longitude": -105.178,
5+
"timezone": "UTC-7",
6+
"name": "NREL",
7+
"pressure": 835.8,
8+
"temperature": 10.0,
9+
"dUT1": 0.0,
10+
"dTT": 64.797
11+
}
12+
}

data/spa-test-data-1.csv

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
Date (M/D/YYYY),Time (H:MM:SS),Topocentric zenith angle,Top. azimuth angle (westward from S),Geocentric sun right ascension,Geocentric sun declination,Observer hour angle,Topocentric sun declination,Topocentric sun right ascension,Topocentric local hour angle,Equation of time
2+
2/10/2020,0:00:00,154.545205,171.580893,323.380105,-14.497823,176.273126,-14.498872,323.379977,176.273254,-14.192253
3+
2/10/2020,1:00:00,152.877843,204.528740,323.421375,-14.484359,191.272924,-14.485417,323.421760,191.272540,-14.193061
4+
2/10/2020,2:00:00,145.831804,229.739939,323.462639,-14.470889,206.272728,-14.471986,323.463511,206.271857,-14.193846
5+
2/10/2020,3:00:00,135.992165,246.833022,323.503898,-14.457411,221.272538,-14.458578,323.505197,221.271239,-14.194608
6+
2/10/2020,4:00:00,124.956008,259.313870,323.545151,-14.443927,236.272353,-14.445188,323.546788,236.270715,-14.195349
7+
2/10/2020,5:00:00,113.481597,269.551345,323.586398,-14.430435,251.272173,-14.431808,323.588263,251.270308,-14.196066
8+
2/10/2020,6:00:00,101.984309,278.890616,323.627640,-14.416936,266.271999,-14.418431,323.629605,266.270034,-14.196762
9+
2/10/2020,7:00:00,90.271221,288.200086,323.668876,-14.403431,281.271831,-14.405049,323.670807,281.269900,-14.197435
10+
2/10/2020,8:00:00,80.093696,298.173365,323.710107,-14.389918,296.271668,-14.391654,323.711872,296.269903,-14.198086
11+
2/10/2020,9:00:00,70.538250,309.466054,323.751332,-14.376399,311.271511,-14.378237,323.752811,311.270031,-14.198715
12+
2/10/2020,10:00:00,62.529806,322.690110,323.792551,-14.362873,326.271359,-14.364792,323.793644,326.270266,-14.199322
13+
2/10/2020,11:00:00,56.816881,338.185524,323.833765,-14.349339,341.271213,-14.351313,323.834397,341.270581,-14.199906
14+
2/10/2020,12:00:00,54.173006,355.543695,323.874974,-14.335799,356.271072,-14.337796,323.875102,356.270944,-14.200468
15+
2/10/2020,13:00:00,55.057694,13.354182,323.916176,-14.322252,11.270938,-14.324241,323.915792,11.271322,-14.201008
16+
2/10/2020,14:00:00,59.308293,29.909722,323.957374,-14.308698,26.270808,-14.310647,323.956503,26.271679,-14.201526
17+
2/10/2020,15:00:00,66.257380,44.277824,323.998565,-14.295137,41.270684,-14.297017,323.997267,41.271982,-14.202022
18+
2/10/2020,16:00:00,75.115609,56.486959,324.039751,-14.281570,56.270566,-14.283357,324.038115,56.272202,-14.202495
19+
2/10/2020,17:00:00,85.175473,67.059713,324.080932,-14.267995,71.270453,-14.269672,324.079069,71.272316,-14.202947
20+
2/10/2020,18:00:00,96.257091,76.643297,324.122107,-14.254414,86.270346,-14.255970,324.120144,86.272309,-14.203376
21+
2/10/2020,19:00:00,107.636331,85.905848,324.163276,-14.240825,101.270244,-14.242260,324.161347,101.272173,-14.203783
22+
2/10/2020,20:00:00,119.147022,95.606166,324.204440,-14.227230,116.270148,-14.228549,324.202676,116.271911,-14.204168
23+
2/10/2020,21:00:00,130.441283,106.802270,324.245599,-14.213628,131.270057,-14.214846,324.244120,131.271535,-14.204531
24+
2/10/2020,22:00:00,140.968202,121.265125,324.286751,-14.200019,146.269972,-14.201157,324.285659,146.271064,-14.204872
25+
2/10/2020,23:00:00,149.620163,142.007513,324.327899,-14.186403,161.269892,-14.187487,324.327267,161.270523,-14.205191
26+
2/11/2020,0:00:00,154.221986,171.660475,324.369040,-14.172781,176.269818,-14.173842,324.368913,176.269945,-14.205488
27+
2/11/2020,1:00:00,152.571640,204.289676,324.410177,-14.159151,191.269749,-14.160221,324.410561,191.269365,-14.205763
28+
2/11/2020,2:00:00,145.574271,229.387021,324.451308,-14.145515,206.269686,-14.146624,324.452178,206.268815,-14.206016
29+
2/11/2020,3:00:00,135.771239,246.489557,324.492433,-14.131872,221.269628,-14.133049,324.493730,221.268331,-14.206247
30+
2/11/2020,4:00:00,124.753998,259.002520,324.533553,-14.118222,236.269576,-14.119491,324.535188,236.267941,-14.206456
31+
2/11/2020,5:00:00,113.285255,269.267989,324.574667,-14.104566,251.269529,-14.105944,324.576528,251.267667,-14.206644
32+
2/11/2020,6:00:00,101.783867,278.627835,324.615776,-14.090903,266.269487,-14.092400,324.617737,266.267526,-14.206809
33+
2/11/2020,7:00:00,90.088722,287.952555,324.656879,-14.077232,281.269452,-14.078850,324.658807,281.267524,-14.206952
34+
2/11/2020,8:00:00,79.863751,297.939834,324.697977,-14.063556,296.269421,-14.065288,324.699739,296.267659,-14.207074
35+
2/11/2020,9:00:00,70.282125,309.251824,324.739069,-14.049872,311.269396,-14.051705,324.740546,311.267919,-14.207173
36+
2/11/2020,10:00:00,62.244758,322.510640,324.780156,-14.036182,326.269377,-14.038094,324.781247,326.268286,-14.207251
37+
2/11/2020,11:00:00,56.505390,338.067897,324.821237,-14.022485,341.269363,-14.024450,324.821868,341.268732,-14.207307
38+
2/11/2020,12:00:00,53.846935,355.516666,324.862313,-14.008781,356.269354,-14.010769,324.862441,356.269226,-14.207341
39+
2/11/2020,13:00:00,54.736020,13.425762,324.903384,-13.995070,11.269351,-13.997050,324.903000,11.269735,-14.207353
40+
2/11/2020,14:00:00,59.007458,30.059274,324.944449,-13.981353,26.269354,-13.983294,324.943579,26.270223,-14.207344
41+
2/11/2020,15:00:00,65.984519,44.475231,324.985508,-13.967629,41.269361,-13.969503,324.984213,41.270657,-14.207313
42+
2/11/2020,16:00:00,74.870054,56.710561,325.026562,-13.953898,56.269375,-13.955681,325.024929,56.271008,-14.207260
43+
2/11/2020,17:00:00,84.955699,67.299421,325.067611,-13.940161,71.269393,-13.941836,325.065751,71.271254,-14.207185
44+
2/11/2020,18:00:00,96.047808,76.897313,325.108654,-13.926417,86.269417,-13.927975,325.106694,86.271377,-14.207088
45+
2/11/2020,19:00:00,107.434878,86.177516,325.149692,-13.912666,101.269447,-13.914105,325.147766,101.271373,-14.206970
46+
2/11/2020,20:00:00,118.944666,95.901900,325.190725,-13.898909,116.269482,-13.900234,325.188964,116.271243,-14.206830
47+
2/11/2020,21:00:00,130.226693,107.128514,325.231752,-13.885145,131.269522,-13.886371,325.230276,131.270998,-14.206669
48+
2/11/2020,22:00:00,140.725830,121.616633,325.272773,-13.871374,146.269568,-13.872522,325.271683,146.270659,-14.206486
49+
2/11/2020,23:00:00,149.332706,142.321771,325.313789,-13.857596,161.269619,-13.858693,325.313159,161.270250,-14.206281
50+
2/12/2020,0:00:00,153.895172,171.746156,325.354800,-13.843812,176.269676,-13.844886,325.354672,176.269804,-14.206055
51+
2/12/2020,1:00:00,152.260338,204.059000,325.395805,-13.830022,191.269738,-13.831104,325.396189,191.269354,-14.205806
52+
2/12/2020,2:00:00,145.310766,229.038909,325.436805,-13.816225,206.269805,-13.817345,325.437674,206.268937,-14.205537
53+
2/12/2020,3:00:00,135.544377,246.147776,325.477800,-13.802421,221.269878,-13.803608,325.479094,221.268583,-14.205246
54+
2/12/2020,4:00:00,124.546361,258.691349,325.518789,-13.788610,236.269956,-13.789887,325.520421,236.268324,-14.204933
55+
2/12/2020,5:00:00,113.083600,268.984140,325.559773,-13.774793,251.270040,-13.776176,325.561631,251.268181,-14.204599
56+
2/12/2020,6:00:00,101.578368,278.364258,325.600751,-13.760969,266.270129,-13.762469,325.602709,266.268171,-14.204243
57+
2/12/2020,7:00:00,89.901067,287.704110,325.641724,-13.747139,281.270223,-13.748757,325.643649,281.268299,-14.203866
58+
2/12/2020,8:00:00,79.629025,297.705410,325.682692,-13.733302,296.270323,-13.735032,325.684451,296.268563,-14.203467
59+
2/12/2020,9:00:00,70.021311,309.036923,325.723654,-13.719459,311.270428,-13.721286,325.725129,311.268953,-14.203047
60+
2/12/2020,10:00:00,61.955070,322.331125,325.764611,-13.705609,326.270538,-13.707514,325.765700,326.269449,-14.202605
61+
2/12/2020,11:00:00,56.189404,337.951535,325.805563,-13.691752,341.270654,-13.693709,325.806193,341.270024,-14.202142
62+
2/12/2020,12:00:00,53.516814,355.492891,325.846509,-13.677889,356.270775,-13.679869,325.846636,356.270648,-14.201657
63+
2/12/2020,13:00:00,54.411147,13.502467,325.887450,-13.664020,11.270902,-13.665991,325.887066,11.271285,-14.201151
64+
2/12/2020,14:00:00,58.704460,30.214836,325.928385,-13.650143,26.271034,-13.652077,325.927517,26.271902,-14.200624
65+
2/12/2020,15:00:00,65.710389,44.678603,325.969315,-13.636261,41.271171,-13.638128,325.968022,41.272465,-14.200075
66+
2/12/2020,16:00:00,74.623825,56.939691,326.010240,-13.622372,56.271314,-13.624151,326.008609,56.272945,-14.199505
67+
2/12/2020,17:00:00,84.735321,67.544198,326.051160,-13.608476,71.271461,-13.610150,326.049303,71.273319,-14.198913
68+
2/12/2020,18:00:00,95.838301,77.156055,326.092074,-13.594574,86.271614,-13.596133,326.090117,86.273571,-14.198301
69+
2/12/2020,19:00:00,107.233096,86.453709,326.132983,-13.580665,101.271773,-13.582108,326.131060,101.273696,-14.197666
70+
2/12/2020,20:00:00,118.741678,96.202056,326.173887,-13.566750,116.271937,-13.568082,326.172129,116.273695,-14.197011
71+
2/12/2020,21:00:00,130.010963,107.459064,326.214785,-13.552828,131.272106,-13.554064,326.213311,131.273579,-14.196334
72+
2/12/2020,22:00:00,140.481606,121.972081,326.255678,-13.538900,146.272281,-13.540059,326.254589,146.273369,-14.195636
73+
2/12/2020,23:00:00,149.042603,142.639478,326.296566,-13.524966,161.272460,-13.526074,326.295936,161.273090,-14.194917
74+
2/13/2020,0:00:00,153.564854,171.837581,326.337448,-13.511025,176.272645,-13.512111,326.337321,176.272773,-14.194177
75+
2/13/2020,1:00:00,151.944080,203.836542,326.378325,-13.497077,191.272836,-13.498171,326.378708,191.272453,-14.193415
76+
2/13/2020,2:00:00,145.041425,228.695692,326.419197,-13.483123,206.273032,-13.484255,326.420064,206.272164,-14.192632
77+
2/13/2020,3:00:00,135.311690,245.807820,326.460063,-13.469163,221.273233,-13.470360,326.461356,221.271940,-14.191828
78+
2/13/2020,4:00:00,124.333197,258.380477,326.500925,-13.455196,236.273439,-13.456481,326.502554,236.271809,-14.191003
79+
2/13/2020,5:00:00,112.876730,268.699890,326.541781,-13.441223,251.273650,-13.442612,326.543636,251.271795,-14.190157
80+
2/13/2020,6:00:00,101.367911,278.099955,326.582631,-13.427243,266.273867,-13.428746,326.584586,266.271912,-14.189289
81+
2/13/2020,7:00:00,89.707671,287.454798,326.623477,-13.413257,281.274090,-13.414875,326.625398,281.272168,-14.188401
82+
2/13/2020,8:00:00,79.389628,297.470119,326.664317,-13.399265,296.274317,-13.400992,326.666074,296.272560,-14.187491
83+
2/13/2020,9:00:00,69.755922,308.821357,326.705152,-13.385266,311.274550,-13.387089,326.706624,311.273077,-14.186560
84+
2/13/2020,10:00:00,61.660855,322.151548,326.745981,-13.371261,326.274788,-13.373159,326.747069,326.273700,-14.185608
85+
2/13/2020,11:00:00,55.869031,337.836418,326.786806,-13.357250,341.275031,-13.359198,326.787435,341.274402,-14.184635
86+
2/13/2020,12:00:00,53.182751,355.472363,326.827625,-13.343232,356.275279,-13.345202,326.827752,356.275152,-14.183641
87+
2/13/2020,13:00:00,54.083183,13.584301,326.868439,-13.329208,11.275533,-13.331170,326.868056,11.275916,-14.182626
88+
2/13/2020,14:00:00,58.399403,30.376392,326.909248,-13.315177,26.275792,-13.317103,326.908381,26.276659,-14.181590
89+
2/13/2020,15:00:00,65.435082,44.887891,326.950051,-13.301141,41.276056,-13.303002,326.948759,41.277348,-14.180533
90+
2/13/2020,16:00:00,74.376995,57.174272,326.990849,-13.287097,56.276326,-13.288872,326.989221,56.277954,-14.179455
91+
2/13/2020,17:00:00,84.514413,67.793948,327.031642,-13.273048,71.276601,-13.274720,327.029788,71.278455,-14.178356
92+
2/13/2020,18:00:00,95.628602,77.419416,327.072430,-13.258992,86.276881,-13.260552,327.070477,86.278834,-14.177236
93+
2/13/2020,19:00:00,107.031000,86.734302,327.113213,-13.244930,101.277166,-13.246377,327.111293,101.279086,-14.176096
94+
2/13/2020,20:00:00,118.538065,96.506488,327.153990,-13.230862,116.277456,-13.232201,327.152235,116.279211,-14.174934
95+
2/13/2020,21:00:00,129.794092,107.793737,327.194762,-13.216787,131.277752,-13.218032,327.193292,131.279223,-14.173751
96+
2/13/2020,22:00:00,140.235533,122.331225,327.235529,-13.202706,146.278053,-13.203876,327.234443,146.279139,-14.172548
97+
2/13/2020,23:00:00,148.749888,142.960327,327.276291,-13.188619,161.278359,-13.189739,327.275663,161.278987,-14.171323

src/Basic/Basic.jl

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function PositionInterface.sunpos(algorithm::BasicAlgorithm, timestamp::ZonedDat
4646
# equation of time from [deg] to [h], 360 deg = 24 h
4747
E_qt = equation_of_time(timestamp) * 24us"h" / 360us"deg"
4848
println("Timestamp: ", timestamp)
49-
println("E_qt: ", E_qt)
49+
println("E_qt: ", E_qt * 60us"min/h")
5050
println("T_local: ", T_local)
5151
println("λ_LSTM: ", λ_LSTM)
5252
println("λ_local: ", λ_local)
@@ -61,15 +61,21 @@ function PositionInterface.sunpos(algorithm::BasicAlgorithm, timestamp::ZonedDat
6161
H = 15us"deg/h" * (12us"h" - T_solar)
6262
println("H: ", H)
6363

64-
# solar elevation angle [deg]
65-
α = asind(sind(β.value) * sind(ϕ_local.value) +
66-
cosd(β.value) * cosd(ϕ_local.value) * cosd(H.value))
67-
68-
# solar azimuth angle [deg]
69-
A = acosd((sind(β.value) * cosd(ϕ_local.value) -
70-
cosd(β.value) * sind(ϕ_local.value) * cosd(H.value)) / cosd(α))
7164
return (
72-
Quantity(α, SymbolicDimensions, deg = 1), Quantity(A, SymbolicDimensions, deg = 1))
65+
Quantity(0.0, SymbolicDimensions, deg = 1),
66+
Quantity(0.0, SymbolicDimensions, deg = 1))
67+
68+
# # solar zenith angle [deg]
69+
# θ_z = acosd(sind(ϕ_local.value) * sind(β.value) +
70+
# cosd(ϕ_local.value) * cosd(β.value) * cosd(H.value))
71+
# println("θ_z: ", θ_z)
72+
73+
# # solar azimuth angle [deg]
74+
# θ_a = atan2d(sind(H.value),
75+
# cosd(H.value) * sind(ϕ_local.value) - tand(β.value) * cosd(ϕ_local.value))
76+
# return (
77+
# Quantity(θ_z, SymbolicDimensions, deg = 1),
78+
# Quantity(A, SymbolicDimensions, deg = 1))
7379
end
7480

7581
algorithm = BasicAlgorithm(Location(latitude = 0.0, longitude = 0.0))

src/PositionInterface/PositionInterface.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ using TimeZones
88

99
export SolarPositionInterface, SolarPositionAlgorithm, sunpos
1010

11-
include("time.jl")
12-
include("angles.jl")
11+
include("time_angles.jl")
1312

1413
abstract type SolarPositionAlgorithm end
1514

src/PositionInterface/angles.jl

Lines changed: 0 additions & 28 deletions
This file was deleted.
Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export equation_of_time, offset_hours, standard_time, fractional_hour
1+
export equation_of_time, offset_hours, standard_time, fractional_hour, declination
22

33
"""
44
equation_of_time(t::Union{Number, DateTime})
@@ -77,4 +77,38 @@ function fractional_hour(t::DateTime)
7777
dt = t - floor(t, Hour(24))
7878
return Float64(dt.value) / (60 * 60 * 1000)
7979
end
80-
fractional_hour(t::ZonedDateTime) = fractional_hour(DateTime(t))
80+
fractional_hour(t::ZonedDateTime) = fractional_hour(DateTime(t))
81+
82+
"""
83+
declination(t::Union{Number, DateTime})
84+
85+
Compute the declination angle [1] of the Sun [deg] at the time `t`, which can be
86+
represented by the day of the year (`Float`) or `DateTime`.
87+
88+
The output is a `Quantity` with the unit of degrees.
89+
90+
# References
91+
92+
- **[1]** pveducation. Declination angle. URL: https://www.pveducation.org/pvcdrom/properties-of-sunlight/declination-angle.
93+
"""
94+
function declination(d::Number)
95+
(0 <= d <= 365) || throw(ArgumentError("day of the year must be in the range [0, 365]"))
96+
δ = -23.45cosd((360 / 365) * (d + 10))
97+
return Quantity(δ, SymbolicDimensions, deg = 1)
98+
end
99+
100+
"""
101+
declination(t::DateTime)
102+
103+
Convert `t` to the day of the year and compute the declination angle.
104+
"""
105+
declination(t::DateTime) = declination(datetime2julian(t) -
106+
datetime2julian(DateTime(year(t), 1, 1)))
107+
declination(t::ZonedDateTime) = declination(DateTime(t))
108+
109+
"""
110+
local_time(t::DateTime)
111+
112+
Convert `t` to the local time in hours as a fraction x/24, where x is the number of hours.
113+
"""
114+
local_time(t::DateTime) = (hour(t) + minute(t) / 60 + second(t) / 3600) / 24

test/Project.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
[deps]
2+
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
3+
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
24
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
35
DynamicQuantities = "06fc5a27-2a28-4c7c-a15d-362465fb6821"
46
Interfaces = "85a1e053-f937-4924-92a5-1367d23b7b87"
7+
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
58
PVSimBase = "2810a8f8-ed9d-50a5-b7a6-1da2da8222f3"
69
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
710
TimeZones = "f269a46b-ccf7-5d73-abea-4c690281aa53"

test/test-angles.jl

Lines changed: 0 additions & 35 deletions
This file was deleted.

test/test-interfaces.jl

Lines changed: 0 additions & 35 deletions
This file was deleted.

test/test-time.jl

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)