Skip to content

Commit

Permalink
v0.1.379
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 581060984
  • Loading branch information
Google Earth Engine Authors authored and bengalin committed Nov 15, 2023
1 parent 16871ff commit 7211f0e
Show file tree
Hide file tree
Showing 30 changed files with 15,266 additions and 15,221 deletions.
1,294 changes: 648 additions & 646 deletions javascript/build/ee_api_js.js

Large diffs are not rendered by default.

14,406 changes: 7,214 additions & 7,192 deletions javascript/build/ee_api_js_debug.js

Large diffs are not rendered by default.

14,450 changes: 7,236 additions & 7,214 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.378",
"version": "0.1.379",
"description": "JavaScript client for Google Earth Engine API.",
"author": "Google LLC",
"license": "Apache-2.0",
Expand Down
9 changes: 5 additions & 4 deletions javascript/src/apiclient.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ goog.module.declareLegacyNamespace();

const GoogConst = goog.require('goog.string.Const');
const Throttle = goog.require('goog.async.Throttle');
const TrustedResourceUrl = goog.require('goog.html.TrustedResourceUrl');
const Uri = goog.require('goog.Uri');
const XhrIo = goog.require('goog.net.XhrIo');
const XhrLike = goog.requireType('goog.net.XhrLike');
Expand All @@ -21,11 +20,12 @@ const jsloader = goog.require('goog.net.jsloader');
const {MakeRequestParams, processParams} = goog.require('eeapiclient.request_params');
const {NULL_VALUE, Serializable, SerializableCtor, deserialize, serialize} = goog.require('eeapiclient.domain_object');
const {PromiseRequestService} = goog.require('eeapiclient.promise_request_service');
const {trustedResourceUrl} = goog.require('safevalues');

/** @namespace */
const apiclient = {};

const API_CLIENT_VERSION = '0.1.378';
const API_CLIENT_VERSION = '0.1.379';

exports.VERSION = apiVersion.VERSION;
exports.API_CLIENT_VERSION = API_CLIENT_VERSION;
Expand Down Expand Up @@ -1147,8 +1147,9 @@ apiclient.ensureAuthLibLoaded_ = function(callback) {
delete goog.global[callbackName];
done();
};
jsloader.safeLoad(TrustedResourceUrl.format(
apiclient.AUTH_LIBRARY_URL_, {'onload': callbackName}));
jsloader.safeLoad(
trustedResourceUrl`https://apis.google.com/js/client.js?onload=${
callbackName}`);
}
};

