Created
June 17, 2020 12:36
-
-
Save ayushprd/f2e8447fc266b5a087d26113b20d733c to your computer and use it in GitHub Desktop.
Function to read in netCDF file, calculate LAI and save it back in a netCDF file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import xarray as xr | |
import satellitetools.biophys_xarray as bio | |
from satellitetools import gee | |
import geopandas as gpd | |
import os | |
def select_data_LAI(pathtoinputfile, outdir): | |
ds_disk = xr.open_dataset(pathtoinputfile) | |
#calculating LAI | |
area = bio.run_snap_biophys(ds_disk, "LAI") | |
timeseries = {} | |
timeseries_variable = ["lai"] | |
if not os.path.exists(outdir): | |
os.makedirs(outdir, exist_ok=True) | |
# creating a timerseries and saving the netCDF file | |
area.to_netcdf(os.path.join(outdir, area.name + ".nc")) | |
timeseries[area.name] = gee.xr_dataset_to_timeseries(area, timeseries_variable) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment