תצוגה חזותית של ImageCollection

אפשר להציג את התמונות שמרכיבות ImageCollection כאנימציה או כסדרה של תמונות ממוזערות שנקראת "רצועת תמונות". השיטות האלה מאפשרות להעריך במהירות את התוכן של ImageCollection, והן אמצעי יעיל לצפייה בשינויים במרחב ובזמן (איור 1).

בקטעים הבאים מוסבר איך להכין ImageCollection להצגה חזותית, מוצג קוד לדוגמה לכל שיטה להצגה חזותית של אוסף, ומתוארות כמה טכניקות מתקדמות של אנימציה.


איור 1. אנימציה שמראה התקדמות של שלושה ימים של הוריקנים באוקיינוס האטלנטי בספטמבר 2017.

הכנת האוסף

אפשר לסנן, לשלב, למיין ולעצב תמונות באוסף כדי להציג רק את התמונות הרלוונטיות או להדגיש תופעה מסוימת. אפשר להזין כל ImageCollection לפונקציות של התצוגה החזותית, אבל אוסף שנבחר בקפידה תוך התחשבות בטווחי תאריכים שנתיים ובין-שנתיים, במרווח התצפית, בהיקף האזורי, באיכות ובייצוג יכול להניב תוצאות טובות יותר.

סינון

מסננים אוסף תמונות כך שיכלול רק נתונים רלוונטיים שתומכים במטרת ההמחשה החזותית. חשוב להביא בחשבון תאריכים, היקף מרחבי, איכות ומאפיינים אחרים שספציפיים למערך נתונים נתון.

לדוגמה, סינון של אוסף מידת ההחזרה של פני השטח של Sentinel-2 לפי:

טווח תאריכים אחד,

Code Editor (JavaScript)

var s2col = ee.ImageCollection('COPERNICUS/S2_SR_HARMONIZED')
  .filterDate('2018-01-01', '2019-01-01');

טווח של ימים בשנה,

Code Editor (JavaScript)

var s2col = ee.ImageCollection('COPERNICUS/S2_SR_HARMONIZED')
  .filter(ee.Filter.calendarRange(171, 242, 'day_of_year'));

אזור עניין,

Code Editor (JavaScript)

var s2col = ee.ImageCollection('COPERNICUS/S2_SR_HARMONIZED')
  .filterBounds(ee.Geometry.Point(-122.1, 37.2));

או מאפיין של תמונה.

Code Editor (JavaScript)

var s2col = ee.ImageCollection('COPERNICUS/S2_SR_HARMONIZED')
  .filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 50));

לשרשר כמה מסננים.

Code Editor (JavaScript)

var s2col = ee.ImageCollection('COPERNICUS/S2_SR_HARMONIZED')
  .filterDate('2018-01-01', '2019-01-01')
  .filterBounds(ee.Geometry.Point(-122.1, 37.2))
  .filter('CLOUDY_PIXEL_PERCENTAGE < 50');

מרוכב

שילוב של טווחי תאריכים שנתיים ורב-שנתיים כדי לצמצם את מספר התמונות באוסף ולשפר את האיכות. לדוגמה, נניח שאתם רוצים ליצור תצוגה חזותית של NDVI שנתי באפריקה. אפשרות אחת היא פשוט לסנן אוסף NDVI של 16 ימים ב-MODIS כך שיכלול את כל התצפיות של 2018.

Code Editor (JavaScript)

var ndviCol = ee.ImageCollection('MODIS/061/MOD13A2')
  .filterDate('2018-01-01', '2019-01-01')
  .select('NDVI');

תמונה מורכבת רב-שנתית לפי סינון והפחתה

התצוגה החזותית של האוסף שלמעלה מראה רעש משמעותי באזורים המיוערים שבהם יש כיסוי עננים כבד (איור 2א). כדי לקבל ייצוג טוב יותר, אפשר לצמצם את טווחי התאריכים הסדרתיים לפי החציון בכל השנים באוסף MODIS.

Code Editor (JavaScript)

// Make a day-of-year sequence from 1 to 365 with a 16-day step.
var doyList = ee.List.sequence(1, 365, 16);

// Import a MODIS NDVI collection.
var ndviCol = ee.ImageCollection('MODIS/061/MOD13A2').select('NDVI');

// Map over the list of days to build a list of image composites.
var ndviCompList = doyList.map(function(startDoy) {
  // Ensure that startDoy is a number.
  startDoy = ee.Number(startDoy);

  // Filter images by date range; starting with the current startDate and
  // ending 15 days later. Reduce the resulting image collection by median.
  return ndviCol
    .filter(ee.Filter.calendarRange(startDoy, startDoy.add(15), 'day_of_year'))
    .reduce(ee.Reducer.median());
});

// Convert the image List to an ImageCollection.
var ndviCompCol = ee.ImageCollection.fromImages(ndviCompList);

האנימציה שנוצרת מהאוסף הזה פחות רועשת, כי כל תמונה מייצגת את החציון של קומפוזיציית NDVI של 16 ימים, עם נתונים של יותר מ-20 שנה (איור 1b). במדריך הזה מוסבר איך ליצור את האנימציה הזו.

איור 2א. מדד NDVI שנתי ללא קומפוזיציה בין-שנתית. איור 2ב. ‫NDVI שנתי עם קומפוזיציה בין-שנתית.

תמונה מורכבת של שנה מסוימת לפי סינון וצמצום

בדוגמה הקודמת השתמשנו בקומפוזיציה בין-שנתית. אפשר גם ליצור קומפוזיציה של סדרת תצפיות תוך-שנתיות. לדוגמה, נתוני Landsat נאספים כל 16 ימים לסצנה נתונה לכל חיישן, אבל לעיתים קרובות חלק מהתמונות מוסתרות על ידי עננים. הסתרת העננים ושילוב של כמה תמונות מאותה עונה יכולים ליצור ייצוג עם פחות עננים. נבחן את הדוגמה הבאה, שבה תמונות Landsat 5 מיולי ומאוגוסט משולבות באמצעות חציון לכל שנה מ-1985 עד 2011.

Code Editor (JavaScript)

// Assemble a collection of Landsat surface reflectance images for a given
// region and day-of-year range.
var lsCol = ee.ImageCollection('LANDSAT/LT05/C02/T1_L2')
  .filterBounds(ee.Geometry.Point(-122.9, 43.6))
  .filter(ee.Filter.dayOfYear(182, 243))
  // Add the observation year as a property to each image.
  .map(function(img) {
    return img.set('year', ee.Image(img).date().get('year'));
  });


// Define a function to scale the data and mask unwanted pixels.
function maskL457sr(image) {
  // Bit 0 - Fill
  // Bit 1 - Dilated Cloud
  // Bit 2 - Unused
  // Bit 3 - Cloud
  // Bit 4 - Cloud Shadow
  var qaMask = image.select('QA_PIXEL').bitwiseAnd(parseInt('11111', 2)).eq(0);
  var saturationMask = image.select('QA_RADSAT').eq(0);

  // Apply the scaling factors to the appropriate bands.
  var opticalBands = image.select('SR_B.').multiply(0.0000275).add(-0.2);
  var thermalBand = image.select('ST_B6').multiply(0.00341802).add(149.0);

  // Replace the original bands with the scaled ones and apply the masks.
  return image.addBands(opticalBands, null, true)
      .addBands(thermalBand, null, true)
      .updateMask(qaMask)
      .updateMask(saturationMask);
}

// Define a list of unique observation years from the image collection.
var years = ee.List(lsCol.aggregate_array('year')).distinct().sort();

// Map over the list of years to build a list of annual image composites.
var lsCompList = years.map(function(year) {
  return lsCol
    // Filter image collection by year.
    .filterMetadata('year', 'equals', year)
    // Apply cloud mask.
    .map(maskL457sr)
    // Reduce image collection by median.
    .reduce(ee.Reducer.median())
    // Set composite year as an image property.
    .set('year', year);
});

// Convert the image List to an ImageCollection.
var lsCompCol = ee.ImageCollection.fromImages(lsCompList);

תמונה מורכבת של שנה אחת באמצעות צירוף וצמצום

שימו לב ששתי השיטות הקודמות ליצירת קומפוזיציה ממפות List של ימים ושנים כדי להגדיר באופן מצטבר תאריכים חדשים לסינון וליצירת קומפוזיציה. דרך נוספת לבצע את הפעולה הזו היא להחיל צירוף. בקטע הקוד הבא, מוגדר אוסף ייחודי של שנים, ואז מוחל saveAll join כדי לזהות את כל התמונות שתואמות לשנה נתונה. התמונות ששייכות לשנה מסוימת מקובצות באובייקט List, שמאוחסן כמאפיין של השנה הרלוונטית באוסף השנים הנפרדות. תמונות שנתיות מורכבות נוצרות מהרשימות האלה על ידי צמצום של ImageCollections שמוגדר על ידן בפונקציה שממופה על פני אוסף השנים הנפרדות.

Code Editor (JavaScript)

// Assemble a collection of Landsat surface reflectance images for a given
// region and day-of-year range.
var lsCol = ee.ImageCollection('LANDSAT/LT05/C02/T1_L2')
  .filterBounds(ee.Geometry.Point(-122.9, 43.6))
  .filter(ee.Filter.dayOfYear(182, 243))
  // Add the observation year as a property to each image.
  .map(function(img) {
    return img.set('year', ee.Image(img).date().get('year'));
  });

// Make a distinct year collection; one image representative per year.
var distinctYears = lsCol.distinct('year').sort('year');

// Define a join filter; one-to-many join on ‘year’ property.
var filter = ee.Filter.equals({leftField: 'year', rightField: 'year'});

// Define a join.
var join = ee.Join.saveAll('year_match');

// Apply the join; results in 'year_match' property being added to each distinct
// year representative image. The list includes all images in the collection
// belonging to the respective year.
var joinCol = join.apply(distinctYears, lsCol, filter);

// Define a function to scale the data and mask unwanted pixels.
function maskL457sr(image) {
  // Bit 0 - Fill
  // Bit 1 - Dilated Cloud
  // Bit 2 - Unused
  // Bit 3 - Cloud
  // Bit 4 - Cloud Shadow
  var qaMask = image.select('QA_PIXEL').bitwiseAnd(parseInt('11111', 2)).eq(0);
  var saturationMask = image.select('QA_RADSAT').eq(0);

  // Apply the scaling factors to the appropriate bands.
  var opticalBands = image.select('SR_B.').multiply(0.0000275).add(-0.2);
  var thermalBand = image.select('ST_B6').multiply(0.00341802).add(149.0);

  // Replace the original bands with the scaled ones and apply the masks.
  return image.addBands(opticalBands, null, true)
      .addBands(thermalBand, null, true)
      .updateMask(qaMask)
      .updateMask(saturationMask);
}

