Friday
Sep062013

PyNOMAD 0.1.0 uploaded to PyPI 

I wanted a small test project for learning how to upload a package to PyPI for release to the world. USNO’s NOMAD is a stellar catalog1 I use for a bunch of projects. For speed and reliability I keep local copies (30gigs compressed) in a few places. PyNOMAD is some quick little code I wrote to access NOMAD locally. You can download it here or easy_install pynomad should work too.

If you have a local copy of the NOMAD files, then this python code might be useful to you, e.g.:

A typical usage to fetch a region of the catalog is:

#!/usr/bin/env python

from nomad import fetch_nomad_box

ra_range = [281., 281.05]  #    RA is in degrees
dec_range = [-30.6, -30.55]  #  Dec is in degrees
stars = fetch_nomad_box(ra_range, dec_range, epoch=2000.0)

A typical usage to retrieve by NOMAD catalog ID is:

#!/usr/bin/env python

from nomad import fetch_star_by_nomad_id

star = fetch_star_by_nomad_id(['0594-0896798'], epoch=None)

stars = fetch_star_by_nomad_id(['0594-0896794', '0594-0896795', 
                                '0594-0896796', '0594-0896798'], epoch=None)

Note that in all cases the returned object is a pandas.DataFrame.

Wednesday
Apr102013

An Automator service to split PDF files by page

For a while I've been splitting PDF files into their individual pages using the AppleScript provided with PDFPenPro (and now PDFPenPro 6). One can even use their script as a droplet. But, I wanted it as a service and to make a few other minor changes, including:

  • Don't ask me, just save the resulting files in the same directory as the original
  • Don't do anything if the file is already only one page long
  • Keep the creation date the same as the original file, but in a nod to not screwing things up too badly, let the modification time be when the file was split up

I started from the script provided with PDFPenPro 6 by Smile in ~/Library/Application Scripts/com.smileonmymac.PDFpenPro6.MacAppStore/Split PDF.scpt and went from there. After some head-banging and teeth-gnashing my googling brought me, as it so often does in the midst of applescript induced head-banging and teeth-gnashing, back to Dr. Drang, specifically here and here. From those and a few other sources I cobbled together the following in Automator:

  • Open a new doc and select it to be a Service
  • Service receives selected: PDF files in Finder
  • Add a Run AppleScript action
  • Paste in the following AppleScript

The end, except the script:

on split(fileList)
    tell application "PDFpenPro 6"
        repeat with aFile in fileList
            open aFile as alias
            set myDoc to document 1
            set fullOriginalFilePath to (path of myDoc as string)
            if fullOriginalFilePath ends with ".pdf" then
                set fullOriginalFilePathLength to (length of fullOriginalFilePath)
                set fullBaseFilePath to (characters 1 thru (fullOriginalFilePathLength - 4) of fullOriginalFilePath as string)
            end if

            set pageCount to 1
            set originalDoc to myDoc
            -- if only 1 page, don't do anything
            set numPages to count (pages of originalDoc)
            if numPages > 1 then
                repeat with aPage in pages of originalDoc
                    set newDoc to make new document
                    copy page pageCount of originalDoc to end of pages of newDoc
                    set zeroCount to 3
                    if (pageCount div 10) > 0 then
                        set zeroCount to 2
                    end if
                    if (pageCount div 100) > 0 then
                        set zeroCount to 1
                    end if
                    if (pageCount div 1000) > 0 then
                        set zeroCount to 0
                    end if
                    set fullSavePath to fullBaseFilePath & "-"
                    repeat zeroCount times
                        set fullSavePath to fullSavePath & "0"
                    end repeat
                    set fullSavePath to fullSavePath & pageCount & ".pdf"
                    -- The try block is necessary to avoid a sandbox issue
                    try
                        close document 1 saving in POSIX file fullSavePath
                    end try
                    -- set creation time of new file to same as old file (but keep modified time as right now)
                    do shell script ("cp -p " & fullSavePath & " /tmp/split_PDF_temp_file.pdf")
                    do shell script ("touch -r " & fullOriginalFilePath & " " & fullSavePath)
                    do shell script ("touch -m -r /tmp/split_PDF_temp_file.pdf " & fullSavePath)
                    do shell script ("rm /tmp/split_PDF_temp_file.pdf")
                    set pageCount to pageCount + 1
                end repeat
            end if
            close originalDoc
        end repeat
    end tell    
