<jupyter_start><jupyter_text>Create Geocontext (Currently not actually using any of this except the dates)I was originally aiming to only compute the resulting mosaic over the AOI only using the geocontext but I binned it in the end and just let the interactive map constrain it to the AOI. Might be worth looking into further<jupyter_code>with open("aoi_small_train.geojson") as f:
    fc = json.load(f)
    
aoi_geo = fc["features"][0]["geometry"]

aoi = wf.GeoContext(
    geometry = aoi_geo,
    crs="EPSG:3857",
    resolution = 10.0)

start_datetime = "2020-04-01"
end_datetime = "2020-07-28"<jupyter_output><empty_output><jupyter_text>Dilation FunctionWith Kernel<jupyter_code># Define simple functions for erosion and dilation
def erode_op(map_layer, iters, kernel):
    map_layer = ~map_layer
    for i in range(iters):
        map_layer = wf.conv2d(map_layer, kernel) > 0
    map_layer = ~map_layer 
    return map_layer

def dilate_op(map_layer, iters, kernel):
    for i in range(iters):
        map_layer = map_layer * 1.0
        map_layer = wf.conv2d(map_layer, kernel) > 0
    return map_layer

# Define a kernel and perform one erosion followed by two dilations
kernel = wf.Kernel(dims=(3,3), data=[0., 1., 0.,
                                      1., 1., 1.,
                                      0., 1., 0.])<jupyter_output><empty_output><jupyter_text>Sentinel 2 stack w/ cloud maskUsing whatever bands you like<jupyter_code>sentinel_stack = (wf.ImageCollection.from_id("sentinel-2:L1C",
                                            start_datetime = start_datetime,
                                            end_datetime = end_datetime)
                  .pick_bands("red green blue cloud-mask red-edge-2 red-edge-3 red-edge-4 nir swir1 swir2")
                 )

sentinel_stack = sentinel_stack.filter(lambda img:img.properties["cloud_fraction"] <= 0.06)

dilated_mask = dilate_op(sentinel_stack.pick_bands("cloud-mask"), iters=75, kernel=kernel)
dilated_mask = dilated_mask.rename_bands("dilated-cloud-mask")

sentinel_stack = sentinel_stack.concat_bands(dilated_mask)

sentinel_masked = sentinel_stack.map(lambda img: img.mask(img.pick_bands('dilated-cloud-mask')==1))<jupyter_output><empty_output><jupyter_text>Create the image mosaic and compute over the AOI<jupyter_code>sentinel_mosaic = (sentinel_masked
                   .mosaic()
                   .pick_bands("red green blue"))

#sentinel_image = sentinel_mosaic.compute(aoi)<jupyter_output><empty_output><jupyter_text>Visualise the imageI think it looks pretty good, but there's room for improvement. Zoom out to see where it's not great (outside the city)<jupyter_code>a_map = wf.interactive.MapApp()
a_map.center = (18.5577, -69.9145)  #18.5265, -69.9129
a_map.zoom = 15

sentinel_mosaic.visualize('image', scales=[(0, 1), (0, 1), (0, 1)], map=a_map)

a_map<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10504347826086957, 'fraction_numerical': 0.030260869565217393, 'mean_word_length': 3.4589147286821706, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 9, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '533793', 'license': 'RSA-MD', 'n_tokens_mistral': 1049, 'n_tokens_neox': 950, 'n_words': 231, 'path': 'settlement_segmentation/randomforest/cloud_mosaic_test.ipynb', 'repo_name': 'ai4er-cdt/gtc-exposure', 'size': '2875'}