psex.py

This is a python script (python/coords/psex.py) that takes a Ra,Dec input as sexigecimal format from standard in. New forms of the positions in floating point numbers with units of degrees and hours are written to standard out:


% psex.py 12:30:45.223 -30:28:12.2 
12:30:45.223 -30:28:12.2 187.688429167 12.512561944 -30.470055556

Using psex.py in a script I typically redirect the 
output to a file (ptools.1) that I can then read 
to set variables within the bash script: 

psex.py $1 $2 >ptools.1 
read rasex decsex radeg rahrs decdeg < ptools.1

N.B. In this case arg1 and arg2 are the Ra,Dec in sexigeciaml format. 

In the final example above, the shell variables read from ptools.1 (radeg,rahrs,decdeg) can be used by a variety of other scripts.

A quantum leap in quality!

In June2015 I have learned how to use the argparse library. Adding a few lines to psex.py, I now have the option to run in some new and very useful modes:

 
% psex.py 12:12:12.12 +12:30:45.1 
12:12:12.12 +12:30:45.1 183.050500000 12.203366667 12.512527778

% psex.py --help 
usage: psex.py [-h] [-v] arg1 arg2

positional arguments:
  arg1           RA in sexigecimal format
  arg2           DEC in sexigecimal format

optional arguments:
  -h, --help     show this help message and exit
  -v, --verbose  Verbose responses

% psex.py -v 12:12:12.12 +12:30:45.1 
RA,DEC = 12:12:12.12 +12:30:45.1
RA,DEC = 183.050500000 12.512527778
RA(hours) = 12.203366667

% psex.py 12:12:12.12 
usage: psex.py [-h] [-v] arg1 arg2
psex.py: error: too few arguments
Hence with no optional flags (-v, --verbose, -h, --help) the psex.py code runs just as it always has. With the flags, I get extra useful information for the user. Moreover, if the command line is constructed badly, I get an informative error message. All of these new capalbilities derive from argparse.


IMPORTANT POINT:

Apparently I need to call psex.py with a "--". If not, then negative declinations will not be handled correctly. Here are examples:

 
[sco@mcs ~/tmp]$  psex.py -v -- 12:12:12.22 -10:10:10.1 
Input ra,dec = 12:12:12.22 -10:10:10.1
RA,DEC = 12:12:12.22 -10:10:10.1
RA,DEC = 183.050916667 -10.169472222
RA(hours) = 12.203394444

[sco@mcs ~/tmp]$  psex.py -- 12:12:12.22 -10:10:10.1 
12:12:12.22 -10:10:10.1 183.050916667 12.203394444 -10.169472222

[sco@mcs ~/tmp]$  psex.py -- 07:29:47.706 -01:56:41.64 
07:29:47.706 -01:56:41.64 112.448775000 7.496585000 -1.944900000

[sco@mcs ~/tmp]$ psex.py -- 12:12:12.22 +10:10:10.1  
12:12:12.22 +10:10:10.1 183.050916667 12.203394444 10.169472222




Back to SCO CODES page