הודעה: כל הפרויקטים הלא מסחריים שנרשמו לשימוש ב-Earth Engine לפני 15 באפריל 2025 חייבים לעבור אימות של הזכאות לשימוש לא מסחרי כדי לשמור על הגישה ל-Earth Engine.
קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
פונקציות Reducer הן הדרך לצבור נתונים לאורך זמן, במרחב, בפסות, במערכים ובמבנים אחרים של נתונים ב-Earth Engine. הכיתה ee.Reducer קובעת את אופן צבירת הנתונים. ב-reducers מהקלאס הזה אפשר לציין סטטיסטיקה פשוטה לשימוש בצבירה (למשל, מינימום, מקסימום, ממוצע, חציון, סטיית תקן וכו'), או סיכום מורכב יותר של נתוני הקלט (למשל, תרשים היסטוגרמה, רגרסיה לינארית, רשימה). הפחתות יכולות להתרחש לאורך זמן (imageCollection.reduce()), במרחב (image.reduceRegion(), image.reduceNeighborhood()), בתחומים (image.reduce()) או במרחב המאפיינים של FeatureCollection (featureCollection.reduceColumns() או שיטות FeatureCollection שמתחילות ב-aggregate_).
למצמצמים יש קלטים ופלטים
הפונקציות האלה מקבלות מערך נתונים של קלט ומפיקות פלט יחיד. כשמפעילים Reducer יחיד של קלט על תמונה עם כמה פסים, מערכת Earth Engine מעתיקה את ה-Reducer באופן אוטומטי ומפעילה אותו בנפרד בכל אחד מהפסים. כתוצאה מכך, לתמונה בפלט יש את אותו מספר של פסגות כמו לתמונה בקלט. כל פסגה בפלט היא הפחתת הפיקסלים מהפסגה התואמת בנתוני הקלט. חלק מהמרכזים מקבלים צמדי ערכים של מערכי נתונים של קלט. המצמצמים האלה לא ישוחזרו באופן אוטומטי לכל פס. לדוגמה, הפונקציה ee.Reducer.LinearRegression() מקבלת כמה מערכי נתונים של חזויים (שמייצגים משתנים עצמאיים ברגרסיה) בסדר מסוים (ראו פונקציות הפחתה של רגרסיה).
חלק מהמכשירים להפחתת נתונים יוצרים כמה פלטים, למשל ee.Reducer.minMax(), ee.Reducer.histogram() או ee.Reducer.toList(). לדוגמה:
הפונקציה הזו תיצור פלט עם מספר הלהקות הכפול של הקלט, כאשר שמות הלהקות בפלט יתווספו להם '_min' או '_max'.
סוג הפלט צריך להתאים לחישוב. לדוגמה, למצמצם שמוחל על ImageCollection יש פלט Image. מכיוון שהפלט מפורש כערך פיקסל, צריך להשתמש ב-reducers עם פלט מספרי כדי לצמצם את הערך של ImageCollection (reducers כמו toList() או histogram() לא יפעלו).
Reducers משתמשים בנתוני קלט משוקלים
כברירת מחדל, הפחתות בערכים של הפיקסלים מקבלות משקל לפי המסכה שלהן, אבל אפשר לשנות את ההתנהגות הזו (ראו הקטע 'משקל'). לא ייעשה שימוש בפיקסלים עם מסיכה שווה ל-0 בהפחתה.
שילוב של reducers
אם אתם רוצים להחיל כמה מחליפים על אותם נתוני קלט, מומלץ combine() את המחליפים כדי לשפר את היעילות. באופן ספציפי, קריאה ל-combine() במצמצם עם הערך sharedInputs שמוגדר כ-true תגרום לפעולה אחת בלבד על הנתונים. לדוגמה, כדי לחשב את הממוצע וסטיית התקן של הפיקסלים בתמונה, אפשר להשתמש בקוד הבא:
בתוצאה, שימו לב שהשמות של המצמצמים מצורפים לשמות של מקורות הקלט כדי להבדיל בין הפלט של המצמצמים. ההתנהגות הזו רלוונטית גם לפלט של תמונות, שבו שם המצמצם יתווסף לשמות של פסולות הפלט.
אם משלבים reducers שמשתמשים בקלט ללא משקלים ו-reducers שמשתמשים בקלט עם משקלים, כל הקלט עם המשקלים חייב להופיע לפני כל הקלט ללא המשקלים.
[[["התוכן קל להבנה","easyToUnderstand","thumb-up"],["התוכן עזר לי לפתור בעיה","solvedMyProblem","thumb-up"],["סיבה אחרת","otherUp","thumb-up"]],[["חסרים לי מידע או פרטים","missingTheInformationINeed","thumb-down"],["התוכן מורכב מדי או עם יותר מדי שלבים","tooComplicatedTooManySteps","thumb-down"],["התוכן לא עדכני","outOfDate","thumb-down"],["בעיה בתרגום","translationIssue","thumb-down"],["בעיה בדוגמאות/בקוד","samplesCodeIssue","thumb-down"],["סיבה אחרת","otherDown","thumb-down"]],["עדכון אחרון: 2025-07-25 (שעון UTC)."],[[["\u003cp\u003eReducers in Earth Engine aggregate data over time, space, bands, arrays, and other data structures, using methods like \u003ccode\u003ereduceRegion()\u003c/code\u003e and \u003ccode\u003ereduce()\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eReducers can calculate simple statistics (e.g., mean, minimum) or more complex summaries (e.g., histograms, linear regressions) on images, image collections, and feature collections.\u003c/p\u003e\n"],["\u003cp\u003eWhen applied to multi-band images, single input reducers are automatically applied to each band, producing an output with the same number of bands.\u003c/p\u003e\n"],["\u003cp\u003eReducers can be combined using \u003ccode\u003ecombine()\u003c/code\u003e for efficient processing, allowing multiple calculations in a single pass over the data.\u003c/p\u003e\n"],["\u003cp\u003eBy default, pixel values in reductions are weighted by their mask, meaning pixels with a mask of 0 are excluded from the calculation.\u003c/p\u003e\n"]]],[],null,["# Reducer Overview\n\nReducers are the way to aggregate data over time, space, bands, arrays and other data\nstructures in Earth Engine. The `ee.Reducer` class specifies how data is\naggregated. The reducers in this class can specify a simple statistic to use for the\naggregation (e.g. minimum, maximum, mean, median, standard deviation, etc.), or a more complex\nsummary of the input data (e.g. histogram, linear regression, list). Reductions may occur over\ntime (`imageCollection.reduce()`), space (`image.reduceRegion()`,\n`image.reduceNeighborhood()`), bands (`image.reduce()`), or the\nattribute space of a `FeatureCollection` (`featureCollection.reduceColumns()`\nor `FeatureCollection` methods that start with `aggregate_`).\n\nReducers have inputs and outputs\n--------------------------------\n\n\nReducers take an input dataset and produce a single output. When a single input reducer is\napplied to a multi-band image, Earth Engine automatically replicates the reducer and applies\nit separately to each band. As a result, the output image has the same number of bands as the\ninput image; each band in the output is the reduction of pixels from the corresponding band in\nthe input data. Some reducers take tuples of input datasets. These reducers will not be\nautomatically replicated for each band. For example,\n`ee.Reducer.LinearRegression()` takes multiple predictor datasets (representing\nindependent variables in the regression) in a particular order (see\n[Regression reducers](/earth-engine/guides/reducers_regression)).\n\n\nSome reducers produce multiple outputs, for example `ee.Reducer.minMax()`,\n`ee.Reducer.histogram()` or `ee.Reducer.toList()`. For example:\n\n### Code Editor (JavaScript)\n\n```javascript\n// Load and filter the Sentinel-2 image collection.\nvar collection = ee.ImageCollection('COPERNICUS/S2_HARMONIZED')\n .filterDate('2016-01-01', '2016-12-31')\n .filterBounds(ee.Geometry.Point([-81.31, 29.90]));\n\n// Reduce the collection.\nvar extrema = collection.reduce(ee.Reducer.minMax());\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\n### Colab (Python)\n\n```python\n# Load and filter the Sentinel-2 image collection.\ncollection = (\n ee.ImageCollection('COPERNICUS/S2_HARMONIZED')\n .filterDate('2016-01-01', '2016-12-31')\n .filterBounds(ee.Geometry.Point([-81.31, 29.90]))\n)\n\n# Reduce the collection.\nextrema = collection.reduce(ee.Reducer.minMax())\n```\n\n\nThis will produce an output with twice the number of bands of the inputs, where band names in\nthe output have '_min' or '_max' appended to the band name.\n\n\nThe output type should match the computation. For example, a reducer applied to an\n`ImageCollection` has an `Image` output. Because the output is\ninterpreted as a pixel value, you must use reducers with a numeric output to reduce an\n`ImageCollection` (reducers like `toList()` or\n`histogram()` won't work).\n\nReducers use weighted inputs\n----------------------------\n\n\nBy default, reductions over pixel values are weighted by their mask, though this behavior can\nbe changed (see the [Weighting section](/earth-engine/guides/reducers_weighting)). Pixels with mask\nequal to 0 will not be used in the reduction.\n\nCombining reducers\n------------------\n\n\nIf your intent is to apply multiple reducers to the same inputs, it's good practice to\n`combine()` the reducers for efficiency. Specifically, calling\n`combine()` on a reducer with `sharedInputs` set to\n`true` will result in only a single pass over the data. For example, to compute the\nmean and standard deviation of pixels in an image, you could use something like this:\n\n### Code Editor (JavaScript)\n\n```javascript\n// Load a Landsat 8 image.\nvar image = ee.Image('LANDSAT/LC08/C02/T1/LC08_044034_20140318');\n\n// Combine the mean and standard deviation reducers.\nvar reducers = ee.Reducer.mean().combine({\n reducer2: ee.Reducer.stdDev(),\n sharedInputs: true\n});\n\n// Use the combined reducer to get the mean and SD of the image.\nvar stats = image.reduceRegion({\n reducer: reducers,\n bestEffort: true,\n});\n\n// Display the dictionary of band means and SDs.\nprint(stats);\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\n### Colab (Python)\n\n```python\n# Load a Landsat 8 image.\nimage = ee.Image('LANDSAT/LC08/C02/T1/LC08_044034_20140318')\n\n# Combine the mean and standard deviation reducers.\nreducers = ee.Reducer.mean().combine(\n reducer2=ee.Reducer.stdDev(), sharedInputs=True\n)\n\n# Use the combined reducer to get the mean and SD of the image.\nstats = image.reduceRegion(reducer=reducers, bestEffort=True)\n\n# Display the dictionary of band means and SDs.\ndisplay(stats)\n```\n\n\nIn the output, note that the names of the reducers have been appended to the names of the\ninputs to distinguish the reducer outputs. This behavior also applies to image outputs, which\nwill have the name of the reducer appended to output band names.\n\n\nIf you are combining reducers using unweighted inputs and reducers using weighted inputs, all\nweighted inputs must be before all unweighted inputs."]]