Friday, 29 May 2015

Compiling matplotlib from source, freetype dependence problem

This tutorial applies to matplotlib version 1.4.3 and freetype >= 2.3. This tutorial describes how to install matplotlib and freetype to my $HOME/.local directory.

If you're installing matplotlib locally, like this (for example):
python setup.py install --prefix=/home/xbaker/.local/
you might run into the common problem of resolving a freetype dependence. Check your freetype version:
freetype-config --ftversion
I have version 2.2.1, but matplotlib requires at least 2.3. First we have to install a newer version of freetype. Download the source here:
http://sourceforge.net/projects/freetype/files/freetype2/
Unzip and install (I'm installing to my .local directory).
./configure --prefix=$HOME/.local
make
make install
Now we need to download and configure matplotlib. Download the source from here:
https://github.com/matplotlib/matplotlib/releases
When I attempted to install matplotlib directly:
python setup.py install --prefix=/home/xbaker/.local/
the build failed, saying that it still detected the old version of freetype on the system. The solution has two parts: first we inform python of the freetype version, then we fix the matplotlib script to ignore the old version. The first step comes from
http://mattshirley.com/compiling-matplotlib-with-custom-freetype-and-png-libraries
export PKG_CONFIG_PATH=/home/matt/.local
Unzip and look for the setupext.py file (it's in the root of the extracted archive). Edit the file, looking for lines 948-951:
Once the script


Thursday, 21 June 2012

Response to 'Women Medical Physicists'


The Denial


LinkedIn Groups

  • Group: Women Medical Physicists
  • Subject: Your request to join Women Medical Physicists
Thank you for your interest in the Women Medical Physicists LinkedIn Group. At this time our policy is that only women medical physics students and practicing clinical or research medical physicists who are women will be granted membership. The intent behind this policy is to establish a "community" of women medical physicists who can work toward improving the professional lives of women working in this field. 

We appreciate your understanding and if we have incorrectly assessed that you do not fall within the group cited above, please do not hesitate to contact us.

Best regards,

Nicole Ranger
Azam Niroomand-Rand
azam@georgetown.edu
Moderators
Women Medical Physicists Group @ LinkedIn.com 


My Response


Dr. Niroomand-Rad,

"if we have incorrectly assessed that you do not fall within the group cited above..."
Since I'm a medical physics student, I think you mean to say, "if I'm not a woman."

Discriminating by gender does your group a great disservice.  Not only insofar as your group's response to sexism is sexism itself, but because having a good ally does not necessarily mean having an ally of the same gender.  Seems to me that your purported goal to create a community "who can work toward improving the professional lives of women working in [medical physics]" will only be hampered by your unwillingness to include all of your allies.  Particularly a group so prevalent in medical physics today: men.

Please take this into humble consideration with regards to your policy,

Mark

Thursday, 2 February 2012

32bit VMC++ on 64bit Architecture

In trying to migrate to a 64-bit architecture, I found that the 64-bit version of my (closed source) executable was corrupt.  But, since I still had a 32-bit version, it was no problem to setup the necessary 32-bit libraries and use the 32-bit version of my executable.  I am using Ubuntu 10.04 to illustrate this procedure.

First we must install the libraries needed by our executable.  If you run this on the command line:
ldd executable_filename
linux-gate.so.1 => not found
libvmcpp.so (0xf7677000)
libm.so.6 => not found
libgcc_s.so.1 =>not found
libc.so.6 => not found
libdl.so.2 => not found
libpthread.so.0 => not found
/lib/ld-linux.so.2 (0xf7712000)
libstdc++.so.5 => not found
you see all of the dynamic libraries on which this binary depends.  In my example, most of the needed libraries can't be found.  Install the ia32-libs package:
sudo apt-get install ia32-libs
This will satisfy most dependencies, but there is just one left for vmc++: libstdc++.so.5.  In previous Ubuntu versions, this library was packaged with ia32-libs package.  This problem already has an associated bug, but it sounds like we won't see a fix.  So, here is the way to get the 32-bit version of that last package (derived from this thread):
  1. Go to the Ubuntu package database
  2. Download the i386 version of the .deb (which is an archive containing the library we need)
  3. Extract the contents of the .deb file with this command:
    ar vx libstdc++5_3.3.6-15ubuntu4_i386.deb
  4. Copy the libstdc++.so.5.0.7 file to /usr/lib32/
    sudo cp libstdc++.so.5.0.7 /usr/lib32/.
  5. Create a symbolic link with the standard name
    sudo ln -s /usr/lib32/libstdc++.so.5.0.7 /usr/lib32/libstdc++.so.5
Try to run your executable again: it should automatically detect the presence of the new libraries.  Yay!

Tuesday, 13 December 2011

Compile dosxyz_show on Ubuntu (10.04, 14.04)

I was surprised to find that this program does't come compiled with BEAM (or other EGSnrc packages) nor does it come packaged using the autotools suite.  Well, we can easily make up for this by compiling it the old fashioned way.  Sadly, whatever functionality autotools would normally provide, we must now provide ourselves.  So get ready and relax, this won't be too painful.

Before this will work, you must have installed EGSnrc (this is where the source for dosxyz_show is found).  Go to the source for dosxyz_show, found in
cd $HEN_HOUSE/omega/progs/dosxyz_show/
The only files present here are the Makefile (which holds the details needed by the compiler) and the .c file (which holds the code to be compiled).  Like every good linux user, I tried running this on the command line as soon as I saw the Makefile:
make
If everything were fine, this should work and then you are done installing dosxyz_show.  Unfortunately for me, the following error chain was produced (I removed many lines from this output because it was too long!):
gcc -O2  -I/usr/X11R6/include  -o /home/xxxxxx/HEN_HOUSE/bin/i686-pc-linux-gnu-/dosxyz_show -L/usr/X11R6/lib  dosxyz_show.c -lXm -lXt -lX11 -lmdosxyz_show.c:46:22: error: Xm/XmAll.h: No such file or directorydosxyz_show.c:101: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘NoName_status’dosxyz_show.c:109: error...
Looking at the first error:
Xm/XmAll.h: No such file or directory
It is clear that a library is missing.  So I went to the NRC site for dosxyz_show and found that I needed to add the Motif libraries.  The documentation recommended installing LessTif, an open-source equivalent.  In fact, it is not equivalent (which can be validated by looking through the files in the package... some includes we will need are missing at least).  A google search for the file name revealed a file listing for the package libmotif-dev.  So we install that, naively assuming that it's the correct package:
sudo apt-get install libmotif-dev
I also noticed that the default paths in the Makefile were not appropriate for Ubuntu.  In particular, we see this in the Makefile:
X11_include = -I/usr/X11R6/include
# On our system, Motif include files are in /usr/X11R6/include/Xm =>
# we don't need a separate -I for Motif. If this is different on your
# system, adjust accordingly.
Motif_include =
X11_libdir = -L/usr/X11R6/lib
# On our system, the Motif library is /usr/X11R6/lib =>
# we don't need a separate -L for Motif. If this is different on your
# system, adjust accordingly.
Motif_libdir =
Searching for the directories listed above reveals that they do not exist.  OK, lets set the paths correctly. Use these settings instead:
X11_include = -I/usr/include/X11
# On our system, Motif include files are in /usr/X11R6/include/Xm =>
# we don't need a separate -I for Motif. If this is different on your
# system, adjust accordingly.
Motif_include =
X11_libdir = -L/usr/lib/X11
# On our system, the Motif library is /usr/X11R6/lib =>
# we don't need a separate -L for Motif. If this is different on your
# system, adjust accordingly.
Motif_libdir =
Now we compile again
make
If you're using Ubuntu 14.04, that may have been sufficient. However, I sometimes get the following error:

In file included from /usr/include/Xm/XmAll.h:33:0,
                 from dosxyz_show.c:34:
/usr/include/Xm/Xm.h:59:27: fatal error: X11/Intrinsic.h: No such file or directory
 #include <X11/Intrinsic.h>

Which can be solved by installing libxt-dev:

sudo apt-get install libxt-dev
make 

If you've added the environment variables suggested during the EGS install, the path to the executable should already be in your path (check this by trying to auto-complete dosxyz_show on the shell).

If you're using Ubuntu 10.04, you should end up with a new error!  Progress!
gcc -O2  -I/usr/X11R6/include  -o /home/xxxxxxx/HEN_HOUSE/bin/i686-pc-linux-gnu-/dosxyz_show -L/usr/X11R6/lib  dosxyz_show.c -lXm -lXt -lX11 -lmIn file included from /usr/include/Xm/XmAll.h:46,                 from dosxyz_show.c:46:/usr/include/Xm/Xm.h:59:34: error: X11/extensions/Print.h: No such file or directoryIn file included from /usr/include/Xm/XmAll.h:46,                 from dosxyz_show.c:46:/usr/include/Xm/Xm.h:827: error: expected specifier-qualifier-list before ‘XPContext’In file included from /usr/include/Xm/XmAll.h:86,                 from dosxyz_show.c:46:/usr/include/Xm/Print.h:46...
Identifying the first error:
X11/extensions/Print.h: No such file or directory
it is clear that my package installation didn't fully do the trick.  Another google search for the error revealed that I can search for the packages containing a certain file using apt-file.  So we set that up and look for our file (it may take a minute or so to update the apt-file index):
sudo apt-get install apt-file
sudo apt-file update
apt-file search X11/extensions/Print.h
x11proto-print-dev: usr/include/X11/extensions/Print.h
The search reveals that the file is in the x11proto-print-dev package.  We install it:
sudo apt-get install x11proto-print-dev
and we try to build again, with complete success (nevermind all the warnings about fscanf):
gcc -O2  -I/usr/include/X11  -o /home/xbaker/staging/beamnrc/HEN_HOUSE/bin/i686-pc-linux-gnu-/dosxyz_show -L/usr/lib/X11  dosxyz_show.c -lXm -lXt -lX11 -lmdosxyz_show.c: In function ‘get_data’:dosxyz_show.c:1280: warning: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result...
The binary executable produced by the compilation process must be made executable, and then you can run it:
cd $HEN_HOUSE/omega/progs/dosxyz_show 
chmod u+x dosxyz_show
./dosxyz_show <EGSPHANT> <3DDOSE>
Done!

Wednesday, 7 December 2011

Ensuring vmc++ has the standard library

The short answer:

If you're getting an error like this:
./vmcpp: error while loading shared libraries: libstdc++.so.5: cannot open shared object file: No such file or directory
while running VMC++, then you need to add gcc-3.3 to your system, which adds the missing library file mentioned in the error.  In Ubuntu, you can fix this by adding this line to your /etc/apt/sources.list file (choose your mirror from http://packages.ubuntu.com/hardy/i386/libstdc++5/download):

deb http://ubuntu.wikimedia.org/ubuntu/ hardy main universe

and then opening synaptic, reloading, and installing the libstdc++5 package:
sudo apt-get install libstdc++5


More details

In my version of Ubuntu (10.04 lucid), the standard c++ library is the one that comes packaged with gcc-4.4. Unfortunately, the version of the VMC++ monte carlo package that I have was compiled with an older version of gcc. Here is the message I received:
 ./vmcpp: error while loading shared libraries: libvmcpp.so: cannot open shared object file: No such file or directory 
Ooops, that's actually the first error I received while running the program. That simply requires the addition of the lib files that came with the VMC++ executable (including libphsp_source.so, libsimple_source.so, libvmcpp.so) to your system's library path.  If you don't want to install them the 'correct' way, you can get away with adding their directory to the environment variable LD_LIBRARY_PATH, like this (in bash):
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:`pwd` 
Indeed, the real error I received was this:
./vmcpp: error while loading shared libraries: libstdc++.so.5: cannot open shared object file: No such file or directory
This required some digging.  A Google search revealed the Ubuntu repositories containing my desired package (libstdc++5).  After choosing the package (the one with /usr/lib/libstdc++.so.5 for my system) and -- on the next page -- my architecture (i386), I was guided to the download location.  I added the appropriate line to my /etc/apt/sources.list file, reloaded my synaptic, then installed the package libstdc++5.

Wednesday, 6 July 2011

Using dcm4che to read image data: installing JAI

This tutorial describes the installation of JAI in Ubuntu, though it should work for any flavour of linux.  Reading jpg formatted images from a dicom file is easy with dcm4che:


To use this package to read image data from dicom files in this way:

http://forums.dcm4che.org/jiveforums/message.jspa?messageID=17102#17102
http://samucs.blogspot.com/2008/03/converting-dicom-to-jpeg-using-dcm4che.html

requires the installation of the Java Advanced Imaging (JAI) package.  Sadly, JAI is no longer being developed, so very few efforts are being made to improve accessibility to these packages.  However, nothing is easy to find anymore, as you can read from the testimonials in this thread:

http://forums.dcm4che.org/jiveforums/message.jspa?messageID=14576

Despite this, Java has a new place where the source code is being stored:

http://java.net/projects/jai-imageio

But we aren't going to compile this from source today because we have access (for now, at least) to the pre-made jars we require.  As First, download the jai-imageio build which is appropriate to your architecture from here:

http://download.java.net/media/jai-imageio/builds/release/1.1/

Since I'm using Ubuntu (10.10), I selected

jai_imageio-1_1-lib-linux-i586-jdk.bin

from the list.  I opened a terminal and (as the root user) went to the location of my java install.

sudo -i
cd /usr/lib/jvm/java-6-openjdk

At this location you should find a 'jre' directory.  Copy over the file you downloaded above into this directory and then add the witchcraft which follows (this is all BASH):

cp /home/myUsename/Downloads/jai_imageio-1_1-lib-linux-i586-jdk.bin .

chmod a+x jai_imageio-1_1-lib-linux-i586-jdk.bin

_POSIX2_VERSION=199209
export _POSIX2_VERSION

./jai_imageio-1_1-lib-linux-i586-jdk.bin

This sets the POSIX version for the compatibility of the 'tail' command used by the installer.  Don't blame me for that POSIX crap, it's because no one has updated this installer since the time when you couldn't use 'tail +5' (nowadays you have to use 'tail -5' to do the same thing).  Anyway, proceed through the installer and you should be left with these new files:



  inflating: COPYRIGHT-jai_imageio.txt
  inflating: DISTRIBUTIONREADME-jai_imageio.txt
  inflating: ENTITLEMENT-jai_imageio.txt
  inflating: LICENSE-jai_imageio.txt
  inflating: THIRDPARTYLICENSEREADME-jai_imageio.txt
  inflating: UNINSTALL-jai_imageio
  inflating: jre/lib/i386/libclib_jiio.so
  inflating: jre/lib/ext/jai_imageio.jar
  inflating: jre/lib/ext/clibwrapper_jiio.jar




All done!

Monday, 30 May 2011

3D Plotting in Java (Ubuntu with JOGL and jzy3d)

A quick google search and StackOverflow check revealed two appropriate Java packages for displaying surface plots.  One uses OpenGL, and the other does not.  Since I want maximal functionality for verifying the data visually, I'm going with the OpenGL implementation.

Originally, I tried building the library myself, but the resulting jars didn't seem to contain the correct class information (or they were broken, though the build was successful).  Some links related to this method are found below.

In ubuntu, open synaptic and install this package (as instucted in http://ubuntuforums.org/showthread.php?t=1670765):
libjogl-java
This will add two libraries to your /usr/share/java directory, namely jogl.jar and gluegen-rt.jar.  In eclipse, add these libraries to your build path, then associate the native libraries (which were also automatically installed with libjogl-java) with those jars.  I found out (from http://forum.worldwindcentral.com/archive/index.php?t-21608.html) that these libraries are stored in /usr/lib/jni.  Specify that path as the native library path in Eclipse.

Then you can add the jzy3d jar to your class and you can start drawing with the tutorials found here:


You'll also need the syntax for drawing the Chart objects from jzy3d in AWT/Swing containers:

http://code.google.com/p/jzy3d/wiki/EmbeddingChartInAnExistingApplication