Python ee.Number() Examples
The following are 30
code examples of ee.Number().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
ee
, or try the search function
.
Example #1
Source File: eeWishart.py From earthengine with MIT License | 6 votes |
def pv(imList,p,median,j): ''' calculate -2log(R_ell,j) and return P-value ''' imList = ee.List(imList) p = ee.Number(p) j = ee.Number(j) f = p one = ee.Number(1.0) # 1 - (1. + 1./(j*(j-1)))/(6.*p*n) rhoj = one.subtract(one.add(one.divide(j.multiply(j.subtract(one)))).divide(6*ENL)) # -(f/4.)*(1.-1./rhoj)**2' omega2j = one.subtract(one.divide(rhoj)).pow(2.0).multiply(f.divide(-4.0)) Z = ee.Image(ee.Image(log_det_sum(imList,j.subtract(1)))).multiply(j.subtract(1)) \ .add(log_det(imList,j)) \ .add(p.multiply(j).multiply(ee.Number(j).log())) \ .subtract(p.multiply(j.subtract(1)).multiply(j.subtract(1).log())) \ .subtract(ee.Image(log_det_sum(imList,j)).multiply(j)) \ .multiply(rhoj) \ .multiply(-2*ENL) # (1.-omega2j)*stats.chi2.cdf(Z,[f])+omega2j*stats.chi2.cdf(Z,[f+4]) P = ee.Image( chi2cdf(Z,f).multiply(one.subtract(omega2j)).add(chi2cdf(Z,f.add(4)).multiply(omega2j)) ) # 3x3 median filter return ee.Algorithms.If(median, P.focal_median(), P)
Example #2
Source File: mission_specifics.py From ee-atmcorr-timeseries with Apache License 2.0 | 6 votes |
def solar_z(image, mission): """ solar zenith angle (degrees) """ def sentinel2(image): return ee.Number(image.get('MEAN_SOLAR_ZENITH_ANGLE')) def landsat(image): return ee.Number(90).subtract(image.get('SUN_ELEVATION')) switch = { 'Sentinel2':sentinel2, 'Landsat8':landsat, 'Landsat7':landsat, 'Landsat5':landsat, 'Landsat4':landsat } getSolarZenith = switch[mission] return getSolarZenith(image)
Example #3
Source File: scores.py From geebap with GNU General Public License v3.0 | 6 votes |
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)
Example #4
Source File: eeMad.py From earthengine with MIT License | 6 votes |
def covarw(image, weights, maxPixels=1e9): '''Return the weighted centered image and its weighted covariance matrix''' geometry = image.geometry() bandNames = image.bandNames() N = bandNames.length() scale = image.select(0).projection().nominalScale() weightsImage = image.multiply(ee.Image.constant(0)).add(weights) means = image.addBands(weightsImage) \ .reduceRegion(ee.Reducer.mean().repeat(N).splitWeights(), scale=scale,maxPixels=maxPixels) \ .toArray() \ .project([1]) centered = image.toArray().subtract(means) B1 = centered.bandNames().get(0) b1 = weights.bandNames().get(0) nPixels = ee.Number(centered.reduceRegion(ee.Reducer.count(), scale=scale, maxPixels=maxPixels).get(B1)) sumWeights = ee.Number(weights.reduceRegion(ee.Reducer.sum(),geometry=geometry, scale=scale, maxPixels=maxPixels).get(b1)) covw = centered.multiply(weights.sqrt()) \ .toArray() \ .reduceRegion(ee.Reducer.centeredCovariance(), geometry=geometry, scale=scale, maxPixels=maxPixels) \ .get('array') covw = ee.Array(covw).multiply(nPixels).divide(sumWeights) return (centered.arrayFlatten([bandNames]), covw)
Example #5
Source File: imagecollection.py From gee_tools with MIT License | 6 votes |
def enumerateProperty(collection, name='enumeration'): """ :param collection: :param name: :return: """ enumerated = eecollection.enumerate(collection) def over_list(l): l = ee.List(l) index = ee.Number(l.get(0)) element = l.get(1) return ee.Image(element).set(name, index) imlist = enumerated.map(over_list) return ee.ImageCollection(imlist)
Example #6
Source File: eeMad_old.py From earthengine with MIT License | 6 votes |
def covw(centeredImage, weights=None, maxPixels=1e9): '''Return the (weighted) covariance matrix of a centered image''' if weights==None: weights = centeredImage.multiply(0).add(ee.Image.constant(1)) B1 = centeredImage.bandNames().get(0) b1 = weights.bandNames().get(0) sumWeights = ee.Number(weights.reduceRegion(ee.Reducer.sum(), maxPixels=maxPixels).get(b1)) nPixels = ee.Number(centeredImage.reduceRegion(ee.Reducer.count(), maxPixels=maxPixels).get(B1)) # arr = dataArray(centeredImage.multiply(weights.sqrt())) # return arr.matrixTranspose().matrixMultiply(arr).divide(sumWeights) covW = centeredImage \ .multiply(weights.sqrt()) \ .toArray() \ .reduceRegion(ee.Reducer.centeredCovariance(), maxPixels=1e9) \ .get('array') return ee.Array(covW).multiply(nPixels.divide(sumWeights))
Example #7
Source File: atmospheric.py From ee-atmcorr-timeseries with Apache License 2.0 | 6 votes |
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))
Example #8
Source File: eeWishart.py From earthengine with MIT License | 6 votes |
def filter_j(current,prev): P = ee.Image(current) prev = ee.Dictionary(prev) ell = ee.Number(prev.get('ell')) cmap = ee.Image(prev.get('cmap')) smap = ee.Image(prev.get('smap')) fmap = ee.Image(prev.get('fmap')) bmap = ee.Image(prev.get('bmap')) threshold = ee.Image(prev.get('threshold')) j = ee.Number(prev.get('j')) cmapj = cmap.multiply(0).add(ell.add(j).subtract(1)) cmap1 = cmap.multiply(0).add(1) tst = P.gt(threshold).And(cmap.eq(ell.subtract(1))) cmap = cmap.where(tst,cmapj) fmap = fmap.where(tst,fmap.add(1)) smap = ee.Algorithms.If(ell.eq(1),smap.where(tst,cmapj),smap) idx = ell.add(j).subtract(2) tmp = bmap.select(idx) bname = bmap.bandNames().get(idx) tmp = tmp.where(tst,cmap1) tmp = tmp.rename([bname]) bmap = bmap.addBands(tmp,[bname],True) return ee.Dictionary({'ell':ell,'j':j.add(1),'threshold':threshold,'cmap':cmap,'smap':smap,'fmap':fmap,'bmap':bmap})
Example #9
Source File: test_c_image.py From openet-ssebop-beta with Apache License 2.0 | 6 votes |
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), # })
Example #10
Source File: season.py From geebap with GNU General Public License v3.0 | 6 votes |
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
Example #11
Source File: image.py From gee_tools with MIT License | 6 votes |
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))
Example #12
Source File: string_test.py From earthengine with MIT License | 6 votes |
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)
Example #13
Source File: date.py From geebap with GNU General Public License v3.0 | 6 votes |
def get(date, unit="days"): """ get the date (ee.Date) of the given value in 'unit'. Currentrly ONLY process 'days', so: `date.Date.get(365) = '1971-01-01T00:00:00` :param date: the value to transform :type date: int :param unit: date's unit (currently ONLY 'days') :return: date corresponding to the given value :rtype: ee.Date """ if unit == "days": mili = ee.Number(date).multiply(Date.oneday) d = ee.Date(mili) # dstr = d.format() return d
Example #14
Source File: image.py From gee_tools with MIT License | 6 votes |
def doyToDate(image, dateFormat='yyyyMMdd', year=None): """ Make a date band from a day of year band """ if not year: year = image.date().get('year') doyband = image.select([0]) leap = date.isLeap(year) limit = ee.Number(ee.Algorithms.If(leap, 365, 364)) alldoys = ee.List.sequence(1, limit) def wrap(doy, i): i = ee.Image(i) doy = ee.Number(doy) d = date.fromDOY(doy, year) date_band = ee.Image.constant(ee.Number.parse(d.format(dateFormat))) condition = i.eq(doy) return i.where(condition, date_band) datei = ee.Image(alldoys.iterate(wrap, doyband)) return datei.rename('date')
Example #15
Source File: image.py From gee_tools with MIT License | 6 votes |
def vectorize(image, categories, label='label'): """ Reduce to vectors the selected classes fro a classified image :param categories: the categories to vectorize :type categories: list """ def over_cat(cat, ini): cat = ee.Number(cat) ini = ee.Image(ini) return ini.add(image.eq(cat).multiply(cat)) filtered = ee.Image( ee.List(categories).iterate(over_cat, empty(0, [label]))) out = filtered.neq(0) filtered = filtered.updateMask(out) return filtered.reduceToVectors(**{ 'scale': 30, 'maxPixels':1e13, 'labelProperty': label})
Example #16
Source File: utils.py From openet-ssebop-beta with Apache License 2.0 | 6 votes |
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)
Example #17
Source File: string_test.py From aqua-monitor with GNU Lesser General Public License v3.0 | 6 votes |
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)
Example #18
Source File: image.py From gee_tools with MIT License | 5 votes |
def repeatBand(image, times=None, names=None, properties=None): """ Repeat one band. If the image parsed has more than one band, the first will be used """ band = ee.Image(image.select([0])) if times is not None: times = ee.Number(times) proxylist = ee.List.repeat(0, times.subtract(1)) def add(band, i): band = ee.Image(band) i = ee.Image(i) return i.addBands(band) proxyImg = proxylist.map(lambda n: band) repeated = ee.Image(proxyImg.iterate(add, band)) else: newNames = ee.List(names) firstName = ee.String(newNames.get(0)) rest = ee.List(newNames.slice(1)) def add(name, i): name = ee.String(name) i = ee.Image(i) return i.addBands(band.rename(name)) first = band.rename(firstName) repeated = ee.Image(rest.iterate(add, first)) if properties: repeated = repeated.setMulti(properties) return ee.Image(repeated)
Example #19
Source File: image.py From gee_tools with MIT License | 5 votes |
def computeBits(image, start, end, newName): """ Compute the bits of an image :param start: start bit :type start: int :param end: end bit :type end: int :param newName: new name for the band :type newName: str :return: A function which single argument is the image and returns a single band image of the extracted bits, giving the band a new name :rtype: function """ pattern = ee.Number(0) start = ee.Number(start).toInt() end = ee.Number(end).toInt() newName = ee.String(newName) seq = ee.List.sequence(start, end) def toiterate(element, ini): ini = ee.Number(ini) bit = ee.Number(2).pow(ee.Number(element)) return ini.add(bit) patt = seq.iterate(toiterate, pattern) patt = ee.Number(patt).toInt() good_pix = image.select([0], [newName]).toInt() \ .bitwiseAnd(patt).rightShift(start) return good_pix.toInt()
Example #20
Source File: image.py From gee_tools with MIT License | 5 votes |
def normalDistribution(image, band, mean=None, std=None, region=None, scale=None, name='normal_distribution', **kwargs): """ Compute a Normal Distribution using the Gaussian Function """ pi = ee.Number(math.pi) image = image.select(band) if mean is None: mean = image.reduceRegion(reducer=ee.Reducer.mean(), geometry=region, scale=scale, **kwargs) mean = ee.Image.constant(mean.get(band)) else: mean = castImage(mean) if std is None: std = image.reduceRegion(reducer=ee.Reducer.stdDev(), geometry=region, scale=scale, **kwargs) std = ee.Image.constant(std.get(band)) else: std = castImage(std) output_max = ee.Image(1)\ .divide(std.multiply(ee.Image(2).multiply(pi).sqrt())) return gaussFunction(image, band, mean=mean, std=std, output_max=output_max, name=name, **kwargs)
Example #21
Source File: conftest.py From openet-ssebop-beta with Apache License 2.0 | 5 votes |
def test_init(): # Make a simple EE request ee.Number(1).getInfo()
Example #22
Source File: cloud_mask.py From gee_tools with MIT License | 5 votes |
def decodeBitsEE(bit_reader, qa_band): """ :param bit_reader: the bit reader :type bit_reader: BitReader :param qa_band: name of the band that holds the bit information :type qa_band: str :return: a function to map over a collection. The function adds all categories masks as new bands """ options = ee.Dictionary(bit_reader.info) categories = ee.List(bit_reader.all_categories) def wrap(image): def eachcat(cat, ini): ini = ee.Image(ini) qa = ini.select(qa_band) # get data for category data = ee.Dictionary(options.get(cat)) lshift = ee.Number(data.get('lshift')) length = ee.Number(data.get('bit_length')) decoded = ee.Number(data.get('shifted')) # move = places to move bits right and left back move = lshift.add(length) # move bits right and left rest = qa.rightShift(move).leftShift(move) # subtract the rest norest = qa.subtract(rest) # right shift to compare with decoded data to_compare = norest.rightShift(lshift) ## Image # compare if is equal, return 0 if not equal, 1 if equal mask = to_compare.eq(decoded) # rename to the name of the category qa_mask = mask.select([0], [cat]) return ini.addBands(qa_mask) return ee.Image(categories.iterate(eachcat, image)) return wrap
Example #23
Source File: test_a_utils.py From openet-ssebop-beta with Apache License 2.0 | 5 votes |
def test_getinfo(): assert utils.getinfo(ee.Number(1)) == 1
Example #24
Source File: test_b_model.py From openet-ssebop-beta with Apache License 2.0 | 5 votes |
def test_Model_dt_calc_rs_ea(tmax, tmin, elev, doy, lat, rs, ea, expected, tol=0.0001): """Test dt calculation using 'measured' Rs and Ea (from Tdew, sph, vp)""" dt = utils.getinfo(model.dt( tmax=ee.Number(tmax), tmin=ee.Number(tmin), elev=ee.Number(elev), rs=ee.Number(rs), ea=ee.Number(ea), doy=ee.Number(doy), lat=ee.Number(lat))) assert abs(float(dt) - expected) <= tol
Example #25
Source File: test_b_model.py From openet-ssebop-beta with Apache License 2.0 | 5 votes |
def test_Model_dt_calc_rso_ea(tmax, tmin, elev, doy, lat, ea, expected, tol=0.0001): """Test dt calculation using 'measured' Ea (from Tdew, sph, vp) and Rso""" dt = utils.getinfo(model.dt( tmax=ee.Number(tmax), tmin=ee.Number(tmin), elev=ee.Number(elev), ea=ee.Number(ea), doy=ee.Number(doy), lat=ee.Number(lat))) assert abs(float(dt) - expected) <= tol
Example #26
Source File: test_b_model.py From openet-ssebop-beta with Apache License 2.0 | 5 votes |
def test_Model_dt_calc_rs_no_ea(tmax, tmin, elev, doy, lat, rs, expected, tol=0.0001): """Test dt calculation using measured Rs and Ea from Tmin""" dt = utils.getinfo(model.dt( tmax=ee.Number(tmax), tmin=ee.Number(tmin), elev=ee.Number(elev), rs=ee.Number(rs), doy=ee.Number(doy), lat=ee.Number(lat))) assert abs(float(dt) - expected) <= tol
Example #27
Source File: test_b_model.py From openet-ssebop-beta with Apache License 2.0 | 5 votes |
def test_Model_dt_calc_rso_no_ea(tmax, tmin, elev, doy, lat, expected, tol=0.0001): """Test dt calculation using Rso and Ea from Tmin""" dt = utils.getinfo(model.dt( tmax=ee.Number(tmax), tmin=ee.Number(tmin), elev=ee.Number(elev), rs=None, doy=ee.Number(doy), lat=ee.Number(lat))) assert abs(float(dt) - expected) <= tol
Example #28
Source File: test_b_landsat.py From openet-ssebop-beta with Apache License 2.0 | 5 votes |
def toa_image(red=0.1, nir=0.9, bt=305): """Construct a fake Landsat 8 TOA image with renamed bands""" return ee.Image.constant([red, nir, bt])\ .rename(['red', 'nir', 'tir']) \ .set({ # 'system:time_start': ee.Date(SCENE_DATE).millis(), 'k1_constant': ee.Number(607.76), 'k2_constant': ee.Number(1260.56), })
Example #29
Source File: model.py From openet-ssebop-beta with Apache License 2.0 | 5 votes |
def et_fraction(lst, tmax, tcorr, dt, elr_flag=False, elev=None): """SSEBop fraction of reference ET (ETf) Parameters ---------- lst : ee.Image Land surface temperature (lst) [L]. tmax : ee.Image Maximum air temperature [K]. tcorr : ee.Image, ee.Number Tcorr. dt : ee.Image, ee.Number Temperature difference [K]. elr_flag : bool, optional If True, apply Elevation Lapse Rate (ELR) adjustment (the default is False). elev : ee.Image, ee.Number, optional Elevation [m] (the default is None). Only needed if elr_flag is True. Returns ------- ee.Image References ---------- """ # Adjust air temperature based on elevation (Elevation Lapse Rate) if elr_flag: tmax = ee.Image(lapse_adjust(tmax, ee.Image(elev))) et_fraction = lst.expression( '(lst * (-1) + tmax * tcorr + dt) / dt', {'tmax': tmax, 'dt': dt, 'lst': lst, 'tcorr': tcorr}) return et_fraction.updateMask(et_fraction.lt(1.3))\ .clamp(0, 1.05)\ .rename(['et_fraction'])
Example #30
Source File: _helpers_test.py From aqua-monitor with GNU Lesser General Public License v3.0 | 5 votes |
def testProfilePrintingDefaultSmoke(self): # This will print to sys.stderr, so we can't make any assertions about the # output. But we can check that it doesn't fail. with ee.profilePrinting(): self.assertEquals('hooked=True getProfiles=False', ee.Number(1).getInfo())