dimage.path package

Package for accessing NASA-Sloan Atlas locally or remotely.

Includes the Path class. It requires the environmental variable $ATLAS_DATA to be set to the root of the NSA data tree, and finds templates for the file paths in $DIMAGE_DIR/data/dimage_paths.ini. The Path class has the method get() which returns the file name.

A typical use case will be:

import fitsio
import dimage.path
apath= dimage.path.Path()
filename= apath.get('original', iauname='J095641.38+005057.1', band='g',
                     survey='sdss', version='v1_0_0')
image= fitsio.read(filename)

To access the same mosaic remotely, the code will download from the server at http://data.sdss.org into your local $ATLAS_DATA directory. Then you will be able to access the file:

import dimage.path
apath= dimage.path.Path()
# insert SDSS username and password as strings below!
apath.remote(username=, password=)
filename= apath.get('original', iauname='J095641.38+005057.1', band='g',
                     survey='sdss', version='v1_0_0')
image= fitsio.read(filename)

The remote access configuration will build local “mirror” under $ATLAS_DATA of the remote site consisting of just the files that have been requested. This mirror is used as a cache and files are not downloaded again if they already appear there. This cache needs to be cleared manually to force a download.

The template paths are defined as follows:
  • pieces enclosed in {} are interpreted according to python’s string format() method, using input keywords
  • environmental variables indicated by $ are substituted
  • defined special functions can be called with % (they are given the input keywords)

For example, the location of one of the original images for NASA-Sloan Atlas analysis is defined as:

original= $ATLAS_DATA/%v1/detect/{survey}/%subdir/%iauname-{band}.fits.gz

Depends on urllib2, os, sdss, and astropy v1.0 or later. In particular, within sdss it utilizes the base_path class in sdss.files.path.

class dimage.path.Path(pathfile=None)[source]

Bases: sdss.files.path.base_path

Class for supporting construction of NASA-Sloan Atlas paths. Typical usage relies on the get() method.

Methods

aid(filetype, **kwargs)[source]

Path utility to interpret %aid directive

get(filetype, **kwargs)[source]

Returns file name, downloading if remote access configured.

Parameters:

filetype : str

type of file

keyword arguments :

keywords to fully specify path

Notes

Path templates are defined in $DIMAGE_DIR/data/dimage_paths.ini

iauname(filetype, **kwargs)[source]

Path utility to interpret %iauname directive

iauname_to_nsaid(iauname, **kwargs)[source]

Returns NSAID given IAUNAME

Parameters:

iauname : str

IAUNAME to infer NSAID from

Returns:

nsaid : np.int32

NSAID index

Notes

Uses translation table set up by _nsaid_init(), which involves reading the original atlas.fits file. Large overhead on first call.

local()[source]

Configures local access for NASA-Sloan Atlas

nsaid_to_aid(nsaid, pid, **kwargs)[source]

Returns AID values for NSAID/PID

Parameters:

nsaid : int

NSAID

pid : int

parent ID

Returns:

aid : int

aid of detected object

nsaid_to_iauname(nsaid, **kwargs)[source]

Returns IAUNAME given NSAID

Parameters:

nsaid : int

NSAID to infer IAUNAME from

Returns:

iauname : str

IAUNAME to infer NSAID from

Notes

Uses translation table set up by _nsaid_init(), which involves reading the original atlas.fits file. Large overhead on first call.

nsaid_to_pid(nsaid, **kwargs)[source]

Returns PID value for NSAID

Parameters:

nsaid : int

NSAID

Returns:

pid : int

parent IDs of processed objects in image

pid(filetype, **kwargs)[source]

Path utility to interpret %pid directive

remote(remote_base=None, local_base=None, username=None, password=None)[source]

Configures remote access for NASA-Sloan Atlas.

Parameters:

remote_base : str

base URL path for remote repository

local_base : str

base file path for local repository

username : str

user name for remote repository

password : str

password for local repository

subdir(filetype, **kwargs)[source]

Path utility to interpret %subdir directive

url(filetype, **kwargs)[source]

Constructs URL based on file name

Parameters:

filetype : str

type of file

keyword arguments :

keywords to fully specify URL

Notes

Path templates are defined in $DIMAGE_DIR/data/dimage_paths.ini

v1(filetype, **kwargs)[source]

Path utility to interpret %v1 directive

v2(filetype, **kwargs)[source]

Path utility to interpret %v2 directive

class dimage.path.base_path(pathfile)[source]

Bases: object

Class for construction of paths in general.

Attributes

templates (dict) The set of templates read from the configuration file.

Methods

dir(filetype, **kwargs)[source]

Return the directory containing a file of a given type.

Parameters:

filetype : str

File type parameter.

Returns:

dir : str

Directory containing the file.

full(filetype, **kwargs)[source]

Return the full name of a given type of file.

Parameters:

filetype : str

File type parameter.

Returns:

full : str

The full path to the file.

name(filetype, **kwargs)[source]

Return the directory containing a file of a given type.

Parameters:

filetype : str

File type parameter.

Returns:

name : str

Name of a file with no directory information.

dimage.path.download_file(url, filename)[source]

Download a file at a url and put it into a local location

Parameters:

url : str

URL of file to download

filename : str

local path to put file in

dimage.path.iauname_to_subdir(iauname, **kwargs)[source]

Convert IAUNAME to a subdirectory name in NASA-Sloan Atlas

Parameters:

iauname : str

IAU-style name corresponding to ID (JHHMMSS.SS[+-]DDMMSS.S)

Returns:

subdir : str

subdirectory based on IAU-style name

Notes

Subdirectory is of the form: [RA]/[DEC]/[IAUNAME], where RA is 00h, 01h, etc. and DEC is [..., m02, m00, p00, p02, ...]

dimage.path.local_to_url(local, local_base='/data', remote_base='http://data.sdss.org')[source]

Convert a local path to the remote URL

Parameters:

local : str

path to convert

local_base : str

base path on local system

remote_base : str

corresponding base path on remote system

dimage.path.radec_to_iauname(ra, dec, **kwargs)[source]

Function to convert RA, Dec to an IAU-style name (JHHMMSS.SS[+-]DDMMSS.S)

Parameters:

ra : float

Right ascension, in deg

dec : float

Declination, in deg

Returns:

iauname : str

IAU-style name corresponding to ID (JHHMMSS.SS[+-]DDMMSS.S)

dimage.path.version_to_detectdir(version)[source]

Convert version name into detection subdirectory

Parameters:

version : str

version of NSA (vN_M_P)

Returns:

detectdir : str

detection subdirectory vN_M

dimage.path.version_to_topdir(version)[source]

Convert version name into top directory of atlas

Parameters:

version : str

version of NSA (vN_M_P)

Returns:

topid : str

top directory name vN