// Map over the distinct years collection to build a list of annual image
// composites.
var lsCompList = joinCol.map(function(img) {
  // Get the list of images belonging to the given year.
  return ee.ImageCollection.fromImages(img.get('year_match'))
    // Apply cloud mask.
    .map(maskL457sr)
    // Reduce image collection by median.
    .reduce(ee.Reducer.median())
    // Set composite year as an image property.
    .copyProperties(img, ['year']);
});

// Convert the image List to an ImageCollection.
var lsCompCol = ee.ImageCollection(lsCompList);

‫Same-day composite by join and reduce

מקרה נוסף שבו משתמשים בקומפוזיציה הוא ליצירת פסיפסים של תמונות עם רציפות מרחבית. נניח שהאזור שמעניין אתכם משתרע על פני שתי שורות של Landsat באותו נתיב, והמטרה שלכם היא להציג פסיפס של שתי התמונות לכל מסלול של Landsat 8 בשנים 2017 ו-2018. כאן, אחרי סינון האוסף לפי נתיב ושורה, נעשה שימוש בפעולת איחוד כדי ליצור פסיפס של תמונות Landsat מאותו מסלול, שמוגדר לפי תאריך הצילום.

Code Editor (JavaScript)

var lsCol = ee.ImageCollection('LANDSAT/LC08/C02/T1_L2')
  .filterDate('2017-01-01', '2019-01-01')
  .filter('WRS_PATH == 38 && (WRS_ROW == 28 || WRS_ROW == 29)')
  .map(function(img) {
    var date = img.date().format('yyyy-MM-dd');
    return img.set('date', date);
  });

var distinctDates = lsCol.distinct('date').sort('date');
var filter = ee.Filter.equals({leftField: 'date', rightField: 'date'});
var join = ee.Join.saveAll('date_match');
var joinCol = join.apply(distinctDates, lsCol, filter);

var lsColMos = ee.ImageCollection(joinCol.map(function(col) {
  return ee.ImageCollection.fromImages(col.get('date_match')).mosaic();
}));

מיון

אפשר למיין אוסף לפי זמן כדי לוודא שהסדר הכרונולוגי נכון, או לפי מאפיין לבחירתכם. כברירת מחדל, סדרת הפריימים של התצוגה החזותית ממוינת לפי הסדר הטבעי של האוסף. אפשר לשנות את סדר הסדרות באמצעות שיטת האיסוף sort, שבה בוחרים מאפיין Image למיון בסדר עולה או יורד. לדוגמה, כדי למיין לפי זמן התצפית, משתמשים במאפיין system:time_start שנמצא בכל מקום.

Code Editor (JavaScript)

var s2col = ee.ImageCollection('COPERNICUS/S2_SR_HARMONIZED')
  .filterBounds(ee.Geometry.Point(-122.1, 37.2))
  .sort('system:time_start');

או שאולי צריך להגדיר את הסדר לפי עלייה ברמת העננות, כמו במקרה הזה של תמונות Sentinel-2.

Code Editor (JavaScript)

var s2col = ee.ImageCollection('COPERNICUS/S2_SR_HARMONIZED')
  .filterBounds(ee.Geometry.Point(-122.1, 37.2))
  .sort('CLOUDY_PIXEL_PERCENTAGE');

אפשר גם להגדיר את הסדר לפי מאפיין נגזר, כמו NDVI אזורי ממוצע. כאן, ה-NDVI האזורי מתווסף כמאפיין לכל תמונה בפונקציה ממופה, ואחריו מתבצע מיון לפי המאפיין החדש.

Code Editor (JavaScript)

// Define an area of interest geometry.
var aoi = ee.Geometry.Point(-122.1, 37.2).buffer(1e4);

// Filter MODIS NDVI image collection by a date range.
var ndviCol = ee.ImageCollection('MODIS/061/MOD13A1')
  .filterDate('2018-01-01', '2019-01-01')
  .select('NDVI')
  // Map over the image collection to calculate regional mean NDVI and add
  // the result to each image as a property.
  .map(function(img) {
    var meanNdvi = img.reduceRegion({
      reducer: ee.Reducer.mean(), geometry: aoi, scale: 500});
    return img.set('meanNdvi', meanNdvi.get('NDVI'));
  })
  // Sort the collection by descending regional mean NDVI.
  .sort('meanNdvi', false);

המחשה באמצעות תמונות

הדמיית תמונה הופכת מספרים לצבעים. יש שלוש דרכים לשלוט באופן שבו נתוני התמונה מיוצגים כצבע בשיטות להצגה חזותית של אוסף:

  1. מספקים ארגומנטים של תצוגה חזותית ישירות ל-getVideoThumbURL ול-getFilmstripThumbURL.
  2. ממפים את השיטה visualize של התמונה על אוסף התמונות לפני שמפעילים את getVideoThumbURL ו-getFilmstripThumbURL.
  3. ממפים את השיטה sldStyle של התמונה על אוסף התמונות לפני שמפעילים את getVideoThumbURL ו-getFilmstripThumbURL. מידע נוסף זמין במאמר Styled Layer Descriptor.

הדוגמאות במדריך הזה משתמשות באפשרויות 1 ו-2, שבהן ההמחשה החזותית מושגת על ידי מיפוי של שלוש רצועות תמונה של תמונה עם כמה רצועות לערוצי הצבעים אדום, ירוק וכחול, או דירוג ערכים של רצועה אחת באופן ליניארי לאורך לוח צבעים. הפרמטרים של ההמחשה כוללים:

