This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Warning: quick and dirty code. | |
import dnachisel as dc | |
import proglog | |
proglog.notebook() | |
import matplotlib.pyplot as plt | |
from dna_features_viewer import BiopythonTranslator, GraphicFeature | |
counter = [0] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# REQUIRES PACKAGES Numpy AND Scipy INSTALLED | |
import numpy as np | |
import scipy.integrate | |
import scipy.interpolate | |
class ddeVar: | |
""" special function-like variables for the integration of DDEs """ | |
def __init__(self,g,tc=0): | |
""" g(t) = expression of Y(t) for t<tc """ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Code for this GIF: | |
# http://imgur.com/gallery/pTypr1Y | |
# This demonstrates how to freeze a region with MoviePy | |
from moviepy.editor import * | |
clip = (VideoFileClip("the_fault_in_our_stars.mp4") | |
.subclip("00:59:48.4","00:59:49.6") | |
.resize(width=600) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Model of a Zombie outbreak in France, starting in Grenoble | |
This is a rewrite from this blog post by Max Berrgren: | |
http://maxberggren.github.io/2014/11/27/model-of-a-zombie-outbreak/ | |
with a different country, a slightly different model, and different | |
libraries. The map of population density is taken from Wikimedia Commons |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
import numpy as np | |
def graph_editor(grid=True, grid_N = 12): | |
""" | |
This function enables to draw a graph manually using | |
Matplotlib's interactive plotting capabilites. | |
In a first phase you are asked to place the nodes | |
(left-click to place a node, right-click to remove |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Provides a naive solution to the following problem: | |
Given a couple (a,b), use the transformations | |
L: (a,b)->( 2a, b+1 ) | |
R: (a,b)->( a+1, 2b ) | |
to come to two equal integers. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
segments_lengths = [3, 2, 2, 2, 1, 1, 1, 2, 2, 1, 1, 2, 1, 2, 1, 1, 2] | |
assert sum(segments_lengths) == 27 | |
def solve(cube, position, direction, segment_number): | |
if segment_number == len(segments_lengths): | |
return cube | |
x, y, z = direction | |
a1, a2 = np.array([y, z, x]), np.array([z, x, y]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
This script produces a video analysis proving for the first time in history | |
that bacterial populations grow exponentially. See the result here: | |
http://i.imgur.com/uoITKiA.gif | |
We proceed as follows: | |
- Download a video of bacteria growing under a microscope. | |
- Cut the video to keep only the first 7 seconds. | |
- Threshold each frame to find where the bacteria are, and compute the |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Result: http://i.imgur.com/thrh1TU.gif | |
from moviepy.editor import * | |
# We start with a looping gif, and we will add some text | |
clip = VideoFileClip("eugene.gif").speedx(0.7) # slow down a little | |
txt = (TextClip("Hey", fontsize=78, font='Impact-Normal', | |
color='yellow', stroke_color='black', | |
stroke_width=3, kerning=1.5) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# IMPORTS: THIS SCRIPT REQUIRES THE PACKAGES PYLAB AND MOVIEPY | |
# It produces this gif: http://i.imgur.com/LbU55oK.gif | |
from pylab import * | |
import moviepy.editor as mp | |
from moviepy.video.io.bindings import mplfig_to_npimage | |
# PARAMETERS OF THE CURVE AND THE GIF |