I am trying to calculate the exact amount of daylight hours for a given day and location. I have been looking at the python module "Ephem" for the sunrise and set calculation. Here is the code below:
import ephem
California_forest = ephem.Observer()
California_forest.date = '2001/01/01 00:00'
California_forest.pressure = 0
California_forest.horizon = '-0:34'
California_forest.lat, California_forest.lon = '38.89525', '-120.63275'
California_forest.altitude = 1280
print(California_forest.previous_rising(ephem.Sun()))
2000/12/31 15:21:06
print(California_forest.previous_rising(ephem.Sun()))
2001/1/1 00:50:46
The module works just fine like its tutorial showed. However, I thought you could save the "sunrise" and "sunset" output as a string. When I saved the calculation to a variable, it gives me a floating number that I dont understand:
sunrise = California_forest.previous_rising(ephem.Sun())
sunrise
36890.13965508334
sunset = California_forest.next_setting(ephem.Sun())
sunset
36890.53525430675
I was expecting a string that was the same as the print statement output, but I was mistaken. Does anyone have a suggestion as to how I can use these outputs and calculate the amount of daylight hours for a given location? It would be greatly appreciated!
print(repr(sunrise))
, what if youprint(sunrise)
and what if youprint(type(sunrise))
?