Skip to content

Commit db15764

Browse files
including solar_day_of_year_for_longitude
1 parent faccada commit db15764

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

solar_apparent_time/solar_apparent_time.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,29 @@ def solar_day_of_year_for_area(time_UTC: datetime, geometry: rt.RasterGeometry)
7676

7777
return doy
7878

79+
def solar_day_of_year_for_longitude(time_UTC: datetime, lon: Union[float, np.ndarray]) -> Union[float, np.ndarray]:
80+
"""
81+
Calculates the day of year based on the given UTC time and longitude.
82+
83+
Args:
84+
time_UTC (datetime.datetime): The UTC time to calculate the day of year for.
85+
lon (Union[float, np.ndarray]): The longitude in degrees.
86+
87+
Returns:
88+
Union[float, np.ndarray]: The calculated day of year.
89+
"""
90+
# Calculate the day of year at the given longitude
91+
DOY_UTC = time_UTC.timetuple().tm_yday
92+
hour_UTC = time_UTC.hour + time_UTC.minute / 60 + time_UTC.second / 3600
93+
offset = UTC_offset_hours(lon)
94+
hour_of_day = hour_UTC + offset
95+
DOY = DOY_UTC
96+
# Adjust the day of year if the hour of day is outside the range [0, 24]
97+
DOY = np.where(hour_of_day < 0, DOY - 1, DOY)
98+
DOY = np.where(hour_of_day > 24, DOY + 1, DOY)
99+
100+
return DOY
101+
79102
def solar_hour_of_day_for_area(time_UTC: datetime, geometry: rt.RasterGeometry) -> rt.Raster:
80103
"""
81104
Calculates the hour of the day for a given UTC time and raster geometry.

0 commit comments

Comments
 (0)