Created
February 12, 2023 00:47
-
-
Save osbm/6fb398dcb26e3412ce03a1376e18b4c4 to your computer and use it in GitHub Desktop.
This code can run in Google earth engine web editor.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var geometry = | |
/* color: #ffc82d */ | |
/* shown: false */ | |
ee.Geometry.Polygon( | |
[[[36.803785364345735, 37.6022824651851], | |
[36.84292415829105, 37.569634979372736], | |
[36.8896160528223, 37.548134235962486], | |
[36.96171383114261, 37.54377889953015], | |
[36.99741939754886, 37.565280899470345], | |
[36.97819332333011, 37.58759286852694], | |
[36.92600826473636, 37.59820231254613], | |
[36.886182825283235, 37.60473044936202], | |
[36.84910396786136, 37.60527443490601], | |
[36.81889156551761, 37.605818416471855], | |
[36.809278528408235, 37.60527443490601]]]); | |
var area = ee.FeatureCollection(geometry); | |
Map.centerObject(geometry) | |
// print image dates from | |
var sentinel_id = "COPERNICUS/S2_SR_HARMONIZED" | |
var pre_quake_start = "2023-01-15" | |
var pre_quake_end = "2023-01-25" | |
var post_quake_start = "2023-02-07" | |
var post_quake_end = "2023-02-12" | |
var imagery = ee.ImageCollection(sentinel_id) | |
// .filterDate(pre_quake_end, post_quake_start) | |
// .filterBounds(geometry) | |
var pre_quake = ee.ImageCollection( | |
imagery.filterDate(pre_quake_start, pre_quake_end).filterBounds(area) | |
) | |
var post_quake = ee.ImageCollection( | |
imagery.filterDate(post_quake_start, post_quake_end).filterBounds(area) | |
) | |
print(pre_quake.first().date()) | |
print(post_quake.first().date()) | |
Map.centerObject(area); | |
function maskS2sr(image) { | |
// Bits 10 and 11 are clouds and cirrus, respectively. | |
var cloudBitMask = ee.Number(2).pow(10).int(); | |
var cirrusBitMask = ee.Number(2).pow(11).int(); | |
// Get the pixel QA band. | |
var qa = image.select('QA60'); | |
// All flags should be set to zero, indicating clear conditions. | |
var mask = qa.bitwiseAnd(cloudBitMask).eq(0) | |
.and(qa.bitwiseAnd(cirrusBitMask).eq(0)); | |
// Return the masked image, scaled to TOA reflectance, without the QA bands. | |
return image.updateMask(mask) | |
.copyProperties(image, ["system:time_start"]); | |
} | |
var pre_quake_CM = pre_quake.map(maskS2sr); | |
var post_quake_CM = post_quake.map(maskS2sr); | |
var pre_mos = pre_quake.mosaic().clip(area); | |
var post_mos = post_quake.mosaic().clip(area); | |
var vis = {bands: ['B4', 'B3', 'B2'], max: 2000, gamma: 1.5}; | |
Map.addLayer(pre_mos, vis,'Pre-quake image'); | |
Map.addLayer(post_mos, vis,'Post-quake image'); | |
print(pre_mos) | |
print(post_mos) | |
Export.image.toDrive({ | |
image: pre_mos.visualize(vis), | |
description: 'export_premos', | |
folder: 'earthengine', | |
scale: 10, | |
maxPixels:1e10, | |
region: geometry, | |
}); | |
Export.image.toDrive({ | |
image: post_mos.visualize(vis), | |
description: 'export_postmos', | |
folder: 'earthengine', | |
scale: 10, | |
maxPixels:1e10, | |
region: geometry, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment