MCPcopy Index your code
hub / github.com/MarcCoru/locationencoder

github.com/MarcCoru/locationencoder @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
197 symbols 592 edges 37 files 31 documented · 16% updated 1y ago★ 1096 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Geographic Location Encoding with Spherical Harmonics and Sinusoidal Representation Networks

For a paper summary, please click on the youtube video below or click this link.

ICLR video

You can find the paper on ArXiv and OpenReview

if you want to cite our work, use:

@inproceedings{russwurm2024locationencoding,
      title={Geographic Location Encoding with Spherical Harmonics and Sinusoidal Representation Networks}, 
      author={Marc Rußwurm and Konstantin Klemmer and Esther Rolf and Robin Zbinden and Devis Tuia},
      year={2024},
      booktitle = {Proceedings of the International Conference on Learning Representations (ICLR)},
      year = {2024},
      url = {https://iclr.cc/virtual/2024/poster/18690}
}

Getting Started

Check this Colab Notebook to get started. Open In Colab

It 1. clones the current repository 2. installs the required packages 3. trains Siren(SH) on the landocean dataset 4. predicts the following map:

Using Siren(SH)

To use Spherical Harmonic embedding function with SirenNet, i.e., Siren(SH(lon,lat)), in your code, instantiate the LocationEncoder class in locationencoder/locationencoder.py with Siren and Spherical Harmonics and a hyperparameter dict hparams as follows:

from locationencoder import LocationEncoder

hparams = dict(
    legendre_polys=10,
    dim_hidden=64,
    num_layers=2,
    optimizer=dict(lr=1e-4, wd=1e-3),
    num_classes=1
)

# Pytorch Lightning Model
model = LocationEncoder("sphericalharmonics", "siren", hparams)

# input longitude latitude in degrees
import torch
lonlat = torch.tensor([[51.9,5.6]], dtype=torch.float32)

# forward pass
output = model(lonlat)

Using Spherical Harmonics

We provide the analytically calculated Spherical Harmonic Basis Functions in locationencoder/pe/spherical_harmonics_ylm.py up to L=100 (! 40k lines, 7.7MB source code file). This file was generated with SymPy using locationencoder/pe/spherical_harmonics_generate_ylms.py.

To instantiate only the Spherical Harmonic positional encoder (no trainable weights) run

from locationencoder.pe import SphericalHarmonics
sh = SphericalHarmonics(legendre_polys=20)

# use lonlat coordinates, as above
embedded_lonlat = sh(lonlat) 

Reproduce Results

Run the following lines to reproduce results from the paper. The hyperparameter are configured in hparams.yaml.

Tables 1a (--dataset checkerboard) and 1b (--dataset landoceandataset) with

python experiments/exp_quantitative.py \ 
    --dataset landoceandataset \
    --nn linear fcnet siren \ 
    --pe sphericalharmonics theory grid spherec spherecplus spherem spheremplus direct cartesian3d wrap 

For Fig 4b) run

python experiments/exp_longitudinal_accuracy.py

For Fig 4a) run

python experiments/exp_resolution.py

Code Acknowledgements

This repository uses and relies on * SymPy for the analytic calculation of spherical harmonic basis functions * Pytorch Lightning for smooth model fitting * the SirenNet implementation (Sitzmann et al., 2020) by Phil Wang/lucidrains

Core symbols most depended-on inside this repo

plot_predictions
called by 10
utils/plot_results.py
parse_resultsdir
called by 10
experiments/exp_era5.py
parse_resultsdir
called by 9
utils/utils.py
log_loss
called by 7
utils/losses.py
exists
called by 7
locationencoder/nn/siren.py
fit
called by 6
train.py
generate_fibonaccilattice
called by 5
data/checkerboarddataset.py
forward
called by 5
locationencoder/pe/wrap.py

Shape

Function 88
Method 87
Class 22

Languages

Python100%

Modules by API surface

locationencoder/nn/siren.py18 symbols
data/checkerboarddataset.py18 symbols
data/inat2018_loader.py15 symbols
locationencoder/locationencoder.py12 symbols
data/era5dataset.py10 symbols
utils/losses.py9 symbols
data/landoceandataset.py9 symbols
locationencoder/pe/grid_and_sphere.py8 symbols
locationencoder/locationimageencoder.py8 symbols
locationencoder/imageencoder.py8 symbols
experiments/exp_era5.py8 symbols
utils/plot_results.py7 symbols

For agents

$ claude mcp add locationencoder \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact