Movie Maker

Collections of classes that allow to produce movies from a series of ProDiMo models. Currently only contour plot movies are available.

This is still quite experimental and not very flexible. I guess there are several other possibilities for movies. For example evolution of columndensities as function of time in a time dependent model. Contributions are very welcome !

Usage example

import numpy as np
import prodimopy.read as pread
import prodimopy.movie as pmovie


"""
Example for a time-dependent ProDimo model.
"""

# the ages of the model. As the log10 of the ages is used age of 1 is avoided.
# the unit is in yr
# If you want to make a movie it is recommended to run the time-dependent ProDiMo
# model with small first time step (e.g. 1 yr) otherwise it might be the the
# movie routine has problems with the interpolation
ages=np.array([1.000000000001,1e3,1e4,1e5,5e5,1e6,2e6,3.e6,5.e6])

# read all the time output from the time-dependent ProDiMo model.
# Assumes the model is in the current working directory of that script.
models=list()
for i in range(len(ages)):
  models.append(pread.read_prodimo(".",td_fileIdx="{:02d}".format(i+1),readlineEstimates=False))

# Make movie showing the time evolution of the CO abundance in mp4 format.
pm=pmovie.ContourMovie(ages,models,[2.e-9,2.e-4],species="CO",nframes=100,plot_cont_dict={"zr": True})
pm.make_movie("CO.mp4")

# now write the same movie in html format (video tag)
# this movie is shown below
pm.make_movie("CO.html")

# no make one for the gas temperature. Also evolves with time as the heating/cooling was solved
# consistently with the time-dependent chemistry in this model.
pm=pmovie.ContourMovie(ages,models,[5,5000],field="tg",nframes=100,cblabel=r"log T$_g$ [K]")
pm.make_movie("tgas.mp4")

Source documentation

class prodimopy.movie.MovieABC(ages, models, timescalefac=3.0, ageslog=True, nframes=40, nbins=40)[source]

A abstract class to make a movie for a series of ProDiMo models for a 2D contour plot. For each model also an age (a time) needs to be supplied. To produce a smooth video the data from the ProDiMo models are interpolated. For example one can provide 10 ProDiMo models but produce 100 frames for the movie.

Currently linear intepolation in either logspace or linear space is used.

Uses matplotlib.animation.FuncAnimation. To produce an mp4 movie ffmpeg needs to be available.

Currently this routine was only tested on macOS X with ffmpeg installed via port and on a Scientifc Linux maching with ffmpeg preinstalled. Those cases worked without problems.

Alternatively also an html file (html video tag) can be written. But it is unclear of ffmpeg or something similar is required. Worked on macOS X.

Also calls init_figure()

models

array_like(objects,ndim=1): A list of model objects (data). Must have the same length as ages

timescalefac

float: The runtime of the movie will be scaled by this value. Currently the runtime of the movie is given by log10 of the maximum age times timescalefac.

ageslog

bool: Use the log10 of ages or not: Defalt True

nframes

int: How many frames should this movie have. Has impact on the smoothness and the size of the video. Does not afect the runtime of the movie.

nbins

int: How many bins should be use for the contourf plot.

abstract init_figure()[source]

Initialisation of the matplotlib figure. Also here the parts that stay fixed are plotted. In this case for example the colourbar.

This routine should set the internal attribute _fig,`_cont` and _timelabel for the ContourMovie object.

Needs to be implmented by the subclass.

abstract animate(frame)[source]

Animate function. I called for each frame of the movie. This routine should only replot the stuff that is actually animated.

For more details see also matplotlib.animation.FuncAnimation.

Parameters:

frame (int) – The frame number (starting from 0)

Return type:

Has to return a list of artists that should be updated.

make_movie(outfile)[source]

Makes the movie and writes it to a file. The routine uses matplotlib.animation.FuncAnimation

There are three possivle formats for the movie: .mp4,`.html` and .gif. The mp4 format requires ffmpeg installed. In case of the html format the html 5 video tag is used. It likely also required ffmpeg (I am not sure). For gif format imagemagick is necessary.

The format is derived from the given filename outfile.

Parameters:

outfile (str) – Outputfile name. The name also defines the outputformat.

class prodimopy.movie.ContourMovie(ages, models, zlim, field=None, species=None, timescalefac=3.0, ageslog=True, nframes=40, nbins=40, cblabel=None, plot_cont_dict={})[source]

