Skip to content
Snippets Groups Projects
Commit 5e3fb9e7 authored by Wit, Allard de's avatar Wit, Allard de
Browse files

version of snap_biovar that takes zenith/azimuth angles from grompy 1.3 dataframe

parent f9f2c958
Branches main
No related tags found
No related merge requests found
......@@ -15,18 +15,17 @@ from .fapar import compute_fapar
from .lai import compute_lai
from .fcover import compute_fcover
__version__ = "1.0.0"
__version__ = "1.0.2"
def compute_biovar(df_s2, longitude, latitude, timezone="Europe/Amsterdam",
view_zenith_mean=None, view_azimuth_mean=None):
def compute_biovar(df_s2, longitude, latitude, timezone="Europe/Amsterdam"):
"""
:param df_s2: The dataframe with Sentinel2 timeseries data
:param longitude: The site longitude
:param latitude: The site latitude
:param timezone: The timezone
:param view_zenith_mean: the view zenith angle
:param view_azimuth_mean: the view azimuth angle
:param sensor_zenith: the view zenith angle
:param sensor_azimuth: the view azimuth angle
:return: the same dataframe with several columns added:
- lai: the calculated leaf area index
- fapar: the calculated fraction of absorbed PAR
......@@ -51,16 +50,16 @@ def compute_biovar(df_s2, longitude, latitude, timezone="Europe/Amsterdam",
loc = LocationInfo("", "", timezone, latitude, longitude)
S2_bands = ["B02", "B03", "B04", "B05", "B06", "B07", "B08", "B11", "B12", "B8A", "NDVI"]
# Scale to reflectance values
df_s2.iloc[:,1:-1] /= 10000
df_s2.loc[:,S2_bands] /= 10000
# We assume a local overpass time of 10:30 in the morning (adding 10.5 hours)
tmp = pd.to_datetime(df_s2.day) + pd.Timedelta(10.5, unit="h")
df_s2["day_tz"] = tmp.dt.tz_localize(timezone)
df_s2["solar_azimuth"] = df_s2.day_tz.apply(Location(loc).solar_azimuth)
df_s2["solar_zenith"] = df_s2.day_tz.apply(Location(loc).solar_zenith)
df_s2["fapar"] = compute_fapar(df_s2, view_zenith_mean, view_azimuth_mean)
df_s2["lai"] = compute_lai(df_s2, view_zenith_mean, view_azimuth_mean)
df_s2["fcover"] = compute_fcover(df_s2, view_zenith_mean, view_azimuth_mean)
df_s2["fapar"] = compute_fapar(df_s2)
df_s2["lai"] = compute_lai(df_s2)
df_s2["fcover"] = compute_fcover(df_s2)
return df_s2
\ No newline at end of file
......@@ -14,9 +14,9 @@ def compute_fapar(input):
b8a_norm = normalize(input.B8A, 0.026690138082061, 0.782011770669178)
b11_norm = normalize(input.B11, 0.016388074192258, 0.493761397883092)
b12_norm = normalize(input.B12, 0, 0.493025984460231)
viewZen_norm = normalize(np.cos(input.view_zenith_mean * degToRad), 0.918595400582046, 1)
viewZen_norm = normalize(np.cos(input.sensor_zenith * degToRad), 0.918595400582046, 1)
sunZen_norm = normalize(np.cos(input.solar_zenith * degToRad), 0.342022871159208, 0.936206429175402)
relAzim_norm = np.cos((input.solar_azimuth - input.view_azimuth_mean) * degToRad)
relAzim_norm = np.cos((input.solar_azimuth - input.sensor_azimuth) * degToRad)
inp = (b03_norm,b04_norm,b05_norm,b06_norm,b07_norm,b8a_norm,
b11_norm,b12_norm, viewZen_norm,sunZen_norm,relAzim_norm)
......
......@@ -14,9 +14,9 @@ def compute_fcover(input):
b8a_norm = normalize(input.B8A, 0.026690138082061, 0.782011770669178)
b11_norm = normalize(input.B11, 0.016388074192258, 0.493761397883092)
b12_norm = normalize(input.B12, 0, 0.493025984460231)
viewZen_norm = normalize(np.cos(input.view_zenith_mean * degToRad), 0.918595400582046, 1)
viewZen_norm = normalize(np.cos(input.sensor_zenith * degToRad), 0.918595400582046, 1)
sunZen_norm = normalize(np.cos(input.solar_zenith * degToRad), 0.342022871159208, 0.936206429175402)
relAzim_norm = np.cos((input.solar_azimuth - input.view_azimuth_mean) * degToRad)
relAzim_norm = np.cos((input.solar_azimuth - input.sensor_azimuth) * degToRad)
inp = (b03_norm,b04_norm,b05_norm,b06_norm,b07_norm,b8a_norm,
b11_norm,b12_norm, viewZen_norm,sunZen_norm,relAzim_norm)
......
......@@ -14,9 +14,9 @@ def compute_lai(input):
b8a_norm = normalize(input.B8A, 0.026690138082061, 0.782011770669178)
b11_norm = normalize(input.B11, 0.016388074192258, 0.493761397883092)
b12_norm = normalize(input.B12, 0, 0.493025984460231)
viewZen_norm = normalize(np.cos(input.view_zenith_mean * degToRad), 0.918595400582046, 1)
viewZen_norm = normalize(np.cos(input.sensor_zenith * degToRad), 0.918595400582046, 1)
sunZen_norm = normalize(np.cos(input.solar_zenith * degToRad), 0.342022871159208, 0.936206429175402)
relAzim_norm = np.cos((input.solar_azimuth - input.view_azimuth_mean) * degToRad)
relAzim_norm = np.cos((input.solar_azimuth - input.sensor_azimuth) * degToRad)
inp = (b03_norm,b04_norm,b05_norm,b06_norm,b07_norm,b8a_norm,
b11_norm,b12_norm, viewZen_norm,sunZen_norm,relAzim_norm)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment