I'm trying to calculate the hour angle for using the PVLIB's function "pvl.solarposition.hour_angle()".
The code that I'm developing is structured in 02 parts:
- First I'm transforming GPS time (seconds of week) in UTC Time formated in '%Y-%m-%d %H:%M:%S'. The result obtained here is in UTC time because the GPS time is refering in UTC.
- On second part I try to calculate the hour angle using PVLIB and on this part I'm having problems.
When I'll run the hour angle the python is returning the an error message:
"naive_times = times.tz_localize(None) # naive but still localized AttributeError: 'str' object has no attribute 'tz_localize".
I know that this erros is about the class for variable "final_time" on the code implemented. According the PVLIB documentation this variable is need stay on class pandas.DatetimeIndex (https://pvlib-python.readthedocs.io/en/latest/generated/pvlib.solarposition.hour_angle.html) and I dont know transform correctly the GPS time to this class and then, use this result on the PVLIB to compute the hour angle.
Bellow follow part of algorithm that I'm using here on the tests:
import datetime
import pvlib as pvl
t_gps = 138088.886582 #seconds of week
lat = -23.048576 # degress
long = -46.305043 # degrees
## Transfomring the GPS time (seconds of week) in Date Time
## The result printed here is in UTC time because the GPS time is refered in UTC Time.
datetimeformat = ('%Y-%m-%d %H:%M:%S')
leapsecond = 37
epoch = datetime.datetime.strptime ( "1980-01-06 00:00:00" , datetimeformat)
decorrido = datetime.timedelta( days = (2024 * 7 ), seconds = t_gps + leapsecond)
final_time = datetime.datetime.strftime(epoch + decorrido, datetimeformat)
print(final_time)
print(type(final_time))
## Calculating the hour angle using PVLIB
solar_declin = pvl.solarposition.declination_spencer71(295)
print(solar_declin)
eq_time = pvl.solarposition.equation_of_time_pvcdrom(295)
print(eq_time)
hour_angle = pvl.solarposition.hour_angle(final_time, long, eq_time)
print(hour_angle)
For this problem my questions are:
How may I transform GPS time (seconds of week) to the format '%Y-%m-%d %H:%M:%S' and on the class pandas.DatetimeIndex?
- How the result after the GPS time transformation is in UTC time, I need convert to the local time first and transform again for UTC time including the tz_localize?