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: update target path naming hierarchy TDE-955 #845

Merged
merged 2 commits into from
Feb 8, 2024
Merged
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
79 changes: 17 additions & 62 deletions src/commands/path/__test__/generate.path.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ describe('GeneratePathImagery', () => {
category: 'urban-aerial-photos',
geographicDescription: 'Napier',
region: 'hawkes-bay',
event: undefined,
date: '2017-2018',
gsd: 0.05,
epsg: 2193,
Expand All @@ -33,25 +32,20 @@ describe('GeneratePathImagery', () => {
const metadata: PathMetadata = {
targetBucketName: 'nz-imagery',
category: 'rural-aerial-photos',
geographicDescription: undefined,
geographicDescription: 'North Island Weather Event',
l0b0 marked this conversation as resolved.
Show resolved Hide resolved
region: 'hawkes-bay',
event: 'North Island Weather Event',
date: '2023',
gsd: 0.25,
epsg: 2193,
};
assert.equal(
generatePath(metadata),
's3://nz-imagery/hawkes-bay/hawkes-bay-north-island-weather-event_2023_0.25m/rgb/2193/',
);
assert.equal(generatePath(metadata), 's3://nz-imagery/hawkes-bay/north-island-weather-event_2023_0.25m/rgb/2193/');
});
it('Should match - no optional metadata', () => {
const metadata: PathMetadata = {
targetBucketName: 'nz-imagery',
category: 'urban-aerial-photos',
geographicDescription: undefined,
region: 'auckland',
event: undefined,
date: '2023',
gsd: 0.3,
epsg: 2193,
Expand All @@ -67,7 +61,6 @@ describe('GeneratePathElevation', () => {
category: 'dem',
geographicDescription: undefined,
region: 'auckland',
event: undefined,
date: '2023',
gsd: 1,
epsg: 2193,
Expand All @@ -80,7 +73,6 @@ describe('GeneratePathElevation', () => {
category: 'dsm',
geographicDescription: undefined,
region: 'auckland',
event: undefined,
date: '2023',
gsd: 1,
epsg: 2193,
Expand All @@ -94,9 +86,8 @@ describe('GeneratePathSatelliteImagery', () => {
const metadata: PathMetadata = {
targetBucketName: 'nz-imagery',
category: 'satellite-imagery',
geographicDescription: 'North Island',
geographicDescription: 'North Island Cyclone Gabrielle',
region: 'new-zealand',
event: 'Cyclone Gabrielle',
date: '2023',
gsd: 0.5,
epsg: 2193,
Expand All @@ -115,7 +106,6 @@ describe('GeneratePathHistoricImagery', () => {
category: 'scanned-aerial-imagery',
geographicDescription: undefined,
region: 'wellington',
event: undefined,
date: '1963',
gsd: 0.5,
epsg: 2193,
Expand All @@ -128,13 +118,13 @@ describe('GeneratePathHistoricImagery', () => {

describe('formatName', () => {
it('Should match - region', () => {
assert.equal(formatName('hawkes-bay', '', ''), 'hawkes-bay');
assert.equal(formatName('hawkes-bay', undefined), 'hawkes-bay');
});
it('Should match - region & geographic description', () => {
assert.equal(formatName('hawkes-bay', 'Napier', ''), 'napier');
assert.equal(formatName('hawkes-bay', 'Napier'), 'napier');
});
it('Should match - region & event', () => {
assert.equal(formatName('canterbury', '', 'Christchurch Earthquake'), 'canterbury-christchurch-earthquake');
assert.equal(formatName('canterbury', 'Christchurch Earthquake'), 'christchurch-earthquake');
});
});

Expand Down Expand Up @@ -190,14 +180,12 @@ describe('geographicDescription', async () => {
const collection = await fsa.readJson<StacCollection & StacCollectionLinz>(
'./src/commands/path/__test__/sample.json',
);
const gd = collection['linz:geographic_description'];
assert.equal(gd, 'Palmerston North');
assert.equal(collection['linz:geographic_description'], 'Palmerston North');
const metadata: PathMetadata = {
targetBucketName: 'bucket',
category: 'urban-aerial-photos',
geographicDescription: gd,
geographicDescription: collection['linz:geographic_description'],
region: 'manawatu-whanganui',
event: '',
date: '2020',
gsd: 0.05,
epsg: 2193,
Expand All @@ -215,7 +203,6 @@ describe('geographicDescription', async () => {
category: 'urban-aerial-photos',
geographicDescription: collection['linz:geographic_description'],
region: 'manawatu-whanganui',
event: undefined,
date: '2020',
gsd: 0.05,
epsg: 2193,
Expand All @@ -224,44 +211,6 @@ describe('geographicDescription', async () => {
});
});

describe('event', async () => {
it('Should return event', async () => {
const collection = await fsa.readJson<StacCollection & StacCollectionLinz>(
'./src/commands/path/__test__/sample.json',
);
assert.equal(collection['linz:event_name'], 'Storm');
const metadata: PathMetadata = {
targetBucketName: 'bucket',
category: 'urban-aerial-photos',
geographicDescription: undefined,
region: 'nelson',
event: collection['linz:event_name'],
date: '2020',
gsd: 0.05,
epsg: 2193,
};
assert.equal(generatePath(metadata), 's3://bucket/nelson/nelson-storm_2020_0.05m/rgb/2193/');
});
it('Should return undefined - no event metadata', async () => {
const collection = await fsa.readJson<StacCollection & StacCollectionLinz>(
'./src/commands/path/__test__/sample.json',
);
delete collection['linz:event_name'];
assert.equal(collection['linz:event_name'], undefined);
const metadata: PathMetadata = {
targetBucketName: 'bucket',
category: 'urban-aerial-photos',
geographicDescription: undefined,
region: 'nelson',
event: collection['linz:event_name'],
date: '2020',
gsd: 0.05,
epsg: 2193,
};
assert.equal(generatePath(metadata), 's3://bucket/nelson/nelson_2020_0.05m/rgb/2193/');
});
});

describe('region', async () => {
it('Should return region', async () => {
const collection = await fsa.readJson<StacCollection & StacCollectionLinz>(
Expand All @@ -273,16 +222,22 @@ describe('region', async () => {

describe('formatDate', async () => {
it('Should return date as single year', async () => {
const collection = await fsa.readJson<StacCollection>('./src/commands/path/__test__/sample.json');
const collection = await fsa.readJson<StacCollection & StacCollectionLinz>(
'./src/commands/path/__test__/sample.json',
);
assert.equal(formatDate(collection), '2022');
});
it('Should return date as two years', async () => {
const collection = await fsa.readJson<StacCollection>('./src/commands/path/__test__/sample.json');
const collection = await fsa.readJson<StacCollection & StacCollectionLinz>(
'./src/commands/path/__test__/sample.json',
);
collection.extent.temporal.interval[0] = ['2022-12-31T11:00:00Z', '2023-12-31T11:00:00Z'];
assert.equal(formatDate(collection), '2022-2023');
});
it('Should fail - unable to retrieve date', async () => {
const collection = await fsa.readJson<StacCollection>('./src/commands/path/__test__/sample.json');
const collection = await fsa.readJson<StacCollection & StacCollectionLinz>(
'./src/commands/path/__test__/sample.json',
);
collection.extent.temporal.interval[0] = [null, null];
assert.throws(() => {
formatDate(collection), Error;
Expand Down
11 changes: 4 additions & 7 deletions src/commands/path/path.generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export interface PathMetadata {
category: string;
geographicDescription?: string;
region: string;
event?: string;
date: string;
gsd: number;
epsg: number;
Expand Down Expand Up @@ -70,7 +69,6 @@ export const commandGeneratePath = command({
category: collection['linz:geospatial_category'],
region: collection['linz:region'],
geographicDescription: collection['linz:geographic_description'],
event: collection['linz:event_name'],
date: formatDate(collection),
gsd: extractGsd(tiff),
epsg: extractEpsg(tiff),
Expand All @@ -94,7 +92,7 @@ export const commandGeneratePath = command({
* @returns {string}
*/
export function generatePath(metadata: PathMetadata): string {
const name = formatName(metadata.region, metadata.geographicDescription, metadata.event);
const name = formatName(metadata.region, metadata.geographicDescription);
if (metadata.category === dataCategories.SCANNED_AERIAL_PHOTOS) {
// nb: Historic Imagery is out of scope as survey number is not yet recorded in collection metadata
throw new Error(`Automated target generation not implemented for historic imagery`);
Expand Down Expand Up @@ -122,14 +120,13 @@ function formatBucketName(bucketName: string): string {
* @export
* @param {string} region
* @param {?string} [geographicDescription]
* @param {?string} [event]
* @returns {string}
*/
export function formatName(region: string, geographicDescription?: string, event?: string): string {
export function formatName(region: string, geographicDescription?: string): string {
if (geographicDescription) {
return slugify([geographicDescription, event].filter(Boolean).join('-'));
return slugify(geographicDescription);
}
return slugify([region, event].filter(Boolean).join('-'));
return slugify(region);
}

export function formatDate(collection: StacCollection): string {
Expand Down
Loading