Day 2 Lecture Slides

All of the notes from the intro of day 2. This includes some movie ideas, and some beginnings of thinking in 3D (in the 2nd half of the day).

Code

We are going to break up our code into two parts - one part to calculate trajectories and save the info to a text file, and the second part to read in saved data and make png plot images.

PART 1: Calculate the trajectories & Save data

This is exactly the code from "Choose your Own Adventure #1" from Day 4, but with some code to save information about the trajectories in a text file instead of plotting. Feel free to just grab the end bits of this code that does the saving of positions and velocities as your code probably differs in initial conditions.

PART 2: Read data & make plots

This is exactly the end part of the code from "Choose your Own Adventure #1" from Day 4, but instead of generating trajectories it reads in data from the saved text file from PART 1 and plots stuff.

PART 2, GALAXIES: Read data & make plots

If you worked with galaxy mergers last week, use this code to generate movies from saved data. See the "Resources" section for the data download. Note - its a 77Mb zip file.

FFmpeg Instructions

Step 1: Download FFmpeg from here. There are binaries for most distributions under "Get the packages" so select one that matches your OS.

Step 2: Once you have a series of images generated from the "Code" section above, you can create a movie with the following (assuming /FFMPEG_DIRECTORY/ is the directory where FFmpeg unpacks):

  • /FFMPEG_DIRECTORY/ffmpeg -framerate 15 -pattern_type glob -i 'traj*.png' -c:v libx264 -pix_fmt yuv420p out.mp4
  • The above is for a Mac, but the calling sequence might be slightly different on your OS, so let someone know if it doesn't work and we can take a look at it.

    Note: If you get a "width not divisible by 2" error, this means your saved images have a height or width that is not divisible by 2. You can solve this with a comment such as (if the width is not divisible by 2):

  • /FFMPEG_DIRECTORY/ffmpeg -framerate 15 -pattern_type glob -i 'traj*.png' -vf "crop=in_w-1:in_h" -c:v libx264 -pix_fmt yuv420p out.mp4
  • But certainly let someone know if this doesn't fix the problem.

    Also, check out "Resources" section for some FFmpeg links.

    Resources

    Download FFmpeg

    The main download site.

    Images to Movie with FFmpeg

    Lots of information about what the different parameters are for using FFmpeg to make a movie from a series of png files.

    Other Movie Resources

    A list of other movie making resources if you HATE FFmpeg.

    Download Galaxy Merger data

    77Mb of galaxy merger awesomeness.

    Code

    Planets

    Code to make the set of OBJ + MTL Planet files

    This code reads in planet data and makes the files needed to view a series of 3D spheres based on a single time snapshot (static model).

    Galaxies

    Code to make the PLY file for an N-body galaxy sim

    This code reads in 2-particle type galaxy data and makes a PLY file containing each particle as a colored vertex.

    Code to make the PLY file for a hydro galaxy sim

    This code reads in multi-particle type galaxy data and makes a PLY file containing each particle as a colored vertex. Make sure you have the "large galaxy data" from the resources list below for this code.

    Code for Galaxy Simulators: NOTE - Not well documented

    Convert galaxy merger HDF5 into text file

    Reads in Gadget-2/Gizmo/Arepo-like data and converts it to text file format. Also can be used to reduce the number of particles. So far, only 2 particle types, but more can be added by the user.

    Reads & decimates files

    Reads in SPH text file data and reduces the number of particles.

    Resources

    Planets

    Simple Mars Model

    This is a simple low-ish resolution sphere wrapped with a Mars texture map.

    Wavefront .obj file format

    Detailed wiki article about the Wavefront file format.

    Generic Planet Files + Texture Maps

    These are the files to go in your "generic_dir" to plot planets in 3D.

    Just a google search of planet maps

    This is just a google search for planet texture maps. Make sure they have widths about 1000-1200 pixels - bigger ones take up too much memory.

    Galaxies