Пример #1
0
 def _evaluate_function(self, halos, input_descriptions, input_values):
     from .. import properties
     sim = consistent_collection.consistent_simulation_from_halos(halos)
     results = []
     calculator = properties.providing_class(self.name())(
         sim, *input_descriptions)
     for inputs in zip(halos, *input_values):
         if self._has_required_properties(inputs[0]) and all(
             [x is not None for x in inputs]):
             results.append(
                 calculator.live_calculate_named(self.name(), *inputs))
         else:
             results.append(None)
     return calculator, self._as_1xn_array(results)
Пример #2
0
    def values_and_description(self, halos):
        from .. import properties
        values = self.values(halos)
        if len(halos) == 0:
            # cannot build a meaningful property description as we don't have any halos, therefore don't know
            # anything about the simulation or which property calculations are relevant for it
            return values, None

        sim = consistent_collection.consistent_simulation_from_halos(halos)
        description_class = properties.providing_class(
            self._name, sim.output_handler_class, silent_fail=True)
        description = None
        if description_class is not None:
            try:
                description = description_class(sim)
            except Exception as e:
                warnings.warn(
                    "%r occurred while trying to produce a property description from class %r"
                    % (e, description_class), RuntimeWarning)
        return values, description
Пример #3
0
    def _evaluate_function(self, halos, input_descriptions, input_values):
        from .. import properties
        sim = consistent_collection.consistent_simulation_from_halos(halos)
        calculator = properties.providing_class(self.name())(
            sim, *input_descriptions)
        timestep_ordering = np.argsort([h.timestep.id for h in halos])
        results = [None for i in range(len(halos))]
        current_ts = None
        for i in timestep_ordering:
            inputs = [input[i] for input in input_values]
            halo = halos[i]
            if self._has_required_properties(halo) and all(
                [x is not None for x in inputs]):
                if halo.timestep != current_ts:
                    current_ts = halo.timestep
                    calculator.preloop(None, current_ts)
                results[i] = calculator.live_calculate_named(
                    self.name(), halo, *inputs)

        return calculator, self._as_1xn_array(results)
Пример #4
0
def test_generate_from_halos():
    col2 = cc.consistent_simulation_from_halos([h1, h2, h2])
    assert col2['consistent_property'] == 1.0