Skip to content

Commit

Permalink
Merge branch 'master' into fix/retry-network-error
Browse files Browse the repository at this point in the history
  • Loading branch information
guss84 committed Jan 6, 2025
2 parents 2c51297 + 4f885c7 commit 71ccf07
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 69 deletions.
5 changes: 1 addition & 4 deletions src/dataimport/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ export enum PlanetARPSType {

export enum PlanetARPSId {
PS_ARD_SR_DAILY = 'PS_ARD_SR_DAILY',
PS_ARD_SR_BIWEEKLY = 'PS_ARD_SR_BIWEEKLY',
PS_ARD_SR_MONTHLY = 'PS_ARD_SR_MONTHLY',
}

export enum PlanetPVType {
Expand All @@ -91,7 +89,6 @@ export enum PlanetPVType {
}

export enum PlanetPVId {
BIOMASS_PROXY_V3_0_10 = 'BIOMASS-PROXY_V3.0_10',
BIOMASS_PROXY_V4_0_10 = 'BIOMASS-PROXY_V4.0_10',
LST_AMSR2_V1_0_100 = 'LST-AMSR2_V1.0_100',
LST_AMSRE_V1_0_1000 = 'LST-AMSRE_V1.0_1000',
Expand All @@ -118,7 +115,7 @@ export enum PlanetPVId {
}

export const PlanetSupportedPVIds = {
[PlanetPVType.BiomassProxy]: [PlanetPVId.BIOMASS_PROXY_V3_0_10, PlanetPVId.BIOMASS_PROXY_V4_0_10],
[PlanetPVType.BiomassProxy]: [PlanetPVId.BIOMASS_PROXY_V4_0_10],
[PlanetPVType.LandSurfaceTemperature]: [
PlanetPVId.LST_AMSR2_V1_0_100,
PlanetPVId.LST_AMSRE_V1_0_1000,
Expand Down
25 changes: 17 additions & 8 deletions src/layer/BYOCLayer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AxiosRequestConfig } from 'axios';
import moment from 'moment';
import axios from 'axios';
import axios, { ResponseType } from 'axios';
import { Geometry } from '@turf/helpers';

import { getAuthToken } from '../auth';
Expand Down Expand Up @@ -296,14 +296,23 @@ export class BYOCLayer extends AbstractSentinelHubV3Layer {
throw new Error('Fetching available bands for ZARR not supported.');
}

const url = `${this.getSHServiceRootUrl()}api/v1/metadata/collection/${this.getTypeId()}`;
const headers = { Authorization: `Bearer ${getAuthToken()}` };
const res = await axios.get(url, {
responseType: 'json',
headers: headers,
const commonReqConfig = {
responseType: 'json' as ResponseType,
headers: { Authorization: `Bearer ${getAuthToken()}` },
...getAxiosReqParams(innerReqConfig, CACHE_CONFIG_30MIN),
});
return res.data.bands;
};

const metadataUrl = `${this.getSHServiceRootUrl()}api/v1/metadata/collection/${this.getTypeId()}`;
const metadataRes = await axios.get(metadataUrl, commonReqConfig);
const metadataBands: BYOCBand[] = metadataRes.data.bands;

const catalogUrl = `${metadataRes.data.location.catalogUrl}/collections/${this.getTypeId()}`;
const catalogRes = await axios.get(catalogUrl, commonReqConfig);
const catalogBands: { name: string }[] = catalogRes.data.summaries['eo:bands'];

// we need bands' sampleTypes that are returned from Metadata API
// but want to use only bands that are also returned from Catalog API
return metadataBands.filter((mb) => !!catalogBands.find((cb) => cb.name === mb.name));
}, reqConfig);
return bandsResponseData;
}
Expand Down
4 changes: 2 additions & 2 deletions src/layer/__tests__/BYOCLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ describe('Test updateLayerFromServiceIfNeeded for ZARR', () => {
});
expect(layer.locationId).toEqual(null);
mockNetwork
.onGet('https://services.sentinel-hub.com/configuration/v1/wms/instances/INSTANCE_ID/layers')
.onGet('https://services.sentinel-hub.com/api/v2/configuration/instances/INSTANCE_ID/layers')
.replyOnce(200, mockedLayersResponse);
await layer.updateLayerFromServiceIfNeeded();
expect(layer.locationId).toEqual(LocationIdSHv3.awsEuCentral1);
Expand All @@ -224,7 +224,7 @@ describe('Test updateLayerFromServiceIfNeeded for ZARR', () => {
});
expect(layer.locationId).toEqual(LocationIdSHv3.creo);
mockNetwork
.onGet('https://services.sentinel-hub.com/configuration/v1/wms/instances/INSTANCE_ID/layers')
.onGet('https://services.sentinel-hub.com/api/v2/configuration/instances/INSTANCE_ID/layers')
.replyOnce(200, mockedLayersResponse);
await layer.updateLayerFromServiceIfNeeded();
expect(layer.locationId).toEqual(LocationIdSHv3.creo);
Expand Down
8 changes: 4 additions & 4 deletions src/layer/__tests__/LayersFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ describe('Test endpoints for getting layers parameters', () => {
},
[{ code: 200, data: [] }],
function expectedEndpoint(instanceId: string): string {
return `https://services.sentinel-hub.com/configuration/v1/wms/instances/${instanceId}/layers`;
return `https://services.sentinel-hub.com/api/v2/configuration/instances/${instanceId}/layers`;
},
],
[
Expand Down Expand Up @@ -217,7 +217,7 @@ describe('Test endpoints for getting layers parameters', () => {
},
[{ code: 200, data: [] }],
function expectedEndpoint(instanceId: string): string {
return `https://sh.dataspace.copernicus.eu/configuration/v1/wms/instances/${instanceId}/layers`;
return `https://sh.dataspace.copernicus.eu/api/v2/configuration/instances/${instanceId}/layers`;
},
],
[
Expand Down Expand Up @@ -255,7 +255,7 @@ describe('Test endpoints for getting layers parameters', () => {
},
[{ code: 200, data: [] }],
function expectedEndpoint(instanceId: string): string {
return `https://services.sentinel-hub.com/configuration/v1/wms/instances/${instanceId}/layers`;
return `https://services.sentinel-hub.com/api/v2/configuration/instances/${instanceId}/layers`;
},
],

Expand All @@ -281,7 +281,7 @@ describe('Test endpoints for getting layers parameters', () => {
},
[{ code: 200, data: [] }],
function expectedEndpoint(instanceId: string): string {
return `https://sh.dataspace.copernicus.eu/configuration/v1/wms/instances/${instanceId}/layers`;
return `https://sh.dataspace.copernicus.eu/api/v2/configuration/instances/${instanceId}/layers`;
},
],

Expand Down
4 changes: 2 additions & 2 deletions src/layer/__tests__/S2L1CCDASLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ describe('Test findDatesUTC using catalog', () => {
});

test.each([
['https://services.sentinel-hub.com/configuration/v1/datasets/S2L1C/dataproducts/99999', false],
['https://services.sentinel-hub.com/configuration/v1/datasets/S2L1C/dataproducts/643', true],
['https://services.sentinel-hub.com/api/v2/configuration/datasets/S2L1C/dataproducts/99999', false],
['https://services.sentinel-hub.com/api/v2/configuration/datasets/S2L1C/dataproducts/643', true],
])(
'AbstractSentinelHubV3Layer.supportsApiType correctly handles DataProducts supported by Processing API',
(dataProduct, expectedResult) => {
Expand Down
4 changes: 2 additions & 2 deletions src/layer/__tests__/S2L1CLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ describe('Test findDatesUTC using catalog', () => {
});

test.each([
['https://services.sentinel-hub.com/configuration/v1/datasets/S2L1C/dataproducts/99999', false],
['https://services.sentinel-hub.com/configuration/v1/datasets/S2L1C/dataproducts/643', true],
['https://services.sentinel-hub.com/api/v2/configuration/datasets/S2L1C/dataproducts/99999', false],
['https://services.sentinel-hub.com/api/v2/configuration/datasets/S2L1C/dataproducts/643', true],
])(
'AbstractSentinelHubV3Layer.supportsApiType correctly handles DataProducts supported by Processing API',
(dataProduct, expectedResult) => {
Expand Down
8 changes: 4 additions & 4 deletions src/layer/__tests__/fixtures.BYOCLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ export function constructFixtureUpdateLayerFromServiceIfNeeded({
const mockedResponse = [
{
'@id':
'https://services.sentinel-hub.com/configuration/v1/wms/instances/cc6082af-2788-4b20-b0fe-54e13454bc66/layers/BYOC3',
'https://services.sentinel-hub.com/api/v2/configuration/instances/cc6082af-2788-4b20-b0fe-54e13454bc66/layers/BYOC3',
id: 'BYOC3',
title: 'byoc3',
description: '',
Expand All @@ -313,7 +313,7 @@ export function constructFixtureUpdateLayerFromServiceIfNeeded({
orderHint: 0,
instance: {
'@id':
'https://services.sentinel-hub.com/configuration/v1/wms/instances/cc6082af-2788-4b20-b0fe-54e13454bc66',
'https://services.sentinel-hub.com/api/v2/configuration/instances/cc6082af-2788-4b20-b0fe-54e13454bc66',
},
dataset: {
'@id': 'https://services.sentinel-hub.com/configuration/v1/datasets/CUSTOM',
Expand All @@ -339,7 +339,7 @@ export function constructFixtureUpdateLayerFromServiceIfNeeded({
},
{
'@id':
'https://services.sentinel-hub.com/configuration/v1/wms/instances/cc6082af-2788-4b20-b0fe-54e13454bc66/layers/BYOC_AZER_SKY_TRUE_COLOR',
'https://services.sentinel-hub.com/api/v2/configuration/instances/cc6082af-2788-4b20-b0fe-54e13454bc66/layers/BYOC_AZER_SKY_TRUE_COLOR',
id: 'BYOC_AZER_SKY_TRUE_COLOR',
title: 'BYOC_AZER_SKY_TRUE_COLOR',
description: '',
Expand All @@ -354,7 +354,7 @@ export function constructFixtureUpdateLayerFromServiceIfNeeded({
orderHint: 0,
instance: {
'@id':
'https://services.sentinel-hub.com/configuration/v1/wms/instances/cc6082af-2788-4b20-b0fe-54e13454bc66',
'https://services.sentinel-hub.com/api/v2/configuration/instances/cc6082af-2788-4b20-b0fe-54e13454bc66',
},
dataset: {
'@id': 'https://services.sentinel-hub.com/configuration/v1/datasets/CUSTOM',
Expand Down
34 changes: 11 additions & 23 deletions src/layer/__tests__/fixtures.makeLayersSHv3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { DATASET_S2L2A } from '../dataset';

export const getLayersFromConfigurationService = [
{
'@id': 'https://services.sentinel-hub.com/configuration/v1/wms/instances/instanceId/layers/1_TRUE_COLOR',
id: '1_TRUE_COLOR',
title: 'True color',
description: 'Based on bands 4,3,2',
Expand All @@ -14,11 +13,9 @@ export const getLayersFromConfigurationService = [
},
],
orderHint: 0,
instance: {
'@id': 'https://services.sentinel-hub.com/configuration/v1/wms/instances/instanceId',
},
dataset: { '@id': 'https://services.sentinel-hub.com/configuration/v1/datasets/S2L2A' },
datasetSource: { '@id': 'https://services.sentinel-hub.com/configuration/v1/datasets/S2L2A/sources/2' },
instanceId: 'instanceId',
collectionType: 'S2L2A',
datasetSourceIdId: '2',
defaultStyleName: 'default',
datasourceDefaults: {
temporal: false,
Expand All @@ -27,7 +24,6 @@ export const getLayersFromConfigurationService = [
},
},
{
'@id': 'https://services.sentinel-hub.com/configuration/v1/wms/instances/instanceId/layers/8-NDSI',
id: '8-NDSI',
title: 'NDSI',
description: 'Based on combination of bands (B3 - B11)/(B3 + B11)',
Expand All @@ -40,11 +36,9 @@ export const getLayersFromConfigurationService = [
},
],
orderHint: 70,
instance: {
'@id': 'https://services.sentinel-hub.com/configuration/v1/wms/instances/instanceId',
},
dataset: { '@id': 'https://services.sentinel-hub.com/configuration/v1/datasets/S2L2A' },
datasetSource: { '@id': 'https://services.sentinel-hub.com/configuration/v1/datasets/S2L2A/sources/2' },
instanceId: 'instanceId',
collectionType: 'S2L2A',
datasetSourceId: '2',
defaultStyleName: 'default',
datasourceDefaults: {
upsampling: 'NEAREST',
Expand All @@ -56,26 +50,20 @@ export const getLayersFromConfigurationService = [
},
},
{
'@id': 'https://services.sentinel-hub.com/configuration/v1/wms/instances/instanceId',
id: 'B8A',
title: 'B8A',
description: 'Band 8A - Vegetation Red Edge - 865 nm|#bc0e10',
styles: [
{
name: 'default',
description: 'Default layer style',
dataProduct: {
'@id':
'https://services.sentinel-hub.com/configuration/v1/datasets/S2L2A/dataproducts/dataProductId',
},
dataProductId: 'dataProductId',
},
],
orderHint: 0,
instance: {
'@id': 'https://services.sentinel-hub.com/configuration/v1/wms/instances/instanceId',
},
dataset: { '@id': 'https://services.sentinel-hub.com/configuration/v1/datasets/S2L2A' },
datasetSource: { '@id': 'https://services.sentinel-hub.com/configuration/v1/datasets/S2L2A/sources/2' },
instanceId: 'instanceId',
collectionType: 'S2L2A',
datasetSourceId: '2',
defaultStyleName: 'default',
datasourceDefaults: {
mosaickingOrder: 'mostRecent',
Expand Down Expand Up @@ -215,7 +203,7 @@ export const expectedResultConfigurationService = (
evalscript: null as string,
evalscriptUrl: null as string,
dataProduct:
'https://services.sentinel-hub.com/configuration/v1/datasets/S2L2A/dataproducts/dataProductId',
'https://services.sentinel-hub.com/api/v2/configuration/datasets/S2L2A/dataproducts/dataProductId',
upsampling: null as string,
downsampling: null as string,
mosaickingOrder: 'mostRecent',
Expand Down
4 changes: 2 additions & 2 deletions src/layer/__tests__/fixtures.mosaickingOrder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const getMapParams: GetMapParams = {

const mockedLayersResponse = [
{
'@id': 'https://services.sentinel-hub.com/configuration/v1/wms/instances/INSTANCE_ID/layers/LAYER_ID',
'@id': 'https://services.sentinel-hub.com/api/v2/configuration/instances/INSTANCE_ID/layers/LAYER_ID',
id: 'LAYER_ID',
title: 'Title',
description: 'Description',
Expand All @@ -27,7 +27,7 @@ const mockedLayersResponse = [
],
orderHint: 0,
instance: {
'@id': 'https://services.sentinel-hub.com/configuration/v1/wms/instances/INSTANCE_ID',
'@id': 'https://services.sentinel-hub.com/api/v2/configuration/instances/INSTANCE_ID',
},
dataset: { '@id': 'https://services.sentinel-hub.com/configuration/v1/datasets/S2L2A' },
datasetSource: { '@id': 'https://services.sentinel-hub.com/configuration/v1/datasets/S2L2A/sources/2' },
Expand Down
2 changes: 1 addition & 1 deletion src/layer/__tests__/testUtils.layers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ export const checkLayersParamsEndpoint = async (
});
await layer.updateLayerFromServiceIfNeeded({});
expect(mockNetwork.history.get[0].url).toBe(
`${expectedEndpoint}/configuration/v1/wms/instances/${instanceId}/layers`,
`${expectedEndpoint}/api/v2/configuration/instances/${instanceId}/layers`,
);
};
2 changes: 1 addition & 1 deletion src/layer/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ export const DEFAULT_FIND_TILES_MAX_COUNT_PARAMETER = 50;
export type DataProductId = string;

export const SUPPORTED_DATA_PRODUCTS_PROCESSING: DataProductId[] = [
'https://services.sentinel-hub.com/configuration/v1/datasets/S2L1C/dataproducts/643',
'https://services.sentinel-hub.com/api/v2/configuration/datasets/S2L1C/dataproducts/643',
];

export type BYOCBand = {
Expand Down
36 changes: 20 additions & 16 deletions src/layer/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ export async function fetchLayerParamsFromConfigurationService(
throw new Error('Must be authenticated to fetch layer params');
}
const configurationServiceHostName = shServiceHostName ?? SH_SERVICE_ROOT_URL.default;
const url = `${configurationServiceHostName}configuration/v1/wms/instances/${instanceId}/layers`;
const url = `${configurationServiceHostName}api/v2/configuration/instances/${instanceId}/layers`;
const headers = {
Authorization: `Bearer ${authToken}`,
};
Expand All @@ -219,21 +219,25 @@ export async function fetchLayerParamsFromConfigurationService(
...getAxiosReqParams(reqConfigWithMemoryCache, null),
};
const res = await axios.get(url, requestConfig);
const layersParams = res.data.map((l: any) => ({
layerId: l.id,
title: l.title,
description: l.description,
...l.datasourceDefaults,
//maxCloudCoverPercent vs maxCloudCoverage
...(l.datasourceDefaults?.maxCloudCoverage !== undefined && {
maxCloudCoverPercent: l.datasourceDefaults.maxCloudCoverage,
}),
evalscript: l.styles[0].evalScript,
dataProduct: l.styles[0].dataProduct ? l.styles[0].dataProduct['@id'] : undefined,
legend: l.styles.find((s: any) => s.name === l.defaultStyleName)
? l.styles.find((s: any) => s.name === l.defaultStyleName).legend
: null,
}));
const layersParams = res.data.map((l: any) => {
const defaultStyle = l.styles.find((s: any) => s.name === l.defaultStyleName) ?? l.styles[0];

return {
layerId: l.id,
title: l.title,
description: l.description,
...l.datasourceDefaults,
//maxCloudCoverPercent vs maxCloudCoverage
...(l.datasourceDefaults?.maxCloudCoverage !== undefined && {
maxCloudCoverPercent: l.datasourceDefaults.maxCloudCoverage,
}),
evalscript: defaultStyle.evalScript,
dataProduct: defaultStyle.dataProductId
? `${configurationServiceHostName}api/v2/configuration/datasets/${l.collectionType}/dataproducts/${defaultStyle.dataProductId}`
: undefined,
legend: defaultStyle ? defaultStyle.legend : null,
};
});
return layersParams;
}

Expand Down

0 comments on commit 71ccf07

Please sign in to comment.