Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/solposx/solarposition/iqbal.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def iqbal(times, latitude, longitude):
"""
times_utc = _pandas_to_utc(times)

dayofyear = times_utc.dayofyear
dayofyear = np.asarray(times_utc.dayofyear)
day_angle = 2 * np.pi * (dayofyear - 1) / 365 # [radians]

declination = (
Expand Down
6 changes: 3 additions & 3 deletions src/solposx/solarposition/michalsky.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ def michalsky(
hour = _fractional_hour(times_utc)

if julian_date == "original":
year = times_utc.year
day = times_utc.dayofyear
year = np.asarray(times_utc.year)
day = np.asarray(times_utc.dayofyear)
delta = year - 1949
leap = np.floor(delta / 4)
jd = 2432916.5 + delta * 365 + leap + day + hour / 24
elif julian_date == "pandas":
jd = times_utc.to_julian_date()
jd = np.asarray(times_utc.to_julian_date())
else:
raise ValueError("`julian_date` has to be either `original` or `pandas`.")

Expand Down
2 changes: 1 addition & 1 deletion src/solposx/solarposition/noaa.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def noaa(times, latitude, longitude, *, delta_t=67.0):
https://maia.usno.navy.mil/products/deltaT
"""
times_utc = _pandas_to_utc(times)
julian_date = times_utc.to_julian_date()
julian_date = np.asarray(times_utc.to_julian_date())
jc = (julian_date - 2451545) / 36525

# Allow for latitude of -90 and 90 on Ubunty and MacOS
Expand Down
8 changes: 4 additions & 4 deletions src/solposx/solarposition/psa.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,12 @@ def psa(times, latitude, longitude, *, coefficients=2020):

time_utc = _pandas_to_utc(times)

year = time_utc.year
month = time_utc.month
day = time_utc.day
year = np.asarray(time_utc.year)
month = np.asarray(time_utc.month)
day = np.asarray(time_utc.day)
hour = _fractional_hour(time_utc)

month_term = ((time_utc.month - 14) / 12).values.astype(int)
month_term = ((month - 14) / 12).astype(int)

jd = (
(1461 * ((year + 4800 + month_term)) / 4).astype(int)
Expand Down
15 changes: 9 additions & 6 deletions src/solposx/solarposition/sg2.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ def sg2(times, latitude, longitude, elevation=0, *, pressure=101325, temperature
# convert time to UTC
times_utc = _pandas_to_utc(times)

year = times_utc.year
month = times_utc.month
day = times_utc.day # this is day of month and not day of year
year = np.asarray(times_utc.year)
month = np.asarray(times_utc.month)
day = np.asarray(times_utc.day) # this is day of month and not day of year
hour = _fractional_hour(times_utc)

# year in decimal form
Expand Down Expand Up @@ -107,9 +107,12 @@ def sg2(times, latitude, longitude, elevation=0, *, pressure=101325, temperature
),
).astype(int)

# Look the coefficients up as numpy arrays; indexing a pandas Series by a
# per-timestamp row array is a slow, index-aligning operation.
year_ref = params_t["y"].to_numpy()[row]
delta_t = 0.0
for k in range(0, 6):
delta_t += params_t[f"a_{k}"][row] * (year - params_t["y"][row]) ** k
delta_t = delta_t + params_t[f"a_{k}"].to_numpy()[row] * (year - year_ref) ** k

year_mod = np.where((month == 1) | (month == 2), year - 1, year)
month_mod = np.where((month == 1) | (month == 2), month + 12, month)
Expand All @@ -127,7 +130,7 @@ def sg2(times, latitude, longitude, elevation=0, *, pressure=101325, temperature
+ np.floor(year_mod / 400.0)
)

jd_tt = jd_ut + delta_t.values / 86400
jd_tt = jd_ut + delta_t / 86400

jd_ut_mod = jd_ut - 2444239.5
jd_tt_mod = jd_tt - 2444239.5
Expand All @@ -152,7 +155,7 @@ def sg2(times, latitude, longitude, elevation=0, *, pressure=101325, temperature
)

# I reshape the jd and dataframe in order to do the sum operation
jd_tt_mod_reshaped = jd_tt_mod.to_numpy().reshape(len(jd_tt_mod), 1)
jd_tt_mod_reshaped = np.asarray(jd_tt_mod).reshape(len(jd_tt_mod), 1)
f_L = params["f_L"].to_numpy().reshape(1, 10)
rho_L = params["rho_L"].to_numpy().reshape(1, 10)
phi_L = params["phi_L"].to_numpy().reshape(1, 10)
Expand Down
4 changes: 2 additions & 2 deletions src/solposx/solarposition/usno.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def usno(times, latitude, longitude, *, delta_t=67.0, gmst_option=1):
if delta_t is None:
delta_t = spa.calculate_deltat(times_utc.year, times_utc.month)

JD = times_utc.to_julian_date()
JD = np.asarray(times_utc.to_julian_date())

D = JD - 2451545.0

Expand Down Expand Up @@ -87,7 +87,7 @@ def usno(times, latitude, longitude, *, delta_t=67.0, gmst_option=1):
# JD_0 is the Julian date of the previous midnight (0h) UT1
midnight = times_utc.normalize() # Convert times_utc to midnight

JD_0 = midnight.to_julian_date()
JD_0 = np.asarray(midnight.to_julian_date())

# Hours of UT1 elapsed since the previous midnight
H = (JD - JD_0) * 24
Expand Down
4 changes: 2 additions & 2 deletions src/solposx/solarposition/walraven.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ def walraven(times, latitude, longitude):

longitude = -longitude # outdated convention used by Walraven

year = times_utc.year
day = times_utc.dayofyear
year = np.asarray(times_utc.year)
day = np.asarray(times_utc.dayofyear)
T = _fractional_hour(times_utc)

delta = year - 1980
Expand Down
13 changes: 10 additions & 3 deletions src/solposx/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,18 @@ def _fractional_hour(times):

Returns
-------
fraction_of_hour : pd.Index
fraction_of_hour : numpy.ndarray
"""
# Extract the fields as plain numpy arrays: arithmetic on pandas Index
# objects allocates a new Index per operation, which dominates the runtime
# of the algorithms for small inputs and adds copies for large ones.
hour = (
times.hour
+ (times.minute + (times.second + times.microsecond * 1e-6) / 60) / 60
np.asarray(times.hour)
+ (
np.asarray(times.minute)
+ (np.asarray(times.second) + np.asarray(times.microsecond) * 1e-6) / 60
)
/ 60
)
return hour

Expand Down
3 changes: 2 additions & 1 deletion tests/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ def expected_fractional_hour():

def test_fractional_hour(times_index, expected_fractional_hour):
result = _fractional_hour(times_index)
pd.testing.assert_index_equal(result, expected_fractional_hour)
assert isinstance(result, np.ndarray)
np.testing.assert_array_equal(result, expected_fractional_hour.to_numpy())


@pytest.fixture
Expand Down
Loading