Expand Down
3 changes: 1 addition & 2 deletions javascript/src/ee.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,7 @@ ee.promote_ = function(arg, klass) {
return new ee.Image(/** @type {Object} */ (arg));
case 'Feature':
if (arg instanceof ee.Collection) {
// TODO(user): Decide whether we want to leave this in. It can be
// quite dangerous on large collections.
// This can be quite dangerous on large collections.
return ee.ApiFunction._call(
'Feature', ee.ApiFunction._call('Collection.geometry', arg));
} else {
Expand Down
1 change: 1 addition & 0 deletions javascript/src/eeapiclient/api_client.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// g3-format-clang
import {Serializable, serialize} from './domain_object';
import {GeneratedRequestParams} from './generated_types';
import {MultipartRequest} from './multipart_request';
Expand Down
1 change: 1 addition & 0 deletions javascript/src/eeapiclient/api_request_hook.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// g3-format-clang
import {GeneratedRequestParams} from './generated_types';

export interface ApiClientRequestHook {
Expand Down
1 change: 1 addition & 0 deletions javascript/src/eeapiclient/domain_object.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/**
* g3-format-clang
* Utility map for ClassMetadata to describe how to create instances of child
* properties.
*/
Expand Down
1 change: 1 addition & 0 deletions javascript/src/eeapiclient/generated_types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// g3-format-clang
import {Serializable, SerializableCtor} from './domain_object';
import {MultipartRequest} from './multipart_request';

Expand Down
1 change: 1 addition & 0 deletions javascript/src/eeapiclient/multipart_request.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// g3-format-clang
import {Serializable, serialize} from './domain_object';

export class MultipartRequest {
Expand Down
1 change: 1 addition & 0 deletions javascript/src/eeapiclient/promise_api_client.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// g3-format-clang
import {ApiClient, toMakeRequestParams, toMultipartMakeRequestParams} from './api_client';
import {ApiClientHookFactory, getRequestHook} from './api_request_hook';
import {Serializable} from './domain_object';
Expand Down
1 change: 1 addition & 0 deletions javascript/src/eeapiclient/promise_request_service.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// g3-format-clang
import {deserialize, Serializable, SerializableCtor} from './domain_object';
import {MakeRequestParams, processParams} from './request_params';

Expand Down
1 change: 1 addition & 0 deletions javascript/src/eeapiclient/request_params.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// g3-format-clang
import * as httpCors from 'goog:goog.net.rpc.HttpCors';

import {GeneratedQueryParams} from './generated_types';
Expand Down
1 change: 1 addition & 0 deletions javascript/src/eeapiclient/request_params_test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// g3-format-clang
import 'jasmine';

import {buildQueryParams, bypassCorsPreflight, MakeRequestParams} from './request_params';
Expand Down
58 changes: 0 additions & 58 deletions javascript/src/examples/CloudMasking/Sentinel2ClearComposites.js

This file was deleted.

35 changes: 35 additions & 0 deletions javascript/src/examples/CloudMasking/Sentinel2CloudScorePlus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// This example demonstrates how to use Cloud Score+ QA bands to generate a
// clear median composite for a specified date range.

// Harmonized Sentinel-2 Level 2A collection.
var s2 = ee.ImageCollection('COPERNICUS/S2_SR_HARMONIZED');

// Cloud Score+ image collection. Note Cloud Score+ is produced from Sentinel-2
// Level 1C data and can be applied to either L1C or L2A collections.
var csPlus = ee.ImageCollection('GOOGLE/CLOUD_SCORE_PLUS/V1/S2_HARMONIZED');

// Region of interest.
var ROI = ee.Geometry.Point(-119.9087, 37.4159);

// Use 'cs' or 'cs_cdf', depending on your use-case; see docs for guidance.
var QA_BAND = 'cs_cdf';

// The threshold for masking; values between 0.50 and 0.65 generally work well.
// Higher values will remove thin clouds, haze & cirrus shadows.
var CLEAR_THRESHOLD = 0.60;

// Make composite.
var composite = s2
.filterBounds(ROI)
.filterDate('2023-01-01', '2023-02-01')
.linkCollection(csPlus, [QA_BAND])
.map(function(img) {
return img.updateMask(img.select(QA_BAND).gte(CLEAR_THRESHOLD));
})
.median();

// Sentinel-2 visualization parameters.
var s2Viz = {bands: ['B4', 'B3', 'B2'], min: 0, max: 2500};

Map.addLayer(composite, s2Viz, 'median composite');
Map.centerObject(ROI, 11);
9 changes: 3 additions & 6 deletions python/ee/__init__.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
#!/usr/bin/env python3
"""The EE Python library."""

__version__ = '0.1.378'
__version__ = '0.1.379'

# Using lowercase function naming to match the JavaScript names.
# pylint: disable=g-bad-name

import collections
import datetime
import inspect
import numbers
import os
from typing import Any, Hashable, List as ListType, Optional, Sequence, Type, Union

from ee import _cloud_api_utils
from ee import batch
from ee import data
from ee import deserializer
Expand Down Expand Up @@ -111,7 +109,7 @@ def Initialize(
credentials: Optional[Any] = 'persistent',
opt_url: Optional[str] = None,
cloud_api_key: Optional[str] = None,
http_transport: Optional[_cloud_api_utils.HttpTransportable] = None,
http_transport: Optional[Any] = None,
project: Optional[Union[str, int]] = None,
) -> None:
"""Initialize the EE library.
Expand Down Expand Up @@ -224,8 +222,7 @@ def _Promote(arg: Optional[Any], a_class: str) -> Optional[Any]:
return Image(arg)
elif a_class == 'Feature':
if isinstance(arg, Collection):
# TODO(user): Decide whether we want to leave this in. It can be
# quite dangerous on large collections.
# This can be quite dangerous on large collections.
return ApiFunction.call_(
'Feature', ApiFunction.call_('Collection.geometry', arg))
else:
Expand Down
55 changes: 23 additions & 32 deletions python/ee/_cloud_api_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
import json
import os
import re
from typing import Any, Callable, Dict, List, Optional, Protocol, Sequence, Tuple, Type, Union
from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Type, Union
import warnings

from google import auth
import google_auth_httplib2
from googleapiclient import discovery
from googleapiclient import http
Expand All @@ -40,27 +39,16 @@
_cloud_api_user_project: Optional[str] = None


class HttpTransportable(Protocol):
"""A protocol for HTTP transport objects."""

def request( # pylint: disable=invalid-name
self,
uri: str,
method: str,
body: Optional[str],
headers: Optional[Dict[str, str]],
redirections: Optional[int],
connection_type: Optional[Type[Any]],
) -> Any:
"""Make an HTTP request."""


class _Http:
"""A httplib2.Http-like object based on requests."""
_session: requests.Session
_timeout: Optional[float]

def __init__(self, timeout: Optional[float] = None):
def __init__(
self, session: requests.Session, timeout: Optional[float] = None
):
self._timeout = timeout
self._session = session

def request( # pylint: disable=invalid-name
self,
Expand All @@ -72,15 +60,15 @@ def request( # pylint: disable=invalid-name
connection_type: Optional[Type[Any]] = None,
) -> Tuple[httplib2.Response, Any]:
"""Makes an HTTP request using httplib2 semantics."""
del connection_type # Unused

with requests.Session() as session:
session.max_redirects = redirections
response = session.request(
method, uri, data=body, headers=headers, timeout=self._timeout)
headers = dict(response.headers)
headers['status'] = response.status_code
content = response.content
del connection_type # Ignored
del redirections # Ignored

response = self._session.request(
method, uri, data=body, headers=headers, timeout=self._timeout
)
headers = dict(response.headers)
headers['status'] = response.status_code
content = response.content
return httplib2.Response(headers), content


Expand Down Expand Up @@ -143,18 +131,21 @@ def set_cloud_api_user_project(cloud_api_user_project: str) -> None:

def build_cloud_resource(
api_base_url: str,
session: requests.Session,
api_key: Optional[str] = None,
credentials: Optional[auth.credentials.Credentials] = None,
credentials: Optional[Any] = None,
timeout: Optional[float] = None,
headers_supplier: Optional[Callable[[], Dict[str, Any]]] = None,
response_inspector: Optional[Callable[[Any], None]] = None,
http_transport: Optional[HttpTransportable] = None,
http_transport: Optional[Any] = None,
raw: Optional[bool] = False,
) -> discovery.Resource:
) -> Any:
"""Builds an Earth Engine Cloud API resource.
Args:
api_base_url: The base URL of the cloud endpoints.
session: The Requests session to issue all requests in. This manages
shared resources, such as connection pools.
api_key: An API key that's enabled for use with the Earth Engine Cloud API.
credentials: OAuth2 credentials to use when authenticating to the API.
timeout: How long a timeout to set on requests, in seconds.
Expand All @@ -172,7 +163,7 @@ def build_cloud_resource(
'{}/$discovery/rest?version={}&prettyPrint=false'
.format(api_base_url, VERSION))
if http_transport is None:
http_transport = _Http(timeout)
http_transport = _Http(session, timeout)
if credentials is not None:
http_transport = google_auth_httplib2.AuthorizedHttp(
credentials, http=http_transport
Expand Down Expand Up @@ -236,7 +227,7 @@ def build_cloud_resource_from_document(
"""
request_builder = _wrap_request(headers_supplier, response_inspector)
if http_transport is None:
http_transport = _Http()
http_transport = _Http(requests.Session())
alt_model = model.RawModel() if raw else None
return discovery.build_from_document(
discovery_document,
Expand Down
3 changes: 1 addition & 2 deletions python/ee/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ def profilePrinting(destination: TextIO = sys.stderr) -> Iterator[None]:
Defaults to sys.stderr.
"""
# TODO(user): Figure out why ee.Profile.getProfiles isn't generated and fix
# that.
# Profile.getProfiles is `hidden`, so call it explicitly.
getProfiles = apifunction.ApiFunction.lookup('Profile.getProfiles')

profile_ids = []
Expand Down
2 changes: 1 addition & 1 deletion python/ee/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def filterDate(
def getInfo(self) -> Optional[Any]:
"""Returns all the known information about this collection.
This function makes an REST call to to retrieve all the known information
This function makes a REST call to to retrieve all the known information
about this collection.
Returns:
Expand Down
Loading

0 comments on commit 7211f0e

Please sign in to comment.