Compute a spectral index or an expression without defining a sensor

This example shows how to compute an expression or an index in a time series (or at one acquisition) without defining a sensor.

Use sample from Sentinel2 level 3A syntheses (from Theia)

from museopheno.time_series import expression_manager
from museopheno import datasets

X,dates = datasets.Sentinel2_3a_2018(return_dates=True,return_random_sample=True)

print(X.shape)

Out:

Total number of blocks : 1
(55842, 70)

We have to define the band order and the number of compenent (i.e. number of band per date)

bands_order = ['2','3','4','8','5','6','7','8A','11','12']

As our raster has 10 bands per date, let’s check the number of columns of X array divided by the numver of bands per date

print('Image contains {} dates.'.format(int(X.shape[1]/len(bands_order))))

Out:

Image contains 7 dates.

Let’s create an expression

expression = 'B8/(B2+1)'

result = expression_manager(X,bands_order=bands_order,expression=expression)

print(result)

Out:

[[29.15     31.653631 28.006369 ... 21.634285 23.138159 11.891509]
 [26.018072 32.120804 28.919708 ... 23.013699 24.86508  12.335052]
 [28.894365 37.02362  30.872    ... 20.8125   20.554745 10.108571]
 ...
 [24.484848 35.560974 24.670807 ... 18.333334 17.838888  8.68    ]
 [27.095238 37.45299  24.62264  ... 18.994566 18.543478  9.601626]
 [32.585365 41.92233  26.326666 ... 18.347368 18.052357  9.585657]]

Plot result

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,result.T[:,:100],'-o')
computeIndex

Out:

