Commit ce56fb8c authored by Greifeneder Felix's avatar Greifeneder Felix

added the support to extract soil moisture time series for a list of points

parent 244c0209
......@@ -18,21 +18,18 @@ class GEE_pt(object):
"""Class to create an interface with GEE for the extraction of parameter time series
Attributes:
loc: tuple or list of tuples containing longitude and latitude (lon, lat)
lon: longitude in decimal degrees
lat: latitude in decimal degrees
workdir: path to a directory to save output e.g. time-series plots
buffer: radius of the time-series footprint
"""
"""
def __init__(self, loc, workdir, buffer=20):
def __init__(self, lon, lat, workdir, buffer=20):
ee.Reset()
ee.Initialize()
if isinstance(loc, list):
print('Multiple points are not yet supported. Please specify pos as a tuple (lon,lat)')
else:
self.lon = loc[0]
self.lat = loc[1]
self.lon = lon
self.lat = lat
self.buffer = buffer
self.workdir = workdir
......
......@@ -94,54 +94,81 @@ def get_map(minlon, minlat, maxlon, maxlat, outpath,
GEE_interface = None
def get_ts(lon, lat,
def get_ts(loc,
workpath,
tracknr=None,
footprint=50,
masksnow=True,
calc_anomalies=False,
create_plots=False):
"""Get S1 soil moisture time-series"""
# initialize GEE point object
gee_pt_obj = GEE_pt(lon, lat, workpath, buffer=footprint)
sm_ts = gee_pt_obj.extr_SM(tracknr=tracknr, masksnow=masksnow, calc_anomalies=calc_anomalies)
# create plots
if create_plots == True:
if calc_anomalies == False:
# plot s1 soil moisture vs gldas_downscaled
fig, ax = plt.subplots(figsize=(6.5,2.7))
line1, = ax.plot(sm_ts.index, sm_ts,
color='b',
linestyle='-',
marker='+',
label='S1 Soil Moisture',
linewidth=0.2)
ax.set_ylabel('Soil Moisture [%-Vol.]')
plotname = 's1_sm_' + str(lon) + '_' + str(lat) + '.png'
else:
fig, ax = plt.subplots(figsize=(6.5,2.7))
line1, = ax.plot(sm_ts.index, sm_ts['ANOM'].values,
color='r',
linestyle='-',
marker='+',
label='S1 Soil Moisture Anomaly',
linewidth=0.2)
x0 = [sm_ts.index[0], sm_ts.index[-1]]
y0 = [0, 0]
line2, = ax.plot(x0, y0,
color='k',
linestyle='--',
linewidth=0.2)
ax.set_ylabel('Soil Moisture Anomaly [%-Vol.]')
#plt.legend(handles=[line1, line2])
plotname = 's1_sm_anom' + str(lon) + '_' + str(lat) + '.png'
plt.setp(ax.get_xticklabels(), fontsize=6)
plt.savefig(workpath + plotname, dpi=300)
return sm_ts
"""Get S1 soil moisture time-series
Atributes:
loc: (tuple or list of tuples) longitude and latitude in decimal degrees
workpath: destination for output files
tracknr (optional): Use data from a specific Sentinel-1 track only
footprint: time-series footprint
masksnow: apply automatic wet snow mask
calc_anomalies: (boolean) calculate anomalies
create_plots: (boolean) generate and save time-series plots to workpath
"""
if isinstance(loc, list):
print('list')
else:
loc = [loc]
sm_ts_out = list()
for iloc in loc:
# iterate through the list of points to extract
lon = iloc[0]
lat = iloc[1]
print('Estimating surface soil moisture for lon: ' + str(lon) + ' lat: ' + str(lat))
# initialize GEE point object
gee_pt_obj = GEE_pt(lon, lat, workpath, buffer=footprint)
sm_ts = gee_pt_obj.extr_SM(tracknr=tracknr, masksnow=masksnow, calc_anomalies=calc_anomalies)
# create plots
if create_plots == True:
if calc_anomalies == False:
# plot s1 soil moisture vs gldas_downscaled
fig, ax = plt.subplots(figsize=(6.5,2.7))
line1, = ax.plot(sm_ts.index, sm_ts,
color='b',
linestyle='-',
marker='+',
label='S1 Soil Moisture',
linewidth=0.2)
ax.set_ylabel('Soil Moisture [%-Vol.]')
plotname = 's1_sm_' + str(lon) + '_' + str(lat) + '.png'
else:
fig, ax = plt.subplots(figsize=(6.5,2.7))
line1, = ax.plot(sm_ts.index, sm_ts['ANOM'].values,
color='r',
linestyle='-',
marker='+',
label='S1 Soil Moisture Anomaly',
linewidth=0.2)
x0 = [sm_ts.index[0], sm_ts.index[-1]]
y0 = [0, 0]
line2, = ax.plot(x0, y0,
color='k',
linestyle='--',
linewidth=0.2)
ax.set_ylabel('Soil Moisture Anomaly [%-Vol.]')
#plt.legend(handles=[line1, line2])
plotname = 's1_sm_anom' + str(lon) + '_' + str(lat) + '.png'
plt.setp(ax.get_xticklabels(), fontsize=6)
plt.savefig(workpath + plotname, dpi=300)
sm_ts_out.append(sm_ts)
gee_pt_obj = None
return sm_ts_out
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment