Skip to main content

No project description provided

Project description

GH Actions badge License PyPI badge

Flanders: Fast 2D nearest neighbor search with an angle

                                                        `.-:://////:-.`
                                                 `-/oyhddddmmddddddNmdmdhs/`
                                              -ohddddddddddddNddddddNddddmmds.
                                            `hmmmmmdddddddddddNddddmmddddmmddm.
                                           `hddddddmmddddddhyyysoossyhdmNmdddNs
                                           sddddddddmmho/:-------------:odmmmmo
                                          :mddddddddd+-------------------:hddd.
                                          dddddddddm+---------------------:ms.
                                         :mddddddddd-----------------------s/`
                                         yddddddddds------------------------:s
                                        `mddddddddm+-----://////+/:---://////y`
                                        -Nddddddddm/----+:`     `./+-+-`    `.+:
                                        /mddddddddN:---o`          -d-    -.   o-
                                        omddddddddN////y  -d/      `m.    y+   +:
                                        sdddhhNmmmN+/::o: `-`     `+so++//:. `:+`
               `---.                    ydd+::mdddm:----/+-.````-:+:------:+s/-
               o/::/+-                  sN:-oomdddm+------://+///:---------:s
       `.-.`   s-----+/`                oN:---smddds------------:+oyhhysssydhs:.
      -o/://+-`.o:----/o`               /mh:---hyyy/----------+hdmmmmdddddmmmddho.
      /+-----:+/-o:----:+`       `..    .mddyyydo-----:///::ohdmmdmmdmddNdmmdmmddd/
       :+/-----:+/y-----:+-`  .:+///+.   dddddddd----:mMMNNddddddmddmdddmmdmddmdddm:
       ``-/+:----::-------:/+++:----/+   +mdddddN----:MMMMMNmmmmmmmdddddddhhhhhys+/.
    .////+//+o:--------------/-----/o`    sdddddm/----oNmdmNNNNMMMm//os--...``
    y:-----:/+o------------------:o:       :ydddm+-----:oyyyysydMMm:::o+.
    :o/:----------------+o:-----:s`          .::+o--------://++oooo+:--:s
      -:/+/:--------------s/----s.              -o------------------:/o+.
          `-/+o------------/---+d-             `+o------------------::h
              .s/---------:::ohhhs             y.-++:-----------------d:`
               dhys+///+oyhhhhyhm/            `s````:/++o+//:::://+++/-.s.
              /dddhhhhhhyyhhhddhym`           -s`````````..-:::/h/s-````.s`
             :dyyhddddddddddhyyyym           `ydy-`````````````s:.-o/````sy/-`
             yyyyyyyyyyyyyyyyyyyhs     `./+ooymhyhy/.`````````:o....++``:dmdhhhso:`
             dyyyyyyyyyyyyyyyyyym:`-/oyddhyyyyhddyyhhs+-``````hso++ohd++dyyddyyyyhhyo/`
             myyyyyyyyyyyyyyyyyyNhhhyyyyyyyyyyyyddyyyyyhdyso++ddhmhmddhhyyyyddyyyyyyyhdy+.

Installation

$ pip install flanders

Example

In this example we have 6 points (numbered 0 to 5) and two observer points with a certain view vector and view angle (90 degrees). The first observer point finds point 2. The second observer point does not find any neighbor within the view angle and returns -1.

Example

Example code:

import flanders


# as a first step we build the search tree
# we can later reuse the search tree many times

points = [
    (60.4, 51.3),
    (173.9, 143.8),
    (132.9, 124.9),
    (19.5, 108.9),
    (196.5, 9.9),
    (143.3, 53.3),
]

tree = flanders.build_search_tree(points)


# now we will search the indices of nearest neighbor points
# for two observer points

observer_coordinates = [(119.2, 59.7), (155.2, 30.2)]
view_vectors = [(0.0, 1.0), (-1.0, -1.0)]
view_angles_deg = [90.0, 90.0]

indices = flanders.nearest_indices_from_coordinates(
    tree, observer_coordinates, view_vectors, view_angles_deg
)

assert indices == [2, -1]


# instead of using observer coordinates, also the original
# points themselves can be observers and we can select them
# by their index

observer_indices = [0, 1, 2, 3, 4, 5]
view_vectors = [(1.0, 1.0) for _ in observer_indices]
view_angles_deg = [90.0 for _ in observer_indices]

indices = flanders.nearest_indices_from_indices(
    tree, observer_indices, view_vectors, view_angles_deg
)

assert indices == [5, -1, 1, 2, -1, 1]

Efficiency considerations

The above example is very small and simple but this library starts to shine once you have very many points and/or very many observers where a noddy implementation would take too long to compute.

Example timing for 1 M points and 10 k observers (on i7-10710U):

  • constructing the search tree: 3.0 s
  • nearest neighbor search: 9.6 s

If you compute nearest neighbors for many observers it is a good idea to send in an entire batch of observers instead of computing one by one. If you send in an entire batch, the code will shared-memory parallelize the loop over the observers.

References used during development

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

flanders-0.3.3-cp314-cp314-win_amd64.whl (177.2 kB view details)

Uploaded CPython 3.14Windows x86-64

flanders-0.3.3-cp314-cp314-manylinux_2_34_x86_64.whl (292.7 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.34+ x86-64

flanders-0.3.3-cp314-cp314-macosx_11_0_arm64.whl (254.6 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

flanders-0.3.3-cp313-cp313-win_amd64.whl (177.3 kB view details)

Uploaded CPython 3.13Windows x86-64

flanders-0.3.3-cp313-cp313-manylinux_2_34_x86_64.whl (294.0 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

flanders-0.3.3-cp313-cp313-macosx_11_0_arm64.whl (254.2 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

flanders-0.3.3-cp312-cp312-win_amd64.whl (177.3 kB view details)

Uploaded CPython 3.12Windows x86-64

flanders-0.3.3-cp312-cp312-manylinux_2_34_x86_64.whl (293.9 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

flanders-0.3.3-cp312-cp312-macosx_11_0_arm64.whl (254.1 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

flanders-0.3.3-cp311-cp311-win_amd64.whl (178.7 kB view details)

Uploaded CPython 3.11Windows x86-64

flanders-0.3.3-cp311-cp311-manylinux_2_34_x86_64.whl (295.2 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

flanders-0.3.3-cp311-cp311-macosx_11_0_arm64.whl (255.9 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

flanders-0.3.3-cp310-cp310-win_amd64.whl (178.0 kB view details)

Uploaded CPython 3.10Windows x86-64

flanders-0.3.3-cp310-cp310-manylinux_2_34_x86_64.whl (295.3 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

flanders-0.3.3-cp310-cp310-macosx_11_0_arm64.whl (256.1 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file flanders-0.3.3-cp314-cp314-win_amd64.whl.

File metadata

File hashes

Hashes for flanders-0.3.3-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 ed91da30e47f7f515a85dbaeb9ad52ac1647e623787a2af207f63b55127a4433
MD5 6ba64836de5c9c5ed4e79c13299a7786
BLAKE2b-256 cf2f08fb2c1ec284a5324e2a7f3fb690eef760e88e6f82a6ceff9d6100484b99

See more details on using hashes here.

File details

Details for the file flanders-0.3.3-cp314-cp314-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for flanders-0.3.3-cp314-cp314-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 f54f7580330be40e3a0b43de41148f5eabc13ca81dd911a0dfeb51425d750bd7
MD5 96561710ddfc71cf8cd41b4c5b7cbd7d
BLAKE2b-256 899ad848bc90651fe9e7aeb5a30a9ba878f28678a4958929119beb779caf50eb

See more details on using hashes here.

File details

Details for the file flanders-0.3.3-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for flanders-0.3.3-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 364613633877f9476455e6d807faa1e35ba3534e41c54fa5d72995419f9aea9b
MD5 e3cf4746a85375ee7c4e8a9c44f541e9
BLAKE2b-256 7caef5210d89e2afb788dd5df9a65ab97368cb2e65aaf21d045a02a7e2b4cd03

See more details on using hashes here.

File details

Details for the file flanders-0.3.3-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for flanders-0.3.3-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 b1e6e62fd3aa173aacdb08d0fa6667cf101e578cbff77c69066d79a7c955e0ec
MD5 f1754e8437908f1e423e31f5211696fe
BLAKE2b-256 3e6bf8d7dea31da5975e0ba4ddc005f0e9cb497738647f2eb31500df99eaba60

See more details on using hashes here.

File details

Details for the file flanders-0.3.3-cp313-cp313-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for flanders-0.3.3-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 8b53da14e38fef1c0c294539c5aad9baaa467b06baaa79865d29ace41e6b0d31
MD5 a24fc18526ce1565e498d03c7d0b08e8
BLAKE2b-256 551a88e738a391d830fe24480d0edccf7db05148c7676016e94f8a3521fe63b5

See more details on using hashes here.

File details

Details for the file flanders-0.3.3-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for flanders-0.3.3-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3cd7af62bf26d4990c9fe67d2f6d02ca2bbdcbb68f0276db20727ba12e7a5160
MD5 d870918a0653842ee88646b7c3e9aa9c
BLAKE2b-256 0d6114f5d397b5496e55e94a1d0ffd72b1941450e76a6d8bc1ce7a59dc8a7133

See more details on using hashes here.

File details

Details for the file flanders-0.3.3-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for flanders-0.3.3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 5373152174532bef109c59a050472d5745cfb636a75680fba3a8acc0a343b5ef
MD5 6ec5ca7f90990f4340669c80348b17b0
BLAKE2b-256 bb29fe8c4ed666e906d8b1406b3dd522653ca86569d6283e0d0f7b29817d865a

See more details on using hashes here.

File details

Details for the file flanders-0.3.3-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for flanders-0.3.3-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 ab8951b95573a8e998d87b4187247028dcbcbdfb4883111be463a8d9c71c6f00
MD5 63b98ff6ddbc1f655b112c56443d80cd
BLAKE2b-256 dbf9a36296bb24b841a4745d30270dceccbd2760439cca1c4a1e8e7f5b1a47c9

See more details on using hashes here.

File details

Details for the file flanders-0.3.3-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for flanders-0.3.3-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3138dfc6a1d828f0350f9761abd499979d7d8c3733b2aedac01e7487e9c441a2
MD5 f2f1e74d421d1121602d53f7eb0a2000
BLAKE2b-256 8ac46046d8b3975f4965e3461528388adba9410610e640fd5bb0bf2319c5eb9e

See more details on using hashes here.

File details

Details for the file flanders-0.3.3-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for flanders-0.3.3-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 f7a22dbd038729a2256d126085d0ffb4e17f0bb0013b8e2f60fb22d9ccaa6f6b
MD5 18ec89d52b4e56f19e1eaf0e7b9dc371
BLAKE2b-256 201be22b2b3b2af048c906426b3a2743ef5f9f104f10989359870a38410d0e5c

See more details on using hashes here.

File details

Details for the file flanders-0.3.3-cp311-cp311-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for flanders-0.3.3-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 0417200a00cf5fcb13a1732766a9582630bd9642922276ddc764c416c3d29853
MD5 a1ac00e6f5b802edd47e7cf296965422
BLAKE2b-256 1e9155aeb13cb033079436e647b086bffaa1e82f841c03c727ae97741847434e

See more details on using hashes here.

File details

Details for the file flanders-0.3.3-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for flanders-0.3.3-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7043d2fbeb6a174343136d00bb3c153c18e74bcabaf1859df09c6d3319fcb404
MD5 ebaf7ab56faeb995f6368a9372be4e1e
BLAKE2b-256 880637fc0d8fac1cb1276442e5ab50e4eb87b2abac33e453de4507dd8eae5bdf

See more details on using hashes here.

File details

Details for the file flanders-0.3.3-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for flanders-0.3.3-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 5beb7ca8b8d9d0cf50bf49be46818f99b382064d70b23a7d3f3a376ff6eb5728
MD5 bfc627454665c9389ed2dae72d0ebf6a
BLAKE2b-256 bd9bd3a07c89c1c5476050353ed46ab27336d9796202b310195dbd538c63bc31

See more details on using hashes here.

File details

Details for the file flanders-0.3.3-cp310-cp310-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for flanders-0.3.3-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 27189c65445a3e43b8195d3eb1ff75a034af56a804c948d01d328a82772124a7
MD5 d1a73478bc69b74c3b654c0879074bbc
BLAKE2b-256 62f9a319d6e8ad4bc9767481b72ee6d694b2d945bdc7a6c95dbdac2653fda95a

See more details on using hashes here.

File details

Details for the file flanders-0.3.3-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for flanders-0.3.3-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4a5a56a52e5490ad94b291c62cbd0871ef6b9f315748b2ce4821a3336a4a373f
MD5 96dd9b765a6d6e904514327c2826ff57
BLAKE2b-256 beae9f40f3b9e3897c9fae0a789ba36aa46b9b0eeeca5c99017948354b7e964b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page