kylebarron / suncalc-py

A Python port of suncalc.js for calculating sun position and sunlight phases
MIT License
61 stars 9 forks source link

Vectorisation all casts to same datetime #10

Open MLUY opened 1 year ago

MLUY commented 1 year ago

Hi Kyle First of all thanks for this great package! I am having trouble to get the vectorization to work as per your example I have a pandas date frame with a 'Date' column of (datetimes) and a long and lat (floats) When I run the vector operation I am getting a single date back (ref attachment)

What could I be doing wrong?

Thanks a lot Michiel

cast1969

nyooc commented 1 year ago

Michiel, I managed to reproduce your example. The problem is that your date series is TZ-naive and it should be TZ-aware. (And I understand the get_times() API should tell you this...) You can correct it for example by localizing it to a given timezone:

df['Date'] = df['Date'].dt.tz_localize('utc')

If you want a set up a local hourly date series for some place with a non-fixed UTC-offset (think DST changes), you might be better off with initializing your date series right away as a TZ-aware series, something like

df['Date'] = pd.date_range('1979-01-01', '2019-01-01', inclusive='left', freq='H', tz='Europe/Budapest')

Another remark, there will be one sunrise time per local day, so you'll computationally better off if you use a dataset with just a single observation per day.