Skip to content

Commit 69c0ad1

Browse files
Add LAI to global data selection (#69)
* Add LAI to global data selection, tests * Correct test data generation * Add instructions, download script & parsing nb * Linter fix
1 parent ee04b5a commit 69c0ad1

7 files changed

Lines changed: 838 additions & 11 deletions

File tree

PyStemmusScope/global_data_selection.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def extract_lai_data( # noqa:PLR0913 (too many arguments)
219219
start_time: np.datetime64,
220220
end_time: np.datetime64,
221221
timestep: str,
222-
) -> xr.DataArray:
222+
) -> np.ndarray:
223223
"""Generate LAI values, until a dataset is chosen.
224224
225225
Args:
@@ -234,9 +234,13 @@ def extract_lai_data( # noqa:PLR0913 (too many arguments)
234234
Returns:
235235
DataArray containing the LAI of the specified site for the given timeframe.
236236
"""
237-
timeseries = xr.date_range(start=start_time, end=end_time, freq=timestep)
238-
return xr.DataArray(
239-
data=np.ones(len(timeseries)) * 4,
240-
dims=["time"],
241-
coords={"time": timeseries},
242-
)
237+
238+
def preproc(ds):
239+
ds = ds.drop_vars(["crs", "LAI_ERR", "retrieval_flag"])
240+
ds = ds.sel(lat=lat, lon=lon, method="nearest")
241+
return ds.drop_vars(["lat", "lon"])
242+
243+
ds_lai = xr.open_mfdataset(files_lai, preprocess=preproc)
244+
ds_lai = ds_lai.resample(time=timestep).interpolate("linear")
245+
ds_lai = ds_lai.sel(time=slice(start_time, end_time))
246+
return ds_lai["LAI"].values

0 commit comments

Comments
 (0)