Showing posts with label software. Show all posts
Showing posts with label software. Show all posts

Sunday, 25 April 2010

Using a blog as a Logbook

Last productivity post for a while I promise, then back to proper physics.

I'm trying out using a private blog (secured and unlisted etc) as a logbook. Logbooks are so important, the first time you realise you need one it's too late. My reasoning for going online goes:
  1. I can access from anywhere, including emailing in posts from my phone. For example I could take a photo of a whiteboard discussion and send it to the blog so I won't forget about it.
  2.  It's safely backed up on the servers of whoever's hosting it.
  3. I'm more likely to actually make entries because it's easy.
  4. A blog is much like a logbook anyway so it's naturally suited.
I can see some downsides but they're all pretty minor. Security could be an issue but how sensitive is the information you put in your logbook? Well mine isn't much, I don't want to accidentally broadcast my latest idea but it wouldn't cause a new climategate or anything. Besides, I think it's pretty secure.

I've chosen to use WordPress for my logbook for one simple reason. The LaTeX integration is fantastic. It's so good I'd consider moving this blog if it wasn't such a pain (for the record I otherwise like blogger). In wordpress you do this:

I will now insert an equation here, $latex E=mc^2$, inline with the text.

which would look like
although the superscripts do appear to have messed up the alignment... Otherwise it does a brilliant job at interpreting the tex and inserting the image. If you need a lot of LaTeX then there are programmes that convert between regular .tex files and the wordpress format.

There are similar things available for blogger but I think you lose your source code in a more drastic way. Anyway, I'm going to see how it goes.

Wednesday, 21 April 2010

Pipes and Python

I spent ages writing a post about some tricks I use to do quick analysis of data but it got incredibly bloated and started waffling about work flows and so on. Anyway, I woke up from that nightmare so I thought I'd just bash out a couple of my top tips.

This is a pretty nerdy post, you may want to back away slowly.

Pipes
Pipes are, in my opinion, why the command line will reign for many years to come. Using the pipe I can quickly process my data by passing it between different programmes gradually refining it as it goes. Here's an example that makes a histogram (from a Bash terminal):

> cat myfile.data | awk 'NR>100 {print $5}' | histogram | xmgrace -pipe

The first command prints the data file. The | is the pipe, this redirects the output to the next programme, Awk, which here we are simply using to pick out the 5th column for all rows over 100 and print the result. Our pruned data is piped down the line to a programme I made called histogram which does the histogram and outputs the final result to my favourite plotting programme to have a look at it.

So we've used three programmes with a single "one liner" (some of my one-liners become ginormous). Once you start getting the hang of this sort of daisy chaining it can speed things up incredibly. One bit that took me a while the first time was the histogram programme. This took an annoying amount of time to set up because I used C.

This is where Python now comes in.

Python

I won't even try to give a Python tutorial. I'm a decade late to the party and have barely scratched the surface. However, I've found that for relatively little effort you can get access to thousands of functions, libraries and even graphics. Most importantly you can quickly write a programme, pipe in some data, and do sophisticated analysis on it.

With the scipy and numpy libraries I've done root-finding and integration. The pylab module seems to provide many of the functions you'd get in MatLab. Python is a bit of a missing link for me, it's much lighter than huge programmes like Mathematica or MatLab and I just get things done quickly. Here's that histogram programme, Python style.


#! /usr/bin/env python
import sys
import pylab
import numpy

# Check the inputs from the command line
if len(sys.argv)!=3:
   print "Must provide file name and number of bins"
   sys.exit(1)

# Read in the data file
f = open(sys.argv[1],'r')
histo=[]
for line in f.readlines():
   histo.append(map(float, line.split()))

dimension = len(histo[0])

if dimension == 1:
   pylab.hist(histo, bins=int(sys.argv[2]))

   pylab.xlabel("x")
   pylab.ylabel("N(x)")
   pylab.show()

elif dimension == 2:
   # Need to chop up the histo list into two 1D lists
   x=[]
   y=[]
   for val in histo:
      x.append(val[0])
      y.append(val[1])

   # This function is apparently straight out of MatLab
   # I killed most of the options
   pylab.hexbin(x, y, gridsize = int(sys.argv[2]))

   pylab.show()


Which conveniently detects how many dimensions we're histogramming in so you don't need two programmes. This is pretty short for a programme that does what it does.

I hate wasting my time trying to do something that my brain imagined hours ago. I wouldn't say that these techniques are super easy, but once you've learned the tools they are quick to reuse. I'd say they're as important to my work now as knowing C. Got any good tricks? Leave a comment.

Something less nerdy next week I promise.

Wednesday, 9 December 2009

Backup news

Anyone that's been here from the start will know I have a slightly unhealthy obsession with backups.  A couple of things have changed since I last blogged about this.

Time Machine
Firstly, I now have a mac at home and I've started using Time Machine. I don't want to pat Apple on the back too much because that really gets of my nerves, but Time Machine is absolutely fantastic.

It's exactly how personal backup software should work. You buy an external hard disk, tell Time Machine to backup there, and then you're done. You never need to worry about it again. Most of the time when I need my backup it's because I've accidentally deleted something I shouldn't. Time Machine allows you to, as the name suggests, just go back in time and find it before you made the mistake. Works like a dream.

