Skip to content

funcs

load_maps(dset_name, cfg, fnames, comm)

Load the ACT maps and ivar maps.

Parameters:

Name Type Description Default
dset_name str

Name of the dataset in the config.

required
cfg dict

The config. If datasets.<dset_name>.zero_mean is True (default) the ivar weighted mean is subtracted from each map.

required
fnames list

(map, ivar) file name pairs from get_files.

required
comm Intracomm

Communicator for the maps.

required

Returns:

Type Description
SolutionSet

The loaded maps.

Source code in witch/external/act_map/funcs.py
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
def load_maps(
    dset_name: str, cfg: dict, fnames: list, comm: MPI.Intracomm
) -> SolutionSet:
    """
    Load the ACT maps and ivar maps.

    Parameters
    ----------
    dset_name : str
        Name of the dataset in the config.
    cfg : dict
        The config. If `datasets.<dset_name>.zero_mean` is True (default) the
        ivar weighted mean is subtracted from each map.
    fnames : list
        `(map, ivar)` file name pairs from `get_files`.
    comm : MPI.Intracomm
        Communicator for the maps.

    Returns
    -------
    SolutionSet
        The loaded maps.
    """
    map_names = [f[0] for f in fnames]
    ivar_names = [f[1] for f in fnames]
    map_glob = cfg["datasets"][dset_name].get("glob", "*_map.fits")

    imaps = []
    for fname, iname in zip(map_names, ivar_names):
        name = os.path.basename(fname)[: (1 - len(map_glob))]
        # The actual map
        f: fits.HDUList = fits.open(fname)
        wcs = WCS(f[0].header)  # type: ignore
        # `WCSMap.xy` puts x along the first axis, so transpose the FITS (y, x) layout.
        dat = jnp.array(f[0].data.astype(float)).T  # type: ignore
        f.close()
        # The ivar map
        f: fits.HDUList = fits.open(iname)
        ivar = jnp.array(f[0].data.astype(float)).T  # type: ignore
        f.close()
        if cfg["datasets"][dset_name].get("zero_mean", True):
            # Match the zero-mean convention of the other datasets, this is a cutout
            # so its mean is not zero. The mean is ivar weighted and ignores empty pixels.
            dat = dat - jnp.sum(dat * ivar) / jnp.sum(ivar)
        imaps += [maps.WCSMap(name, dat, comm, JAXWCS.from_astropy(wcs), ivar=ivar)]
    mapset = SolutionSet(imaps, comm)

    return mapset