Physics, Python programming, Miscellaneous geekness

Hailstone pics

Just for reference, I need to link to the recent news reports about the big storm we had last week, which used my photo.

Pasting syntax-highlighted code

I just found this guide on pasting syntax highlighted code (escaped with this form) into Blogger blogs. It's probably not all that useful, but anyway, let's give it a go with a function I use to read a binary file output by xmds into Python:

def read_file(indat_fname, xsil_fname):
# get datafile name and precisions
if got_lxml:
with open(xsil_fname) as xml:
xsil = objectify.parse(xml).getroot()
ulong_len = xsil.XSIL.Array[1].Stream.Metalink.get("UnsignedLong")
precision = xsil.XSIL.Array[1].Stream.Metalink.get("precision")
xml = open(xsil_fname).read()
ulong_len = str(xml2obj.xml2obj(xml).XSIL[0].Array[1].Stream.Metalink.UnsignedLong)
precision = str(xml2obj.xml2obj(xml).XSIL[0].Array[1].Stream.Metalink.precision)
ulong_type = {'uint32':'<u4','uint64':'<u8'}[ulong_len]
float_type = {'single':'<f4','double':'<f8'}[precision]

with open(indat_fname,'rb') as f:
xlen = fromfile(f, ulong_type, 1)[0]
xs = fromfile(f, float_type, xlen)
ylen = fromfile(f, ulong_type, 1)[0]
ys = fromfile(f, float_type, ylen)
zlen = fromfile(f, ulong_type, 1)[0]
zs = fromfile(f, float_type, zlen)

rlen1 = fromfile(f, ulong_type, 1)[0]
reals1 = fromfile(f, float_type, rlen1)
ilen1 = fromfile(f, ulong_type, 1)[0]
imags1 = fromfile(f, float_type, ilen1)
psi1 = (reals1+1j*imags1).astype(np.complex64).reshape(xlen,ylen,zlen)
del reals1, imags1

rlen2 = fromfile(f, ulong_type, 1)[0]
reals2 = fromfile(f, float_type, rlen2)
ilen2 = fromfile(f, ulong_type, 1)[0]
imags2 = fromfile(f, float_type, ilen2)
psi2 = (reals2+1j*imags2).astype(np.complex64).reshape(xlen,ylen,zlen)
del reals2, imags2

return psi1, psi2

which sort of works, except for the wrapping - maybe I did something wrong with the template. I'll have another go one day (maybe)

Origami documentary

I just watched an incredible documentary called "Between the Folds" on the art and science of origami. There was something about it that fired my "inspiration" centre. I need to put this aside for now, what with thesis writing, but I must it again later and look into the subjects of that film.

Changing the eSlick text font

On the Foxit eSlick Forum are various somewhat unclear instructions for changing the text font. To be explicit, the steps are:
1. Create a folder named "Fonts" in the root folder of the eSlick's internal memory.
2. Find a Truetype font, i.e. a *.ttf font - I used the Gentium Book Basic font.
3. Rename "GenBkBasR.ttf" (or whatever) to "fxfont.ttc" and copy it to the "Fonts" folder.
4. Reset the eSlick by depressing the recessed Reset switch on its back whilst it is powered on.

Chickens and eggs of physics

Whilst listening today to the ABC science show, I mused on the following (poorly thought-out) inequities of science communication.

Astronomers and paleontoligists have an advantage over the rest of us trying to communicate our science in that they can assume a greater level of knowledge amongst the general public. Thus they get to explain more of what's new to the general public within a given amount of time. Is this why Catalyst seem to have an overrepresentation of stories on astronomy and dinosours? Or is it because two of their prominent reporters have backgrounds in these areas? Probably the latter. However, experience of dealing with Monash media and marketing people, would tend to support me, so I'll stand by my suspicion that there is a bias.

Astronomers like to talk about how big things are, how old things are, how far away things are ... in short how far from everyday experience the things they study are. I also do this when talking to people about my research, because this is what "bends their minds". Luckily I at least work in an are where I can explain how small things are, which gives me a "hook". However, I often think that this distorts the intrinsic value of all the other things that I (and other scientists) encounter in research - many of the beautiful parts of my research are simply too hard to explain to non-specialists without also relating a significant number of background concepts.

By the way, Paleontologists like to talk about how big dinosaurs were, how long ago they lived, how easily they could crush a human skull etc.

Some interesting articles

The latest Edge has an interesting article. I like
this one arguing against Gardner's theory of Multiple Intelligences in favour of a single useful measure "g", which is presumably IQ. The argument is that the curriculum in schools is pandering to Gardner's labels, which aren't orthogonal. I tend to agree that this is a problem, but I wonder whether a roughly-orthogonal set could be found using proper research and data mining or Principle Component Analysis techniques.

Guide to reducing borders around text in a pdf

OK, here’s a howto on using LaTeX with the pdfpages package to strip whitespace from around the text of an existing pdf document. Say you have a pdf with a large blank marginspace around the text. The following LaTeX file will make a new version. Unfortunately, it will lose any bookmarks, links etc. I usually run it with pages={-8} to process just a few pages, tweaking the offset and scale values until it’s stripping out the bits I want, then change back to pages={-} or maybe a different page range to strip out any guff you don’t want. It’ll also let you glue together multiple pdfs into one file.

\includepdf[pages={-},offset=0mm -5mm,scale=1.3,pagecommand={}]{”pdf_file_name”}