hetaz.py

This is a python script (python/coords/hetaz.py) that takes a Dec input as floating point value in units of degrees and outputs the HET optimal structure azimuth.

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

positional arguments:
  arg1           DEC in floating point degrees

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

% hetaz.py -v 12.0
Input dec = 12.0
The tuple az properties:

3
(2, 115.27876517764319, 244.72123482235679)
AZ(east,west) = 115.278765 244.721234822

% hetaz.py 12.0
2 115.278765178 244.721234822 
 

Using a tuple returned from a function

I have wondered how to retrun multiple quantities from a function anf Niv Drory's code (in the form of optaz) showme how. Below I show my calling script (the subject of this page: hetax.py) and then I show Niv's function (which is ni my module scomods.getRAdeg.py). Notice how in the example above, when I run in verbose mode, I print the EAST azimuth as a formatted float, and I print the WEST azimuth as the string from the tuple.

 

Here is the script:  
% cat $codes/python/coords/hetaz.py
#!/usr/bin/env python
"""Read dec floating point degrees and use N.Drory 
   routine optaz.py (scomods.getRAdeg.optaz) to compute 
   the opttimal structure azimuth for HET. s""" 

from scomods.getRAdeg import optaz

import argparse as ARGP 
parser = ARGP.ArgumentParser()
parser.add_argument("arg1", help="DEC in floating point degrees")
parser.add_argument("-v","--verbose", help="Verbose responses",
                    action="store_true") 
args = parser.parse_args()

# assign some readable names 
decread = args.arg1
if args.verbose:
 print "Input dec = %s" % (decread)    

dec = float(decread)  

# compute the RA,DEC as floating point in DEGREES 
# NOTE: optaz returns a tuple, an immutable list 
az = optaz(dec) 

if args.verbose:
 print "The tuple az properties:\n",
 print type(az)
 print len(az)
 print az
 azE = float(az[1])
 azW = az[2]
 print "AZ(east,west) = %.6f %s\n" % (azE,azW),
else:
 print "%s %s %s \n" % (az),


Here is the function:  
% cat $codes/python/scomods/getRAdeg.py  (just the optaz part): 
def optaz (dec):
    """
    Calculate optimal Azimuth given DEC.

    Params:
    dec, input, Declination in degrees.

    Returns:
    n_tracks, az1, az2

    """
    lat = 30.681436/180.0*np.pi   # HET latitude
    alt = 55.055223/180.0*np.pi   # HET elevation
    tsr = 8.2/180.0*np.pi         # Tracking sphere angular extent

    P = np.cos(alt)*np.cos(lat)   # HET constants
    Q = np.sin(alt)*np.sin(lat)

    dec = dec/180.0*np.pi
    TDE_N = np.arcsin (P+Q)
    TDE_S = np.arcsin (-P+Q)

    if dec>=TDE_S and dec<=TDE_N:
        az1 = np.arccos((np.sin(dec)-Q)/P)    # TR43 eq. 5
        az2 = 2.0*np.pi-az1
        tracks = 2
    elif dec<=TDE_S and dec>=TDE_S-tsr:
        az1 = az2 = np.pi
        tracks = 1
    elif dec>=TDE_N and dec<=TDE_N+tsr:
        az1 = 0.0
        az2 = 2.0*np.pi
        tracks = 1
    else:
        az1 = az2 = 0
        tracks = 0

    return tracks, az1/np.pi*180.0, az2/np.pi*180.0




Back to SCO CODES page