A class to make a movie for a series of ProDiMo models for a 2D contour plot. For each model also an age (a time) need to be supllied. To produce a smooth video the data from the ProDiMo models are interpolated. For example one can provide 10 ProDiMo models but produce 100 frames for the movie.

Currently linear intepolation in either logspace or linear space is used.

Uses matplotlib.animation.FuncAnimation. To produce an mp4 movie ffmpeg needs to be available.

Currently this routine was only tested on macOS X with ffmpeg installed via port and on a Scientifc Linux maching with ffmpeg preinstalled. Those cases worked without problems.

Alternatively also an html file (html video tag) can be written. But it is unclear of ffmpeg or something similar is required. Worked on macOS X.

Also calls init_figure()

field

str: The attribute of Data_ProDiMo that should be plotted (e.g. tg). The routine then trys to find this field for each ProDiMo model. Is opitonal, but than species must be set.

species

str: A species name. If given the abundance of that species is plotted. Optional, if not set field must be set.

zlim

array_like(float,ndim=1): The minimum and maximum for the data range [min,max]. Needs to be set and will be the same for all frames of the movie.

cblabel

str: The label for the colorbar.

make_movie(outfile)

Makes the movie and writes it to a file. The routine uses matplotlib.animation.FuncAnimation

There are three possivle formats for the movie: .mp4,`.html` and .gif. The mp4 format requires ffmpeg installed. In case of the html format the html 5 video tag is used. It likely also required ffmpeg (I am not sure). For gif format imagemagick is necessary.

The format is derived from the given filename outfile.

Parameters:

outfile (str) – Outputfile name. The name also defines the outputformat.

models

array_like(objects,ndim=1): A list of model objects (data). Must have the same length as ages

timescalefac

float: The runtime of the movie will be scaled by this value. Currently the runtime of the movie is given by log10 of the maximum age times timescalefac.

ageslog

bool: Use the log10 of ages or not: Defalt True

nframes

int: How many frames should this movie have. Has impact on the smoothness and the size of the video. Does not afect the runtime of the movie.

nbins

int: How many bins should be use for the contourf plot.

init_figure()[source]

Initialisation of the matplotlib figure. Also here the parts that stay fixed are plotted. In this case for example the colourbar.

This routines set the internal attribute _fig,`_cont` and _timelabel for the ContourMovie object.

animate(frame)[source]

Animate function. I called for each frame of the movie. This routine should only replot the stuff that is actually animated.

Here only the filled contours and the timelabel is updadted.

For more details see also matplotlib.animation.FuncAnimation.

Parameters:

frame (int) – The frame number (starting from 0)

Return type:

A list of artists that should be updated.

class prodimopy.movie.CasaSimMovie(ages, models, timescalefac=3.0, ageslog=True, nframes=40, nbins=40, plot_dict={})[source]

Make a movie out of Casa/ALMA simulations. Currently only integrated images (total intensity, continuum) can be used. For example at each age there is one image.

make_movie(outfile)

Makes the movie and writes it to a file. The routine uses matplotlib.animation.FuncAnimation

There are three possivle formats for the movie: .mp4,`.html` and .gif. The mp4 format requires ffmpeg installed. In case of the html format the html 5 video tag is used. It likely also required ffmpeg (I am not sure). For gif format imagemagick is necessary.

The format is derived from the given filename outfile.

Parameters:

outfile (str) – Outputfile name. The name also defines the outputformat.

models

array_like(objects,ndim=1): A list of model objects (data). Must have the same length as ages

timescalefac

float: The runtime of the movie will be scaled by this value. Currently the runtime of the movie is given by log10 of the maximum age times timescalefac.

ageslog

bool: Use the log10 of ages or not: Defalt True

nframes

int: How many frames should this movie have. Has impact on the smoothness and the size of the video. Does not afect the runtime of the movie.

nbins

int: How many bins should be use for the contourf plot.

init_figure()[source]

Initialisation of the matplotlib figure. Also here the parts that stay fixed are plotted. In this case for example the colourbar.

This routine should set the internal attribute _fig,`_cont` and _timelabel for the ContourMovie object.

Needs to be implmented by the subclass.

animate(frame)[source]

Animate function. I called for each frame of the movie. This routine should only replot the stuff that is actually animated.

For more details see also matplotlib.animation.FuncAnimation.

Parameters:

frame (int) – The frame number (starting from 0)

Return type:

Has to return a list of artists that should be updated.