Announcement: All noncommercial projects registered to use Earth Engine before April 15, 2025 must verify noncommercial eligibility to maintain Earth Engine access.
Stay organized with collections
Save and categorize content based on your preferences.
Calculates the remainder of the first value divided by the second for each matched pair of bands in image1 and image2. If either image1 or image2 has only 1 band, then it is used against all the bands in the other image. If the images have the same number of bands, but not the same names, they're used pairwise in the natural order. The output bands are named for the longer of the two inputs, or if they're equal in length, in image1's order. The type of the output pixels is the union of the input types.
Usage
Returns
Image.mod(image2)
Image
Argument
Type
Details
this: image1
Image
The image from which the left operand bands are taken.
image2
Image
The image from which the right operand bands are taken.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2023-10-06 UTC."],[[["\u003cp\u003e\u003ccode\u003emod()\u003c/code\u003e calculates the remainder when the first image is divided by the second, band-by-band.\u003c/p\u003e\n"],["\u003cp\u003eIt handles single-band images by applying them to all bands of the other image.\u003c/p\u003e\n"],["\u003cp\u003eOutput bands are named based on the input images, prioritizing the longer one's band names.\u003c/p\u003e\n"],["\u003cp\u003eThe output pixel type combines the types of the input images.\u003c/p\u003e\n"],["\u003cp\u003eThe method returns a new \u003ccode\u003eImage\u003c/code\u003e object containing the calculated remainders.\u003c/p\u003e\n"]]],["The `mod()` function calculates the remainder of a division operation between two images (`image1` and `image2`). It pairs bands from each image. If one image has a single band, that band is used against all bands of the other. Otherwise, bands are paired in order. The output image's band names are based on the input images' names, and the output pixel type is a union of the input types. Examples for other operations such as addition, subtraction, division, multiplication, and exponent are provided.\n"],null,["Calculates the remainder of the first value divided by the second for each matched pair of bands in image1 and image2. If either image1 or image2 has only 1 band, then it is used against all the bands in the other image. If the images have the same number of bands, but not the same names, they're used pairwise in the natural order. The output bands are named for the longer of the two inputs, or if they're equal in length, in image1's order. The type of the output pixels is the union of the input types.\n\n\u003cbr /\u003e\n\n| Usage | Returns |\n|---------------------|---------|\n| Image.mod`(image2)` | Image |\n\n| Argument | Type | Details |\n|----------------|-------|---------------------------------------------------------|\n| this: `image1` | Image | The image from which the left operand bands are taken. |\n| `image2` | Image | The image from which the right operand bands are taken. |\n\nExamples\n\nCode Editor (JavaScript) \n\n```javascript\n// A Sentinel-2 surface reflectance image.\nvar img = ee.Image('COPERNICUS/S2_SR/20210109T185751_20210109T185931_T10SEG');\n\n// Subset two image bands and display them on the map.\nvar swir1 = img.select('B11');\nvar swir2 = img.select('B12');\nMap.setCenter(-122.276, 37.456, 12);\nMap.addLayer(swir1, {min: 0, max: 3000}, 'swir1');\nMap.addLayer(swir2, {min: 0, max: 3000}, 'swir2');\n\n// The following examples demonstrate ee.Image arithmetic methods using two\n// single-band ee.Image inputs.\nvar addition = swir1.add(swir2);\nMap.addLayer(addition, {min: 100, max: 6000}, 'addition');\n\nvar subtraction = swir1.subtract(swir2);\nMap.addLayer(subtraction, {min: 0, max: 1500}, 'subtraction');\n\nvar multiplication = swir1.multiply(swir2);\nMap.addLayer(multiplication, {min: 1.9e5, max: 9.4e6}, 'multiplication');\n\nvar division = swir1.divide(swir2);\nMap.addLayer(division, {min: 0, max: 3}, 'division');\n\nvar remainder = swir1.mod(swir2);\nMap.addLayer(remainder, {min: 0, max: 1500}, 'remainder');\n\n// If a number input is provided as the second argument, it will automatically\n// be promoted to an ee.Image object, a convenient shorthand for constants.\nvar exponent = swir1.pow(3);\nMap.addLayer(exponent, {min: 0, max: 2e10}, 'exponent');\n```\nPython setup\n\nSee the [Python Environment](/earth-engine/guides/python_install) page for information on the Python API and using\n`geemap` for interactive development. \n\n```python\nimport ee\nimport geemap.core as geemap\n```\n\nColab (Python) \n\n```python\n# A Sentinel-2 surface reflectance image.\nimg = ee.Image('COPERNICUS/S2_SR/20210109T185751_20210109T185931_T10SEG')\n\n# Subset two image bands and display them on the map.\nswir_1 = img.select('B11')\nswir_2 = img.select('B12')\nm = geemap.Map()\nm.set_center(-122.276, 37.456, 12)\nm.add_layer(swir_1, {'min': 0, 'max': 3000}, 'swir_1')\nm.add_layer(swir_2, {'min': 0, 'max': 3000}, 'swir_2')\n\n# The following examples demonstrate ee.Image arithmetic methods using two\n# single-band ee.Image inputs.\naddition = swir_1.add(swir_2)\nm.add_layer(addition, {'min': 100, 'max': 6000}, 'addition')\n\nsubtraction = swir_1.subtract(swir_2)\nm.add_layer(subtraction, {'min': 0, 'max': 1500}, 'subtraction')\n\nmultiplication = swir_1.multiply(swir_2)\nm.add_layer(multiplication, {'min': 1.9e5, 'max': 9.4e6}, 'multiplication')\n\ndivision = swir_1.divide(swir_2)\nm.add_layer(division, {'min': 0, 'max': 3}, 'division')\n\nremainder = swir_1.mod(swir_2)\nm.add_layer(remainder, {'min': 0, 'max': 1500}, 'remainder')\n\n# If a number input is provided as the second argument, it will automatically\n# be promoted to an ee.Image object, a convenient shorthand for constants.\nexponent = swir_1.pow(3)\nm.add_layer(exponent, {'min': 0, 'max': 2e10}, 'exponent')\nm\n```"]]