コード例 #1
0
    def values_and_description(self, halos):
        if self.locator.n_columns() != 1:
            raise ValueError(
                "Cannot use property %r, which returns more than one column, as a halo locator"
                % (str(self.locator)))
        target_halos = self._get_target_halos(halos)
        results = np.empty((self.n_columns(), len(halos)), dtype=object)

        mask = QueryMask()
        mask.mark_nones_as_masked(target_halos)
        target_halo_masked = mask.mask(target_halos)

        if self._expect_multivalues:
            if self._multi_selection_basis == 'first':
                for i in range(len(target_halo_masked)):
                    if len(target_halo_masked[i]) > 1:
                        warnings.warn(
                            "More than one relation for target %r has been found. Picking the first."
                            % str(self.locator), RuntimeWarning)
                    target_halo_masked[i] = target_halo_masked[i][0]
            else:
                multivalue_folding = QueryMultivalueFolding(
                    self._multi_selection_basis, self._multi_selection_column,
                    self._constraints_columns)
                target_halo_masked = multivalue_folding.unfold(
                    target_halo_masked)
        values, description = self._get_values_and_description_from_halo_id_list(
            [x.id for x in target_halo_masked])

        if self._expect_multivalues and self._multi_selection_basis != 'first':
            values = multivalue_folding.refold(values)

        results[:] = mask.unmask(values)

        return results, description
コード例 #2
0
    def values_and_description(self, halos):
        results = np.empty((self.n_columns(), len(halos)), dtype=object)
        c_column = 0
        halos = np.asarray(halos, dtype=object)
        mask = QueryMask()
        mask.mark_nones_as_masked(halos)
        for c in self.calculations:
            values, description = c.values_and_description(mask.mask(halos))
            results[c_column:c_column + c.n_columns()] = mask.unmask(values)
            # TODO: in principle this masking should _not_ occur unless we know the user has called values_sanitized
            # - other calls should not cross-contaminate columns in this way
            mask.mark_nones_as_masked(values)
            c_column += c.n_columns()

        # TODO - problem: there is no good description of multiple properties
        return results, description