Giter VIP home page Giter VIP logo

pynuts's Introduction

pynuts

Easy access to NUTS and LAU codes for a given location.

The package provides a quick way to find NUTS and LAU codes (and some additional information) for a given point (latitude, longitude) on the surface. The package automatically downloads the necessary input tables and shapefiles from Eurostat's servers.

The package uses NUTS codes from 2016 and LAU codes from 2019 which is currently the most recent data. Future versions will enable users to select specific years for which updates to NUTS and LAU are available.

Note: This package has been developed and tested using Linux. Your mileage on Windows and MacOS may vary.

Usage

Installation

To install the package just type:

git clone git@github.com:marcwie/pynuts.git
cd pynuts
python setup.py install

Installation via pip will be available soon.

Getting started

In order to get started you should look at the jupyter notebooks in the examples-folder.

Load data

If you only wish to obtain the official LAU and NUTS tables you can achieve this like so:

from pynuts import dataio

lau = dataio.load_lau_table(country_code="FR")
nuts = dataio.load_nuts_table(country_code="FR", spatial_resolution=10, level=2)

You need to specify a two-character country-code. For NUTS-tables you also need to specify the desired resolution (1, 3, 10, 20, 60 -- the lower the better) and the NUTS level (1, 2, or 3 -- the higher the finer).

Find NUTS-region corresponding to a specific location

Let's assume you know the latitude and longitude of your location (for instance in Italy). You can then obtain the corresponding NUTS1 regions like so:

from pynuts import NutsFinder

finder = NutsFinder(country_code="IT", spatial_resolution=60, level=1)
region = finder.find(lat=42.61923574439346, lon=13.010336619663239)
print("Point lies in NUTS1-Region", region.NUTS_NAME, "with ID", region.NUTS_ID)

which prints

Loading LEVEL1 NUTS data from 2016 for IT at 60m spatial resolution
Point lies in NUTS1-Region Centro (IT) with ID ITI

Similarly, you could do the same for NUTS2- and NUTS3-regions:

from pynuts import NutsFinder

finder = NutsFinder(country_code="IT", spatial_resolution=60, level=2)
region = finder.find(lat=42.61923574439346, lon=13.010336619663239)
print("Point lies in NUTS2-Region", region.NUTS_NAME, "with ID", region.NUTS_ID, end="\n\n")

finder = NutsFinder(country_code="IT", spatial_resolution=60, level=3)
region = finder.find(lat=42.61923574439346, lon=13.010336619663239)
print("Point lies in NUTS3-Region", region.NUTS_NAME, "with ID", region.NUTS_ID)

which prints

Loading LEVEL2 NUTS data from 2016 for IT at 60m spatial resolution
Point lies in NUTS2-Region Lazio with ID ITI4

Loading LEVEL3 NUTS data from 2016 for IT at 60m spatial resolution
Point lies in NUTS3-Region Rieti with ID ITI42

If you run these commands for the first time, the package first needs to download the necessary shapefiles. This can take a while but only needs to be done once.

Find LAU-region corresponding to a specific location

You can do the same now for LAU-regions which are a very fine grained tessalation of countries into local administrative units. To find the LAU corresponding to a specific location just type

from pynuts import LauFinder

finder = LauFinder(country_code="IT")
region = finder.find(lat=42.61923574439346, lon=13.010336619663239)
print("Point lies in LAU-Region", region.LAU_NAME, "with ID", region.LAU_ID)

which prints

Loading LAU data from 2019 for IT
Loading additional NUTS data for hierarchical search.
Loading LEVEL3 NUTS data from 2016 for IT at 1m spatial resolution
Loading LEVEL3 NUTS data from 2016 for IT at 60m spatial resolution
Loading correspondence table for IT
Point lies in LAU-Region Monteleone di Spoleto with ID 054031

Note that the LauFinder loads multiple shape-files. That is because it performs a hierarchical search where it first looks up the NUTS-region of the location, then uses a correspondence table to find the LAU-regions within that NUTS-region and then performs the search for the LAU-region only on this subset. This yields a 6-8 time performance increase over simply searching only within the LAU data.

Useful links

The package compiles data from the following sources:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.