Skip to content

Instantly share code, notes, and snippets.

View mlubej's full-sized avatar

Matic Lubej mlubej

  • EO Research Team @ Sinergise
  • Ljubljana, Slovenia
View GitHub Profile
# Define the workflow
eo_workflow = eolearn.core.LinearWorkflow(
add_sentinel2_data, # Sentinel-2 data task
add_cloud_mask, # cloud mask task
append_ndvi, # calculate ndvi
append_ndwi, # calculate ndwi
append_norm, # calculate norm
add_valid_mask, # add new feature: valid mask
add_count_valid, # add new feature: valid counts
*reference_task_array, # add an array of tasks for adding each reference label
import numpy as np
p, t, w, h, d = features_array.shape
# move t axis from position 1 to position 3
features_array = np.moveaxis(features_array, 1, 3)
# reshape array
features_array = features_array.reshape(p*w*h, t*d)
Model Overall Accuracy [%] F_1 Score [%]
Uniform at 16-day rate 94.4 94.1
Uniform at 8-day rate 94.5 94.3
Optimally selected 94.6 94.4
# load EOPatch
EOPatch.load('path_to_eopatches/eopatch-0x6/')
EOPatch(
data: {
BANDS: numpy.ndarray(shape=(80, 1010, 999, 6), dtype=float32)
}
mask: {
CLM: numpy.ndarray(shape=(80, 1010, 999, 1), dtype=uint8)
IS_DATA: numpy.ndarray(shape=(80, 1010, 999, 1), dtype=uint8)
IS_VALID: numpy.ndarray(shape=(80, 1010, 999, 1), dtype=bool)
}
mask_timeless: {
eopatch.timestamp
eopatch.mask['LULC']
eopatch.data['CLM'][0]
eopatch.data['BANDS'][5][..., [3, 2, 1]]
function setup() {
return {
input: ["sunZenithAngles", "sunAzimuthAngles"],
mosaicking: Mosaicking.ORBIT,
output: { id:"default", bands: 0}
}
}
function updateOutputMetadata(scenes, inputMetadata, outputMetadata) {
def get_unique_orientations(poly):
"""
Out of all possible rotations and flips, take into account the polygon symmetry and
obtain the unique polygon orientations.
:param poly: input polygon
:return: array of unique settings of (rotation, flip)
"""
cx, cy = poly.centroid.x, poly.centroid.y
pts = np.array(poly.checkers)[:, :-1]
checkers = np.array(poly.checkers)[:, -1]
for idx, c in enumerate(chromosome):
if np.random.rand() < mutation_probability:
has_mutated = True
rand_idx = np.random.choice(range(len(chromosome)))
chromosome[idx], chromosome[rand_idx] = chromosome[rand_idx], chromosome[idx]
def mate(self, partner):
"""
Create offspring with a order-crossover method
:param partner: a second p1 which will participate in the mating
:return: two new offspring individuals
"""
c1, c2 = np.zeros((2, self.n_pieces), dtype=int)
start, end = np.sort(np.random.choice(range(self.n_pieces), 2, replace=False))
p1 = self.chromosome