Need a good explaination on how to create PIF files with Python

4 months ago by
Hello everyone! I am a student who is trying to do a foam-coarsening simulation. So I have been following the instructions on the quick start manual, but I did not figure out exactly what I must type and where, to generate PIF files with Python... So it would be really kind that someone explain it to me as it is really important for what I am trying to do!

4 Answers

4 months ago by
If you are working through the foam example in the quick start guide I believe there is a pif file already created for that, look for the file “foaminit2D.piff” in the folder “C:\CompuCell3D\Demos\CompuCellPythonTutorial\scientificHistBarPlots\Simulation”.

If you want to create your own piff file, either by hand or using Python, the format is pretty simple. Each line of a pif file has the same format:

      Cell_id Cell_type x_low x_high y_low y_high z_low z_high

Where Cell_id is a unique cell index (integer). A PIF may have multiple, possibly non-adjacent, lines starting with the same Cell_id; all lines with the same Cell_id define pixels of the same generalized cell. Cell_type is the name of the type of cell being described. The values x_low, x_high, y_low, y_high, z_low and z_high define rectangles (parallelepipeds in 3D) of pixels belonging to the cell. In the case of overlapping pixels, a later line overwrites pixels defined by earlier lines. The following line describes a 6 x 6-pixel square cell with cell index 0 and type Amoeba:

      0 Amoeba 10 15 10 15 0 0

The above could also be done with multiple lines, even one line per pixel, for example;

      0 Amoeba 10 10 10 10 0 0
      0 Amoeba 10 10 10 11 0 0
      0 Amoeba 10 10 10 12 0 0
      0 Amoeba 10 10 10 13 0 0
      0 Amoeba 10 10 10 14 0 0
      0 Amoeba 10 10 10 15 0 0
      0 Amoeba 10 11 10 10 0 0
      0 Amoeba 10 11 10 11 0 0
      0 Amoeba 10 11 10 12 0 0

Note that the reference point for the lattice is (0,0,0) so in the line “0 Amoeba 10 10 10 10 0 0” the pixel is the eleventh from the origin on both the X and Y axis.

In the file “foaminit2D.piff” the first lines are;

      0 Foam 0 13 0 5 0 0
      1 Foam 13 25 0 5 0 0
      2 Foam 25 39 0 5 0 0
      3 Foam 39 46 0 5 0 0
      4 Foam 46 57 0 5 0 0

These five lines define five separate cells (cell_id 0 through 4), all of cell_type “Foam”. The first cell is 14 pixels wide and 6 pixels tall and has one corner at the origin (0,0,0).
Thanks you so much for you reply, I discovered in /Simulation thanks to you a file named "Foam coarsening" who works really well. However, my real question was how do you generate PIF files with Python, it is merely written in the quick start guide that the script needs to take several arguments "./ -r -i -o -z -m. "but it is not really explained in simple words for me how it has to be written. Do you have any Python script to create PIF files so I could keep it but change the arguments?
written 4 months ago by Arthur M 
4 months ago by
What exactly are you trying to do? Are you trying to create your own pif file to use as input to CC3D? If that is the case the file format is as described above and you can use python or any other programming language to create the file. You can even create the file by hand in a text editor.

Once you've created a pif file you should put it in the Simulation folder for your project. To load the pif add the lines below to the cc3d porject's xml file;

<Steppable Type="PIFInitializer">

(Change your file name from "test" to something more informative.)
Yes I am trying to create my own PIF files: one to simulate a polydisperse foam and the other to simulate a monodisperse foam. I want to use Python to create the file, but I do not know what I must code exactly. I am not a Python expert especially to create files. That is why I was asking to you if you had any example of Python script to generate this file so I could change the parameters as I want.
written 4 months ago by Arthur M 
4 months ago by
Here is a simple python file to write to a pif. You'll need to change the path to fit your machine. You'll will need to write your own code to decide where the cells actually go.
### Script to write a CC3D PIFF file  J. Sluka
path="C:/Users/James Sluka/Desktop/Jims compucell/Piff and other python scripts"
pifFileName = path + "/" + pifname
print "pifFileName: " + pifFileName

pifFile= open(pifFileName,'w')

pifFile.write("0 red 0 10 0 10 0 0 \n") # cell id 1 is of type "red"
pifFile.write("1 small 20 30 5 15 0 0 \n") # cell id 2 is of type "small"

print "done"
Thank you very much, I will now try to set up a loop on your script so I could generate enough bubbles (I need approximately 120 bubbles in order to compare with my experiences made in laboratory) but this time I may do it by my own, you already helped me a lot!
written 4 months ago by Arthur M 
3 months ago by
If you can draw the layout you want in a program like MS Paint (or any program that can export a bit mapped image), I have a Python file that will convert that drawing into a PIFF file. You just draw all cells of one type the same color and outline all cells with a black lines. In the attached file the left image was drawn in a drawing program. It has tiny red cells, middle sized green cells and large blue cells, with individual cells outlined in black. My script converted the image to a PIFF. The results in CC3D is shown in the right hand image.

I finally managed to make my own monodisperse foam with the help of your Python script, but I have been struggling to make a really polydisperse foam.I know there is already a PIFF file (foaminit2D.piff) but it may be not enough polydisperse to compare his evolution with the evolution of the monodisperse foam (I want to highlight there are some kind of stages when the number of bubbles in a monodisperse foam decreases ), so your Python file would be very useful, thank you so much for your help!
written 3 months ago by Arthur M 
I think I have finally found a idea to write a Python script generating the polydisperse foam that I want, so I do not need your Python script working with MSPaint, but thank you a lot for your help!
written 3 months ago by Arthur M 
Please login to add an answer/comment or follow this question.

Similar posts:
Search »