<jupyter_start><jupyter_text>Lesson 07<jupyter_code>import PIL.ImageFilter as ImageFilter
import bqplot<jupyter_output><empty_output><jupyter_text>If the above doesn't work, try uncommenting below:<jupyter_code>#!conda install -c conda-forge bqplot --yes
import bqplot<jupyter_output><empty_output><jupyter_text>You may have to do:<jupyter_code>#!jupyter nbextension enable --py bqplot

### or instead
#!jupyter nbextension enable --py widgetsnbextension --sys-prefix

#import bqplot<jupyter_output><empty_output><jupyter_text>Note: it is possible you may have to refresh your browser or close and reopen anaconda and jupyter notebook after you install this. Try out this interactive plot.  You should be able to pan and zoom.  Don't worry about the code right now, we'll get to it in week 03.<jupyter_code>x = np.arange(100)
y = np.random.random(100) + 5

x_sc = bqplot.LinearScale()
y_sc = bqplot.LinearScale()

lines = bqplot.Lines(x = x, y = y, scales = {'x': x_sc, 'y': y_sc})

ax_x = bqplot.Axis(scale = x_sc, label = 'x value')
ax_y = bqplot.Axis(scale = y_sc, label = 'y value', orientation = 'vertical')

pz = bqplot.interacts.PanZoom( scales = {'x': [x_sc], 'y': [y_sc]} )
bqplot.Figure(marks = [lines], axes = [ax_x, ax_y], interaction = pz)<jupyter_output><empty_output><jupyter_text>Note, if the above doesn't work you can try replacing:```pythonbqplot.Figure(marks = [lines], axes = [ax_x, ax_y], interaction = pz)```with```pythondisplay(bqplot.Figure(marks = [lines], axes = [ax_x, ax_y], interaction = pz))```<jupyter_code>import h5py<jupyter_output><empty_output><jupyter_text>If the above doesn't work try uncommenting:<jupyter_code>#!conda install -c anaconda h5py --yes
#import h5py
import requests<jupyter_output><empty_output><jupyter_text>If the above doesn't work, you can try uncommenting the following:<jupyter_code>#!conda install -c anaconda requests --yes
import geopandas
gdf = geopandas.read_file('https://opendata.arcgis.com/datasets/1f75636917604299861fb408bbf79378_1.geojson')
gdf.plot()<jupyter_output><empty_output><jupyter_text>If the above doesn't work, you can try uncommenting the following:<jupyter_code>#!conda install -c conda-forge geopandas --yes
#!conda install geopandas --yes<jupyter_output><empty_output><jupyter_text>Install `contextify` for background maps:<jupyter_code>import contextily as ctx<jupyter_output><empty_output><jupyter_text>If the above doesn't work try uncommenting:<jupyter_code>#!conda install -c conda-forge contextily --yes<jupyter_output><empty_output><jupyter_text>Test with a map (there might be a warning printed out here about an +init that you can ignore):<jupyter_code>df = geopandas.read_file(geopandas.datasets.get_path('nybb'))
ax = df.plot(figsize=(10, 10), alpha=0.5, edgecolor='k')
df = df.to_crs(epsg=3857)
ax = df.plot(figsize=(10, 10), alpha=0.5, edgecolor='k')
ctx.add_basemap(ax)<jupyter_output><empty_output><jupyter_text>Lesson 09 More info here: http://www2.compute.dtu.dk/projects/GEL/PyGEL/<jupyter_code>#from PyGEL3D import gel
#from PyGEL3D import js<jupyter_output><empty_output><jupyter_text>You will probably have to pip install:<jupyter_code>#!pip install PyGEL3D
#from PyGEL3D import gel
#from PyGEL3D import js
import ipyvolume<jupyter_output><empty_output><jupyter_text>You will probably have to install this:<jupyter_code>#!conda install -c conda-forge ipyvolume --yes
#import ipyvolume<jupyter_output><empty_output><jupyter_text>If that doesn't work you can try:<jupyter_code>#!pip install ipyvolume<jupyter_output><empty_output><jupyter_text>You may have to uncomment the following:<jupyter_code>#!jupyter nbextension enable --py --sys-prefix ipyvolume
#!jupyter nbextension enable --py --sys-prefix widgetsnbextension<jupyter_output><empty_output><jupyter_text>Make a test box:<jupyter_code>import numpy as np
import ipyvolume as ipv
V = np.zeros((128,128,128)) # our 3d array
# outer box
V[30:-30,30:-30,30:-30] = 0.75
V[35:-35,35:-35,35:-35] = 0.0
# inner box
V[50:-50,50:-50,50:-50] = 0.25
V[55:-55,55:-55,55:-55] = 0.0
ipv.quickvolshow(V, level=[0.25, 0.75], opacity=0.03, level_width=0.1, data_min=0, data_max=1)<jupyter_output>/opt/anaconda3/envs/myENV/lib/python3.7/site-packages/ipyvolume/serialize.py:92: RuntimeWarning: invalid value encountered in true_divide
  gradient = gradient / np.sqrt(gradient[0] ** 2 + gradient[1] ** 2 + gradient[2] ** 2)<jupyter_text>For saving movies & making animations:<jupyter_code>from matplotlib import animation
import matplotlib.pyplot as plt
import numpy as np

def update_line(num, data, line):
    line.set_data(data[..., :num])
    return line,
fig1 = plt.figure()

# Fixing random state for reproducibility
np.random.seed(19680801)

data = np.random.rand(2, 25)
l, = plt.plot([], [], 'r-')
plt.xlim(0, 1)
plt.ylim(0, 1)
plt.xlabel('x')
plt.title('test')
line_ani = animation.FuncAnimation(fig1, update_line, 25, fargs=(data, l),
                                   interval=50, blit=True)<jupyter_output><empty_output><jupyter_text>To save you can try:<jupyter_code>line_ani.save('anim.mp4')<jupyter_output><empty_output><jupyter_text>Or you might have to install ffmpeg and specify it as a writer:<jupyter_code># I think its this one 
#  you might have to restart kernel after this
#!conda install -c conda-forge ffmpeg --yes 

# you can also install imagemagick or use it as a writer!
Writer = animation.writers['ffmpeg']
writer = Writer(fps=15, metadata=dict(artist='Me'), bitrate=1800)
line_ani.save('anim.mp4')<jupyter_output><empty_output><jupyter_text>Now open and look:<jupyter_code>from IPython.display import Video
Video("anim.mp4",width=800)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13051959567299168, 'fraction_numerical': 0.03369391736123426, 'mean_word_length': 6.4504623513870545, 'pattern_counts': {'":': 0, '<': 84, '<?xml version=': 0, '>': 84, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '21', 'dir': 'jupyter-structured-clean-dedup', 'id': '73968', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 2266, 'n_tokens_neox': 2130, 'n_words': 487, 'path': 'lesson07/test_imports_lesson07.ipynb', 'repo_name': 'jnaiman/csci-p-14110_su2020', 'size': '5639'}