def __init__(self, names, *species, **kwargs): if len(set(names)) != len(names): raise ValueError("each species must have a unique name") if not all(cat.comm is species[0].comm for cat in species): raise ValueError("communicator mismatch in MultipleSpeciesCatalog") if len(names) != len(species): raise ValueError("a name must be provided for each species catalog provided") CatalogSourceBase.__init__(self, species[0].comm) self.attrs['species'] = names # update the dictionary with data/randoms attrs for cat, name in zip(species, names): self.attrs.update(attrs_to_dict(cat, name + '.')) # update the rest of meta-data self.attrs.update(kwargs) # no size! self.size = NotImplemented self.csize = NotImplemented # store copies of the original input catalogs as (name:catalog) dict self._sources = {name:cat.copy() for name,cat in zip(names, species)}
def __init__(self, names, *species, **kwargs): if len(set(names)) != len(names): raise ValueError("each species must have a unique name") if not all(cat.comm is species[0].comm for cat in species): raise ValueError("communicator mismatch in MultipleSpeciesCatalog") if len(names) != len(species): raise ValueError( "a name must be provided for each species catalog provided") CatalogSourceBase.__init__(self, species[0].comm) self.attrs['species'] = names # update the dictionary with data/randoms attrs for cat, name in zip(species, names): self.attrs.update(attrs_to_dict(cat, name + '.')) # update the rest of meta-data self.attrs.update(kwargs) # no size! self.size = NotImplemented self.csize = NotImplemented # store copies of the original input catalogs as (name:catalog) dict self._sources = {name: cat.copy() for name, cat in zip(names, species)}
def __getitem__(self, key): """ This provides access to the underlying data in two ways: - The CatalogSource object for a species can be accessed if ``key`` is a species name. - Individual columns for a species can be accessed using the format: ``species/column``. """ # return a new CatalogSource holding only the specific species if isinstance(key, string_types): if key in self.species: return self._sources[key] species, subcol = split_column(key, self.species) return CatalogSourceBase.__getitem__(self._sources[species], subcol) return CatalogSourceBase.__getitem__(self, key)
def __new__(cls, source, BoxSize, Nmesh, dtype, weight, value, selection, position='Position', interlaced=False, compensated=False, window='cic', **kwargs): # source here must be a CatalogSource assert isinstance(source, CatalogSourceBase) # new, empty CatalogSource obj = CatalogSourceBase.__new__(cls, source.comm) # copy over size from the CatalogSource obj._size = source.size obj._csize = source.csize # copy over the necessary meta-data to attrs obj.attrs['BoxSize'] = BoxSize obj.attrs['Nmesh'] = Nmesh obj.attrs['interlaced'] = interlaced obj.attrs['compensated'] = compensated obj.attrs['window'] = window # copy meta-data from source too obj.attrs.update(source.attrs) # store others as straight attributes obj.dtype = dtype obj.weight = weight obj.value = value obj.selection = selection obj.position = position # add in the Mesh Source attributes MeshSource.__init__(obj, obj.comm, Nmesh, BoxSize, dtype) # finally set the base as the input CatalogSource # NOTE: set this AFTER MeshSource.__init__() obj.base = source return obj
def __setitem__(self, col, value): """ Add columns to any of the species catalogs. .. note:: New column names should be prefixed by 'species/' where 'species' is a name in the :attr:`species` attribute. """ species, subcol = split_column(col, self.species) # check size size = len(self._sources[species]) if not numpy.isscalar(value): if len(value) != size: args = (col, size, len(value)) raise ValueError("error setting '%s' column, data must be array of size %d, not %d" % args) # add the column to the CatalogSource in "_sources" return CatalogSourceBase.__setitem__(self._sources[species], subcol, value)
def __finalize__(self, other): """ Finalize the creation of a CatalogMesh object by copying over attributes from a second CatalogMesh. This also copies over the relevant MeshSource attributes via a call to :func:`MeshSource.__finalize__`. Parameters ---------- obj : CatalogMesh the second CatalogMesh to copy over attributes from """ if isinstance(other, CatalogSourceBase): self = CatalogSourceBase.__finalize__(self, other) if isinstance(other, MeshSource): self = MeshSource.__finalize__(self, other) return self
def __delitem__(self, col): """ Delete a column of the form ``species/column`` """ species, subcol = split_column(col, self.species) return CatalogSourceBase.__delitem__(self._sources[species], subcol)