Saturday, 18 May 2013

Using python to access netcdf files

I needed to write out some arrays in a binary format from a c program. I decided to use the netcdf libraries to store the files in a more structured format.

I also wanted to use python to do dome additional analysis. So I need a way to read netcdf files from the python scripting language. There are a number of different python libraries which can read netcdf files. After some exploration I decided to use Module netCDF4.

There are some good instructions on how to install the netcdf4 python module on Ubuntu.

First the hdf5 library needs to be installed

 gunzip  hdf5-1.8.11.tar.gz 
 tar xvf hdf5-1.8.11.tar 
 cd hdf5-1.8.11/

 ./configure --prefix=/usr/local --enable-shared --enable-hl
 sudo make install

Next the netcdf library needs to be installed.

 gunzip  netcdf-4.3.0.tar.gz
 tar xvf netcdf-4.3.0.tar 
 cd netcdf-4.3.0/
 LDFLAGS="-L/usr/local/lib CPPFLAGS=-I/usr/local/include"
 ./configure --enable-netcdf-4 --enable-dap --enable-shared --prefix=/usr/local
 sudo make install

Now finally we can install the python library. However first I needed to install a python library to compile against c code.
sudo apt-get install python-dev
sudo ldconfig
Now we need to install the python library.

gunzip netCDF4-1.0.4.tar.gz

tar xvf netCDF4-1.0.4.tar
cd netCDF4-1.0.4/

cp setup.cfg.template  setup.cfg

Then I needed to edit setup.cfg
python build
sudo python install

Friday, 8 February 2013

Reading physics papers on a kobo ebook reader

So I am on mission to do a way with paper copies of physics papers. Every day there are papers published on the Cornell archive site, but what is the best way to organise and read the papers?

Well my colleague in the next office to me came into my office to show me his new ebook reader. He had purchased a  kobo ebook 7 inch ebook reader, so that he could read physics papers.

You can see from the picture that the paper looks OK on this ereader. When I originally played with papers on my kindle, the plots looked like crap (see also). The reader below is high definition, so the graphs look OK on it. So high definition is the way to go.

There was a web browser on the device which he used to download the papers in pdf format.
The text looked a bit small, but it was readable. The next issue is how easy it is to organize the papers on the ereader. Does it allow tage? Can you annotate the papers? This is possible with books in ebook format.

Wednesday, 6 February 2013

Is there a better way to organize physics papers?

Part of doing physics research involves reading scientific papers. Typically the papers are printed out  to read later. Sometime if I am working on a specific project I will have a bunch of papers. After a while I end up with a big pile of papers in my office and in my flat. I do sometimes file things away. Many papers are printed off multiple times, because I can't always find the paper I need to read.

The most "famous" place with big piles of papers was John Ellis's office in CERN.

I have taken a number of papers with me to conferences for reference. But a big collection of papers is heavy and it is not so easy to read them on a plane.

There are some very good tools to collect papers online. For example I use citeulike.

I can't help feeling that both me and John Ellis need to be able to read and organize physics papers on a tablet or on the kindle. In later posts I will see what can be done with today's tablets.

Saturday, 26 January 2013

Hello world in scala

I am slowly reading Seven Languages in Seven Weeks. The book briefly describes 7 computer languages, with just enough detail to get the flavour of each language. Today I had a little play with scala The point is to learn new techniques that some languages make easier.

New smaller languages seem to be very popular at the moment. For example the software for twitter  was originally written in ruby, but as the site got bigger they rewrote it in scala. I see a lot of adverts for jobs in scala -- perhaps even at the BBC for the Iplayer. Scala is a mixed object oriented and functional language. It runs on the java VM.

I downloaded the scala run time stuff via the standard package manager from Ubuntu.
First off is to print hello world. I just followed the instructions on wikipedia.

So my first program.

ubuntu >cat HelloWorld.scala 
object HelloWorld extends App {
   println("Hello, World!")

Compile and run:

ubuntu >scalac HelloWorld.scala
ubuntu >scala -classpath . HelloWorld
Hello, World!