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

Support pmtile based admin layers; COUNTRY=global #1417

Open
wants to merge 16 commits into
base: master
Choose a base branch
from

Conversation

gislawill
Copy link
Collaborator

@gislawill gislawill commented Jan 23, 2025

Description

This addresses #1404 by adding support PMTiles (vector tiles) for admin boundaries. This branch does not yet support running analysis (zonal stats) on these PMTiles. We will add support in a following PR that involves querying a S3-hosted geoparquet.

How to test the feature:

  • Open the surge deployment
  • Pan and scroll around loading the tiles
  • Try to find admin-level based functionality that I missed

Checklist - did you ...

Test your changes with

  • REACT_APP_COUNTRY=rbd yarn start
  • REACT_APP_COUNTRY=cambodia yarn start
  • REACT_APP_COUNTRY=mozambique yarn start
  • Add / update necessary tests?
  • Add / update outdated documentation?

Screenshot/video of feature:

https://www.loom.com/share/a7c80f04dbbb43a5b4cd68334886d088?sid=cda64d68-f6b3-4307-8b9e-3bf827a3faac

Copy link

github-actions bot commented Jan 23, 2025

Build succeeded and deployed at https://prism-1417.surge.sh
(hash f71adf6 deployed at 2025-03-05T00:00:02)

@gislawill gislawill changed the title Draft: Support pmtile based admin layers; COUNTRY=global Support pmtile based admin layers; COUNTRY=global Jan 24, 2025
@gislawill gislawill linked an issue Feb 5, 2025 that may be closed by this pull request
@gislawill gislawill marked this pull request as ready for review February 5, 2025 03:38
@gislawill
Copy link
Collaborator Author

Heads up @ericboucher and @wadhwamatic, this is ready for review. I believe all features but the Analysis Layers are functional.

I did run into some performance issues with the loadBoundaryRelations functionality that is required for the Alerts module. We've have over 20000 admin level 2 regions in the dataset and that much data caused a slowdown in start up time. Are any deployments still using the alerts module??

Comment on lines +145 to +149
<Source
id={`source-${layer.id}`}
type="vector"
url={`pmtiles://${layer.path}`}
>
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: we might get some performance benefits by rendering one source per PMTiles even when we're pulling multiple layers from the same file.

@wadhwamatic
Copy link
Member

Are any deployments still using the alerts module??

@gislawill great! Look forward to digging into this later. No, there are no active deployments that are using alerts. But it's a feature that we need functioning in the next month for upcoming deployments.

@gislawill
Copy link
Collaborator Author

@wadhwamatic sounds good. @ericboucher it'd be helpful to get your thoughts on loadBoundaryRelations (in frontend/src/components/Common/BoundaryDropdown/utils.ts) and if there's any way it could be simplified while still supporting alerts. That function alone is taking about 22 seconds to run on my computer 😅

@wadhwamatic
Copy link
Member

Hi @gislawill. The chart feature accessed through map interaction only works admin 0 in the surge deployment.

I see the request is missing the admin code for admin level 1 and 2 requests. For example:
https://api.earthobservation.vam.wfp.org/stats/admin?level=1&id_code=undefined&coverage=full&vam=rfh&start=2024-01-22&end=2025-01-21

To reproduce:

  1. Choose layer: rainfall > rainfall amount > rainfall aggregate 10-day
  2. Click on the map. In the tooltip windows, choose country and see that the chart loads correctly
  3. Choose any level below national and see the chart error:
Screenshot 2025-02-10 at 17 15 02

@gislawill
Copy link
Collaborator Author

The chart feature accessed through map interaction only works admin 0 in the surge deployment.

@wadhwamatic this is should now be fixed via the layer.json updates in 83b324c and 5153708

@wadhwamatic
Copy link
Member

@wadhwamatic this is should now be fixed via the layer.json updates in 83b324c and 5153708

Hi @gislawill. Sorry, I missed this before. I see the request is correctly passing the admin codes now for each level, thanks! Something is currently broken on the chart API though and we're getting null results. I'm following up with Valentin on that.

@gislawill
Copy link
Collaborator Author

Something is currently broken on the chart API though and we're getting null results. I'm following up with Valentin on that.

