@@ -342,40 +342,36 @@ def ephemeris(time, location, pressure=101325, temperature=12):
342
342
SunAz = np .degrees (np .arctan2 (- 1 * np .sin (HrAngleR ), np .cos (LatR ) *
343
343
(np .tan (DecR )) - np .sin (LatR )* (np .cos (HrAngleR ))))
344
344
SunAz [SunAz < 0 ] += 360
345
- # potential error in the following line
346
- SunEl = np .degrees (np .arcsin ((np .cos (LatR ) * (np .cos (DecR )) *
347
- (np .cos (HrAngleR )) + np .sin (LatR )* (np .sin (DecR )))))
348
-
345
+
346
+ SunEl = np .degrees (np .arcsin (
347
+ np .cos (LatR ) * np .cos (DecR ) * np .cos (HrAngleR ) +
348
+ np .sin (LatR ) * np .sin (DecR ) ))
349
+
349
350
SolarTime = (180 + HrAngle ) / 15.
350
351
351
352
# Calculate refraction correction
352
- # replace with conditional array assignment
353
- Refract = []
354
- for Elevation in SunEl :
355
- TanEl = np .tan (np .radians (Elevation ))
356
- if Elevation > 5 and Elevation <= 85 :
357
- Refract .append ((58.1 / float (TanEl ) - 0.07 / float (TanEl ** 3 ) +
358
- 8.6e-05 / float (TanEl ** 5 )))
359
- elif Elevation > - 0.575 and Elevation <= 5 :
360
- Refract .append ((Elevation * ((- 518.2 + Elevation *
361
- ((103.4 + Elevation * ((- 12.79 + Elevation *
362
- (0.711 ))))))) + 1735 ))
363
- elif Elevation > - 1 and Elevation <= - 0.575 :
364
- Refract .append (- 20.774 / float (TanEl ))
365
- else :
366
- Refract .append (0 )
367
-
368
- Refract = (np .array (Refract ) * ((283 / (273. + temperature ))) *
369
- pressure / 101325. / 3600. )
370
-
371
- SunZen = 90 - SunEl
353
+ Elevation = SunEl
354
+ TanEl = pd .Series (np .tan (np .radians (Elevation )), index = time_utc )
355
+ Refract = pd .Series (0 , index = time_utc )
356
+
357
+ Refract [(Elevation > 5 ) & (Elevation <= 85 )] = (
358
+ 58.1 / TanEl - 0.07 / (TanEl ** 3 ) + 8.6e-05 / (TanEl ** 5 ))
359
+
360
+ Refract [(Elevation > - 0.575 ) & (Elevation <= 5 )] = ( Elevation *
361
+ (- 518.2 + Elevation * (103.4 + Elevation * (- 12.79 + Elevation * 0.711 ))) +
362
+ 1735 )
363
+
364
+ Refract [(Elevation > - 1 ) & (Elevation <= - 0.575 )] = - 20.774 / TanEl
365
+
366
+ Refract *= (283 / (273. + temperature )) * (pressure / 101325. ) / 3600.
372
367
373
368
ApparentSunEl = SunEl + Refract
374
369
370
+ # make output DataFrame
375
371
DFOut = pd .DataFrame (index = time_utc ).tz_convert (location .tz )
376
372
DFOut ['elevation' ] = SunEl
377
373
DFOut ['azimuth' ] = SunAz
378
- DFOut ['zenith' ] = SunZen
374
+ DFOut ['zenith' ] = 90 - SunEl
379
375
DFOut ['apparent_elevation' ] = ApparentSunEl
380
376
DFOut ['apparent_zenith' ] = 90 - ApparentSunEl
381
377
DFOut ['solar_time' ] = SolarTime
0 commit comments