radec_to_targname

grizli.utils.radec_to_targname(ra=0, dec=0, round_arcsec=(4, 60), precision=2, targstr='j{rah}{ram}{ras}{sign}{ded}{dem}', header=None)[source]

Turn decimal degree coordinates into a string with rounding.

Parameters
ra, decfloat

Sky coordinates in decimal degrees

round_arcsec(scalar, scalar)

Round the coordinates to nearest value of round, in arcseconds.

precisionint

Sub-arcsecond precision, in to_string.

targstrstring

Build targname with this parent string. Arguments rah, ram, ras, rass, sign, ded, dem, des, dess are computed from the (rounded) target coordinates (ra, dec) and passed to targstr.format.

headerHeader, None

Try to get ra, dec from header keywords, first CRVAL and then RA_TARG, DEC_TARG.

Returns
targnamestr

Target string, see the example above.

Examples

>>> # Test dec: -10d10m10.10s
>>> dec = -10. - 10./60. - 10.1/3600
>>> # Test ra: 02h02m02.20s
>>> cosd = np.cos(dec/180*np.pi)
>>> ra = 2*15 + 2./60*15 + 2.2/3600.*15
>>> # Round to nearest arcmin
>>> from grizli.utils import radec_to_targname
>>> print(radec_to_targname(ra=ra, dec=dec, round_arcsec=(4,60),
                       targstr='j{rah}{ram}{ras}{sign}{ded}{dem}'))
j020204m1010 # (rounded to 4 arcsec in RA)
>>> # Full precision
>>> targstr = 'j{rah}{ram}{ras}.{rass}{sign}{ded}{dem}{des}.{dess}'
>>> print(radec_to_targname(ra, dec,round_arcsec=(0.0001, 0.0001),
                            precision=3, targstr=targstr))
j020202.200m101010.100