Skip to content

Instantly share code, notes, and snippets.

@ayushprd
Created June 17, 2020 12:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ayushprd/f2e8447fc266b5a087d26113b20d733c to your computer and use it in GitHub Desktop.
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.
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