-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update kelp report with linear data. Remove kelpPersist report
- Loading branch information
Showing
24 changed files
with
809 additions
and
1,961 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
[ | ||
{ | ||
"metricId": "metric", | ||
"value": 43.520270317077255, | ||
"classId": "kelp", | ||
"groupId": null, | ||
"geographyId": "north_sr", | ||
"sketchId": null | ||
}, | ||
{ | ||
"metricId": "metric", | ||
"value": 47.4713821595827, | ||
"classId": "kelp", | ||
"groupId": null, | ||
"geographyId": "northcentral_sr", | ||
"sketchId": null | ||
}, | ||
{ | ||
"metricId": "metric", | ||
"value": 155.14793112016181, | ||
"classId": "kelp", | ||
"groupId": null, | ||
"geographyId": "central_sr", | ||
"sketchId": null | ||
}, | ||
{ | ||
"metricId": "metric", | ||
"value": 315.3763949392171, | ||
"classId": "kelp", | ||
"groupId": null, | ||
"geographyId": "south_sr", | ||
"sketchId": null | ||
}, | ||
{ | ||
"metricId": "metric", | ||
"value": 89.57109047586958, | ||
"classId": "kelp", | ||
"groupId": null, | ||
"geographyId": "north_br", | ||
"sketchId": null | ||
}, | ||
{ | ||
"metricId": "metric", | ||
"value": 156.5684931209522, | ||
"classId": "kelp", | ||
"groupId": null, | ||
"geographyId": "central_br", | ||
"sketchId": null | ||
}, | ||
{ | ||
"metricId": "metric", | ||
"value": 317.08104847029153, | ||
"classId": "kelp", | ||
"groupId": null, | ||
"geographyId": "south_br", | ||
"sketchId": null | ||
}, | ||
{ | ||
"metricId": "metric", | ||
"value": 563.2206320671133, | ||
"classId": "kelp", | ||
"groupId": null, | ||
"geographyId": "world", | ||
"sketchId": null | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { bbox, featureCollection, union } from "@turf/turf"; | ||
import geographies from "../../project/geographies.json" with { type: "json" }; | ||
import { lineOverlap } from "../../src/util/overlapLineLength.js"; | ||
import { | ||
LineString, | ||
loadFgb, | ||
MultiPolygon, | ||
Feature, | ||
Polygon, | ||
genFeatureCollection, | ||
createMetric, | ||
} from "@seasketch/geoprocessing"; | ||
import fs from "fs-extra"; | ||
import projectClient from "../../project/projectClient.js"; | ||
|
||
async function main() { | ||
// Initialize an empty array to store results | ||
const metrics = []; | ||
const metricGroup = projectClient.getMetricGroup("kelp"); | ||
for (const geography of geographies) { | ||
try { | ||
console.log(`Processing geography: ${geography.geographyId}`); | ||
const geo = await loadFgb<Feature<Polygon | MultiPolygon>>( | ||
`http://127.0.0.1:8080/${geography.datasourceId}.fgb`, | ||
); | ||
|
||
// Load features once | ||
const features = await loadFgb<Feature<LineString>>( | ||
"http://127.0.0.1:8080/" + metricGroup.classes[0].datasourceId + ".fgb", | ||
bbox(featureCollection(geo)), | ||
); | ||
|
||
// Use union if there are multiple features | ||
const geoUnion = | ||
geo.length > 1 ? union(genFeatureCollection(geo))! : geo[0]; | ||
|
||
// Calculate total length | ||
const totalLength = lineOverlap(geoUnion, features, { units: "miles" }); | ||
|
||
// Create metric and add it to the array | ||
const metric = createMetric({ | ||
geographyId: geography.geographyId, | ||
classId: "kelp", | ||
value: totalLength, | ||
}); | ||
metrics.push(metric); | ||
} catch (error) { | ||
console.error( | ||
`Error processing geography ${geography.geographyId}:`, | ||
error, | ||
); | ||
} | ||
} | ||
|
||
// Write the results to a JSON file | ||
fs.writeJsonSync(`${import.meta.dirname}/precalcKelp.json`, metrics); | ||
|
||
console.log("All geographies processed."); | ||
} | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
[ | ||
{ | ||
"geographyId": "central_br", | ||
"metricId": "kelp", | ||
"classId": "kelp", | ||
"sketchId": "29784", | ||
"groupId": null, | ||
"value": 7.483337, | ||
"extra": { | ||
"sketchName": "mpa-test" | ||
} | ||
}, | ||
{ | ||
"geographyId": "central_sr", | ||
"metricId": "kelp", | ||
"classId": "kelp", | ||
"sketchId": "29784", | ||
"groupId": null, | ||
"value": 7.483337, | ||
"extra": { | ||
"sketchName": "mpa-test" | ||
} | ||
}, | ||
{ | ||
"geographyId": "north_br", | ||
"metricId": "kelp", | ||
"classId": "kelp", | ||
"sketchId": "29784", | ||
"groupId": null, | ||
"value": 0, | ||
"extra": { | ||
"sketchName": "mpa-test" | ||
} | ||
}, | ||
{ | ||
"geographyId": "north_sr", | ||
"metricId": "kelp", | ||
"classId": "kelp", | ||
"sketchId": "29784", | ||
"groupId": null, | ||
"value": 0, | ||
"extra": { | ||
"sketchName": "mpa-test" | ||
} | ||
}, | ||
{ | ||
"geographyId": "northcentral_sr", | ||
"metricId": "kelp", | ||
"classId": "kelp", | ||
"sketchId": "29784", | ||
"groupId": null, | ||
"value": 0, | ||
"extra": { | ||
"sketchName": "mpa-test" | ||
} | ||
}, | ||
{ | ||
"geographyId": "south_br", | ||
"metricId": "kelp", | ||
"classId": "kelp", | ||
"sketchId": "29784", | ||
"groupId": null, | ||
"value": 0, | ||
"extra": { | ||
"sketchName": "mpa-test" | ||
} | ||
}, | ||
{ | ||
"geographyId": "south_sr", | ||
"metricId": "kelp", | ||
"classId": "kelp", | ||
"sketchId": "29784", | ||
"groupId": null, | ||
"value": 0, | ||
"extra": { | ||
"sketchName": "mpa-test" | ||
} | ||
}, | ||
{ | ||
"geographyId": "world", | ||
"metricId": "kelp", | ||
"classId": "kelp", | ||
"sketchId": "29784", | ||
"groupId": null, | ||
"value": 7.483337, | ||
"extra": { | ||
"sketchName": "mpa-test" | ||
} | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.