Ejemplo n.º 1
0
    def test_filter_choices(self):
        from tao.datasets import filter_choices

        s1 = SimulationFactory.create()
        s2 = SimulationFactory.create()
        
        g1 = GalaxyModelFactory.create()
        g3 = GalaxyModelFactory.create()
        
        d1 = DataSetFactory.create(simulation=s1, galaxy_model=g3)
        d2 = DataSetFactory.create(simulation=s2, galaxy_model=g1)

        dp1 = DataSetPropertyFactory.create(dataset=d1, units='dp1u')
        dp2 = DataSetPropertyFactory.create(dataset=d2, units='dp2u')
        dp3 = DataSetPropertyFactory.create(dataset=d2, units='dp3u')
        DataSetPropertyFactory.create(dataset=d2, units='', data_type = DataSetProperty.TYPE_STRING)

        galaxies = [g1, g3]

        filtered1 = [filter_choices(s1.id, g.id) for g in galaxies]
        filtered1 = [val for galaxies in filtered1 for val in galaxies]

        self.assertEqual([dp1.id],[x.id for x in filtered1])

        filtered2 = [filter_choices(s2.id, g.id) for g in galaxies]
        filtered2 = [val for galaxies in filtered2 for val in galaxies]

        self.assertEqual([dp2.id,dp3.id],[x.id for x in filtered2])
    def __init__(self, *args, **kwargs):
        self.ui_holder = args[0]
        super(RecordFilterForm, self).__init__(*args[1:], **kwargs)
        is_int = False
        if self.ui_holder.is_bound('light_cone'):
            objs = datasets.filter_choices(
                self.ui_holder.raw_data('light_cone', 'dark_matter_simulation'),
                self.ui_holder.raw_data('light_cone', 'galaxy_model'))
            choices = [('X-' + NO_FILTER, 'No Filter')] + [('D-' + str(x.id), x.label + ' (' + x.units + ')') for x in objs] + \
                [('B-' + str(x.id) + '_apparent', x.label) for x in datasets.band_pass_filters_objects()] + \
                [('B-' + str(x.id) + '_absolute', x.label) for x in datasets.band_pass_filters_objects()]
            filter_type, record_filter = args[1]['record_filter-filter'].split('-')
            if filter_type == 'D':
                obj = DataSetProperty.objects.get(pk = record_filter)
                is_int = obj.data_type == DataSetProperty.TYPE_INT or obj.data_type == DataSetProperty.TYPE_LONG_LONG
        else:
            choices = [] # [('X-' + NO_FILTER, 'No Filter')]
        if is_int:
            args = {'required': False,  'decimal_places': 0, 'max_digits': 20}
            val_class = forms.DecimalField
        else:
            args = {'required': False}
            val_class = forms.FloatField

        self.fields['filter'] = forms.ChoiceField(required=True, choices=choices)
        self.fields['max'] = val_class(**dict(args.items()+{'label':_('Max'), 'widget': forms.TextInput(attrs={'maxlength': '20'})}.items()))
        self.fields['min'] = val_class(**dict(args.items()+{'label':_('Min'), 'widget': forms.TextInput(attrs={'maxlength': '20'})}.items()))
        self.fields['filter'].label = 'Apply global catalogue selection using...'

        self.fields['filter'].widget.attrs['data-bind'] = 'options: selections, value: selection, optionsText: function(i) { return i.label }'
        self.fields['min'].widget.attrs['data-bind'] = 'value: selection_min'
        self.fields['max'].widget.attrs['data-bind'] = 'value: selection_max'
Ejemplo n.º 3
0
 def get_expected_filter_options(self, data_set):
     def gen_bp_pairs(objs):
         for obj in objs:
             yield ('B-' + str(obj.id) + '_apparent')
             yield ('B-' + str(obj.id) + '_absolute')
     normal_parameters = datasets.filter_choices(data_set.simulation.id, data_set.galaxy_model.id)
     bandpass_parameters = datasets.band_pass_filters_objects()
     return ['D-' + str(x.id) for x in normal_parameters] + [pair for pair in gen_bp_pairs(bandpass_parameters)]