本文整理汇总了Python中ee.String方法的典型用法代码示例。如果您正苦于以下问题:Python ee.String方法的具体用法?Python ee.String怎么用?Python ee.String使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ee
的用法示例。
在下文中一共展示了ee.String方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testDate
# 需要导入模块: import ee [as 别名]
# 或者: from ee import String [as 别名]
def testDate(self):
"""Verifies that date filters work."""
d1 = datetime.datetime.strptime('1/1/2000', '%m/%d/%Y')
d2 = datetime.datetime.strptime('1/1/2001', '%m/%d/%Y')
instant_range = ee.ApiFunction.call_('DateRange', d1, None)
long_range = ee.ApiFunction.call_('DateRange', d1, d2)
instant_filter = ee.Filter.date(d1)
self.assertEquals(ee.ApiFunction.lookup('Filter.dateRangeContains'),
instant_filter.func)
self.assertEquals({'leftValue': instant_range,
'rightField': ee.String('system:time_start')},
instant_filter.args)
long_filter = ee.Filter.date(d1, d2)
self.assertEquals(ee.ApiFunction.lookup('Filter.dateRangeContains'),
long_filter.func)
self.assertEquals({'leftValue': long_range,
'rightField': ee.String('system:time_start')},
long_filter.args)
示例2: testMapping
# 需要导入模块: import ee [as 别名]
# 或者: from ee import String [as 别名]
def testMapping(self):
lst = ee.List(['foo', 'bar'])
body = lambda s: ee.String(s).cat('bar')
mapped = lst.map(body)
self.assertTrue(isinstance(mapped, ee.List))
self.assertEquals(ee.ApiFunction.lookup('List.map'), mapped.func)
self.assertEquals(lst, mapped.args['list'])
# Need to do a serialized comparison for the function body because
# variables returned from CustomFunction.variable() do not implement
# __eq__.
sig = {
'returns': 'Object',
'args': [{'name': '_MAPPING_VAR_0_0', 'type': 'Object'}]
}
expected_function = ee.CustomFunction(sig, body)
self.assertEquals(expected_function.serialize(),
mapped.args['baseAlgorithm'].serialize())
示例3: testSortAndLimit
# 需要导入模块: import ee [as 别名]
# 或者: from ee import String [as 别名]
def testSortAndLimit(self):
"""Verifies the behavior of the sort() and limit() methods."""
collection = ee.Collection(ee.Function(), {})
limited = collection.limit(10)
self.assertEquals(ee.ApiFunction.lookup('Collection.limit'), limited.func)
self.assertEquals(
{'collection': collection, 'limit': 10},
limited.args)
sorted_collection = collection.sort('bar', True)
self.assertEquals(
ee.ApiFunction.lookup('Collection.limit'),
sorted_collection.func)
self.assertEquals(
{'collection': collection, 'key': ee.String('bar'), 'ascending': True},
sorted_collection.args)
reverse_sorted_collection = collection.sort('bar', False)
self.assertEquals(
ee.ApiFunction.lookup('Collection.limit'),
reverse_sorted_collection.func)
self.assertEquals(
{'collection': collection, 'key': ee.String('bar'), 'ascending': False},
reverse_sorted_collection.args)
示例4: testString
# 需要导入模块: import ee [as 别名]
# 或者: from ee import String [as 别名]
def testString(self):
"""Verifies basic behavior of ee.String."""
bare_string = ee.String('foo')
self.assertEquals('foo', bare_string.encode())
computed = ee.String('foo').cat('bar')
self.assertTrue(isinstance(computed, ee.String))
self.assertEquals(ee.ApiFunction.lookup('String.cat'), computed.func)
self.assertEquals({'string1': ee.String('foo'),
'string2': ee.String('bar')}, computed.args)
# Casting a non-string ComputedObject.
obj = ee.Number(1).add(1)
s = ee.String(obj)
self.assertTrue(isinstance(s, ee.String))
self.assertEquals(ee.ApiFunction.lookup('String'), s.func)
self.assertEquals({'input': obj}, s.args)
示例5: containsAllBands
# 需要导入模块: import ee [as 别名]
# 或者: from ee import String [as 别名]
def containsAllBands(collection, bands):
""" Filter a collection with images cotaining all bands specified in
parameter `bands` """
bands = ee.List(bands)
# add bands as metadata
collection = collection.map(
lambda i: ee.Image(i).set('_BANDS_', ee.Image(i).bandNames()))
band0 = ee.String(bands.get(0))
rest = ee.List(bands.slice(1))
filt0 = ee.Filter.listContains(leftField='_BANDS_', rightValue=band0)
# Get filter
def wrap(band, filt):
band = ee.String(band)
filt = ee.Filter(filt)
newfilt = ee.Filter.listContains(leftField='_BANDS_', rightValue=band)
return ee.Filter.And(filt, newfilt)
filt = ee.Filter(rest.iterate(wrap, filt0))
return collection.filter(filt)
示例6: containsAnyBand
# 需要导入模块: import ee [as 别名]
# 或者: from ee import String [as 别名]
def containsAnyBand(collection, bands):
""" Filter a collection with images cotaining any of the bands specified in
parameter `bands` """
bands = ee.List(bands)
# add bands as metadata
collection = collection.map(
lambda i: ee.Image(i).set('_BANDS_', ee.Image(i).bandNames()))
band0 = ee.String(bands.get(0))
rest = ee.List(bands.slice(1))
filt0 = ee.Filter.listContains(leftField='_BANDS_', rightValue=band0)
# Get filter
def wrap(band, filt):
band = ee.String(band)
filt = ee.Filter(filt)
newfilt = ee.Filter.listContains(leftField='_BANDS_', rightValue=band)
return ee.Filter.Or(filt, newfilt)
filt = ee.Filter(rest.iterate(wrap, filt0))
return collection.filter(filt)
示例7: _add_suffix_prefix
# 需要导入模块: import ee [as 别名]
# 或者: from ee import String [as 别名]
def _add_suffix_prefix(image, value, option, bands=None):
""" Internal function to handle addPrefix and addSuffix """
if bands:
bands = ee.List(bands)
addon = ee.String(value)
allbands = image.bandNames()
bands_ = ee.List(ee.Algorithms.If(bands, bands, allbands))
def over_bands(band, first):
all = ee.List(first)
options = ee.Dictionary({
'suffix': ee.String(band).cat(addon),
'prefix': addon.cat(ee.String(band))
})
return all.replace(band, ee.String(options.get(option)))
newbands = bands_.iterate(over_bands, allbands)
newbands = ee.List(newbands)
return image.select(allbands, newbands)
示例8: minscale
# 需要导入模块: import ee [as 别名]
# 或者: from ee import String [as 别名]
def minscale(image):
""" Get the minimal scale of an Image, looking at all Image's bands.
For example if:
B1 = 30
B2 = 60
B3 = 10
the function will return 10
:return: the minimal scale
:rtype: ee.Number
"""
bands = image.bandNames()
first = image.select([ee.String(bands.get(0))])
ini = ee.Number(first.projection().nominalScale())
def wrap(name, i):
i = ee.Number(i)
scale = ee.Number(image.select([name]).projection().nominalScale())
condition = scale.lte(i)
newscale = ee.Algorithms.If(condition, scale, i)
return newscale
return ee.Number(bands.slice(1).iterate(wrap, ini))
示例9: fromDOY
# 需要导入模块: import ee [as 别名]
# 或者: from ee import String [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)
示例10: getNewBandNames
# 需要导入模块: import ee [as 别名]
# 或者: from ee import String [as 别名]
def getNewBandNames(prefix):
seq = ee.List.sequence(1, bandNames.length())
return seq.map(lambda b: ee.String(prefix).cat(ee.Number(b).int().format()))
# This function accepts mean centered imagery, a scale and
# a region in which to perform the analysis. It returns the
# Principal Components (PC) in the region as a new image.
示例11: set_color
# 需要导入模块: import ee [as 别名]
# 或者: from ee import String [as 别名]
def set_color(f):
c = ee.String(f.get('COLOR')).slice(1)
return f \
.set('R', ee.Number.parse(c.slice(0, 2), 16)) \
.set('G', ee.Number.parse(c.slice(2, 4), 16)) \
.set('B', ee.Number.parse(c.slice(4, 6), 16))
示例12: testInternals
# 需要导入模块: import ee [as 别名]
# 或者: from ee import String [as 别名]
def testInternals(self):
"""Test eq(), ne() and hash()."""
a = ee.String('one')
b = ee.String('two')
c = ee.String('one')
self.assertEquals(a, a)
self.assertNotEquals(a, b)
self.assertEquals(a, c)
self.assertNotEquals(b, c)
self.assertNotEquals(hash(a), hash(b))
示例13: map
# 需要导入模块: import ee [as 别名]
# 或者: from ee import String [as 别名]
def map(self, collection, **kwargs):
"""
:return:
:rtype: ee.Image
"""
name = self.name
increment = self.increment
reducer = self.process
amount = self.dist
outliers = self.apply(collection, bands=self.bands, reducer=reducer,
amount=amount)
pattern = self.bands_ee.map(
lambda name: ee.String(name).cat('_outlier'))
def wrap(img):
out = img.select(pattern)
# As apply method returns 1 for outliers and the score should be 0
# for it, turn it upside down
out = out.Not()
suma = tools.image.sumBands(out, name)
final = suma.select(name) \
.multiply(ee.Image(increment)).rename(name)
no_out = tools.image.removeBands(img, pattern)
return no_out.addBands(final)
return outliers.map(wrap)
示例14: test_Image_from_landsat_c1_sr_scaling
# 需要导入模块: import ee [as 别名]
# 或者: from ee import String [as 别名]
def test_Image_from_landsat_c1_sr_scaling():
"""Test if Landsat SR images images are being scaled"""
sr_img = ee.Image('LANDSAT/LC08/C01/T1_SR/LC08_044033_20170716')
input_img = ee.Image.constant([100, 100, 100, 100, 100, 100, 3000.0, 322])\
.rename(['B2', 'B3', 'B4', 'B5', 'B6', 'B7', 'B10', 'pixel_qa'])\
.set({'SATELLITE': ee.String(sr_img.get('SATELLITE')),
'system:id': ee.String(sr_img.get('system:id')),
'system:index': ee.String(sr_img.get('system:index')),
'system:time_start': ee.Number(sr_img.get('system:time_start'))})
output = utils.constant_image_value(
ssebop.Image.from_landsat_c1_sr(input_img).lst)
# Won't be exact because of emissivity correction
assert abs(output['lst'] - 300) <= 10
# @pytest.mark.parametrize(
# 'image_id',
# [
# 'LANDSAT/LC08/C01/T1_TOA/LC08_044033_20170716',
# 'LANDSAT/LC08/C01/T1_SR/LC08_044033_20170716',
# ]
# )
# def test_Image_from_image_id(image_id):
# """Test instantiating the class using the from_image_id method"""
# output = utils.getinfo(ssebop.Image.from_image_id(image_id).ndvi)
# assert output['properties']['system:index'] == image_id.split('/')[-1]
# assert output['properties']['image_id'] == image_id
示例15: max
# 需要导入模块: import ee [as 别名]
# 或者: from ee import String [as 别名]
def max(collection, band):
""" Make a max composite using the specified band """
band = ee.String(band)
first = collection.first()
originalbands = first.bandNames()
bands = originalbands.remove(band)
bands = bands.insert(0, band)
col = collection.map(lambda img: img.select(bands)) # change bands order
comp = col.reduce(ee.Reducer.max(originalbands.size()))
return comp.rename(bands).select(originalbands)