ee.Filter.calendarRange

傳回篩選器,如果物件的時間戳記落在指定日曆欄位的範圍內,就會通過篩選。monthday_of_yearday_of_monthday_of_week 皆以 1 為基準。系統會假設時間為世界標準時間。系統會假設每週從星期一開始,並將星期一視為第 1 天。如果 end < start,則此測試會檢查 value >= startvalue <= end,以允許換行。

用量傳回
ee.Filter.calendarRange(start, end, field)篩選器
引數類型詳細資料
start整數所需日曆欄位的起始值 (含)。
end整數,預設值為 null所需日曆欄位的結束時間 (含此時間)。預設值與開始時間相同。
field字串,預設值為「day_of_year」要篩選的日曆欄位。選項包括:`year`、`month`、`hour`、`minute`、`day_of_year`、`day_of_month` 和 `day_of_week`。

範例

程式碼編輯器 (JavaScript)

// A Sentinel-2 surface reflectance image collection intersecting the peak of
// Mount Shasta, California, USA.
var ic = ee.ImageCollection('COPERNICUS/S2_SR')
             .filterBounds(ee.Geometry.Point(-122.196, 41.411));

print('Images for a month range (June-August)',
      ic.filter(ee.Filter.calendarRange(6, 8, 'month')));

print('A start value greater than end value is valid (Dec-Feb)',
      ic.filter(ee.Filter.calendarRange(12, 2, 'month')));

// This example uses the 'year' field value. Note that ee.Filter.date is the
// preferred method when filtering by whole years, as it is much faster.
print('Images for a year range (2020-2021)',
      ic.filter(ee.Filter.calendarRange(2020, 2021, 'year')));

// This example uses the 'day_of_year' field value. Note that
// ee.Filter.dayOfYear is the preferred method for filtering by DOY.
// The ee.Date.getRelative function is used to identify DOY from an ee.Date
// object for a representative year. Be mindful of leap years when filtering
// by DOY.
var startDoy = ee.Date('2000-06-01').getRelative('day', 'year');
var endDoy = ee.Date('2000-06-15').getRelative('day', 'year');
print('start DOY =', startDoy,
      'end DOY =', endDoy,
      'Images for a day-of-year range',
      ic.filter(ee.Filter.calendarRange(startDoy, endDoy, 'day_of_year')));

Python 設定

請參閱 Python 環境頁面,瞭解 Python API 和如何使用 geemap 進行互動式開發。

import ee
import geemap.core as geemap

Colab (Python)

# A Sentinel-2 surface reflectance image collection intersecting the peak of
# Mount Shasta, California, USA.
ic = ee.ImageCollection('COPERNICUS/S2_SR').filterBounds(
    ee.Geometry.Point(-122.196, 41.411))

print('Images for a month range (June-August):',
      ic.filter(ee.Filter.calendarRange(6, 8, 'month')).getInfo())

print('A start value greater than end value is valid (Dec-Feb):',
      ic.filter(ee.Filter.calendarRange(12, 2, 'month')).size().getInfo())

# This example uses the 'year' field value. Note that ee.Filter.date is the
# preferred method when filtering by whole years, as it is much faster.
print('Images for a year range (2020-2021):',
      ic.filter(ee.Filter.calendarRange(2020, 2021, 'year')).size().getInfo())

# This example uses the 'day_of_year' field value. Note that
# ee.Filter.dayOfYear is the preferred method for filtering by DOY.
# The ee.Date.getRelative function is used to identify DOY from an ee.Date
# object for a representative year. Be mindful of leap years when filtering
# by DOY.
start_doy = ee.Date('2000-06-01').getRelative('day', 'year')
end_doy = ee.Date('2000-06-15').getRelative('day', 'year')
print('start DOY =', start_doy.getInfo(), 'end DOY =', end_doy.getInfo())
print(
    'Images for a day-of-year range:',
    ic.filter(ee.Filter.calendarRange(start_doy, end_doy, 'day_of_year'))
    .getInfo()
)