Skip to content

Aggregate based on zoom levels#194

Merged
ludovicdmt merged 35 commits intodevfrom
mvt_aggregate
Apr 24, 2025
Merged

Aggregate based on zoom levels#194
ludovicdmt merged 35 commits intodevfrom
mvt_aggregate

Conversation

@ludovicdmt
Copy link
Member

@ludovicdmt ludovicdmt commented Apr 17, 2025

On ne pouvait pas générer des MVTs avec des tuiles 5x5 pour cause d'OOM.

J'ai donc un peu fait des modifs pour :

  • Meilleur chargement des données (load_geodataframe_from_db)
  • Meilleur traitement des données afin de les mettre dans le bon format pour les encoder
  • Agrégats en fonction du niveau de zooms
  • MAJ des couleurs après discussions avec Geoffrey

for i, threshold in enumerate(PLANTABILITY_THRESHOLDS):
if value < threshold:
return i * 2
return 10
Copy link
Contributor

Choose a reason for hiding this comment

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

Normal la suppression de cette ligne ça retourne None maintenant

Copy link
Contributor

Choose a reason for hiding this comment

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

Est-ce que tu ne veux pas plutôt lever une exception ici ? Normalement ça ne devrait pas se produire non ? 

(ma crainte est que le None ne casse rien ici mais casse un truc qqs fonctions plus loin et que ce soit donc difficile à déboguer).

Copy link
Contributor

@Marc-AntoineA Marc-AntoineA left a comment

Choose a reason for hiding this comment

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

Quelques recommendations pour améliorer la lisibilité du code mais j’ai l’impression ok pour moi une fois que tu auras fait le tri dans ce mes commentaires.

Copy link
Contributor

Choose a reason for hiding this comment

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

Non

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, j’ai il faut que tu récupères le submodule, la première, fois, faire :

git submodule update --init --recursive

Default = "Default"
}

export const MIN_ZOOM = 12
Copy link
Contributor

Choose a reason for hiding this comment

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

Bonus : Pas moyen d'avoir ces constantes à un seul endroit (pour back et front). Tu peux par ex. lire un fichier de config dans vite.

@@ -37,17 +39,17 @@ def normalize_plantability(value: float) -> float:
The normalized plantability index.
"""
if value < -5:
Copy link
Contributor

Choose a reason for hiding this comment

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

Les thresholds sont déjà dans une constante (PLANTABILITY_THRESHOLDS) tu peux donc remplacer cette fonction par une boucle for.

Et je suis d'avis que cette fonction soit bougée dans plantability/constants.py à côté des constantes.

N’est-ce pas la fonction score_thresholding exactement ?

for i, threshold in enumerate(PLANTABILITY_THRESHOLDS):
if value < threshold:
return i * 2
return 10
Copy link
Contributor

Choose a reason for hiding this comment

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

Est-ce que tu ne veux pas plutôt lever une exception ici ? Normalement ça ne devrait pas se produire non ? 

(ma crainte est que le None ne casse rien ici mais casse un truc qqs fonctions plus loin et que ce soit donc difficile à déboguer).

from plantability.constants import PLANTABILITY_NORMALIZED


def get_tile_color(normalized_indice: float) -> str:
Copy link
Contributor

Choose a reason for hiding this comment

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

Bien ce refacto.

if len(batch_df_clipped) == 0:
continue

df_grid_clipped = self._make_grid_aggregate(
Copy link
Contributor

Choose a reason for hiding this comment

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

Ici tu ne vérifies pas que le zoom <= 15, c’est ok car en effet zoom < 13 plus haut, sauf que c’est visiblement pour des raisons différentes et à l’avenir, on pourrait, sur une machine ultra puissante changer la condition du if là haut if zoom <= 20 and side_length < 10 et alors on ferait quand même l’aggrégat

)
if not batch_queryset.exists():
continue
batch_df = load_geodataframe_from_db(
Copy link
Contributor

Choose a reason for hiding this comment

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

J’ai vraiment l’impression qu’on pourrait mutualiser ce code (lignes 255 à 260) avec les lignes 275 à 280.

  • le id dans le load_geodataframe_from_db ne me semble pas utile (?).
  • le clip diffère entre les deux blocs et pourrait être l’argument de la fonction (batch_clip_gdf vs clip_mvt_gdf)

Copy link
Member Author

Choose a reason for hiding this comment

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

  • Le id est utilisé dans le _create_mvt_features (ligne 354)

grid = self.create_grid(df_clipped, grid_size)
grid = gpd.clip(grid, df_clipped)
spatial_join = gpd.sjoin(df_clipped, grid, how="left", predicate="intersects")
aggregated = (
Copy link
Contributor

Choose a reason for hiding this comment

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

mean_aggregated ?

return df_clipped

@staticmethod
def _create_mvt_features(
Copy link
Contributor

Choose a reason for hiding this comment

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

J’ai l’impression que ça ne fonctionne que pour la plantability, l’indiquer dans le nom ?


@staticmethod
def map_to_discrete_value(x):
"""Map average value of normalized plantability to normalized plantability set"""
Copy link
Contributor

Choose a reason for hiding this comment

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

Ça peut être utilisé pour autre chose que "l’average value" non ?

@ludovicdmt ludovicdmt linked an issue Apr 24, 2025 that may be closed by this pull request
Copy link
Contributor

@Marc-AntoineA Marc-AntoineA left a comment

Choose a reason for hiding this comment

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

Ça me semble ok.

@ludovicdmt ludovicdmt merged commit c94c705 into dev Apr 24, 2025
9 checks passed
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.

ETQ dev je veux que les tests e2e soient plus rapides ETQ dev je veux que mvt_generator prenne en compte le niveau de zoom pour faire des agrégats

3 participants