פרמטרים של תצוגה חזותית
פרמטר תיאור סוג
להקות רשימה מופרדת בפסיקים של שלושה שמות של ערוצים שימופו ל-RGB list
דקות ערכים למיפוי ל-0 מספר או רשימה של שלושה מספרים, אחד לכל פס
max הערכים למיפוי ל-255 מספר או רשימה של שלושה מספרים, אחד לכל פס
gain הערכים שבהם צריך להכפיל כל ערך של פיקסל מספר או רשימה של שלושה מספרים, אחד לכל פס
bias הערכים שצריך להוסיף לכל DN מספר או רשימה של שלושה מספרים, אחד לכל פס
gamma גורמי תיקון גאמה מספר או רשימה של שלושה מספרים, אחד לכל פס
palette רשימה של מחרוזות צבע בסגנון CSS (תמונות עם פס אחד בלבד) רשימה מופרדת בפסיקים של מחרוזות הקסדצימליות
opacity האטימות של השכבה (0.0 היא שקיפות מלאה ו-1.0 היא אטימות מלאה) number

משתמשים בארגומנט bands כדי לבחור את הרצועות שרוצים להציג. צריך לספק רשימה של שם אחד או שלושה שמות של להקות. בתמונות עם כמה ערוצים, שלושת הערוצים הראשונים נבחרים כברירת מחדל. סדר השמות של הרצועות קובע את הקצאת הצבעים. הרצועה הראשונה, השנייה והשלישית ברשימה ממופות לאדום, ירוק וכחול, בהתאמה.

כשמציגים תמונות, חשוב להביא בחשבון את קנה המידה של טווח הנתונים. כברירת מחדל, ערכי נתונים של נקודה צפה (floating point) בין 0 ל-1 (כולל) מותאמים לערכים בין 0 ל-255 (כולל). ערכים מחוץ לטווח הזה יומרו ל-0 או ל-255, בהתאם לשאלה אם הם קטנים מ-0 או גדולים מ-1, בהתאמה. לגבי נתונים של מספרים שלמים, הקיבולת המלאה שמוגדרת לפי הסוג שלהם מותאמת לטווח שבין 0 ל-255 (לדוגמה, לנתונים של 16 ביט עם סימן יש טווח של ‎-32,768 עד 32,767, שמותאם כברירת מחדל לטווח [0, 255]). אם משתמשים בערכי ברירת המחדל, לעיתים קרובות מקבלים תצוגות חזותיות עם ניגודיות נמוכה או ללא ניגודיות בין מאפייני התמונה. אפשר להשתמש בmin ובmax כדי לשפר את הניגודיות ולהדגיש טווח נתונים מסוים. כלל אצבע טוב הוא להגדיר את min ו-max לערכים שמייצגים את האחוזון השני וה-98 של הנתונים באזור שמעניין אתכם. בדוגמה הבאה מוסבר איך לחשב את הערכים האלה למודל גובה דיגיטלי.

Code Editor (JavaScript)

// Import NASADEM global elevation model.
var demImg = ee.Image('NASA/NASADEM_HGT/001').select('elevation');

// Define a rectangular area of interest.
var aoi = ee.Geometry.Polygon(
  [[
    [-103.84153083119054, 49.083004219142886],
    [-103.84153083119054, 25.06838270664608],
    [-85.64817145619054, 25.06838270664608],
    [-85.64817145619054, 49.083004219142886]
  ]],
  null, false);

// Calculate the 2nd and 98th percentile elevation values from rescaled (to
// 500m) pixels intersecting the area of interest. A Dictionary is returned.
var percentClip = demImg.reduceRegion({
  reducer: ee.Reducer.percentile([2, 98]),
  geometry: aoi,
  scale: 500,
  maxPixels: 3e7
});

// Print the regional 2nd and 98th percentile elevation values. Get the
// dictionary keys and use them to get the values for each percentile summary.
var keys = percentClip.keys();
print('Set vis min to:', ee.Number(percentClip.get(keys.get(0))).round());
print('Set vis max to:', ee.Number(percentClip.get(keys.get(1))).round());

הפרמטר palette מגדיר את הצבעים שמייצגים את תמונת ההמחשה של 8 ביט. הוא חל רק על ייצוגים של פס יחיד. אם מציינים אותו עם תמונה של כמה פסים, תתקבל שגיאה. אם הנתונים הם של פס יחיד או שאתם רוצים להציג פס יחיד מתמונה עם כמה פסים, מגדירים את הפרמטר forceRgbOutput ל-true (לא נחוץ אם הארגומנט palette מסופק). משתמשים בפרמטרים min ו-max כדי להגדיר את טווח הערכים לשינוי קנה מידה לינארי בין 0 ל-255.

הדוגמה הבאה ממחישה מיפוי של פונקציית תצוגה חזותית על אוסף תמונות עם פס יחיד. אוסף MODIS NDVI מיובא, ארגומנטים של תצוגה חזותית לשיטה visualization מוגדרים, ופונקציה שהופכת ערכים לייצוגים של תמונות RGB ממופה על אוסף ה-NDVI.

Code Editor (JavaScript)

// Filter MODIS NDVI image collection by a date range.
var ndviCol = ee.ImageCollection('MODIS/061/MOD13A1')
  .filterDate('2018-01-01', '2019-01-01')
  .select('NDVI');

// Define visualization arguments.
var visArgs = {
  min: 0,
  max: 9000,
  palette: [
    'FFFFFF', 'CE7E45', 'DF923D', 'F1B555', 'FCD163', '99B718', '74A901',
    '66A000', '529400', '3E8601', '207401', '056201', '004C00', '023B01',
    '012E01', '011D01', '011301'
  ]
};

