PHP is annoying

I wanted to randomize the header image for the gaming subcategory…talk about a pain in the neck! PHP seems to be pretty robust, but the syntax is quite different than either Python or C which I am used to. I had to change a few things, first up - category.php; I went from
get_header();
to
<?php
if ( is_category( 'Gaming' ) ) :
  get_header( 'gaming' );
elseif ( is_404() ) :
  get_header( '404' );
else :
  get_header();
endif;
?>
Apparently there are different methods of doing this with curly brackets, but this was the cleanest example I could find and it resembles python. It basically says to use header-gaming.php if the category matches “Gaming”. Next up was that file, which I just made a copy of header.php. I added this relavant code:
<?php
$url = content_url();
$img0 = $url . "/uploads/2013/06/cropped-ORIGINAL.jpg";
$img1 = $url . "/uploads/2013/06/cropped-KUNARK.jpg";
$img2 = $url . "/uploads/2013/06/cropped-VELIOUS.jpg";
$img3 = $url .
"/uploads/2013/06/cropped-arma3_e32013_screenshot_06-100041641-orig1.png";
$imgarray = array($img0,$img1,$img2,$img3);

$cnt = count($imgarray);
$rn = rand(1,$cnt-1);
$img = $imgarray[$rn];
//echo "selecting image " . $rn . " out of " . $cnt;
?>
This was a pain. The first line assigns the variable $url to the wordpress content directory as this is where the header images are currently stored. The next 4 lines combine that directory with the remaining image path. Next I add all of these images to an array called imgarray. I can then count how large that array is, generate a random number, then assign $img using the random number as an index for the $imgarray. Next is the HTML part that actually places the image:
<img src="<?php echo $img; ?>"...
which is pretty straight forward.

Next up: scanning a directory for a list of images and automatically adding them to an array as to make this process automatic. This will allow me to randomize each page with pretty pictures. Start with these stack overflow suggestions.


Comparing Sigma

The new HI gradient stuff finished down to z=3.  Turns out it does make a small difference in the calculated Sobolev values of this particular galaxy.  At the same time however, we find now calculate the HI surface density via the grid calculation and drop that along with it, so the difference between grid & sobolev remains about ~1dex:sigmaHIcompare(plot made via gal_reduction/tools/sigmacompare.py)

Sigma_HSML however remains a front-runner here as it’s separation is only about ~0.5dex or less depending on if we account for the spread.  2xSigma_HSML overshoots the grid calculation by a tiny bit.  In comparing these two galaxies I’ve also found that the Sigma_HI results in slightly less stellar and gas content:

[table]
label,dir,eff epsilon [kpc/h],#of nested grids, pcount, galaxy number, RS halo number, Mgas, Mstar
superlowres,run14,3.13,0,128^3,101,915,2.09e9,1.73e9
lowres,run11,1.56,1,256^3,13,143,8.98e8,1.81e9
hires,run12,0.78,2,512^3,24,995,5.31e8,1.85e9
hires(HIgrad),run16,0.78,2,512^3,25,1024,4.77e8,1.81e9
[/table]

It’s not entirely clear where to go from this point or which option is the best option to estimate the surface density within these SPH sims…

As a side not the KS-relation changed a tiny bit between these two as well:

the beauty of crontab

I’ve never really understood the linux startup process (and still don’t), so it’s always been difficult to figure out how start things on every reboot.  Luckily, crontab is a beautiful thing that allows one to do just this and more!  Say I have a script that I’d like to run as admin on every reboot.  All I have to do is:

> sudo crontab -e

then add the line:

@reboot /home/bob/local/scripts/something.sh

and on upon every reboot the script will run.  What’s even cooler is that there are separate crontabs for each user.  So instead of using sudo in the above command if you simply use ‘crontab -e’ you will edit the current user’s crontab. For instance I have two entries in my server’s current crontab that periodically deletes a huge log file, and starts my ipython notebook server:

# m h  dom mon dow   command
10 06 * * * /home/bob/local/scripts/delxsessionerrs.sh
@reboot /home/bob/local/scripts/ipynotebook.sh

The first command tells the system to run delxsessionerrs.sh at 6:10am every day, the second line launches ipynotebook.sh on every reboot. Now I imagine one could insert the commands directly into the crontab, but I prefer the above script method.


Progress bar….

I got tired of waiting for code to finish and having no idea how far along it was.  Stack exchange provided an elegant solution of which I modified:

 import time,sys

def update_progress(step,datalen):
 progress = float(step)/float(datalen)
 barLength = 10 # Modify this to change the length of the progress bar
 status = ""
 if progress < 0:
 progress = 0
 status = "Halt...rn"
 if step >= datalen-1:
 progress = 1
 status = "Done...rn"

block = int(round(barLength*progress))
 text = "rPercent: [%s] %2.2f%% %s" % ("#"*block +
"-"*(barLength-block),
 progress*100, status)
 sys.stdout.write(text)
 sys.stdout.flush()

datalen=150
 for i in range(datalen):
 time.sleep(0.1) #just to slow it down!
 update_progress(i,datalen)

UPDATE (10/31/13)

here’s a cython version:
 cdef void update_progress(int step, int datalen):
 cdef float progress = float(step)/float(datalen)
 cdef int barLength = 10 # Modify this to change the length of the
 progress bar
 status = ""
 if progress < 0:
 progress = 0
 status = "Halt...rn"
 if step >= datalen-1:
 progress = 1
 status = "Done...rn"

cdef int block = int(np.round(barLength*progress))
 text = "rPercent: [%s] %2.2f%% %s" % ("#"*block +
"-"*(barLength-block),
 progress*100, status)
 sys.stdout.write(text)
 sys.stdout.flush()

Is this thing on?

Today I’m running run16_ken_fixedgradient so I can compare with our old method of doing things. Previously I was calculating the density gradient of the entire particle and using that for h:

\begin{equation*} h=\frac{\rho}{|\nabla \rho|} \end{equation*}

but now It’s changing to:

\begin{equation*} h=\frac{\rho_{\rm{HI}}}{|\nabla \rho_{\rm{HI}}|} \end{equation*}

which may not make much a difference at all, but will be nice to compare.  Run is currently at $$z\sim4.8$$.

Have a SPLOTCH picture!


Arma mission brainstorm…

Mission takes place in cherno. Utter chaos - ongoing battle between BLUFOR & OPFOR.  Mission begins with a helicopter insert into battle where the helicopter is “setcaptive true” along with each unit.  Fast rope in the middle of battle to a rooftop, once this happens setcaptive is set back to false - must get past enemy forces and take out the AA in order to allow air support to come in.