Exemple #1
0
def read_hwp_angle(fname):
	"""Given a filename or a dirfile, reads the half-wave-plate angle in degrees,
	which will be the same length as the tod. Also returns an equal-length array
	of hwp_flags. This is the current standard method
	for reading hwp data as of s17. Older seasons used the various functions below."""
	if isinstance(fname, basestring):
		with pyactgetdata.dirfile(fname) as dfile:
			return dfile.getdata("hwp_angle"), dfile.getdata("hwp_flags")
	else:
		return fname.getdata("hwp_angle"), fname.getdata("hwp_flags")
Exemple #2
0
def read_hwp_angle(fname):
	"""Given a filename or a dirfile, reads the half-wave-plate angle in degrees,
	which will be the same length as the tod. Also returns an equal-length array
	of hwp_flags. This is the current standard method
	for reading hwp data as of s17. Older seasons used the various functions below."""
	if isinstance(fname, basestring):
		with pyactgetdata.dirfile(fname) as dfile:
			return dfile.getdata("hwp_angle"), dfile.getdata("hwp_flags")
	else:
		return fname.getdata("hwp_angle"), fname.getdata("hwp_flags")
Exemple #3
0
def read_boresight(fname):
	"""Given a filename or dirfile, reads the timestamp, azimuth, elevation and
	encoder flags for the telescope's boresight. No deglitching or other corrections
	are performed. Returns [unix time,az (deg),el(deg)], flags."""
	def read(dfile):
		res = np.array([dfile.getdata("C_Time"),dfile.getdata("Enc_Az_Deg_Astro"),dfile.getdata("Enc_El_Deg")]), dfile.getdata("enc_flags")
		return res
	if isinstance(fname, basestring):
		with pyactgetdata.dirfile(fname) as dfile:
			return read(dfile)
	else:
		return read(fname)
Exemple #4
0
def read_boresight(fname):
	"""Given a filename or dirfile, reads the timestamp, azimuth, elevation and
	encoder flags for the telescope's boresight. No deglitching or other corrections
	are performed. Returns [unix time,az (deg),el(deg)], flags."""
	def read(dfile):
		res = np.array([dfile.getdata("C_Time"),dfile.getdata("Enc_Az_Deg_Astro"),dfile.getdata("Enc_El_Deg")]), dfile.getdata("enc_flags")
		return res
	if isinstance(fname, basestring):
		with pyactgetdata.dirfile(fname) as dfile:
			return read(dfile)
	else:
		return read(fname)
Exemple #5
0
def read_hwp_cleaned(fname, mode="auto"):
	"""Given a filename to an uncompressed dirfile containing hwp_angle_fit
	data as produced by Marius, return the hwp samples in degrees."""
	# Try Marius format
	if mode == "marius" or mode == "auto":
		try:
			import zgetdata
			with zgetdata.dirfile(fname) as dfile:
				nsamp = dfile.eof('hwp_angle_fit')
				return dfile.getdata("hwp_angle_fit", zgetdata.FLOAT32, num_samples=nsamp)
		except (zgetdata.BadCodeError, zgetdata.OpenError):
			if mode == "marius": raise IOError("File %s is not in marius format" % fname)
	# Try the other format
	with pyactgetdata.dirfile(fname) as dfile:
		return dfile.getdata("Hwp_Angle")
Exemple #6
0
def read_hwp_cleaned(fname, mode="auto"):
	"""Given a filename to an uncompressed dirfile containing hwp_angle_fit
	data as produced by Marius, return the hwp samples in degrees."""
	# Try Marius format
	if mode == "marius" or mode == "auto":
		try:
			import zgetdata
			with zgetdata.dirfile(fname) as dfile:
				nsamp = dfile.eof('hwp_angle_fit')
				return dfile.getdata("hwp_angle_fit", zgetdata.FLOAT32, num_samples=nsamp)
		except (zgetdata.BadCodeError, zgetdata.OpenError):
			if mode == "marius": raise IOError("File %s is not in marius format" % fname)
	# Try the other format
	with pyactgetdata.dirfile(fname) as dfile:
		return dfile.getdata("Hwp_Angle")