After a botched attempt to upgrade to Snow Leopard I recently had my first call to do a complete system restore. All I can say is that it seemed to work perfectly for me - it didn't even take that long.


Rsync + windows
At work we backup to an external file server. Until recently that was Linux based and so I had no trouble using Rsync. Now we've been moved to a Windows server which creates all kinds of problems. Rsync just doesn't get on with Windows. Anyway, after a bit of poking around I finally have a script that does the job. This is my basic rsync call now:

rsync -rptgoDhpP --modify-window=1 --delete --log-file=RSYNCLOG --exclude-from=./exclude /home/username/ username

I'm pretty sure most of those options could be replaced with the -a but honestly, now it's working I don't want to touch it! The key command is the modify-window. This accounts for the different way that Windows and Unix file systems time stamp modified files.

SVN - Subversion
For programming and writing papers (in LaTeX) I've started using subversion to take care of version control. I'm also using a shared repository to co-write a paper at the moment - it handles simultaneous editing quite well. There is a start up cost in getting your head around how it works, I found this page very helpful, but once you're there it works very nicely.

I mention it here because the version control works a bit like a backup. You can step back through committed versions very easily. If you use OS X then it's installed along with XCode so you probably have it. With Linux it'll be in the standard repositories.

Well that's enough backup geekery for this year. Anyone using anything that they're particularly happy with? I've kind of given up on backing up over the internet for now but would be interested if there's been any developments.

Sunday, 31 August 2008

Mac vs. PC vs. Linux

When I started my new job I was given the option of having an iMac instead of the standard issue Linux PC. They're really nice looking machines and I'd seen the impressive iSight in action so I went for it. I'm a seasoned windows user (from home), Linux user (from the PhD) and after a month getting all my work up and running on the mac I'd say I'm approaching blanket coverage of the major operating systems. Most importantly I'm now in a position to tell those people who get on their high horse about their particular OS to shut up.

Because that's what's always got on my nerves the most. Linux is a lot better than windows in many respects, but a lot worse in many others. The same goes for OS X. It depends what you're doing. Take my work for example: I'm a theoretical physicist and these days the majority of my work is numerical which means getting rather large computers to perform simulations of things rattling about, over and over and over again. All these big computers use Linux and so it's easier if your systems match. More than that though, Linux has a ton of software that is designed exactly for my needs, X-forwarding is great and its heavy use of the command line is much more efficient.

If you got into computers after Windows 95 and you don't like to fiddle under the bonnet then the chances are you won't ever use the command line. This isn't a shame in itself, it's up to you how you use your computer, but it's a shame that your choice is removed because the windows command prompt is so useless. Once you get going with a good command line interface it can make a real difference to your productivity (see for example Imagemagick).

So for work I'll (hopefully) never use Windows again. At home it's a different story. At home I use the web, edit photos and play music. Linux does all this but Windows has a better look and feel. Windows works better with my laptop's hardware (and peripharels) and there is a ton of good general software made for it. In my opinion its best bit of software is Windows Media Player. This is easily the best music player available (codec problems ruin the video playing). It's great for organising music, automatically finding artwork, creating playlists, quick search, seamless playback - the list goes on. It is infinitely better than the terrible iTunes. iTunes feels like it's actively trying to make me angry. I think it's designed to annoy you into only getting your music from the iTunes store. I'm constantly searching the net on how to get it to do this or that, WMP just does it.

Security is the top thing usually thrown at Windows. I go with the usual argument that it's just because there are more Windows PCs than anything else. Get complacent with your mac or Linux box and you'll wind up the same.

So what about the mac? Well Apple have been clever and maintained support for all things unixy (it is based on unix). This means that most of the good Linux features are supported, it does X11 so I can use most Linux programs, I can SSH into it (remote login) and so on. On top of this is has the better look and feel, it runs proprietary stuff like MS Office and it's got the best video chat facility by a mile. Apple (or maybe it's mac users themselves) always seem to be chipping away at improving the user interface. Things like exposé or Quicksilver are good examples. I'm very impressed with my iMac, it's a very neat piece of kit indeed.

Bad things about the mac are well documented. Hardware is expensive and exclusive, in many ways you're buying into a much worse monopoly than Microsoft. You won't be as compatible with everyone else (not a big deal these days), oh, and did I mention how much I hate iTunes? This shouldn't matter but Apple devotees tend to get on my nerves. I think there's a lot of fashion about owning a mac. They're always banging on the MS steal this or that. Honestly, get over yourselves. Everyone's iterating towards a better thing and Apple have reused plenty of ideas themselves (eg. spaces).

If I was buying a new laptop tomorrow I'd go for a mac. For me it covers the maximum amount of my daily stuff and I do like the interface. In general I would only recommend it if you know why you want to spend that bit more. I don't think Linux is ready to be my only OS just yet but I'll always run it on the side. The bottom line is they all do the job, they all crash (despite what people say), but most importantly of all they all run firefox so you won't really notice the difference most of the time.