-
Notifications
You must be signed in to change notification settings - Fork 747
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert API code snippets from JS to Py (img math)
PiperOrigin-RevId: 564857545
- Loading branch information
1 parent
63fc2ef
commit d1635c1
Showing
6 changed files
with
294 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Copyright 2023 The Google Earth Engine Community Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# [START earthengine__apidocs__ee_image_add] | ||
# A Sentinel-2 surface reflectance image. | ||
img = ee.Image('COPERNICUS/S2_SR/20210109T185751_20210109T185931_T10SEG') | ||
|
||
# Subset two image bands and display them on the map. | ||
swir_1 = img.select('B11') | ||
swir_2 = img.select('B12') | ||
m = geemap.Map() | ||
m.set_center(-122.276, 37.456, 12) | ||
m.add_ee_layer(swir_1, {'min': 0, 'max': 3000}, 'swir_1') | ||
m.add_ee_layer(swir_2, {'min': 0, 'max': 3000}, 'swir_2') | ||
|
||
# The following examples demonstrate ee.Image arithmetic methods using two | ||
# single-band ee.Image inputs. | ||
addition = swir_1.add(swir_2) | ||
m.add_ee_layer(addition, {'min': 100, 'max': 6000}, 'addition') | ||
|
||
subtraction = swir_1.subtract(swir_2) | ||
m.add_ee_layer(subtraction, {'min': 0, 'max': 1500}, 'subtraction') | ||
|
||
multiplication = swir_1.multiply(swir_2) | ||
m.add_ee_layer(multiplication, {'min': 1.9e5, 'max': 9.4e6}, 'multiplication') | ||
|
||
division = swir_1.divide(swir_2) | ||
m.add_ee_layer(division, {'min': 0, 'max': 3}, 'division') | ||
|
||
remainder = swir_1.mod(swir_2) | ||
m.add_ee_layer(remainder, {'min': 0, 'max': 1500}, 'remainder') | ||
|
||
# If a number input is provided as the second argument, it will automatically | ||
# be promoted to an ee.Image object, a convenient shorthand for constants. | ||
exponent = swir_1.pow(3) | ||
m.add_ee_layer(exponent, {'min': 0, 'max': 2e10}, 'exponent') | ||
m | ||
# [END earthengine__apidocs__ee_image_add] |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Copyright 2023 The Google Earth Engine Community Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# [START earthengine__apidocs__ee_image_divide] | ||
# A Sentinel-2 surface reflectance image. | ||
img = ee.Image('COPERNICUS/S2_SR/20210109T185751_20210109T185931_T10SEG') | ||
|
||
# Subset two image bands and display them on the map. | ||
swir_1 = img.select('B11') | ||
swir_2 = img.select('B12') | ||
m = geemap.Map() | ||
m.set_center(-122.276, 37.456, 12) | ||
m.add_ee_layer(swir_1, {'min': 0, 'max': 3000}, 'swir_1') | ||
m.add_ee_layer(swir_2, {'min': 0, 'max': 3000}, 'swir_2') | ||
|
||
# The following examples demonstrate ee.Image arithmetic methods using two | ||
# single-band ee.Image inputs. | ||
addition = swir_1.add(swir_2) | ||
m.add_ee_layer(addition, {'min': 100, 'max': 6000}, 'addition') | ||
|
||
subtraction = swir_1.subtract(swir_2) | ||
m.add_ee_layer(subtraction, {'min': 0, 'max': 1500}, 'subtraction') | ||
|
||
multiplication = swir_1.multiply(swir_2) | ||
m.add_ee_layer(multiplication, {'min': 1.9e5, 'max': 9.4e6}, 'multiplication') | ||
|
||
division = swir_1.divide(swir_2) | ||
m.add_ee_layer(division, {'min': 0, 'max': 3}, 'division') | ||
|
||
remainder = swir_1.mod(swir_2) | ||
m.add_ee_layer(remainder, {'min': 0, 'max': 1500}, 'remainder') | ||
|
||
# If a number input is provided as the second argument, it will automatically | ||
# be promoted to an ee.Image object, a convenient shorthand for constants. | ||
exponent = swir_1.pow(3) | ||
m.add_ee_layer(exponent, {'min': 0, 'max': 2e10}, 'exponent') | ||
m | ||
# [END earthengine__apidocs__ee_image_divide] |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Copyright 2023 The Google Earth Engine Community Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# [START earthengine__apidocs__ee_image_mod] | ||
# A Sentinel-2 surface reflectance image. | ||
img = ee.Image('COPERNICUS/S2_SR/20210109T185751_20210109T185931_T10SEG') | ||
|
||
# Subset two image bands and display them on the map. | ||
swir_1 = img.select('B11') | ||
swir_2 = img.select('B12') | ||
m = geemap.Map() | ||
m.set_center(-122.276, 37.456, 12) | ||
m.add_ee_layer(swir_1, {'min': 0, 'max': 3000}, 'swir_1') | ||
m.add_ee_layer(swir_2, {'min': 0, 'max': 3000}, 'swir_2') | ||
|
||
# The following examples demonstrate ee.Image arithmetic methods using two | ||
# single-band ee.Image inputs. | ||
addition = swir_1.add(swir_2) | ||
m.add_ee_layer(addition, {'min': 100, 'max': 6000}, 'addition') | ||
|
||
subtraction = swir_1.subtract(swir_2) | ||
m.add_ee_layer(subtraction, {'min': 0, 'max': 1500}, 'subtraction') | ||
|
||
multiplication = swir_1.multiply(swir_2) | ||
m.add_ee_layer(multiplication, {'min': 1.9e5, 'max': 9.4e6}, 'multiplication') | ||
|
||
division = swir_1.divide(swir_2) | ||
m.add_ee_layer(division, {'min': 0, 'max': 3}, 'division') | ||
|
||
remainder = swir_1.mod(swir_2) | ||
m.add_ee_layer(remainder, {'min': 0, 'max': 1500}, 'remainder') | ||
|
||
# If a number input is provided as the second argument, it will automatically | ||
# be promoted to an ee.Image object, a convenient shorthand for constants. | ||
exponent = swir_1.pow(3) | ||
m.add_ee_layer(exponent, {'min': 0, 'max': 2e10}, 'exponent') | ||
m | ||
# [END earthengine__apidocs__ee_image_mod] |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Copyright 2023 The Google Earth Engine Community Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# [START earthengine__apidocs__ee_image_multiply] | ||
# A Sentinel-2 surface reflectance image. | ||
img = ee.Image('COPERNICUS/S2_SR/20210109T185751_20210109T185931_T10SEG') | ||
|
||
# Subset two image bands and display them on the map. | ||
swir_1 = img.select('B11') | ||
swir_2 = img.select('B12') | ||
m = geemap.Map() | ||
m.set_center(-122.276, 37.456, 12) | ||
m.add_ee_layer(swir_1, {'min': 0, 'max': 3000}, 'swir_1') | ||
m.add_ee_layer(swir_2, {'min': 0, 'max': 3000}, 'swir_2') | ||
|
||
# The following examples demonstrate ee.Image arithmetic methods using two | ||
# single-band ee.Image inputs. | ||
addition = swir_1.add(swir_2) | ||
m.add_ee_layer(addition, {'min': 100, 'max': 6000}, 'addition') | ||
|
||
subtraction = swir_1.subtract(swir_2) | ||
m.add_ee_layer(subtraction, {'min': 0, 'max': 1500}, 'subtraction') | ||
|
||
multiplication = swir_1.multiply(swir_2) | ||
m.add_ee_layer(multiplication, {'min': 1.9e5, 'max': 9.4e6}, 'multiplication') | ||
|
||
division = swir_1.divide(swir_2) | ||
m.add_ee_layer(division, {'min': 0, 'max': 3}, 'division') | ||
|
||
remainder = swir_1.mod(swir_2) | ||
m.add_ee_layer(remainder, {'min': 0, 'max': 1500}, 'remainder') | ||
|
||
# If a number input is provided as the second argument, it will automatically | ||
# be promoted to an ee.Image object, a convenient shorthand for constants. | ||
exponent = swir_1.pow(3) | ||
m.add_ee_layer(exponent, {'min': 0, 'max': 2e10}, 'exponent') | ||
m | ||
# [END earthengine__apidocs__ee_image_multiply] |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Copyright 2023 The Google Earth Engine Community Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# [START earthengine__apidocs__ee_image_pow] | ||
# A Sentinel-2 surface reflectance image. | ||
img = ee.Image('COPERNICUS/S2_SR/20210109T185751_20210109T185931_T10SEG') | ||
|
||
# Subset two image bands and display them on the map. | ||
swir_1 = img.select('B11') | ||
swir_2 = img.select('B12') | ||
m = geemap.Map() | ||
m.set_center(-122.276, 37.456, 12) | ||
m.add_ee_layer(swir_1, {'min': 0, 'max': 3000}, 'swir_1') | ||
m.add_ee_layer(swir_2, {'min': 0, 'max': 3000}, 'swir_2') | ||
|
||
# The following examples demonstrate ee.Image arithmetic methods using two | ||
# single-band ee.Image inputs. | ||
addition = swir_1.add(swir_2) | ||
m.add_ee_layer(addition, {'min': 100, 'max': 6000}, 'addition') | ||
|
||
subtraction = swir_1.subtract(swir_2) | ||
m.add_ee_layer(subtraction, {'min': 0, 'max': 1500}, 'subtraction') | ||
|
||
multiplication = swir_1.multiply(swir_2) | ||
m.add_ee_layer(multiplication, {'min': 1.9e5, 'max': 9.4e6}, 'multiplication') | ||
|
||
division = swir_1.divide(swir_2) | ||
m.add_ee_layer(division, {'min': 0, 'max': 3}, 'division') | ||
|
||
remainder = swir_1.mod(swir_2) | ||
m.add_ee_layer(remainder, {'min': 0, 'max': 1500}, 'remainder') | ||
|
||
# If a number input is provided as the second argument, it will automatically | ||
# be promoted to an ee.Image object, a convenient shorthand for constants. | ||
exponent = swir_1.pow(3) | ||
m.add_ee_layer(exponent, {'min': 0, 'max': 2e10}, 'exponent') | ||
m | ||
# [END earthengine__apidocs__ee_image_pow] |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Copyright 2023 The Google Earth Engine Community Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# [START earthengine__apidocs__ee_image_subtract] | ||
# A Sentinel-2 surface reflectance image. | ||
img = ee.Image('COPERNICUS/S2_SR/20210109T185751_20210109T185931_T10SEG') | ||
|
||
# Subset two image bands and display them on the map. | ||
swir_1 = img.select('B11') | ||
swir_2 = img.select('B12') | ||
m = geemap.Map() | ||
m.set_center(-122.276, 37.456, 12) | ||
m.add_ee_layer(swir_1, {'min': 0, 'max': 3000}, 'swir_1') | ||
m.add_ee_layer(swir_2, {'min': 0, 'max': 3000}, 'swir_2') | ||
|
||
# The following examples demonstrate ee.Image arithmetic methods using two | ||
# single-band ee.Image inputs. | ||
addition = swir_1.add(swir_2) | ||
m.add_ee_layer(addition, {'min': 100, 'max': 6000}, 'addition') | ||
|
||
subtraction = swir_1.subtract(swir_2) | ||
m.add_ee_layer(subtraction, {'min': 0, 'max': 1500}, 'subtraction') | ||
|
||
multiplication = swir_1.multiply(swir_2) | ||
m.add_ee_layer(multiplication, {'min': 1.9e5, 'max': 9.4e6}, 'multiplication') | ||
|
||
division = swir_1.divide(swir_2) | ||
m.add_ee_layer(division, {'min': 0, 'max': 3}, 'division') | ||
|
||
remainder = swir_1.mod(swir_2) | ||
m.add_ee_layer(remainder, {'min': 0, 'max': 1500}, 'remainder') | ||
|
||
# If a number input is provided as the second argument, it will automatically | ||
# be promoted to an ee.Image object, a convenient shorthand for constants. | ||
exponent = swir_1.pow(3) | ||
m.add_ee_layer(exponent, {'min': 0, 'max': 2e10}, 'exponent') | ||
m | ||
# [END earthengine__apidocs__ee_image_subtract] |