Exemple #7
0
def read_tod(fname,
             ids=None,
             mapping=lambda x: [x // 32, x % 32],
             ndet=None,
             shape_only=False,
             nthread=1):
    """Given a filename or dirfile, reads the time ordered data from the file,
	returning ids,data. If the ids argument is specified, only those ids will
	be retrieved. The mapping argument defines the mapping between ids and
	actual fields in the file, and ndet specifies the maximum number of detectors.
	These can usually be ignored. If nthread > 1, the tod fields will be read in parallel,
	which can give a significant speedup. If called this way, the function is not thread
	safe."""

    # Find which ids to read
    def get_ids(dfile, ids, ndet, mapping):
        if ids is None:
            fields = set(dfile.fields)
            id, ids = 0, []
            while "tesdatar%02dc%02d" % tuple(mapping(id)) in fields:
                if ndet is not None and id >= ndet: break
                ids.append(id)
                id += 1
        ids = np.asarray(ids)
        return ids

    def read(dfile, rowcol):
        if shape_only:
            reference = rowcol[:, 0] if rowcol.size > 0 else [0, 0]
            return len(dfile.getdata("tesdatar%02dc%02d" % tuple(reference)))
        else:
            res = dfile.getdata_multi(
                ["tesdatar%02dc%02d" % (r, c) for (r, c) in rowcol.T])
            if res is not None: return res
            else: return np.zeros([0, 0])

    if isinstance(fname, basestring):
        with pyactgetdata.dirfile(fname) as dfile:
            ids = get_ids(dfile, ids, ndet, mapping)
            rowcol = np.asarray(mapping(ids))
            return ids, read(dfile, rowcol)
    else:
        dfile = fname
        ids = get_ids(dfile, ids, ndet, mapping)
        rowcol = np.asarray(mapping(ids))
        return ids, read(dfile, rowcol)
Exemple #8
0
def read_hwp_raw(fname):
	"""Given a filename or a dirfile, reads the half-wave-plate angle. May
	move this into read_boresight later, as it belongs with the other fields
	there."""
	def read(dfile):
		toks = dfile.fname.split(".")
		array = toks.pop()
		if array == "zip":
			array = toks.pop()
		field  = "hwp_pa%s_ang" % array[-1]
		if field in dfile.fields:
			return dfile.getdata(field)
		else:
			_, nsamp = read_tod(dfile, shape_only=True)
			return np.zeros(nsamp,dtype=np.int16)
	if isinstance(fname, basestring):
		with pyactgetdata.dirfile(fname) as dfile:
			return read(dfile)
	else:
		return read(fname)
Exemple #9
0
def read_hwp_raw(fname):
	"""Given a filename or a dirfile, reads the half-wave-plate angle. May
	move this into read_boresight later, as it belongs with the other fields
	there."""
	def read(dfile):
		toks = dfile.fname.split(".")
		array = toks.pop()
		if array == "zip":
			array = toks.pop()
		field  = "hwp_pa%s_ang" % array[-1]
		if field in dfile.fields:
			return dfile.getdata(field)
		else:
			_, nsamp = read_tod(dfile, shape_only=True)
			return np.zeros(nsamp,dtype=np.int16)
	if isinstance(fname, basestring):
		with pyactgetdata.dirfile(fname) as dfile:
			return read(dfile)
	else:
		return read(fname)
Exemple #10
0
def read_tod(fname, ids=None, mapping=lambda x: [x/32,x%32], ndet=None, shape_only=False, nthread=1):
	"""Given a filename or dirfile, reads the time ordered data from the file,
	returning ids,data. If the ids argument is specified, only those ids will
	be retrieved. The mapping argument defines the mapping between ids and
	actual fields in the file, and ndet specifies the maximum number of detectors.
	These can usually be ignored. If nthread > 1, the tod fields will be read in parallel,
	which can give a significant speedup. If called this way, the function is not thread
	safe."""
	# Find which ids to read
	def get_ids(dfile, ids, ndet, mapping):
		if ids is None:
			fields = set(dfile.fields)
			id, ids = 0, []
			while "tesdatar%02dc%02d" % tuple(mapping(id)) in fields:
				if ndet is not None and id >= ndet: break
				ids.append(id)
				id += 1
		ids = np.asarray(ids)
		return ids
	def read(dfile, rowcol):
		if shape_only:
			reference = rowcol[:,0] if rowcol.size > 0 else [0,0]
			return len(dfile.getdata("tesdatar%02dc%02d" % tuple(reference)))
		else:
			res = dfile.getdata_multi(["tesdatar%02dc%02d" % (r,c) for (r,c) in rowcol.T])
			if res is not None: return res
			else: return np.zeros([0,0])
	if isinstance(fname, basestring):
		with pyactgetdata.dirfile(fname) as dfile:
			ids = get_ids(dfile, ids, ndet, mapping)
			rowcol = np.asarray(mapping(ids))
			return ids, read(dfile, rowcol)
	else:
		dfile = fname
		ids = get_ids(dfile, ids, ndet, mapping)
		rowcol = np.asarray(mapping(ids))
		return ids, read(dfile, rowcol)