Skip to content

Commit

Permalink
Update kelp report with linear data. Remove kelpPersist report
Browse files Browse the repository at this point in the history
  • Loading branch information
avmey committed Feb 3, 2025
1 parent 8cc24b9 commit d777f49
Show file tree
Hide file tree
Showing 24 changed files with 809 additions and 1,961 deletions.
66 changes: 66 additions & 0 deletions data/precalc/precalcKelp.json
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
}
]
61 changes: 61 additions & 0 deletions data/precalc/precalcKelp.ts
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();
90 changes: 90 additions & 0 deletions examples/output/mpa-test/kelp.json
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"
}
}
]
7 changes: 7 additions & 0 deletions examples/output/mpa-test/spacing.json
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,13 @@
],
"paths": []
},
{
"id": "kelp",
"replicates": [
"29784"
],
"paths": []
},
{
"id": "eelgrass",
"replicates": [],
Expand Down
Loading

0 comments on commit d777f49

Please sign in to comment.