Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/missing constructor and layer params #213

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions src/layer/S1GRDAWSEULayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
LinkType,
DataProductId,
FindTilesAdditionalParameters,
MosaickingOrder,
} from './const';
import { ProcessingPayload } from './processing';
import { DATASET_AWSEU_S1GRD } from './dataset';
Expand Down Expand Up @@ -56,6 +57,7 @@ interface ConstructorParameters {
evalscript?: string | null;
evalscriptUrl?: string | null;
dataProduct?: DataProductId | null;
mosaickingOrder?: MosaickingOrder | null;
title?: string | null;
description?: string | null;
legendUrl?: string | null;
Expand Down Expand Up @@ -90,14 +92,6 @@ export class S1GRDAWSEULayer extends AbstractSentinelHubV3Layer {
public speckleFilter: SpeckleFilter | null;

public constructor({
instanceId = null,
layerId = null,
evalscript = null,
evalscriptUrl = null,
dataProduct = null,
title = null,
description = null,
legendUrl = null,
acquisitionMode = null,
polarization = null,
resolution = null,
Expand All @@ -106,8 +100,9 @@ export class S1GRDAWSEULayer extends AbstractSentinelHubV3Layer {
backscatterCoeff = BackscatterCoeff.GAMMA0_ELLIPSOID,
orbitDirection = null,
speckleFilter = null,
...rest
}: ConstructorParameters) {
super({ instanceId, layerId, evalscript, evalscriptUrl, dataProduct, title, description, legendUrl });
super(rest);
this.acquisitionMode = acquisitionMode;
this.polarization = polarization;
this.resolution = resolution;
Expand Down
38 changes: 38 additions & 0 deletions src/layer/__tests__/S1GRDAWSLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
OrbitDirection,
LinkType,
setAuthToken,
BackscatterCoeff,
} from '../../index';

import {
Expand All @@ -34,6 +35,8 @@ import {
constructFixtureFindDatesUTCCatalog,
} from './fixtures.findDatesUTC';
import { DATASET_AWSEU_S1GRD } from '../dataset';
import { DEMInstanceTypeOrthorectification, MosaickingOrder } from '../const';
import { SpeckleFilterType } from '../S1GRDAWSEULayer';

test('timezone should NOT be UTC', () => {
// We are testing correctness in case of local timezones, so it doesn't make sense to
Expand Down Expand Up @@ -375,3 +378,38 @@ describe('Test findDatesUTC using catalog', () => {
);
});
});

describe('test constructor', () => {
test('params are set correctly', async () => {
const defaultValues = {
instanceId: 'instanceId',
layerId: 'layerId',
evalscript: '//evalscript',
evalscriptUrl: 'evalscriptUrl',
dataProduct: 'dataProduct',
title: 'title',
description: 'description',
legendUrl: 'legendUrl',
acquisitionMode: AcquisitionMode.EW,
polarization: Polarization.SV,
resolution: Resolution.MEDIUM,
orthorectify: true,
demInstanceType: DEMInstanceTypeOrthorectification.COPERNICUS_90,
backscatterCoeff: BackscatterCoeff.GAMMA0_ELLIPSOID,
orbitDirection: OrbitDirection.DESCENDING,
speckleFilter: {
type: SpeckleFilterType.LEE,
windowSizeX: 5,
windowSizeY: 5,
},
mosaickingOrder: MosaickingOrder.LEAST_RECENT,
};

const layer = new S1GRDAWSEULayer(defaultValues);
Object.keys(defaultValues).forEach(key => {
const expectedValue = (defaultValues as any)[key];
const value = (layer as any)[key];
expect(value).toStrictEqual(expectedValue);
});
});
});
27 changes: 22 additions & 5 deletions src/layer/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,27 @@ export function parseSHInstanceId(baseUrl: string): string {
throw new Error(`Could not parse instanceId from URL: ${baseUrl}`);
}

/*
rename some layer parameters as they are named differently in the configuration service response
*/
const convertLayerParams = (params: Record<string, any>): Record<string, any> => {
return {
...params,
...(params?.maxCloudCoverage !== undefined && {
maxCloudCoverPercent: params.maxCloudCoverage,
}),
...(params?.demInstance !== undefined && {
demInstanceType: params.demInstance,
}),
...(params?.backCoeff !== undefined && {
backscatterCoeff: params.backCoeff,
}),
...(params?.EGM !== undefined && {
egm: params.EGM,
}),
};
};

export async function fetchLayerParamsFromConfigurationService(
instanceId: string,
reqConfig: RequestConfiguration,
Expand Down Expand Up @@ -175,11 +196,7 @@ export async function fetchLayerParamsFromConfigurationService(
layerId: l.id,
title: l.title,
description: l.description,
...l.datasourceDefaults,
//maxCloudCoverPercent vs maxCloudCoverage
...(l.datasourceDefaults?.maxCloudCoverage !== undefined && {
maxCloudCoverPercent: l.datasourceDefaults.maxCloudCoverage,
}),
...convertLayerParams(l.datasourceDefaults),
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)
Expand Down