generated from nmfs-opensci/NOAA-quarto-simple
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgee-bathymetry.js
94 lines (77 loc) · 3.6 KB
/
gee-bathymetry.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//This code has been edited from a previous github and is focusing on ROI Belize
//This is a Javascript code for running in the Google Earth Engine
//edit roi region here, or use the roi input file
var roi = //making polygon with coords:
ee.Geometry.Polygon(
[[[-89, 15.5],
[-87.4, 15.5],
[-87.4, 18.6],
[-89, 18.6],
[-89, 15.5]]]);
//another way to var roi = belize; note this is drawing a polygon
//april may and june are ideal images
// Belize S2 tiles:16QCD
//building the clean mosiac image based on different filters
var cloudBitMask = ee.Number(2).pow(10).int();
var cirrusBitMask = ee.Number(2).pow(11).int();
//this function is used to build clean water mosaic in the Google Earth Engine
//the threshold value could be revised, the current value is suggested for a common clean coral reefs waters
function mask(img){
var qa = img.select('QA60');
var ma = qa.bitwiseAnd(cloudBitMask).eq(0).and(
qa.bitwiseAnd(cirrusBitMask).eq(0));
ma = ma.and(img.select(['SCL']).neq(3));
ma = ma.and(img.select(['SCL']).neq(4));
ma = ma.and(img.select(['SCL']).neq(5));
ma = ma.and(img.select(['SCL']).neq(8));
ma = ma.and(img.select(['SCL']).neq(9));
ma = ma.and(img.select(['SCL']).neq(10));
ma = ma.and(img.select(['B9']).lt(300));
ma = ma.and(img.select(['B9']).gt(50));
ma = ma.and(img.select(['B3']).gt(100));//.focal_min({kernel: ee.Kernel.circle({radius: 5}), iterations: 1}));
ma = ma.focal_min({kernel: ee.Kernel.circle({radius: 1}), iterations: 1});
img = img.mask(ma);
//adjust for mask bad data
img = img.updateMask(img.select([4]).lt(1000));
img = img.updateMask(img.select([7]).lt(300))
var ndwi_revise = (img.select([2]).subtract(img.select([7]))).divide(img.select([2]).add(img.select([7])));
img = img.updateMask(ndwi_revise.gt(0));
//end of adjust
return img;
}
//bad water region maskout end
//set the filter input data to Sentinel-2 depth data
var sentinel = ee.ImageCollection('COPERNICUS/S2_SR').filter(ee.Filter.bounds(roi));
//set the filter input data to Sentinel-2 depth data
//next line of code filters images for dates
//Set up the date range and filter, this example uses TWO YEAR window to build the clean water mosaic
sentinel = sentinel.filter(ee.Filter.date(ee.Date.fromYMD(2019,1,1),ee.Date.fromYMD(2020,12,31)));
//Luis's methods below
//var sentinel = sentinel.filterBounds(roi).filterDate('2020-04-01','2020-06-30')
// .filter(ee.Filter.lte('CLOUDY_PIXEL_PERCENTAGE',30));
//run the mask function
sentinel = sentinel.map(mask);
//get the median value of it
var median = sentinel.reduce(ee.Reducer.median());
//calculate the big Rrs, rrs,and rrs*1000
var bigrrs = median.divide(ee.Number(31415.926));
var rrsvec = bigrrs.divide((bigrrs.multiply(ee.Number(1.7))).add(ee.Number(0.52)));
var rrsvec1k = rrsvec.multiply(ee.Number(1000));
//set the chla value for depth processing
//chla value could be adjusted to specific site
//chla = 0.5 is calculated from 20 global coral reefs regions
var chla = 0.5;
//0.5 is chla value
var m0 = ee.Number(52.073 * Math.exp(0.957*chla));
var m1 = ee.Number(50.156 * Math.exp(0.957*chla));
//calculate rrs vec
var lnrrsvec = rrsvec1k.log();
//calculate depth here
var depth = ((lnrrsvec.select([1]).divide(lnrrsvec.select([2]))).multiply(m0)).subtract(m1);
//set boundary, remove nagative value or large value in the result
var depthA = depth.where(depth.lt(0), ee.Number(0));
var depth_output = depthA.where(depthA.gt(20), ee.Number(20));
//end set
//depth_output is the final bathymetry
//plot depth_output
Map.addLayer(depth_output, {min: 0, max: 15, palette: ['00FFFF', '0000FF']});