Showing posts with label scripts. Show all posts
Showing posts with label scripts. Show all posts

Monday, May 10, 2010

Setting Thresholds

I've made a file to use for setting the thresholds. It is objects in Erin's median seeing file (../boss/boss-qso-stripe82median.fits) that are in the following ra/dec ranges:

(-1 < dec ≤ 1) and
(0 < ra ≤ 1) or (20 < ra ≤ 21) or (40 < ra ≤ 41) or
(320 < ra ≤ 321) or (340 < ra ≤ 341) or (359 ≤ ra < 360)

The area of this file is 2 (degrees in dec) × 6 (degrees in ra) = 12 deg2.
The number of targets in this file 43,134.

Ra/Dec of Threshold Targets
<

I modified the likelihood.script to take as an argument the directory to store the likefile*.fits. So now when you run the likelihood.script you do the following:
./likelihood.script thisrundirectory

This will stores all the likefile*.fits and qsub*.out files in the directory ../likelihood/thisrundirectory

If you don't give the likelihood.script a directory argument it will write in the current directory.

I have found a problem that not all the Stripe-82 quasars in the 3pc catalog are in Erin's median seeing targets catalog. I've pinged him about this. We'll see if he has an idea.

In the mean time, I am determining the thresholds for the old version of the likelihood (v1) on my set of threshold targets above. I'm also re-calculating the likelihoods on the 3pc quasars which I have median seeing for to make sure I get the same numbers again.

The code for this is here: ../logs/100510log.pro
The run directory is here: ../likelihood/likev1

Friday, January 29, 2010

Parallelization

Adam rocks. He helped me figure out a way to parallelize the calculations of my correlation functions to that they all happen at once. Hopefully this will speed up my code by a factor of 10-20. Here is how it works:

A while ago I posted about how to use qsub to run scripts. I've now change my python code to call qsub within the program which calculates the correlation functions.

I have the following script:
runcrossCorr.script
~~~~~~~~~~~~~~
#PBS -l nodes=1
#PBS -N JessCC$job
#PBS -j oe
#PBS -m ea
#PBS -M jakirkpatrick@lbl.gov
#PBS -o qsub.out

cd /home/jessica/repository/ccpzcalib/Jessica/pythonJess
echo "$corr2dfile $argumentfile > $outfile"
$corr2dfile $argumentfile > $outfile
~~~~~~~~~~~~~~
this script is called using the following command:
qsub -v job=0, corr2dfile=./2dcorrFinal, argumentfile=./run2010129_237/wpsInputs0, outfile=./run2010129_237/wps0.dat runcrossCorr.script

where -v basically sets up environment variables for the qsub command so that within the script (in this example)
$job is replaced with 0
$corr2dfile is replaced with ./2dcorrFinal
$argumentfile is replaced with /run2010129_237/wpsInputs0
$outfile is replaced with ./run2010129_237/wps0.dat runcrossCorr.script

Many of these qsub commands can be run in python and they all are sent to the queue and run in parallel on different cluster computers.

I've done this so that python automatically changes the argumentfile and outfile and runs all the correlation functions at once.

These correspond to updated versions of my python functions runcrossCorr and runautoCorr in the correlationData library.

Look at all my jobs running (type qstat into terminal)!

And it even emails me when it's done!

So, now all I do is make a python script that runs all the code and set it going in the background:

python 100128run.py 100128.out 2> 100128.err &

I'm running with 1,000,000 points and finer redshift binning. Hopefully this will work even better!

Monday, November 30, 2009

R Packages on Riemann

I asked Michael Jennings to install R on riemann so I can play with this SVM-light thing for the target selection. He installed R but asked me to install any add-on packages into my home directory. Here is how you do this:
  1. Create a directory where you want the R add-on packages to be stored (i.e. /home/jessica/R/library)
  2. Tell R to look for libraries in this location by adding this to your .path file: export R_LIBS=/home/jessica/R/library
  3. Source your .bashrc file to update path changes
  4. Open R
  5. Type the command: install.packages("e1071", lib = '/home/jessica/R/library', repos = "http://cran.r-project.org") where "e1071" is the name of the package you want to install, lib is the directory you created to store the packages, and repos is the location to download the packages from.
  6. Test to make sure it was successful by closing R, re-opening and importing package you just installed: library("e1071")
And now you have successfully installed a R package on Riemann. Thanks to Michael for working so quickly. Now, to try this SVM thing on the quasar targeting...

Here's the code (also in like:svmcode.r)

