Skip to content

Commit

Permalink
v0.1.381
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 584437309
  • Loading branch information
Google Earth Engine Authors authored and schwehr committed Nov 30, 2023
1 parent 7211f0e commit 0950def
Show file tree
Hide file tree
Showing 45 changed files with 1,815 additions and 1,359 deletions.
10 changes: 0 additions & 10 deletions .github/ISSUE_TEMPLATE/bug_report.md

This file was deleted.

10 changes: 0 additions & 10 deletions .github/ISSUE_TEMPLATE/feature_request.md

This file was deleted.

1,001 changes: 501 additions & 500 deletions javascript/build/ee_api_js.js

Large diffs are not rendered by default.

427 changes: 237 additions & 190 deletions javascript/build/ee_api_js_debug.js

Large diffs are not rendered by default.

471 changes: 259 additions & 212 deletions javascript/build/ee_api_js_npm.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion javascript/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@google/earthengine",
"version": "0.1.379",
"version": "0.1.381",
"description": "JavaScript client for Google Earth Engine API.",
"author": "Google LLC",
"license": "Apache-2.0",
Expand Down
2 changes: 1 addition & 1 deletion javascript/src/apiclient.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const {trustedResourceUrl} = goog.require('safevalues');
/** @namespace */
const apiclient = {};

const API_CLIENT_VERSION = '0.1.379';
const API_CLIENT_VERSION = '0.1.381';

