示例#1
0
###########################################################
# Write metadata in each band (date + band name)
# ------------------------------------------------------

S2.set_description_metadata(raster, dates)

###########################################################
# Generate a raster with NDVI index
# ---------------------------------------------

# show expression and condition of NDVI index
print(S2.get_index_expression('NDVI'))

# generate raster
S2.generate_raster(input_raster=raster,
                   output_raster='/tmp/S2.tif',
                   expression=S2.get_index_expression('NDVI'),
                   dtype=np.float32)

######################################"
# Plot image

rM = RasterMath(raster)
X = rM.get_random_block()
NDVI = S2.generate_index(X, S2.get_index_expression('NDVI'), dtype=np.float32)

from matplotlib import pyplot as plt
from datetime import datetime
dateToDatetime = [datetime.strptime(str(date), '%Y%m%d') for date in dates]
plt.plot_date(dateToDatetime, NDVI[:10, :].T, '-o')
plt.ylabel('Leaf Chlorophyll Content')
示例#2
0
# -------------------------------------------

from museotoolbox.processing import RasterMath
from museotoolbox import datasets
import numpy as np
##############################################################################
# Load HistoricalMap dataset
# -------------------------------------------

raster, vector = datasets.load_historical_data()

##############################################################################
# Initialize rasterMath with raster
# ------------------------------------

rM = RasterMath(raster)

print(rM.get_random_block())

##########################
# Let's suppose you want compute the difference between blue and green band.
# I suggest you to define type in numpy array to save space while creating the raster!

X = rM.get_random_block()

sub = lambda X: np.array((X[:, 0] - X[:, 1])).astype(np.int16)

rM.add_function(sub, out_image='/tmp/sub_lambda.tif')
###########################################################
# Use a python function to use arguments
# ----------------------------------------