end split

on run {input, parameters}
    split(input)
end run
Friday
Sep282012

Using Keyboard Shortcuts in the Print Dialog

For a while I've used MacSparky's tip (originally from macosxhints) to print to a PDF file. Basically by typing ⌘P ⌘P from any application you get directly to the Save as PDF… dialog.

For a while I've wanted to have something similar for saving to my Web Receipts folder, but creating a similar keyboard shortcut doesn't work. (Or only works once you've clicked on the PDF dropdown menu in the print dialog. There's some sort of difference between items above vs. below the grey line in that dropdown.) But, today I realized that using Default Folder X I can create a shortcut in the Save dialog to go straight to Web Receipts (I chose ⌘⇧W for this).

So, now to save something to Web Receipts I type:

⌘P ⌘P ⌘⇧W Return

Wednesday
Sep262012

Shortcut to invert colors on iOS

I've been using inverted colors for reading web pages on an iPad in the middle of the night as it's more comfortable on my eyes.  (Some applications I use for reading, especially Instapaper, have color inversion built in as an option.)

For Safari and applications that don't have an inverted color scheme option, you can invert the colors by diving deeply into the Settings on your iPad or iPhone (iPhone shown here):

Or, a handy shortcut is to use a triple click of the home button to toggle inverted colors on and off.  To set this up scroll a bit further down in the Accessibility menu:

Friday
Aug172012

Install Sextractor on OS X Lion

With thanks to http://okomestudio.net/biboroku/?p=824 this is how I got Sextractor working on OS X Lion:

  • Download latest FFTW (Version 3.3.2 as of this writing.)
  • Download latest LAPACK (Version 3.4.1 as of this writing.)
  • Download latest ATLAS (Version 3.10.0 as of this writing.)
  • Download latest Sextractor (Version 2.8.6 as of this writing.)

If gfortran is not already installed, download 4.8 gfortran only for Lion from here or direct download and install with

 sudo tar -xvf gfortran-lion.tar -C /.

Then, install FFTW with:

cd ~/Downloads
sudo tar -xof fftw-3.3.2.tar -C /usr/local/
pushd /usr/local/fftw-3.3.2/
sudo ./configure --enable-threads
sudo make; sudo make install
sudo ./configure --enable-threads --enable-single
sudo make clean; sudo make; sudo make install
popd

Install ATLAS and LAPACK:

sudo mkdir /usr/local/atlas-3.10.0
sudo tar -xzof atlas3.10.0.tar.bz2 -C /usr/local/atlas-3.10.0 --strip-components 1
sudo cp lapack-3.4.1.tar /usr/local/atlas-3.10.0/lapack.tar
sudo mkdir /usr/local/atlas-3.10.0/build
pushd /usr/local/atlas-3.10.0/build
sudo ../configure -b 64 --shared --prefix=/usr/local --with-netlib-lapack-tarfile=../lapack.tar
sudo make build
sudo make check
sudo make time
sudo make install  #  this threw some errors 
popd

Install Sextractor:

sudo tar -xof sextractor-2.8.6.tar -C /usr/local/
pushd /usr/local/sextractor-2.8.6
sudo sed -i '' -e 's/-llapack/-ltatlas/' -e 's/-lcblas/-ltatlas/' \
         -e 's/-latlas/-ltatlas/' -e 's/-lptcblas/-ltatlas/' ./configure
sudo ./configure --enable-threads
sudo make; sudo make install
popd

Run a test (takes a few minutes):

cd /usr/local/sextractor-2.8.6/tests/
sex galaxies.fits
Page 1 ... 4 5 6 7 8 ... 32 Next 5 Entries »