Created
June 17, 2020 12:26
-
-
Save ayushprd/bb1678e8709890d09e7a11cb37f5b4a6 to your computer and use it in GitHub Desktop.
Function to select data from gee and save it 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
from satellitetools import gee | |
import geopandas as gpd | |
import os | |
def select_data(geofile, outdir, start, end, qi_threshold): | |
# read in the input file containing coordinates | |
df = gpd.read_file(geofile) | |
request = gee.S2RequestParams(start, end) | |
# filter area of interest from the coordinates in the input file | |
area = gee.AOI(df[df.columns[0]].iloc[0], df[df.columns[1]].iloc[0]) | |
# calcuate qi attribute for the AOI | |
gee.ee_get_s2_quality_info(area, request) | |
# get the final data | |
gee.ee_get_s2_data(area, request, qi_threshold=qi_threshold) | |
# convert dataframe to an xarray dataset, used later for converting to netCDF | |
gee.s2_data_to_xarray(area, request) | |
# if specified output directory does not exist, create it. | |
if not os.path.exists(outdir): | |
os.makedirs(outdir, exist_ok=True) | |
# saving the netCDF file | |
area.data.to_netcdf(os.path.join(outdir, area.name + "_test.nc")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment