gboeing / osmnx

OSMnx is a Python package to easily download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap.
https://osmnx.readthedocs.io
MIT License
4.82k stars 821 forks source link

ImportError("scipy must be installed to calculate entropy") #740

Closed merkato closed 3 years ago

merkato commented 3 years ago

Problem description

Environment information

Package Version Location ---------------------------- ---------------- --------------------------------------------------- affine 2.3.0 androguard 3.3.5 anyio 3.3.0 apturl 0.5.2 argcomplete 1.8.1 argon2-cffi 20.1.0 asciitree 0.3.3 asn1crypto 1.4.0 astropy 4.0.1.post1 atomicwrites 1.4.0 attrs 19.3.0 Babel 2.9.1 backcall 0.2.0 beautifulsoup4 4.9.1 binwalk 2.2.0 bleach 3.2.1 blinker 1.4 blosc 1.8.1 boto3 1.13.14 botocore 1.17.22 Bottleneck 1.2.1 bsddb3 6.2.7 catfish 1.4.13 certifi 2020.4.5.1 cffi 1.14.6 cftime 1.2.1 chardet 3.0.4 charset-normalizer 2.0.4 chrome-gnome-shell 0.0.0 click 7.1.2 click-plugins 1.1.1 cligj 0.7.1 cloudpickle 1.3.0 colorama 0.4.3 command-not-found 0.3 configobj 5.0.6 cov-core 1.15.0 coverage 4.5.2 cryptography 3.0 cupshelpers 1.0 cvxopt 1.2.3 cycler 0.10.0 dask 2.11.0+dfsg dbus-python 1.2.16 decorator 4.4.2 defer 1.0.6 defusedxml 0.6.0 Deprecated 1.2.10 descartes 1.1.0 diffoscope 160 distro 1.5.0 distro-info 0.23ubuntu1 dnspython 1.16.0 docutils 0.16 ecdsa 0.15 EditorConfig 0.12.2 enjarify 1.0.3 entrypoints 0.3 et-xmlfile 1.0.1 ExifRead 2.1.2 fasteners 0.14.1 Fiona 1.8.20 fsspec 0.6.1 future 0.18.2 GDAL 3.1.3 geographiclib 1.50 geojson 2.5.0 geopandas 0.9.0 geopy 1.21.0 Glances 3.1.4.1 gpg 1.14.0-unknown gramps 5.1.3 gyp 0.1 h5netcdf 0.8.1 h5py 2.10.0 h5py.-debian-h5py-serial 2.10.0 html5lib 1.1 httplib2 0.18.1 hypothesis 5.29.0 idna 2.10 imgp 2.7 importlib-metadata 1.6.0 iotop 0.6 ipykernel 5.3.4 ipython 7.17.0 ipython-genutils 0.2.0 ipywidgets 6.0.0 jdcal 1.0 jedi 0.17.0 jeepney 0.4.3 Jinja2 2.11.2 jmespath 0.10.0 joblib 0.14.0 jsbeautifier 1.11.0 json5 0.9.6 jsondiff 1.1.1 jsonschema 3.2.0 jupyter-client 6.1.6 jupyter-console 6.1.0 jupyter-core 4.6.3 jupyter-server 1.10.2 jupyterlab 3.1.2 jupyterlab-server 2.6.2 keyring 21.3.0 keyrings.alt 3.4.0 kiwisolver 1.2.0 language-selector 0.1 launchpadlib 1.10.13 lazr.restfulclient 0.14.2 lazr.uri 1.0.5 libarchive-c 2.9 lightdm-gtk-greeter-settings 1.2.2 lios 2.5 llvmlite 0.33.0 locket 0.2.0 lxml 4.5.2 macaroonbakery 1.3.1 MapProxy 1.13.0 MapProxy-WebConf 0.9.post20210216 /home/mechanik/dev/soft/mapspr/mapproxy-webconf/app Markdown 3.2.2 MarkupSafe 1.1.1 matplotlib 3.3.0 mechanize 0.4.5 meld 3.20.2 menulibre 2.2.1 mistune 0.8.4 monotonic 1.5 more-itertools 4.2.0 msgpack 0.6.2 mugshot 0.4.2 munch 2.5.0 nbclassic 0.3.1 nbconvert 5.6.1 nbformat 5.0.7 netCDF4 1.5.4 netifaces 0.10.4 networkx 2.6.2 nose 1.3.7 nose2 0.9.2 notebook 6.0.3 numba 0.50.1 numcodecs 0.0.0 numexpr 2.7.1 numpy 1.21.1 oauth 1.0.1 oauthlib 3.1.0 odfpy 1.4.1 olefile 0.46 onboard 1.4.1 openpyxl 3.0.3 osmnx 1.1.1 OWSLib 0.20.0 packaging 20.4 pandas 1.3.1 pandocfilters 1.4.2 parso 0.7.0 partd 1.0.0 Paste 3.4.3 PasteDeploy 2.1.0 PasteScript 2.0.2 patsy 0.5.1 pdfarranger 1.6.2 pdfminer.six 20200726 pexpect 4.6.0 photocollage 1.4.3 pickleshare 0.7.5 pikepdf 1.17.3+dfsg Pillow 7.2.0 pip 20.1.1 plotly 4.9.0 pluggy 0.13.0 ply 3.11 progressbar 2.5 prometheus-client 0.7.1 prompt-toolkit 3.0.6 protobuf 3.12.3 psutil 5.7.2 psycopg2 2.8.5 ptyprocess 0.7.0 py 1.9.0 pycairo 1.16.2 pycparser 2.20 pycrypto 2.6.1 pycryptodomex 3.9.7 pycups 2.0.1 pycurl 7.43.0.2 pydot 1.4.1 pyenchant 3.0.1 Pygments 2.3.1 PyGObject 3.38.0 PyICU 2.5 PyJWT 1.7.1 pymacaroons 0.13.0 PyNaCl 1.4.0 PyOpenGL 3.1.5 pyOpenSSL 19.1.0 pyparsing 2.4.7 PyPDF2 1.26.0 pyperclip 1.8.0 pyproj 2.6.1 PyQt5 5.15.0 pyqtgraph 0.11.0 pyRFC3339 1.1 pyrsistent 0.15.5 pysal 2.1.0 PySimpleSOAP 1.16.2 pytest 4.6.11 pytest-arraydiff 0.3 pytest-astropy 0.8.0 pytest-astropy-header 0.1.2 pytest-cov 2.8.1 pytest-doctestplus 0.7.0 pytest-filter-subpackage 0.1.1 pytest-openfiles 0.5.0 pytest-remotedata 0.3.2 python-apt 2.1.3+ubuntu1.4 python-dateutil 2.8.1 python-debian 0.1.37 python-debianbts 3.0.2 python-magic 0.4.16 python-sane 2.8.3 pytz 2020.1 pyxattr 0.6.1 pyxdg 0.26 PyYAML 3.13 pyzmq 19.0.2 rasterio 1.2.1 redis 3.3.11 reportlab 3.5.47 requests 2.26.0 requests-unixsocket 0.2.0 retrying 1.3.3 rioxarray 0.3.1 roman 2.0.0 rpm 4.14.2.1 Rtree 0.9.4 s3transfer 0.3.3 scikit-learn 0.23.2 scipy 1.5.2 scour 0.37 seaborn 0.10.1 SecretStorage 3.1.2 Send2Trash 1.5.0 setuptools 49.3.1 sgt-launcher 0.2.5 Shapely 1.7.1 simplejson 3.17.0 sip 4.19.24 six 1.15.0 sniffio 1.2.0 snuggs 1.4.7 sortedcontainers 2.1.0 soupsieve 2.0.1 ssh-import-id 5.10 statsmodels 0.11.1 systemd-python 234 Tempita 0.5.2 terminado 0.10.1 testpath 0.4.4 tlsh 0.2.0 toolz 0.9.0 tornado 6.1 tqdm 4.48.2 traitlets 4.3.3 ubuntu-advantage-tools 24.4 ubuntu-drivers-common 0.0.0 ufw 0.36 unattended-upgrades 0.1 urllib3 1.25.9 usb-creator 0.3.7 vboxapi 1.0 wadllib 1.3.4 waitress 1.4.1 wcwidth 0.1.9 webencodings 0.5.1 websocket-client 1.1.0 wheel 0.34.2 widgetsnbextension 2.0.0 Willow 1.4 wrapt 1.11.2 xarray 0.15.1 xcffib 0.8.1 xkit 0.0.0 xlrd 1.1.0 xlwt 1.3.0 xmltodict 0.12.0 youtube-dl 2020.9.14 zarr 0.0.0 zipp 1.0.0 zope.interface 4.7.1

