Package: latlon-utils
This repository contains utility functions to retrieve information for given
latitudes and longitude.InstallationWe strongly recommend to usecondafor the installation. First, install the
necessary dependencies, namelynetCDF4,shapelyandpandas:conda install netcdf4 shapely pandasTo enable the download of the WorldClim data, you will also needrasterioandxarray(you can skip this if you already downloaded the data) via:conda install rasterio xarrayThen installlatlon_utilsvia:pip install latlon_utilsor from the source directory via:pip install .UsageSo far, the package has two functions: theget_climateandget_countryfunction. Use these likeGet the country for 50 degrees north and 10 degrees east:>>> from latlon_utils import get_country

>>> get_country(50, 10)
'Germany'Get the climate for 50 degrees north and 10 degrees east:>>> from latlon_utils import get_climate

# limit the number of columns printed by pandas
>>> import pandas; pandas.options.display.max_columns = 5

>>> get_climate(50, 10)
tavg  jan     0.044739
      feb     0.974976
      mar     4.705505
      apr     8.232239
      mai    13.150024
      jun    16.012268
      jul    17.958984
      aug    17.828735
      sep    13.779480
      oct     8.787476
      nov     4.039001
      dec     1.430237
      djf     0.816650
      mam     8.695923
      jja    17.266663
      son     8.868652
      ann     8.911972
prec  jan    48.000000
      feb    42.000000
      mar    44.000000
      apr    44.000000
      mai    56.000000
      jun    68.000000
      jul    65.000000
      aug    52.000000
      sep    47.000000
      oct    52.000000
      nov    52.000000
      dec    59.000000
      djf    49.666667
      mam    48.000000
      jja    61.666667
      son    50.333333
      ann    52.416667
Name: (50, 10), dtype: float64


>>> get_climate(50, 10)['tavg', 'djf']
0.816650390625

>>> get_climate([10, 11], [50, 51])
            tavg             ...       prec
             jan        feb  ...        son       ann
lat lon                        ...
10  50   21.810730  22.687988  ...  10.666667  6.833333
11  51   24.617249  24.678040  ...   7.666667  3.750000
<BLANKLINE>
[2 rows x 34 columns]Data downloadThis package is built upon freely available datasets but does not contain any
data. This data is downloaded on request (see the next section). In particular,
theget_climatemethod uses the data from[WorldClim2.1], theget_countryfunction uses thedatasets/geo-countriesrepository.Download directoryTo download and process the necessary datasets, run:python -m latlon_utils.download(seepython-mlatlon_utils.download--helpfor available options).We download the GeoTIFF files fromWorldClimand transform them to netCDF
datasets. The default directory to store the data is in$HOME/.local/share/latlon_utils, where$HOMEstands for the users home
directory. If you want to use a different directory, set theLATLONDATAvariable, e.g.:export LATLONDATA=$HOME/my_data
python download.py $LATLONDATATheLATLONDATAenvironment variable is necessary to ensure that the python
package finds the data later again.WorldClim resolutionsThe default resolution that we use is10m. However, you can also specify
other resolutions in the python functions or via theLATLONRESenvironment
variable. To use, for example the 5 minutes resolutions, simply run:export LATLONRES='5m'References[WorldClim2.1]Fick, S.E. and R.J. Hijmans, 2017. Worldclim 2: New 1-km spatial resolution climate surfaces for global land areas. International Journal of Climatology.http://worldclim.org/