// Define a function to convert an image to an RGB visualization image and copy
// properties from the original image to the RGB image.
var visFun = function(img) {
  return img.visualize(visArgs).copyProperties(img, img.propertyNames());
};

// Map over the image collection to convert each image to an RGB visualization
// using the previously defined visualization function.
var ndviColVis = ndviCol.map(visFun);

הנה דוגמה למיפוי של פונקציית ויזואליזציה על אוסף תמונות עם כמה ערוצים:

Code Editor (JavaScript)

// Assemble a collection of Sentinel-2 surface reflectance images for a given
// region and date range.
var s2col = ee.ImageCollection('COPERNICUS/S2_SR_HARMONIZED')
  .filterBounds(ee.Geometry.Point(-96.9037, 48.0395))
  .filterDate('2019-06-01', '2019-10-01');

// Define visualization arguments.
var visArgs = {bands: ['B11', 'B8', 'B3'], min: 300, max: 3500};

// Define a function to convert an image to an RGB visualization image and copy
// properties from the original image to the RGB image.
var visFun = function(img) {
  return img.visualize(visArgs).copyProperties(img, img.propertyNames());
};

// Map over the image collection to convert each image to an RGB visualization
// using the previously defined visualization function.
var s2colVis = s2col.map(visFun);

במקרה הזה, לא מסופק ארגומנט של לוח צבעים כי ניתנות שלוש רצועות, שמגדירות את העוצמה של כל שכבת RGB. שימו לב שבשתי הדוגמאות נעשה שימוש בפרמטרים min ו-max כדי לקבוע אילו ערכים נמתחים עד לגבולות של נתוני ה-RGB של 8 ביט.

תמונה ממוזערת של סרטון

הפונקציה getVideoThumbURL() יוצרת אנימציה מכל התמונות ב-ImageCollection, כשכל תמונה מייצגת פריים. תהליך העבודה הכללי ליצירת אנימציה הוא:

  1. מגדירים Geometry שהגבולות שלו קובעים את ההיקף האזורי של האנימציה.
  2. מגדירים ImageCollection.
  3. כדאי להוסיף פונקציה של תצוגה חזותית של תמונות: אפשר למפות פונקציה של תצוגה חזותית של תמונות על האוסף או להוסיף ארגומנטים של תצוגה חזותית של תמונות לקבוצת הארגומנטים של האנימציה.
  4. מגדירים את הארגומנטים של האנימציה ומפעילים את השיטה getVideoThumbURL.

התוצאה של getVideoThumbURL היא כתובת URL. מדפיסים את כתובת ה-URL במסוף ולוחצים עליה כדי להפעיל את שרתי Earth Engine שיוצרים את האנימציה בזמן אמת בכרטיסייה חדשה בדפדפן. לחלופין, אפשר להציג את האנימציה במסוף של Code Editor על ידי קריאה לפונקציה ui.Thumbnail באוסף ובארגומנטים המתאימים של האנימציה. אחרי שהעיבוד מסתיים, אפשר להוריד את האנימציה. כדי לעשות את זה, לוחצים עליה לחיצה ימנית ובוחרים את האפשרויות המתאימות בתפריט ההקשר.

בדוגמה הבאה מוסבר איך ליצור אנימציה שמציגה את הטמפרטורות בעולם במשך 24 שעות. שימו לב שהדוגמה הזו כוללת ארגומנטים של המחשה חזותית יחד עם ארגומנטים של אנימציה, בניגוד למיפוי ראשון של פונקציית המחשה חזותית על פני ImageCollection. אחרי שמריצים את הסקריפט הזה, אמורה להופיע אנימציה דומה לאיור 3 במסוף של Code Editor.

Code Editor (JavaScript)

// Define an area of interest geometry with a global non-polar extent.
var aoi = ee.Geometry.Polygon(
  [[[-179.0, 78.0], [-179.0, -58.0], [179.0, -58.0], [179.0, 78.0]]], null,
  false);

// Import hourly predicted temperature image collection for northern winter
// solstice. Note that predictions extend for 384 hours; limit the collection
// to the first 24 hours.
var tempCol = ee.ImageCollection('NOAA/GFS0P25')
  .filterDate('2018-12-22', '2018-12-23')
  .limit(24)
  .select('temperature_2m_above_ground');

// Define arguments for animation function parameters.
var videoArgs = {
  dimensions: 768,
  region: aoi,
  framesPerSecond: 7,
  crs: 'EPSG:3857',
  min: -40.0,
  max: 35.0,
  palette: ['blue', 'purple', 'cyan', 'green', 'yellow', 'red']
};

// Print the animation to the console as a ui.Thumbnail using the above defined
// arguments. Note that ui.Thumbnail produces an animation when the first input
// is an ee.ImageCollection instead of an ee.Image.
print(ui.Thumbnail(tempCol, videoArgs));

// Alternatively, print a URL that will produce the animation when accessed.
print(tempCol.getVideoThumbURL(videoArgs));


איור 3. טמפרטורת פני השטח השעתית ביום ההיפוך החורפי הצפוני, מיוצגת כתמונת GIF מונפשת.

רצועת תמונות

הפונקציה getFilmstripThumbUrl יוצרת תמונה סטטית אחת שמייצגת את השרשור של כל התמונות ב-ImageCollection לסדרה מצפון לדרום. רצף הפריימים ברצועת התמונות תואם לסדר הטבעי של האוסף.