Used orientations example from github and added entropy calculation.


/usr/local/lib/python3.8/dist-packages/osmnx/bearing.py in orientation_entropy(Gu, num_bins, min_length, weight)
    153     if scipy is None:  # pragma: no cover
    154         raise ImportError("scipy must be installed to calculate entropy")
--> 155     bin_counts, _ = _bearings_distribution(Gu, num_bins, min_length, weight)
    156     return scipy.stats.entropy(bin_counts)
    157 

mechanik@en75-01:~/dev/gis/gis_w_gorach/gop$ sudo pip3 install scipy
Requirement already satisfied: scipy in /usr/lib/python3/dist-packages (1.5.2)

----------------------------------------
import matplotlib.pyplot as plt
import scipy
import numpy as np
import osmnx as ox

%matplotlib inline
ox.config(log_console=True)
weight_by_length = True

ox.__version__
scipy.__version__

places = {
    "Bytom": "Bytom, województwo śląskie",
}
gdf = ox.geocode_to_gdf(list(places.values()))
gdf

# create figure and axes
n = len(places)
ncols = 4
nrows = int(np.ceil(n / ncols))
figsize = (ncols * 7, nrows * 6)
fig, axes = plt.subplots(nrows, ncols, figsize=figsize, subplot_kw={"projection": "polar"})

# plot each city's polar histogram
for ax, place in zip(axes.flat, sorted(places.keys())):
    print(ox.utils.ts(), place)

    # get undirected graphs with edge bearing attributes
    G = ox.graph_from_place(place, network_type="drive_service")
    Gu = ox.add_edge_bearings(ox.get_undirected(G))
    Gue = ox.get_undirected(G)
    Gl = ox.stats.street_length_total(Gu)/1000
    Gsl = f"{Gl:.1f}"
    Gc = f"{ox.stats.circuity_avg(Gu):.1f}"
    Gentro = f"{ox.bearing.orientation_entropy(Gue):.2f}"
    opis = place + '\n'+ 'Dł: ' + Gsl + 'km / Entr:' + Gentro
    fig, ax = ox.bearing.plot_orientation(Gu, ax=ax, title=opis, area=True)

# add figure title and save image
suptitle_font = {
    "family": "DejaVu Sans",
    "fontsize": 15,
    "fontweight": "normal",
    "y": 1,
}
fig.suptitle("Orientacja ulic w wybranych miastach - Opracowanie: Tomasz Nycz, na podstawie danych OpenStreetMap - ODbL, http://osm.org", **suptitle_font)
fig.tight_layout()
fig.subplots_adjust(hspace=0.35)
fig.savefig("images/street-orientations.png", facecolor="w", dpi=100, bbox_inches="tight")
plt.close()
gboeing commented 3 years ago

Installed osmnx, jupyter lab, scipy and other packages by Ubuntu 20.04 package manager

Please follow the documented installation instructions instead. This is an issue with your installation playing nicely with Jupyter. If you have further such usage questions, best to ask on StackOverflow.