Thanks @wadhwamatic. I am also seeing cors errors from the charts api (https://api.earthobservation.vam.wfp.org/stats/admin) both in surge and local environments

@wadhwamatic
Copy link
Member

wadhwamatic commented Mar 4, 2025

@gislawill - Valentin fixed the chart API issue and that functionality is now working as expected for this PR. 🙌🏼

The outstanding issues I see are:

  1. The go to feature shows a list of locations (with some errors in that long list) but the interaction doesn't work
  2. Labels in the charts tab are not working properly when comparing locations and periods (see screenshot). The label 'Global' is also incorrectly getting applied for all charts
  3. The analysis feature is not implemented (known gap, but let's discuss a plan)

Sorry - here's the screenshot!
Screenshot 2025-03-04 at 09 22 38

@gislawill
Copy link
Collaborator Author

@wadhwamatic, could you point me to the screenshot?

Labels in the charts tab are not working properly when comparing locations and periods (see screenshot). The label 'Global' is also incorrectly getting applied for all charts

@gislawill
Copy link
Collaborator Author

@wadhwamatic

The outstanding issues I see are:

  1. The go to feature shows a list of locations (with some errors in that long list) but the interaction doesn't work
  2. Labels in the charts tab are not working properly when comparing locations and periods (see screenshot). The label 'Global' is also incorrectly getting applied for all charts
  3. The analysis feature is not implemented (known gap, but let's discuss a plan)

Issues 1 and 2 have been addressed and issue 3 is being addressed in this PR #1437

Copy link
Member

@wadhwamatic wadhwamatic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good from my side Will. Over to @ericboucher for his review

@wadhwamatic
Copy link
Member

wadhwamatic commented Mar 11, 2025

@gislawill - there's an issue I've noticed while testing that I'm hoping we can improve. When a layer is loaded (10-day rainfall for example), boundaries temporarily disappear but then are reloaded and brought to the front, making the experience of loading layers feel clunky. Do you see any opportunities to improve this?

"type": "boundary",
"path": "data/global/adm0_simplified.json",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we keep this one for now? (until we have the analysis part figured out?)

@ericboucher
Copy link
Collaborator

@gislawill really nice work, I'm quite impressed / pleased.

Once thing I would recommend is to explicitely lock the analysis feature when pmtiles are used, a few options for @wadhwamatic

  1. hide the analysis button completely
  2. disable the analysis tooltip with an explanatory tooltip
  3. disable the admin layer selection dropdown with an explanatory tooltip

layerDataSelector(boundaryLayer.id),
) as LayerData<BoundaryLayerProps> | undefined;
const { data } = boundaryLayerData || {};
const baseBoundaryLayer = useSelector(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot 2025-03-11 at 8 50 36 PM Screenshot 2025-03-11 at 8 51 39 PM

There seems to be an empty level/selector in the goto dropdown and a few weird things. Maybe linked to the underlying data?

const baseBoundaryLayer = useSelector(
layerDataSelector(boundaryLayers[0].id),
);
const { data: baseBoundaryLayerData } = baseBoundaryLayer || {};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth adding a few commends detailing what's related to pmtiles?

@@ -65,7 +65,7 @@ export function getAdminBoundaryTree(
partialTree.children[fp[currentLevelCode]] ?? {
adminCode: fp[currentLevelCode],
key: fp[layer.adminLevelNames[level]],
label: fp[locationLevelNames[level]],
label: fp[locationLevelNames[level]] ?? '',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we process out empty lables?

return undefined;
}, [layer.format]);

// This is causing a pretty massive performance hit. It seems to only be necessary for alerts.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO, let's put this PR in a mergeable state, which means no breaking changes for existing deployments. Similarly to analysis maybe we could disable alerts for pmtiles based deployments for now?

Comment on lines +330 to +344
admProps => {
if (!multiCountry) {
return country;
}

if (!admProps) {
return '';
}

if (adminLookup) {
return admProps[adminLookup] as string;
}

return (admProps.admin0Name as string) || '';
},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a few doctrings?

@@ -0,0 +1,24 @@
import { Protocol, PMTiles } from 'pmtiles';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a longer docstring explaining what this is used for and also update the README to explain how to add pmtiles layers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request]: make use of pmtiles for admin boundaries
3 participants