התוצאה של getFilmstripThumbUrl היא כתובת URL. מדפיסים את כתובת ה-URL במסוף ולוחצים עליה כדי להפעיל את שרתי Earth Engine שיוצרים את התמונה בזמן אמת בכרטיסייה חדשה בדפדפן. אחרי שהתמונה נוצרת, אפשר להוריד אותה בלחיצה ימנית עליה ובחירת האפשרויות המתאימות בתפריט ההקשר שלה.

בקטע הקוד הבא נעשה שימוש באותו אוסף כמו בדוגמה של התמונה הממוזערת של הסרטון שלמעלה. אחרי שמריצים את הסקריפט הזה, אמורה להופיע רצועת תמונות דומה לאיור 4 במסוף של עורך הקוד.

Code Editor (JavaScript)

// Define an area of interest geometry with a global non-polar extent.
var aoi = ee.Geometry.Polygon(
  [[[-179.0, 78.0], [-179.0, -58.0], [179.0, -58.0], [179.0, 78.0]]], null,
  false);

// Import hourly predicted temperature image collection for northern winter
// solstice. Note that predictions extend for 384 hours; limit the collection
// to the first 24 hours.
var tempCol = ee.ImageCollection('NOAA/GFS0P25')
  .filterDate('2018-12-22', '2018-12-23')
  .limit(24)
  .select('temperature_2m_above_ground');

// Define arguments for the getFilmstripThumbURL function parameters.
var filmArgs = {
  dimensions: 128,
  region: aoi,
  crs: 'EPSG:3857',
  min: -40.0,
  max: 35.0,
  palette: ['blue', 'purple', 'cyan', 'green', 'yellow', 'red']
};

// Print a URL that will produce the filmstrip when accessed.
print(tempCol.getFilmstripThumbURL(filmArgs));


איור 4. טמפרטורת פני השטח בכל שעה ביום ההיפוך החורפי בחצי הכדור הצפוני, מיוצגת כתמונת PNG של רצועת תמונות. שימו לב שרצועת התמונות חולקה לארבעה חלקים לצורך הצגה. התוצאה של getFilmstripThumbURL היא סדרה אחת של תמונות אוסף שמחוברות מצפון לדרום.

שיטות מתקדמות

בקטעים הבאים מוסבר איך להשתמש בחיתוך, באטימות ובשכבות כדי לשפר את התצוגות החזותיות על ידי הוספת גבולות של פוליגונים, הדגשת אזורים מעניינים והשוואה בין תמונות באוסף.

שימו לב שכל הדוגמאות הבאות בקטע הזה משתמשות באותו ImageCollection בסיסי שמוגדר כאן:

Code Editor (JavaScript)

// Import hourly predicted temperature image collection for northern winter
// solstice. Note that predictions extend for 384 hours; limit the collection
// to the first 24 hours.
var tempCol = ee.ImageCollection('NOAA/GFS0P25')
  .filterDate('2018-12-22', '2018-12-23')
  .limit(24)
  .select('temperature_2m_above_ground');

// Define visualization arguments to control the stretch and color gradient
// of the data.
var visArgs = {
  min: -40.0,
  max: 35.0,
  palette: ['blue', 'purple', 'cyan', 'green', 'yellow', 'red']
};

// Convert each image to an RGB visualization image by mapping the visualize
// function over the image collection using the arguments defined previously.
var tempColVis = tempCol.map(function(img) {
  return img.visualize(visArgs);
});

// Import country features and filter to South American countries.
var southAmCol = ee.FeatureCollection('USDOS/LSIB_SIMPLE/2017')
  .filterMetadata('wld_rgn', 'equals', 'South America');

// Define animation region (South America with buffer).
var southAmAoi = ee.Geometry.Rectangle({
  coords: [-103.6, -58.8, -18.4, 17.4], geodesic: false});

שכבות-על

אפשר להוסיף כמה שכבות של תמונות באמצעות השיטה blend Image, שבה פיקסלים חופפים משתי תמונות משולבים על סמך המסכות שלהם (אטימות).

שכבת-על וקטורית

הוספת מצולעים של גבולות מנהליים וצורות גיאומטריות אחרות לתמונה יכולה לספק הקשר מרחבי חשוב. תסתכלו על האנימציה של טמפרטורת פני השטח היומית ברחבי העולם (איור 3). הגבולות בין היבשה לאוקיינוס ניתנים לזיהוי, אבל אפשר להדגיש אותם על ידי הוספת שכבת-על של פוליגונים של מדינות.

נתוני וקטור (Features) משורטטים לתמונות באמצעות השיטה paint. אפשר לצבוע תכונות בתמונה קיימת, אבל השיטה המומלצת היא לצבוע אותן בתמונה ריקה, לעצב אותה ואז למזג את התוצאה עם שכבות אחרות של תמונות מעוצבות. כשמטפלים בכל שכבה של מחסנית התצוגה החזותית בנפרד, מקבלים יותר שליטה על הסגנון.

בדוגמה הבאה מוצג ציור של גבולות המדינות בדרום אמריקה ב-Image ריק, ושילוב התוצאה עם כל Image של אוסף הטמפרטורות היומיות הגלובליות (איור 5). גבולות המדינות שמוצגים בשכבת-על מבדילים בין יבשה למים ומספקים הקשר לדפוסי הטמפרטורה.

Code Editor (JavaScript)

// Define an empty image to paint features to.
var empty = ee.Image().byte();

// Paint country feature edges to the empty image.
var southAmOutline = empty
  .paint({featureCollection: southAmCol, color: 1, width: 1})
  // Convert to an RGB visualization image; set line color to black.
  .visualize({palette: '000000'});

// Map a blend operation over the temperature collection to overlay the country
// border outline image on all collection images.
var tempColOutline = tempColVis.map(function(img) {
  return img.blend(southAmOutline);
});

// Define animation arguments.
var videoArgs = {
  dimensions: 768,
  region: southAmAoi,
  framesPerSecond: 7,
  crs: 'EPSG:3857'
};

// Display the animation.
print(ui.Thumbnail(tempColOutline, videoArgs));


איור 5. הוספת שכבות וקטוריות לתמונות באוסף כדי לספק הקשר מרחבי.

שכבת-על לתמונה

אפשר להוסיף כמה תמונות כשכבות כדי להשיג את הסגנון הרצוי. נניח שאתם רוצים להדגיש אזור מסוים. אפשר ליצור עותק מעומעם של תמונה כבסיס, ואז להוסיף מעליו שכבה של גרסה חתוכה של התמונה המקורית. בהמשך לדוגמה הקודמת, הסקריפט הבא יוצר את איור 6.

Code Editor (JavaScript)

// Define an empty image to paint features to.
var empty = ee.Image().byte();

// Paint country feature edges to the empty image.
var southAmOutline = empty
  .paint({featureCollection: southAmCol, color: 1, width: 1})
  // Convert to an RGB visualization image; set line color to black.
  .visualize({palette: '000000'});

// Map a blend operation over the temperature collection to overlay the country
// border outline image on all collection images.
var tempColOutline = tempColVis.map(function(img) {
  return img.blend(southAmOutline);
});

// Define a partially opaque grey RGB image to dull the underlying image when
// blended as an overlay.
var dullLayer = ee.Image.constant(175).visualize({
  opacity: 0.6, min: 0, max: 255, forceRgbOutput: true});

// Map a two-part blending operation over the country outline temperature
// collection for final styling.
var finalVisCol = tempColOutline.map(function(img) {
  return img
    // Blend the dulling layer with the given country outline temperature image.
    .blend(dullLayer)
    // Blend a clipped copy of the country outline temperature image with the
    // dulled background image.
    .blend(img.clipToCollection(southAmCol));
});

// Define animation arguments.
var videoArgs = {
  dimensions: 768,
  region: southAmAoi,
  framesPerSecond: 7,
  crs: 'EPSG:3857'
};

// Display the animation.
print(ui.Thumbnail(finalVisCol, videoArgs));


איור 6. כדי להדגיש אזור מסוים, אפשר לחתוך את התמונה ולהציב אותה מעל עותק מעומעם.

אפשר גם לשלב נתוני תמונה עם שכבת בסיס של הצללת גבעות כדי לציין את פני השטח ולהוסיף עומק להמחשה (איור 7).

Code Editor (JavaScript)

// Define a hillshade layer from NASADEM digital elevation model.
var hillshade = ee.Terrain.hillshade(ee.Image('NASA/NASADEM_HGT/001')
  // Exaggerate the elevation to increase contrast in hillshade.
  .multiply(100))
  // Clip the DEM by South American boundary to clean boundary between
  // land and ocean.
  .clipToCollection(southAmCol);

// Map a blend operation over the temperature collection to overlay a partially
// opaque temperature layer on the hillshade layer.
var finalVisCol = tempColVis.map(function(img) {
  return hillshade
    .blend(img.clipToCollection(southAmCol).visualize({opacity: 0.6}));
});

// Define animation arguments.
var videoArgs = {
  dimensions: 768,
  region: southAmAoi,
  framesPerSecond: 7,
  crs: 'EPSG:3857'
};

// Display the animation.
print(ui.Thumbnail(finalVisCol, videoArgs));


איור 7. הצגת פני השטח על ידי שכבת-על של נתוני תמונה שקופים חלקית על שכבת הצללה.

מעברים.

אפשר להתאים אישית אוסף תמונות כדי ליצור אנימציות שמציגות את ההבדלים בין שתי תמונות באוסף באמצעות מעברי עמעום, הבהוב והחלקה. בכל אחת מהדוגמאות הבאות נעשה שימוש באותה תצוגה חזותית בסיסית שנוצרה על ידי הסקריפט הבא:

Code Editor (JavaScript)

// Define an area of interest geometry with a global non-polar extent.
var aoi = ee.Geometry.Polygon(
  [[[-179.0, 78.0], [-179.0, -58.0], [179.0, -58.0], [179.0, 78.0]]], null,
  false);

// Import hourly predicted temperature image collection.
var temp = ee.ImageCollection('NOAA/GFS0P25')

// Define a northern summer solstice temperature image.
var summerSolTemp = temp
  .filterDate('2018-06-21', '2018-06-22')
  .filterMetadata('forecast_hours', 'equals', 12)
  .first()
  .select('temperature_2m_above_ground');

// Define a northern winter solstice temperature image.
var winterSolTemp = temp
  .filterDate('2018-12-22', '2018-12-23')
  .filterMetadata('forecast_hours', 'equals', 12)
  .first()
  .select('temperature_2m_above_ground');

// Combine the solstice images into a collection.
var tempCol = ee.ImageCollection([
  summerSolTemp.set('season', 'summer'),
  winterSolTemp.set('season', 'winter')
]);

// Import international boundaries feature collection.
var countries = ee.FeatureCollection('USDOS/LSIB_SIMPLE/2017');

// Define visualization arguments.
var visArgs = {
  min: -40.0,
  max: 35.0,
  palette: ['blue', 'purple', 'cyan', 'green', 'yellow', 'red']
};