exports.VERSION = apiVersion.VERSION;
exports.API_CLIENT_VERSION = API_CLIENT_VERSION;
Expand Down
32 changes: 25 additions & 7 deletions javascript/src/feature.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,24 +135,42 @@ ee.Feature.prototype.getInfo = function(opt_callback) {
* generating a Map overlay.
*
* @param {?Object=} opt_visParams The visualization parameters. Currently only
* one parameter, 'color', containing an RGB color string is user. If
* vis_params is null, black ("000000") is used.
* one parameter, 'color', containing an RGB color string is allowed. If
* visParams is not specified, black ("000000") is used.
* @param {function(!Object, string=)=} opt_callback An async callback.
* @return {!ee.data.MapId|undefined} An object which may be passed to
* ee.data.getTileUrl or ui.Map.addLayer, including an additional 'image'
* field, containing a Collection.draw image wrapping a FeatureCollection
* containing this feature. Undefined if a callback was specified.
* @export
*/
ee.Feature.prototype.getMap = function(opt_visParams, opt_callback) {
var args =
ee.Feature.prototype.getMapId = function(opt_visParams, opt_callback) {
const args =
ee.arguments.extractFromFunction(ee.Feature.prototype.getMap, arguments);
var collection = ee.ApiFunction._call('Collection', [this]);
return /** @type {ee.FeatureCollection} */(collection)
.getMap(args['visParams'], args['callback']);
const collection = ee.ApiFunction._call('Collection', [this]);
return /** @type {!ee.FeatureCollection} */(collection)
.getMapId(args['visParams'], args['callback']);
};


/**
* An imperative function that returns a map ID and optional token, suitable for
* generating a Map overlay.
*
* @deprecated Use getMapId() instead.
* @param {?Object=} opt_visParams The visualization parameters. Currently only
* one parameter, 'color', containing an RGB color string is allowed. If
* visParams is not specified, black ("000000") is used.
* @param {function(!Object, string=)=} opt_callback An async callback.
* @return {!ee.data.MapId|undefined} An object which may be passed to
* ee.data.getTileUrl or ui.Map.addLayer, including an additional 'image'
* field, containing a Collection.draw image wrapping a FeatureCollection
* containing this feature. Undefined if a callback was specified.
* @export
*/
ee.Feature.prototype.getMap = ee.Feature.prototype.getMapId;


/** @override */
ee.Feature.prototype.name = function() {
return 'Feature';
Expand Down
40 changes: 29 additions & 11 deletions javascript/src/featurecollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,38 +132,56 @@ ee.FeatureCollection.reset = function() {


/**
* An imperative function that returns a map id and token, suitable for
* An imperative function that returns a map ID and optional token, suitable for
* generating a Map overlay.
*
* @param {?Object=} opt_visParams The visualization parameters. Currently only
* one parameter, 'color', containing an RGB color string is allowed. If
* vis_params isn't specified, then the color #000000 is used.
* one parameter, 'color', containing an RGB color string is allowed. If
* visParams is not specified, black ("000000") is used.
* @param {function(!Object, string=)=} opt_callback An async callback.
* If not supplied, the call is made synchronously.
* @return {!ee.data.MapId|undefined} An object which may be passed to
* ee.data.getTileUrl or ui.Map.addLayer, including an additional 'image'
* field, containing a Collection.draw image wrapping a FeatureCollection
* containing this feature. Undefined if a callback was specified.
* @export
*/
ee.FeatureCollection.prototype.getMap = function(opt_visParams, opt_callback) {
var args = ee.arguments.extractFromFunction(
ee.FeatureCollection.prototype.getMap, arguments);
ee.FeatureCollection.prototype.getMapId = function(
opt_visParams, opt_callback) {
const args = ee.arguments.extractFromFunction(
ee.FeatureCollection.prototype.getMapId, arguments);

var painted = /** @type {!ee.Image} */(
ee.ApiFunction._apply('Collection.draw', {
const painted =
/** @type {!ee.Image} */ (ee.ApiFunction._apply('Collection.draw', {
'collection': this,
'color': (args['visParams'] || {})['color'] || '000000'
}));

if (args['callback']) {
painted.getMap(undefined, args['callback']);
painted.getMapId(undefined, args['callback']);
} else {
return painted.getMap();
return painted.getMapId();
}
};


/**
* An imperative function that returns a map ID and optional token, suitable for
* generating a Map overlay.
*
* @deprecated Use getMapId() instead.
* @param {?Object=} opt_visParams The visualization parameters. Currently only
* one parameter, 'color', containing an RGB color string is allowed. If
* visParams is not specified, black ("000000") is used.
* @param {function(!Object, string=)=} opt_callback An async callback.
* @return {!ee.data.MapId|undefined} An object which may be passed to
* ee.data.getTileUrl or ui.Map.addLayer, including an additional 'image'
* field, containing a Collection.draw image wrapping a FeatureCollection
* containing this feature. Undefined if a callback was specified.
* @export
*/
ee.FeatureCollection.prototype.getMap = ee.FeatureCollection.prototype.getMapId;


/**
* An imperative function that returns all the known information about this
* collection via an AJAX call.
Expand Down
20 changes: 18 additions & 2 deletions javascript/src/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ ee.Image.prototype.getInfo = function(opt_callback) {


/**
* An imperative function that returns a map id and optional token, suitable for
* An imperative function that returns a map ID and optional token, suitable for
* generating a Map overlay.
*
* @param {!ee.data.ImageVisualizationParameters=} opt_visParams
Expand All @@ -165,7 +165,7 @@ ee.Image.prototype.getInfo = function(opt_callback) {
* specified.
* @export
*/
ee.Image.prototype.getMap = function(opt_visParams, opt_callback) {
ee.Image.prototype.getMapId = function(opt_visParams, opt_callback) {
const args = ee.arguments.extractFromFunction(
ee.Image.prototype.getMap, arguments);

Expand All @@ -192,6 +192,22 @@ ee.Image.prototype.getMap = function(opt_visParams, opt_callback) {
}
};

/**
* An imperative function that returns a map ID and optional token, suitable for
* generating a Map overlay.
*
* @deprecated Use getMapId() instead.
* @param {!ee.data.ImageVisualizationParameters=} opt_visParams
* The visualization parameters.
* @param {function(!ee.data.MapId, string=)=} opt_callback An async callback.
* If not supplied, the call is made synchronously.
* @return {!ee.data.MapId|undefined} An object which may be passed to
* ee.data.getTileUrl or ui.Map.addLayer. Undefined if a callback was
* specified.
* @export
*/
ee.Image.prototype.getMap = ee.Image.prototype.getMapId;


/**
* Get a download URL for small chunks of image data in GeoTIFF or NumPy
Expand Down
31 changes: 24 additions & 7 deletions javascript/src/imagecollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,31 +255,48 @@ ee.ImageCollection.prototype.getThumbURL_ = function(


/**
* An imperative function that returns a mapid via a synchronous AJAX call.
* An imperative function that returns a map ID via a synchronous AJAX call.
*
* This mosaics the collection to a single image and return a mapid suitable
* This mosaics the collection to a single image and return a map ID suitable
* for building a Google Maps overlay.
*
* @param {?Object=} opt_visParams The visualization parameters.
* @param {function(!Object, string=)=} opt_callback An async callback.
* If not supplied, the call is made synchronously.
* @return {!ee.data.MapId|undefined} Returns a mapid and optional token, which
* @return {!ee.data.MapId|undefined} Returns a map ID and optional token, which
* may be passed to ee.data.getTileUrl or ui.Map.addLayer. Undefined if
* a callback was specified.
* @export
*/
ee.ImageCollection.prototype.getMap = function(opt_visParams, opt_callback) {
ee.ImageCollection.prototype.getMapId = function(opt_visParams, opt_callback) {
var args = ee.arguments.extractFromFunction(
ee.ImageCollection.prototype.getMap, arguments);
ee.ImageCollection.prototype.getMapId, arguments);
var mosaic = /** @type {!ee.Image} */(
ee.ApiFunction._call('ImageCollection.mosaic', this));
if (args['callback']) {
mosaic.getMap(args['visParams'], args['callback']);
mosaic.getMapId(args['visParams'], args['callback']);
} else {
return mosaic.getMap(args['visParams']);
return mosaic.getMapId(args['visParams']);
}
};

/**
* An imperative function that returns a map ID via a synchronous AJAX call.
*
* This mosaics the collection to a single image and return a map ID suitable
* for building a Google Maps overlay.
*
* @deprecated Use getMapId() instead.
* @param {?Object=} opt_visParams The visualization parameters.
* @param {function(!Object, string=)=} opt_callback An async callback.
* If not supplied, the call is made synchronously.
* @return {!ee.data.MapId|undefined} Returns a map ID and optional token, which
* may be passed to ee.data.getTileUrl or ui.Map.addLayer. Undefined if
* a callback was specified.
* @export
*/
ee.ImageCollection.prototype.getMap = ee.ImageCollection.prototype.getMapId;


/**
* An imperative function that returns all the known information about this
Expand Down
4 changes: 2 additions & 2 deletions javascript/test/ee_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ describe('ee', function() {

it('retrieves a map ID synchronously', function() {
const image = new ee.Image('srtm90_v4');
const map = image.getMap({'min': 0, 'max': 1000});
const map = image.getMapId({'min': 0, 'max': 1000});
expect(map.mapid).toMatch(/\w+/);
});

it('retrieves a map ID asynchronously', function(done) {
const image = new ee.Image('srtm90_v4');
image.getMap({'min': 0, 'max': 1000}, ({mapid}) => {
image.getMapId({'min': 0, 'max': 1000}, ({mapid}) => {
expect(mapid).toMatch(/\w+/);
done();
});
Expand Down
24 changes: 15 additions & 9 deletions python/ee/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
"""The EE Python library."""

__version__ = '0.1.379'
__version__ = '0.1.381'

# Using lowercase function naming to match the JavaScript names.
# pylint: disable=g-bad-name
Expand All @@ -12,6 +12,7 @@
import os
from typing import Any, Hashable, List as ListType, Optional, Sequence, Type, Union

from ee import _utils
from ee import batch
from ee import data
from ee import deserializer
Expand All @@ -24,6 +25,7 @@
from ._helpers import profilePrinting
from ._helpers import ServiceAccountCredentials
from .apifunction import ApiFunction
from .blob import Blob
from .collection import Collection
from .computedobject import ComputedObject
from .customfunction import CustomFunction
Expand Down Expand Up @@ -105,9 +107,10 @@ def Authenticate(
)


@_utils.accept_opt_prefix('opt_url')
def Initialize(
credentials: Optional[Any] = 'persistent',
opt_url: Optional[str] = None,
url: Optional[str] = None,
cloud_api_key: Optional[str] = None,
http_transport: Optional[Any] = None,
project: Optional[Union[str, int]] = None,
Expand All @@ -121,9 +124,9 @@ def Initialize(
Args:
credentials: OAuth2 credentials. 'persistent' (default) means use
credentials already stored in the filesystem, or raise an explanatory
exception guiding the user to create those credentials.
opt_url: The base url for the EarthEngine REST API to connect to.
credentials already stored in the filesystem, or raise an explanatory
exception guiding the user to create those credentials.
url: The base url for the EarthEngine REST API to connect to.
cloud_api_key: An optional API key to use the Cloud API.
http_transport: The http transport method to use when making requests.
project: The client project ID or number to use when making API calls.
Expand All @@ -133,15 +136,17 @@ def Initialize(

data.initialize(
credentials=credentials,
api_base_url=(opt_url + '/api' if opt_url else None),
tile_base_url=opt_url,
cloud_api_base_url=opt_url,
api_base_url=(url + '/api' if url else None),
tile_base_url=url,
cloud_api_base_url=url,
cloud_api_key=cloud_api_key,
project=project,
http_transport=http_transport)
http_transport=http_transport,
)

# Initialize the dynamically loaded functions on the objects that want them.
ApiFunction.initialize()
Blob.initialize()
Collection.initialize()
Date.initialize()
Dictionary.initialize()
Expand Down Expand Up @@ -170,6 +175,7 @@ def Reset() -> None:
ApiFunction.reset()
Element.reset() # Must be before Collection.
Collection.reset() # Must be before FeatureCollection and ImageCollection.
Blob.reset()
Date.reset()
Dictionary.reset()
Feature.reset()
Expand Down
43 changes: 43 additions & 0 deletions python/ee/_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env python3
"""General decorators and helper methods which should not import ee."""

import functools
from typing import Any, Callable


def accept_opt_prefix(*opt_args) -> Callable[..., Any]:
"""Decorator to maintain support for "opt_" prefixed kwargs.
Args:
*opt_args: Arguments prefixed with "opt_" to be replaced by the stripped
version. Use a nested tuple to map an old "opt_" arg to a new one, e.g.
`opt_my_arg, (opt_my_arg2, opt_new_name)`.
Returns:
The decorated function which accepts the "opt_" versions of the args.
"""
args_map = dict()
for arg in opt_args:
if isinstance(arg, str):
args_map[arg] = arg.replace('opt_', '', 1)
elif isinstance(arg, tuple):
opt_arg, new_arg = arg
args_map[opt_arg] = new_arg

def opt_fixed(func: Callable[..., Any]):
@functools.wraps(func)
def wrapper(*args, **kwargs):
# Cache the kwarg keys, since kwargs will be modified.
for key in list(kwargs):
if key in args_map:
new_key = args_map.get(key)
# Remove the old key unconditionally.
old_key_val = kwargs.pop(key)
# Ensure that existing keys are not overridden.
if new_key not in kwargs:
kwargs[new_key] = old_key_val
return func(*args, **kwargs)

return wrapper

return opt_fixed
Loading

0 comments on commit 0950def

Please sign in to comment.