Archive

Archive for October, 2011

Using paraview as a post-processor.

October 19th, 2011 No comments

I reviewed paraview about two years ago, and I more or less lambasted it for not being very well documented and that the mailing list was not as responsive to “beginners” questions as one might imagine. Some of the examples on the wiki also did not work back then. I have been quietly monitoring and occasionally evaluating paraview to see how it has been improving. In one of the recent versions this year, they actually released the user guide/handbook, which contains some useful information. The file reader formats have greatly improved and a lot of the features rival that of tecplot, which is not free.

While my research lab recently acquired Abaqus, all of my dissertation code is in the Finite Element Analysis Program (FEAP) from Berkeley. It was written mainly by Robert Taylor (one of the Godfathers of finite elements) and by Sanjay Govindjee. It is a pretty good code, and is written mainly in Fortran/C. Unfortunately, while it includes some sophisticated numerical schemes and efficient solvers, it does not provide much in terms of pre- and post-processing for finite elements. In the past we used Ansys to generate meshes, and manipulated the boundary conditions by hand. However, we have since then, obtained patient-specific heart meshes, and the number of nodes is much larger and the geometry/numbering is not so obvious.

Fortunately, paraview has some powerful selection filters and tools available. Unfortunately, after each selection the number of elements and nodes is renumbered. Paraview actually keeps track of the global id’s but for some reason it is filtered out from the spreadsheet view by default. However this can be changed easily. To use paraview as a pre-processor, the idea is to use successive “Extract Selection” filters after using the “Fustrum” or “Surface” selection tool for nodes/elements in the Selection Toolbar. One should think of it as taking the original mesh, and then slicing or cutting away the parts that are not of interest until you are left with only what you want. Lastly, in the selection explorer, you can also select “Invert Selection”, which effectively allows you to select the portion you want to “cut-away” from the mesh.

The following are instructions to perform this pre-processing selection using paraview.

  1. If not already done, go to Preferences > Charts. Then delete the line that says “vtkOriginalIds” that is in the “hidden” list. This will show the “vtkOriginalIds” value in the spreadsheet view and allow you to “Save Data” on each “Extract Selection”, such that one will get a mapping from vtkOriginalIds to the renumbered fields.
  2. Use the provided selection tools, and “Extract Selection” successively until you arrive at the selection you want.
  3. Click on each “Extract Selection” filter and click on File > Save Data. Select a filename, and make sure to specify either Point/Cell/Field data so you save the proper mapping.
  4. Next you can use the following python script to get the proper mapping using 0-index numbering (paraview indexing). The script takes in a list of “Extraction Selection” csv files and an outputfilename for the global id mapping.
Script source is below:
import os,sys
 
def parse(args):
    extractions, outputfile = map(open,args[:-1]),open(args[-1],"w")
 
    ids = []
    newids = []
 
    for extraction in extractions:
        origids = []
        for line in (extraction.readlines())[1:]:
            orig= line.split(",")[0]
            origids.append(int(orig))
 
        # if ids is filled map rewrite ids accor
        if len(ids) > 0:
           for id in range(len(origids)):
               origids[id] = ids[origids[id]]
 
        ids = origids
 
    for id in ids:
        outputfile.write("%d\n" % (id))
 
    outputfile.close()      
 
if __name__=="__main__":
    parse(sys.argv[1:])

SCPD stream “re-encoding” mencoder to save space

October 15th, 2011 7 comments

The SCPD downloading script posted several years back seems to use some interesting mencoder encoder and so there always appears to be extra information packaged in the video file. Unfortunately, I needed to reduce the size of the streams and it appears that by using ffmpeg and extract the audio and video, and then muxing it back together seems to reduce the overhead file size by about 100 Mb.

I’ve included a simple bash script which you can modify below which takes a list of past streams to re-process (for windows you will need do figure out the dos equivalent). There doesn’t seem to be any loss in video quality and sound quality seems fine, so it seems like a free win.

Note: I have tried using x264 with high10 encoding, but it seems I cannot get the x264 10-bit compilation to produce proper ts video. The windows x264 10-bit from x264.nl seems to do a perfectly fine job, and ffmpeg in linux can then mux it with the audio, but using the linux compiled 10-bit, there seems to be problems with muxing it in ffmpeg, although the actual video only encode works as it should. If both can be used in conjuction, perhaps one could even attain a smaller file size by using 10-bit compression and the reduction in overhead explained here.

while [ -n "$1" ]
do
    echo "$1"
    ffmpeg -threads 0 -i $1 -vn -acodec copy $1.wma
    ffmpeg -threads 0 -i $1 -an -vcodec copy $1.wmv
    ffmpeg -threads 0 -async 1 -i $1.wma -i $1.wmv -vcodec copy $1.mkv
    rm -rf $1.wma $1.wmv
    shift
done

For those of you that interested in 10-bit encoding with the profile high10 in x264 here are some snippets:

# x264 --threads 0 --profile high10 -o $1.264 $1                                
# ffmpeg -threads 0 -i $1 -vn -acodec copy $1.wma                               
# ffmpeg -async 1 -threads 0 -i $1.264 -i $1.wma  -vcodec copy $1.final.mp4
Categories: Uncategorized Tags: , , ,