Skip to content

Instantly share code, notes, and snippets.

@cbur24
Last active August 5, 2020 01:42
Show Gist options
  • Save cbur24/0dc9ce123454713ab04333170d73c99b to your computer and use it in GitHub Desktop.
Save cbur24/0dc9ce123454713ab04333170d73c99b to your computer and use it in GitHub Desktop.
Test SR between landsat collections
import datacube
import matplotlib.pyplot as plt
from matplotlib.pyplot import cm
from matplotlib.patches import Patch
import numpy as np
import sys
import xarray as xr
sys.path.append('../Scripts')
from deafrica_datahandling import load_ard
product = 'usgs_ls8c_level2_2'
lat = 13.9437
lon = -16.5488
lon_buffer = 0.05
lat_buffer = 0.05
lat_range = (lat-lat_buffer, lat+lat_buffer)
lon_range = (lon-lon_buffer, lon+lon_buffer)
years_range = ('2017')
dc = datacube.Datacube(app='test_collections')
query = {
'y': lat_range,
'x': lon_range,
'time': years_range,
'measurements': ['red', 'nir', 'green', 'blue', 'swir1', 'swir2'],
'resolution': (-30,30),
'output_crs': 'epsg:6933'
}
ds = load_ard(dc=dc,
products=[product],
min_gooddata = 0.25,
**query
)
#scale values (10,000 for C1, 65,455 for C2)
ds = ds / 65455
#ds = ds / 10000
fig, axes = plt.subplots(1,1, figsize=(12,6))
color=iter(cm.rainbow(np.linspace(0,1,6)))
x=[]
y=[]
for i,c in zip(ds.data_vars, range(0,6)):
c=next(color)
x.append(c)
y.append(i)
ds[i].mean(['x','y']).plot.line('b--', ax=axes, c=c)
plt.ylim(0,0.4)
plt.title(product + ': SR bands')
axes.legend([Patch(facecolor=x[0]), Patch(facecolor=x[1]), Patch(facecolor=x[2]), Patch(facecolor=x[3]), Patch(facecolor=x[4]),Patch(facecolor=x[5])],
[y[0],y[1],y[2],y[3],y[4],y[5]])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment