本文整理汇总了Python中ee.Date方法的典型用法代码示例。如果您正苦于以下问题:Python ee.Date方法的具体用法?Python ee.Date怎么用?Python ee.Date使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ee
的用法示例。
在下文中一共展示了ee.Date方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: addDate
# 需要导入模块: import ee [as 别名]
# 或者: from ee import Date [as 别名]
def addDate(image):
# parse date stored in 'system:index'
date = ee.Date(image.get('system:index'))
# format date, see http:#www.joda.org/joda-time/apidocs/org/joda/time/format/DateTimeFormat.html
str = date.format('YYYY-mm-dd')
return image.set({'Date': str})
# point = ee.Geometry.Point(-122.262, 37.8719)
# start = ee.Date('2014-06-01')
# finish = ee.Date('2014-10-01')
# filteredCollection = ee.ImageCollection('LANDSAT/LC08/C01/T1') \
# .filterBounds(point) \
# .filterDate(start, finish) \
# .sort('CLOUD_COVER', True)
示例2: atm_corr_image
# 需要导入模块: import ee [as 别名]
# 或者: from ee import Date [as 别名]
def atm_corr_image(imageInfo: dict) -> dict:
"""Retrieves atmospheric params from image.
imageInfo is a dictionary created from an ee.Image object
"""
atmParams = {}
# Python uses seconds, EE uses milliseconds:
scene_date = datetime.datetime.utcfromtimestamp(imageInfo['system:time_start']/1000)
dt1 = ee.Date(str(scene_date).rsplit(sep=' ')[0])
atmParams['doy'] = scene_date.timetuple().tm_yday
atmParams['solar_z'] = imageInfo['MEAN_SOLAR_ZENITH_ANGLE']
atmParams['h2o'] = Atmospheric.water(geom, dt1).getInfo()
atmParams['o3'] = Atmospheric.ozone(geom, dt1).getInfo()
atmParams['aot'] = Atmospheric.aerosol(geom, dt1).getInfo()
return atmParams
示例3: round_month
# 需要导入模块: import ee [as 别名]
# 或者: from ee import Date [as 别名]
def round_month(date):
"""
round date to closest month
"""
# start of THIS month
m1 = date.fromYMD(date.get('year'),date.get('month'),ee.Number(1))
# start of NEXT month
m2 = m1.advance(1,'month')
# difference from date
d1 = ee.Number(date.difference(m1,'day')).abs()
d2 = ee.Number(date.difference(m2,'day')).abs()
# return closest start of month
return ee.Date(ee.Algorithms.If(d2.gt(d1),m1,m2))
示例4: map
# 需要导入模块: import ee [as 别名]
# 或者: from ee import Date [as 别名]
def map(self, collection, **kwargs):
""" Map function to use in BAP
:param year: the analysing year. Must match the year of the bap
:type year: int
"""
range_out = self.range_out
year = kwargs.get('year')
date_range = self.season.add_year(year)
doy = ee.Date(season_module.SeasonDate(self.best_doy).add_year(year))
doy2 = ee.Date(season_module.SeasonDate(self.best_doy).add_year(year-1))
condition = date_range.contains(doy)
best = ee.Number(ee.Algorithms.If(condition, doy, doy2))
return self.apply(collection, best_doy=best, name=self.name,
output_min=range_out[0], output_max=range_out[1],
function=self.function, stretch=self.stretch)
示例5: add_year
# 需要导入模块: import ee [as 别名]
# 或者: from ee import Date [as 别名]
def add_year(self, year):
year = ee.Number(year)
if self.over_end:
start_year = year.subtract(1)
else:
start_year = ee.Number(year)
end_year = ee.Number(year)
sday = self.start.day
eday = self.end.day
# look for feb 29h in non leap
if not is_leap(year):
if self.start.month == 2 and sday == 29:
sday = 28
if self.end.month == 2 and eday == 29:
eday = 28
start = ee.Date.fromYMD(start_year, self.start.month, sday)
end = ee.Date.fromYMD(end_year, self.end.month, eday)
daterange = ee.DateRange(ee.Date(start), ee.Date(end))
return daterange
示例6: make_proxy
# 需要导入模块: import ee [as 别名]
# 或者: from ee import Date [as 别名]
def make_proxy(self, image, collection, year):
""" Make a proxy collection """
size = collection.size()
# unmask all bands
unmasked = image.unmask()
proxy_date = ee.Date('{}-01-01'.format(year))
bands = image.bandNames()
empty = tools.image.empty(0, bands)
proxy = unmasked.where(unmasked, empty)
proxy = proxy.set('system:time_start', proxy_date.millis())
proxy_col = ee.ImageCollection.fromImages([proxy])
return ee.ImageCollection(ee.Algorithms.If(size.gt(0),
collection,
proxy_col))
示例7: date_to_time_0utc
# 需要导入模块: import ee [as 别名]
# 或者: from ee import Date [as 别名]
def date_to_time_0utc(date):
"""Get the 0 UTC time_start for a date
Parameters
----------
date : ee.Date
Returns
-------
ee.Number
"""
return ee.Date.fromYMD(date.get('year'), date.get('month'),
date.get('day')).millis()
# Extra operations are needed since update() does not set milliseconds to 0.
# return date.update(hour=0, minute=0, second=0).millis()\
# .divide(1000).floor().multiply(1000)
示例8: toa_image
# 需要导入模块: import ee [as 别名]
# 或者: from ee import Date [as 别名]
def toa_image(red=0.1, nir=0.9, bt=305):
"""Construct a fake Landsat 8 TOA image with renamed bands"""
mask_img = ee.Image(f'{COLL_ID}/{SCENE_ID}').select(['B3']).multiply(0)
return ee.Image([mask_img.add(red), mask_img.add(nir), mask_img.add(bt)]) \
.rename(['red', 'nir', 'tir'])\
.set({
'system:time_start': SCENE_TIME,
'k1_constant': ee.Number(607.76),
'k2_constant': ee.Number(1260.56),
})
# return ee.Image.constant([red, nir, bt])\
# .rename(['red', 'nir', 'lst']) \
# .set({
# 'system:time_start': ee.Date(SCENE_DATE).millis(),
# 'k1_constant': ee.Number(607.76),
# 'k2_constant': ee.Number(1260.56),
# })
示例9: test_Image_tcorr_scene_source
# 需要导入模块: import ee [as 别名]
# 或者: from ee import Date [as 别名]
def test_Image_tcorr_scene_source(tcorr_source, tmax_source, scene_id,
expected, tol=0.000001):
"""Test getting Tcorr value and index for a single date at a real point"""
scene_date = datetime.datetime.strptime(scene_id.split('_')[-1], '%Y%m%d') \
.strftime('%Y-%m-%d')
input_image = ee.Image.constant(1).set({
'system:index': scene_id,
'system:time_start': ee.Date(scene_date).millis()
})
tcorr_img = ssebop.Image(
input_image, tcorr_source=tcorr_source,
tmax_source=tmax_source, tmax_resample='nearest').tcorr
# Tcorr images are constant images and need to be queried at a point
tcorr = utils.point_image_value(tcorr_img, SCENE_POINT)
index = utils.getinfo(tcorr_img.get('tcorr_index'))
assert abs(tcorr['tcorr'] - expected[0]) <= tol
assert index == expected[1]
# Note, this is calling .tcorr_stats(), which isn't tested till the end.
# I'm not sure if it would make more sense to move this to the end or maybe
# move the .tcorr_stats test further up, since they are independent of most
# of the other functions.
示例10: unmask_slc_off
# 需要导入模块: import ee [as 别名]
# 或者: from ee import Date [as 别名]
def unmask_slc_off(image, optical_bands='B.+'):
""" Unmask pixels that were affected by scl-off error in Landsat 7
Expects a Landsat 7 image and it is meant to be used before any other
masking, otherwise this could affect the previous mask.
The parameter `optical_bands` must be used if band were renamed. By
default it is `B.+` which means that optical bands are those starting
with B: B1 (blue), B2 (green), B3 (red), B4 (nir), B5 (swir),
B6 (thermal), B7 (swir2).
"""
idate = image.date()
slcoff = ee.Date('2003-05-31')
condition = idate.difference(slcoff, 'days').gte(0)
def compute(i):
mask = i.mask()
reduced = mask.select(optical_bands).reduce('sum')
slc_off = reduced.eq(0)
unmasked = i.unmask()
newmask = mask.where(slc_off, 1)
return unmasked.updateMask(newmask)
return ee.Image(ee.Algorithms.If(condition, compute(image), image))
示例11: dispatch
# 需要导入模块: import ee [as 别名]
# 或者: from ee import Date [as 别名]
def dispatch(eeobject):
""" General dispatcher """
if belongToEE(eeobject):
# DISPATCH!!
if isinstance(eeobject, (ee.Image,)):
return dispatchImage(eeobject)
elif isinstance(eeobject, (ee.Date,)):
return dispatchDate(eeobject)
elif isinstance(eeobject, (ee.DateRange,)):
return dispatchDaterange(eeobject)
# ADD MORE ABOVE ME!
else:
info = eeobject.getInfo()
return info
else:
info = str(eeobject)
return info
示例12: fromDOY
# 需要导入模块: import ee [as 别名]
# 或者: from ee import Date [as 别名]
def fromDOY(doy, year):
""" Creat a ee.Date given a Day of Year and a Year """
def less10(doy):
doy = doy.toInt()
return ee.String('00').cat(ee.Number(doy).format())
def less100(doy):
doy = doy.toInt()
return ee.String('0').cat(ee.Number(doy).format())
doy = ee.Number(doy).add(1).toInt()
year_str = ee.Number(year).format()
doy_str = ee.Algorithms.If(doy.lt(10), less10(doy),
ee.String(ee.Algorithms.If(doy.lt(100), less100(doy), doy.format())))
s = ee.String(doy_str).cat(year_str)
return ee.Date.parse('DDDyyyy', s)
示例13: test_daterange_list
# 需要导入模块: import ee [as 别名]
# 或者: from ee import Date [as 别名]
def test_daterange_list():
start_date = ee.Date('2010-01-01')
end_date = ee.Date('2015-01-01')
unit = 'year'
interval = 1
expected = ee.List([
ee.DateRange('2010-01-01', '2011-01-01'),
ee.DateRange('2011-01-01', '2012-01-01'),
ee.DateRange('2012-01-01', '2013-01-01'),
ee.DateRange('2013-01-01', '2014-01-01'),
ee.DateRange('2014-01-01', '2015-01-01')
])
daterange_list = tools.date.daterangeList(start_date, end_date,
interval, unit)
assert expected == daterange_list
示例14: date
# 需要导入模块: import ee [as 别名]
# 或者: from ee import Date [as 别名]
def date(info):
""" Dispatch a ee.Date """
date = ee.Date(info.get('value'))
return Label(date.format().getInfo())
示例15: makeVariables
# 需要导入模块: import ee [as 别名]
# 或者: from ee import Date [as 别名]
def makeVariables(image):
# Compute time of the image in fractional years relative to the Epoch.
year = ee.Image(image.date().difference(ee.Date('1970-01-01'), 'year'))
# Compute the season in radians, one cycle per year.
season = year.multiply(2 * math.pi)
# Return an image of the predictors followed by the response.
return image.select() \
.addBands(ee.Image(1)) \
.addBands(year.rename('t')) \
.addBands(season.sin().rename('sin')) \
.addBands(season.cos().rename('cos')) \
.addBands(image.normalizedDifference().rename('NDVI')) \
.toFloat()
# Load a Landsat 5 image collection.