[<matplotlib.lines.Line2D object at 0x7f72bd4dd610>, <matplotlib.lines.Line2D object at 0x7f72bd4e0910>, <matplotlib.lines.Line2D object at 0x7f72bd4dd410>, <matplotlib.lines.Line2D object at 0x7f72bd4dd3d0>, <matplotlib.lines.Line2D object at 0x7f72bd4dd9d0>, <matplotlib.lines.Line2D object at 0x7f72bd4dde50>, <matplotlib.lines.Line2D object at 0x7f72bd4dd810>, <matplotlib.lines.Line2D object at 0x7f72bd4ddf90>, <matplotlib.lines.Line2D object at 0x7f72bd4dd510>, <matplotlib.lines.Line2D object at 0x7f72bd4ddbd0>, <matplotlib.lines.Line2D object at 0x7f72bda6b950>, <matplotlib.lines.Line2D object at 0x7f72bd498410>, <matplotlib.lines.Line2D object at 0x7f72bd498e10>, <matplotlib.lines.Line2D object at 0x7f72bd498790>, <matplotlib.lines.Line2D object at 0x7f72bd498f90>, <matplotlib.lines.Line2D object at 0x7f72bd498950>, <matplotlib.lines.Line2D object at 0x7f72bd4981d0>, <matplotlib.lines.Line2D object at 0x7f72bd498890>, <matplotlib.lines.Line2D object at 0x7f72bd498b10>, <matplotlib.lines.Line2D object at 0x7f72bd498ad0>, <matplotlib.lines.Line2D object at 0x7f72bd498310>, <matplotlib.lines.Line2D object at 0x7f72bd498690>, <matplotlib.lines.Line2D object at 0x7f72bd4983d0>, <matplotlib.lines.Line2D object at 0x7f72bd498d90>, <matplotlib.lines.Line2D object at 0x7f72bd498c90>, <matplotlib.lines.Line2D object at 0x7f72bd498390>, <matplotlib.lines.Line2D object at 0x7f72bd498650>, <matplotlib.lines.Line2D object at 0x7f72bd498710>, <matplotlib.lines.Line2D object at 0x7f72bd498450>, <matplotlib.lines.Line2D object at 0x7f72bd4bbc90>, <matplotlib.lines.Line2D object at 0x7f72bd4bb790>, <matplotlib.lines.Line2D object at 0x7f72bd4bb090>, <matplotlib.lines.Line2D object at 0x7f72bd4bba90>, <matplotlib.lines.Line2D object at 0x7f72bd4bb190>, <matplotlib.lines.Line2D object at 0x7f72bd4bbe50>, <matplotlib.lines.Line2D object at 0x7f72bd4bbcd0>, <matplotlib.lines.Line2D object at 0x7f72bd4bb910>, <matplotlib.lines.Line2D object at 0x7f72bd4bb4d0>, <matplotlib.lines.Line2D object at 0x7f72bd4bb710>, <matplotlib.lines.Line2D object at 0x7f72bd4bbad0>, <matplotlib.lines.Line2D object at 0x7f72bd4bb510>, <matplotlib.lines.Line2D object at 0x7f72bd4bb210>, <matplotlib.lines.Line2D object at 0x7f72bd4bb3d0>, <matplotlib.lines.Line2D object at 0x7f72bd4bbe90>, <matplotlib.lines.Line2D object at 0x7f72bd4bbed0>, <matplotlib.lines.Line2D object at 0x7f72bd4bb6d0>, <matplotlib.lines.Line2D object at 0x7f72bd4bbe10>, <matplotlib.lines.Line2D object at 0x7f72bd4bb550>, <matplotlib.lines.Line2D object at 0x7f72bd4bb110>, <matplotlib.lines.Line2D object at 0x7f72becbdcd0>, <matplotlib.lines.Line2D object at 0x7f72c060d490>, <matplotlib.lines.Line2D object at 0x7f72c060d790>, <matplotlib.lines.Line2D object at 0x7f72c060d310>, <matplotlib.lines.Line2D object at 0x7f72bd3adbd0>, <matplotlib.lines.Line2D object at 0x7f72bd3adcd0>, <matplotlib.lines.Line2D object at 0x7f72bd3ad0d0>, <matplotlib.lines.Line2D object at 0x7f72bd3aded0>, <matplotlib.lines.Line2D object at 0x7f72bd3ad6d0>, <matplotlib.lines.Line2D object at 0x7f72bd3addd0>, <matplotlib.lines.Line2D object at 0x7f72bd3adf10>, <matplotlib.lines.Line2D object at 0x7f72bd3ad310>, <matplotlib.lines.Line2D object at 0x7f72bd3ada90>, <matplotlib.lines.Line2D object at 0x7f72bd3ad650>, <matplotlib.lines.Line2D object at 0x7f72bd3ad090>, <matplotlib.lines.Line2D object at 0x7f72bd3ad150>, <matplotlib.lines.Line2D object at 0x7f72bd3adc90>, <matplotlib.lines.Line2D object at 0x7f72bd3ad490>, <matplotlib.lines.Line2D object at 0x7f72bd3ad990>, <matplotlib.lines.Line2D object at 0x7f72beadd610>, <matplotlib.lines.Line2D object at 0x7f72beadd1d0>, <matplotlib.lines.Line2D object at 0x7f72beadd790>, <matplotlib.lines.Line2D object at 0x7f72beadd390>, <matplotlib.lines.Line2D object at 0x7f72beadd150>, <matplotlib.lines.Line2D object at 0x7f72beadd910>, <matplotlib.lines.Line2D object at 0x7f72beadde50>, <matplotlib.lines.Line2D object at 0x7f72beaddb10>, <matplotlib.lines.Line2D object at 0x7f72beadd7d0>, <matplotlib.lines.Line2D object at 0x7f72bd7e1b10>, <matplotlib.lines.Line2D object at 0x7f72bd7e1450>, <matplotlib.lines.Line2D object at 0x7f72bd7e1b90>, <matplotlib.lines.Line2D object at 0x7f72bd7e1950>, <matplotlib.lines.Line2D object at 0x7f72bd7e1310>, <matplotlib.lines.Line2D object at 0x7f72bdbdc690>, <matplotlib.lines.Line2D object at 0x7f72bdbdc650>, <matplotlib.lines.Line2D object at 0x7f72bd437350>, <matplotlib.lines.Line2D object at 0x7f72bd437c10>, <matplotlib.lines.Line2D object at 0x7f72bd4374d0>, <matplotlib.lines.Line2D object at 0x7f72bd437bd0>, <matplotlib.lines.Line2D object at 0x7f72bd437150>, <matplotlib.lines.Line2D object at 0x7f72bd437490>, <matplotlib.lines.Line2D object at 0x7f72bd437710>, <matplotlib.lines.Line2D object at 0x7f72bd437610>, <matplotlib.lines.Line2D object at 0x7f72bd4379d0>, <matplotlib.lines.Line2D object at 0x7f72bd437550>, <matplotlib.lines.Line2D object at 0x7f72bd437ad0>, <matplotlib.lines.Line2D object at 0x7f72bd437090>, <matplotlib.lines.Line2D object at 0x7f72bd437c90>, <matplotlib.lines.Line2D object at 0x7f72bd4378d0>, <matplotlib.lines.Line2D object at 0x7f72bd794b90>, <matplotlib.lines.Line2D object at 0x7f72bd794990>]

Total running time of the script: ( 0 minutes 0.933 seconds)

Gallery generated by Sphinx-Gallery