// Convert the image data to RGB visualization images.
// The clip and unmask combination sets ocean pixels to black.
var tempColVis = tempCol.map(function(img) {
  return img
    .visualize(visArgs)
    .clipToCollection(countries)
    .unmask(0)
    .copyProperties(img, img.propertyNames());
});

הבהוב

כשיש רק שתי תמונות באוסף, כמו בדוגמה הזו, הבהוב הוא ברירת המחדל של האנימציה של האוסף. כדי להאיץ או להאט את קצב ההבהוב, משנים את הארגומנט של האנימציה framesPerSecond. הארגומנטים הבאים של ההמחשה החזותית שהוחלו על האוסף שלמעלה מפיקים את איור 8.

Code Editor (JavaScript)

// Define arguments for animation function parameters.
var videoArgs = {
  dimensions: 768,
  region: aoi,
  framesPerSecond: 2,
  crs: 'EPSG:3857'
};

// Display animation to the Code Editor console.
print(ui.Thumbnail(tempColVis, videoArgs));


איור 8. דוגמה להבהוב בין טמפרטורת פני השטח בשעה 12:00 לפי שעון גריניץ' ביום ההיפוך הצפוני וביום ההיפוך החורפי.

עמעום

כדי ליצור מעבר הדרגתי בין שתי שכבות, צריך להפחית בו-זמנית את האטימות של שכבה אחת ולהגביר את האטימות של השכבה השנייה, ברצף של הגברות אטימות מ-0 בקירוב עד 1 (איור 9).

Code Editor (JavaScript)

// Define a sequence of decreasing opacity increments. Note that opacity cannot
// be 0, so near 1 and 0 are used. Near 1 is needed because a compliment is
// calculated in a following step that can result in 0 if 1 is an element of the
// list.
var opacityList = ee.List.sequence({start: 0.99999, end: 0.00001, count: 20});

// Filter the summer and winter solstice images from the collection and set as
// image objects.
var summerImg = tempColVis.filter(ee.Filter.eq('season', 'summer')).first();
var winterImg = tempColVis.filter(ee.Filter.eq('season', 'winter')).first();

// Map over the list of opacity increments to iteratively adjust the opacity of
// the two solstice images. Returns a list of images.
var imgList = opacityList.map(function(opacity) {
  var opacityCompliment = ee.Number(1).subtract(ee.Number(opacity));
  var winterImgFade = winterImg.visualize({opacity: opacity});
  var summerImgFade = summerImg.visualize({opacity: opacityCompliment});
  return summerImgFade.blend(winterImgFade).set('opacity', opacity);
});

// Convert the image list to an image collection; the forward phase.
var fadeForward = ee.ImageCollection.fromImages(imgList);

// Make a copy of the collection that is sorted by ascending opacity to
// represent the reverse phase.
var fadeBackward = fadeForward.sort({property: 'opacity'});

// Merge the forward and reverse phase frame collections.
var fadeCol = fadeForward.merge(fadeBackward);

// Define animation arguments.
var videoArgs = {
  dimensions: 768,
  region: aoi,
  framesPerSecond: 25,
  crs: 'EPSG:3857'
};

// Display the animation.
print(ui.Thumbnail(fadeCol, videoArgs));


איור 9. דוגמה למעבר הדרגתי בין טמפרטורת פני השטח ב-12:00 לפי שעון גריניץ' ביום ההיפוך הקיצי וביום ההיפוך החורפי.

מחוון

מעבר באמצעות פס הזזה מציג ומסתיר בהדרגה את שכבת התמונה שמתחת. כדי לעשות את זה, משנים באופן איטרטיבי את האטימות של התמונה העליונה בטווח של קווי אורך (איור 10).

Code Editor (JavaScript)

// Define a sequence of longitude increments. Start and end are defined by the
// min and max longitude of the feature to be provided to the region parameter
// of the animation arguments dictionary.
var lonSeq = ee.List.sequence({start: -179, end: 179, count: 20});

// Define a longitude image.
var longitude = ee.Image.pixelLonLat().select('longitude');

// Filter the summer and winter solstice images from the collection and set as
// image objects.
var summerImg = tempColVis.filter(ee.Filter.eq('season', 'summer')).first();
var winterImg = tempColVis.filter(ee.Filter.eq('season', 'winter')).first();

// Map over the list of longitude increments to iteratively adjust the mask
// (opacity) of the overlying image layer. Returns a list of images.
var imgList = lonSeq.map(function(lon) {
  lon = ee.Number(lon);
  var mask = longitude.gt(lon);
  return summerImg.blend(winterImg.updateMask(mask)).set('lon', lon);
});

// Convert the image list to an image collection; concealing phase.
var sliderColForward = ee.ImageCollection.fromImages(imgList);

// Make a copy of the collection that is sorted by descending longitude to
// represent the revealing phase.
var sliderColbackward = sliderColForward
  .sort({property: 'lon', ascending: false});

// Merge the forward and backward phase frame collections.
var sliderCol = sliderColForward.merge(sliderColbackward);

// Define animation arguments.
var videoArgs = {
  dimensions: 768,
  region: aoi,
  framesPerSecond: 25,
  crs: 'EPSG:3857'
};

// Display the animation.
print(ui.Thumbnail(sliderCol, videoArgs));


איור 10. דוגמה למעבר בין טמפרטורת פני השטח בשעה 12:00 לפי שעון גריניץ' ביום ההיפוך הקיצי וביום ההיפוך החורפי.