def _make_ledger_in_hp(pixnum): """make initial ledger in a single HEALPixel""" # ADM read in the needed columns from the targets. targs = io.read_targets_in_hp(hpdirname, nside, pixnum, columns=cols) if len(targs) == 0: return # ADM construct a list of all pixels in pixnum at the MTL nside. pixlist = nside2nside(nside, mtlnside, pixnum) # ADM write MTLs for the targs split over HEALPixels in pixlist. return make_ledger_in_hp( targs, outdirname, mtlnside, pixlist, obscon=obscon, indirname=hpdirname, verbose=False)
def find_tycho_files_hp(nside, pixlist, neighbors=True): """Find full paths to Tycho healpix files in a set of HEALPixels. Parameters ---------- nside : :class:`int` (NESTED) HEALPixel nside. pixlist : :class:`list` or `int` A set of HEALPixels at `nside`. neighbors : :class:`bool`, optional, defaults to ``True`` Also return files corresponding to all neighbors that touch the pixels in `pixlist` to prevent edge effects (e.g. a Tycho source is 1 arcsec outside of `pixlist` and so in an adjacent pixel). Returns ------- :class:`list` A list of all Tycho files that need to be read in to account for objects in the passed list of pixels. Notes ----- - The environment variable $TYCHO_DIR must be set. """ # ADM the resolution at which the healpix files are stored. filenside = get_tycho_nside() # ADM check that the TYCHO_DIR is set and retrieve it. tychodir = get_tycho_dir() hpxdir = os.path.join(tychodir, 'healpix') # ADM work with pixlist as an array. pixlist = np.atleast_1d(pixlist) # ADM determine the pixels that touch the passed pixlist. pixnum = nside2nside(nside, filenside, pixlist) # ADM if neighbors was sent, then retrieve all pixels that touch each # ADM pixel covered by the provided locations, to prevent edge effects... if neighbors: pixnum = add_hp_neighbors(filenside, pixnum) # ADM reformat in the healpix format used by desitarget. tychofiles = [os.path.join(hpxdir, io.hpx_filename(pn)) for pn in pixnum] return tychofiles
def read_targets_in_hp(hpdirname, nside, pixlist, columns=None): """Read in targets in a set of HEALPixels. Parameters ---------- hpdirname : :class:`str` Full path to either a directory containing targets that have been partitioned by HEALPixel (i.e. as made by `select_targets` with the `bundle_files` option). Or the name of a single file of targets. nside : :class:`int` The (NESTED) HEALPixel nside. pixlist : :class:`list` or `int` or `~numpy.ndarray` Return targets in these HEALPixels at the passed `nside`. columns : :class:`list`, optional Only read in these target columns. Returns ------- :class:`~numpy.ndarray` An array of targets in the passed pixels. """ # ADM we'll need RA/Dec for final cuts, so ensure they're read. addedcols = [] columnscopy = None if columns is not None: # ADM make a copy of columns, as it's a kwarg we'll modify. columnscopy = columns.copy() for radec in ["RA", "DEC"]: if radec not in columnscopy: columnscopy.append(radec) addedcols.append(radec) # ADM if a directory was passed, do fancy HEALPixel parsing... if os.path.isdir(hpdirname): # ADM check, and grab information from, the target directory. filenside, filedict = check_hp_target_dir(hpdirname) # ADM change the passed pixels to the nside of the file schema. filepixlist = nside2nside(nside, filenside, pixlist) # ADM only consider pixels for which we have a file. isindict = [pix in filedict for pix in filepixlist] filepixlist = filepixlist[isindict] # ADM make sure each file is only read once. infiles = set([filedict[pix] for pix in filepixlist]) # ADM read in the files and concatenate the resulting targets. targets = [] for infile in infiles: targets.append(fitsio.read(infile, columns=columnscopy)) targets = np.concatenate(targets) # ADM ...otherwise just read in the targets. else: targets = fitsio.read(hpdirname, columns=columnscopy) # ADM restrict the targets to the actual requested HEALPixels... ii = is_in_hp(targets, nside, pixlist) # ADM ...and remove RA/Dec columns if we added them. targets = rfn.drop_fields(targets[ii], addedcols) return targets