library("e1071")
library("FITSio")
setwd("/Users/jessica/Documents/workspace/newman/Jessica/likelihood")
qso = readFITS("smallqso.fits")
star = readFITS("smallstar.fits")
x2 <- as.matrix(star$col[[1]],ncol=5)
x1<- as.matrix(qso$col[[1]],ncol=5)
x <- rbind(x1,x2)
y1= seq(1,smallsize)*0+1
y2= seq(1,smallsize)*0

y=c(y1,y2)
fy = factor(y)
m = svm(x,fy)
save(list = ls(), file = "./svmcode.Rdata")


Where smallqso.fits and smallstar.fits are subsets of the qso/star templates used in the likelihood calculation. In this run I am using 100,001 objects for these small files, but that run is taking 2+ days so far on my laptop, so I think I'm going to try to do it with less points for this run on riemann (30,000). To load this session image, type: load("./svmcode.Rdata")

To run this file as a script type the following (for some reason the qsub way of running a script isn't working):
R CMD BATCH ./svmcode.r svmcode.out 2> svmcode.err &

Wednesday, November 18, 2009

Running Scripts (Update)

I want to utilize the fact that I can run the correlation function on multiple nodes of riemann. Eric helped me learn to use qsub to run a script on multiple nodes. I've got it working as follows:

In the file on riemann 091118jess.script there is the following:

#PBS -l nodes=1
#PBS -N jessjob1
#PBS -j oe
#PBS -M kirkpatrick@berkeley.edu
#PBS -V
cd /home/jessica/repository/ccpzcalib/Jessica/pythonJess
./runcode.script


where runcode.script contains the following:
python runReconstructionMock.py

I make both runcode.script and 091118jess.script executables, and then type in the terminal:
qsub 091118jess.script

I then exit from riemann/insure (didn't close it using x button, not sure if this makes a difference).

When I log back in the code is still running. (check using qstat)

Now I need to integrate this into the python code so that qsubs are generated for each correlation function for each redshift slice. This should make things go a lot faster.

The email from Eric:
----------
From: Eric Huff
Date: Wed, Nov 18, 2009 at 3:06 PM
Subject: qsub
To: Jessica Kirkpatrick

Here's a script example:

#PBS -l nodes=1
#PBS -l walltime=24:00:00
#PBS -m bea
#PBS -M emhuff@berkeley.edu
#PBS -V
ulimit -s unlimited
export PHOTO_DATA=/clusterfs/riemann/raid006/bosswork/groups/boss/photo/data
export PHOTO_REDUX=/clusterfs/riemann/raid006/bosswork/groups/boss/photo/redux
cd /home/emhuff/Coadds/Code/Coadd_Data_Root/Scripts
echo `hostname`
/home/emhuff/Coadds/Code/Coadd_Data_Root/Scripts/r.out 380720 6 0 00

And here's some online documentation for qsub:

http://www.doesciencegrid.org/public/pbs/qsub.html
http://njal.physics.sunysb.edu/tutorial-1.html

I'm running the full reconstruction on the mock data, I might have a fully working code tomorrow. Woo hoo!

Thursday, October 22, 2009

Running Scripts

In science it seems that we are supposed to somehow organically learn how to use linux computers. I don't know how people do this. I feel like I know only 15 commands because I use them everyday. Everything else I need to do on linux I either have to ask others to help me, or I look it up when I need it and then promptly forget. All books on the subject seem to give me more information than I need. Is there a 'Practical Linux for Dummies' book?

However, one of the MANY benefits of dating a computer scientist (for those who haven't tried it, I highly recommend it) is that Adam knows how to do almost anything I would want to do on a computer. I've lost track of how many times he has helped me.

Latest example of this is running a script remotely the need to stay logged into the computer. I know this is a basic task, but every time I've tried to get someone to show me how to do it, I've never gotten a clear-cut answer.

So this is how I did it (I am writing it here so that I when I promptly forget how to do this, it will be easy to remind myself):

1) At the top of your python code put the following line (after the import statements):
if __name__ == '__main__':
For more info.

2) Indent the rest of your code (as python requires you to do for all functions)

3) Make sure your code doesn't plotting in it.

4) Save your code as a python script (i.e. code2run.py)

5) In a terminal window type the following:
> python code2run.py code2run.out 2> code2run.err &

6) Check that your code is running by typing the command: top

7) Now you can close your terminal window and come back to check on the run later by typing "top" again.

8) Any outputs to the terminal will go to the file code2run.out, and error messages will go to code2run.err

It would be nice if I could include in this script something where it would email me or send me some sort of message once the run is complete. Anyone know how to do this?