Skip to content

Commit

Permalink
Fix: don't use event in path name
Browse files Browse the repository at this point in the history
  • Loading branch information
MDavidson17 committed Feb 2, 2024
1 parent 6ab7b3a commit 797a9d2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 62 deletions.
57 changes: 5 additions & 52 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,9 +32,8 @@ describe('GeneratePathImagery', () => {
const metadata: PathMetadata = {
targetBucketName: 'nz-imagery',
category: 'rural-aerial-photos',
geographicDescription: undefined,
geographicDescription: 'North Island Weather Event',
region: 'hawkes-bay',
event: 'North Island Weather Event',
date: '2023',
gsd: 0.25,
epsg: 2193,
Expand All @@ -48,7 +46,6 @@ describe('GeneratePathImagery', () => {
category: 'urban-aerial-photos',
geographicDescription: undefined,
region: 'auckland',
event: undefined,
date: '2023',
gsd: 0.3,
epsg: 2193,
Expand All @@ -64,7 +61,6 @@ describe('GeneratePathElevation', () => {
category: 'dem',
geographicDescription: undefined,
region: 'auckland',
event: undefined,
date: '2023',
gsd: 1,
epsg: 2193,
Expand All @@ -77,7 +73,6 @@ describe('GeneratePathElevation', () => {
category: 'dsm',
geographicDescription: undefined,
region: 'auckland',
event: undefined,
date: '2023',
gsd: 1,
epsg: 2193,
Expand All @@ -91,9 +86,8 @@ describe('GeneratePathSatelliteImagery', () => {
const metadata: PathMetadata = {
targetBucketName: 'nz-imagery',
category: 'satellite-imagery',
geographicDescription: undefined,
geographicDescription: 'North Island Cyclone Gabrielle',
region: 'new-zealand',
event: 'North Island Cyclone Gabrielle',
date: '2023',
gsd: 0.5,
epsg: 2193,
Expand All @@ -112,7 +106,6 @@ describe('GeneratePathHistoricImagery', () => {
category: 'scanned-aerial-imagery',
geographicDescription: undefined,
region: 'wellington',
event: undefined,
date: '1963',
gsd: 0.5,
epsg: 2193,
Expand All @@ -125,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'), 'christchurch-earthquake');
assert.equal(formatName('canterbury', 'Christchurch Earthquake'), 'christchurch-earthquake');
});
});

Expand Down Expand Up @@ -193,7 +186,6 @@ describe('geographicDescription', async () => {
category: 'urban-aerial-photos',
geographicDescription: collection['linz:geographic_description'],
region: 'manawatu-whanganui',
event: '',
date: '2020',
gsd: 0.05,
epsg: 2193,
Expand All @@ -211,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 @@ -220,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/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 Down
14 changes: 4 additions & 10 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,17 +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 {
if (event) {
return slugify(event.replace(' ', '-'));
}
export function formatName(region: string, geographicDescription?: string): string {
if (geographicDescription) {
return slugify(geographicDescription.replace(' ', '-'));
return slugify(geographicDescription);
}
return slugify(region.replace(' ', '-'));
return slugify(region);
}

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

0 comments on commit 797a9d2

Please sign in to comment.