当前位置: 首页>>代码示例>>Python>>正文


Python defaults.get_defaults函数代码示例

本文整理汇总了Python中safe.defaults.get_defaults函数的典型用法代码示例。如果您正苦于以下问题:Python get_defaults函数的具体用法?Python get_defaults怎么用?Python get_defaults使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了get_defaults函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_check_aggregation_single_attribute

    def test_check_aggregation_single_attribute(self):
        """Aggregation attribute is chosen correctly when there is only
        one attr available."""
        layer_path = os.path.join(
            TESTDATA, 'kabupaten_jakarta_singlepart_1_good_attr.shp')
        file_list = [layer_path]
        # add additional layers
        load_layers(file_list, clear_flag=False)
        attribute_key = get_defaults('AGGR_ATTR_KEY')

        # with 1 good aggregation attribute using
        # kabupaten_jakarta_singlepart_1_good_attr.shp
        result, message = setup_scenario(
            self.DOCK,
            hazard='Continuous Flood',
            exposure='Population',
            function_id='FloodEvacuationRasterHazardFunction',
            aggregation_layer='kabupaten jakarta singlepart 1 good attr')
        set_jakarta_extent(dock=self.DOCK)
        assert result, message
        # Press RUN
        # noinspection PyCallByClass,PyTypeChecker
        self.DOCK.accept()
        aggregator = self.DOCK.impact_function.aggregator
        attribute = aggregator.attributes[attribute_key]
        message = (
            'The aggregation should be KAB_NAME. Found: %s' % attribute)
        self.assertEqual(attribute, 'KAB_NAME', message)
开发者ID:jobel-openscience,项目名称:inasafe,代码行数:28,代码来源:test_aggregator.py

示例2: test_check_aggregation_no_attributes

 def test_check_aggregation_no_attributes(self):
     """Aggregation attribute chosen correctly when no attr available."""
     layer_path = os.path.join(
         TESTDATA, 'kabupaten_jakarta_singlepart_0_good_attr.shp')
     file_list = [layer_path]
     # add additional layers
     load_layers(file_list, clear_flag=False)
     attribute_key = get_defaults('AGGR_ATTR_KEY')
     # with no good aggregation attribute using
     # kabupaten_jakarta_singlepart_0_good_attr.shp
     result, message = setup_scenario(
         DOCK,
         hazard='A flood in Jakarta like in 2007',
         exposure='People',
         function_id='Flood Evacuation Function',
         aggregation_layer='kabupaten jakarta singlepart 0 good attr')
     set_jakarta_extent(dock=DOCK)
     assert result, message
     # Press RUN
     DOCK.accept()
     DOCK.runtime_keywords_dialog.accept()
     attribute = DOCK.analysis.aggregator.attributes[attribute_key]
     message = (
         'The aggregation should be None. Found: %s' % attribute)
     assert attribute is None, message
开发者ID:severinmenard,项目名称:inasafe,代码行数:25,代码来源:test_aggregator.py

示例3: setUp

    def setUp(self):
        """Fixture run before all tests"""
        register_impact_functions()
        self.maxDiff = None  # show full diff for assert errors
        os.environ['LANG'] = 'en'
        self.DOCK.show_only_visible_layers_flag = True
        load_standard_layers(self.DOCK)
        self.DOCK.cboHazard.setCurrentIndex(0)
        self.DOCK.cboExposure.setCurrentIndex(0)
        self.DOCK.cboFunction.setCurrentIndex(0)
        self.DOCK.run_in_thread_flag = False
        self.DOCK.show_only_visible_layers_flag = False
        self.DOCK.set_layer_from_title_flag = False
        self.DOCK.zoom_to_impact_flag = False
        self.DOCK.hide_exposure_flag = False
        self.DOCK.show_intermediate_layers = False
        set_jakarta_extent()

        self._keywordIO = KeywordIO()
        self._defaults = get_defaults()

        # Set extent as Jakarta extent
        geo_crs = QgsCoordinateReferenceSystem()
        geo_crs.createFromSrid(4326)
        self.extent = extent_to_geo_array(CANVAS.extent(), geo_crs)
开发者ID:jobel-openscience,项目名称:inasafe,代码行数:25,代码来源:test_aggregator.py

示例4: test_get_defaults

    def test_get_defaults(self):
        """Test we can get the defaults.
        """
        expected = {
            'ADULT_RATIO_KEY': 'adult ratio default',
            'ADULT_RATIO_ATTR_KEY': 'adult ratio attribute',
            'ADULT_RATIO': 0.659,

            'FEMALE_RATIO_KEY': 'female ratio default',
            'FEMALE_RATIO_ATTR_KEY': 'female ratio attribute',
            'FEMALE_RATIO': 0.5,

            'ELDERLY_RATIO_ATTR_KEY': 'elderly ratio attribute',
            'ELDERLY_RATIO_KEY': 'elderly ratio default',
            'ELDERLY_RATIO': 0.078,

            'YOUTH_RATIO': 0.263,
            'YOUTH_RATIO_ATTR_KEY': 'youth ratio attribute',
            'YOUTH_RATIO_KEY': 'youth ratio default',

            'NO_DATA': u'No data',

            'AGGR_ATTR_KEY': 'aggregation attribute',
            'ISO19115_EMAIL': '[email protected]',
            'ISO19115_LICENSE': 'Free use with accreditation',
            'ISO19115_ORGANIZATION': 'InaSAFE.org',
            'ISO19115_TITLE': 'InaSAFE analysis result',
            'ISO19115_URL': 'http://inasafe.org'}

        actual = get_defaults()
        self.maxDiff = None
        self.assertDictEqual(expected, actual)
开发者ID:Charlotte-Morgan,项目名称:inasafe,代码行数:32,代码来源:test_defaults.py

示例5: test_check_aggregation_no_attributes

 def test_check_aggregation_no_attributes(self):
     """Aggregation attribute chosen correctly when no attr available."""
     layer_path = os.path.join(
         TESTDATA, 'kabupaten_jakarta_singlepart_0_good_attr.shp')
     file_list = [layer_path]
     # add additional layers
     load_layers(file_list, clear_flag=False)
     attribute_key = get_defaults('AGGR_ATTR_KEY')
     # with no good aggregation attribute using
     # kabupaten_jakarta_singlepart_0_good_attr.shp
     result, message = setup_scenario(
         self.DOCK,
         hazard='Continuous Flood',
         exposure='Population',
         function_id='FloodEvacuationRasterHazardFunction',
         aggregation_layer='kabupaten jakarta singlepart 0 good attr')
     set_jakarta_extent(dock=self.DOCK)
     self.assertTrue(result, message)
     # Press RUN
     self.DOCK.accept()
     aggregator = self.DOCK.impact_function.aggregator
     attribute = aggregator.attributes[attribute_key]
     message = (
         'The aggregation should be None. Found: %s' % attribute)
     self.assertIsNone(attribute, message)
开发者ID:jobel-openscience,项目名称:inasafe,代码行数:25,代码来源:test_aggregator.py

示例6: test_get_defaults

    def test_get_defaults(self):
        """Test we can get the defaults.
        """
        expected = {
            "ADULT_RATIO_KEY": "adult ratio default",
            "ADULT_RATIO_ATTR_KEY": "adult ratio attribute",
            "ADULT_RATIO": 0.659,
            "FEMALE_RATIO_KEY": "female ratio default",
            "FEMALE_RATIO_ATTR_KEY": "female ratio attribute",
            "FEMALE_RATIO": 0.5,
            "ELDERLY_RATIO_ATTR_KEY": "elderly ratio attribute",
            "ELDERLY_RATIO_KEY": "elderly ratio default",
            "ELDERLY_RATIO": 0.078,
            "YOUTH_RATIO": 0.263,
            "YOUTH_RATIO_ATTR_KEY": "youth ratio attribute",
            "YOUTH_RATIO_KEY": "youth ratio default",
            "NO_DATA": u"No data",
            "AGGR_ATTR_KEY": "aggregation attribute",
            "ISO19115_EMAIL": "[email protected]",
            "ISO19115_LICENSE": "Free use with accreditation",
            "ISO19115_ORGANIZATION": "InaSAFE.org",
            "ISO19115_TITLE": "InaSAFE analysis result",
            "ISO19115_URL": "http://inasafe.org",
        }

        actual = get_defaults()
        self.maxDiff = None
        self.assertDictEqual(expected, actual)
开发者ID:Mloweedgar,项目名称:inasafe,代码行数:28,代码来源:test_defaults.py

示例7: setup

    def setup(self, params):
        """concrete implementation it takes care of the needed parameters being
         initialized

        Args:
            params: dict of parameters to pass to the post processor
        Returns:
            None
        Raises:
            None
        """
        AbstractPostprocessor.setup(self, None)
        if self.impact_total is not None:
            self._raise_error('clear needs to be called before setup')

        self.impact_total = params['impact_total']
        try:
            #either all 3 ratio are custom set or we use defaults
            self.youth_ratio = params['youth_ratio']
            self.adult_ratio = params['adult_ratio']
            self.elder_ratio = params['elder_ratio']
        except KeyError:
            self._log_message('either all 3 age ratio are custom set or we'
                              ' use defaults')
            defaults = get_defaults()
            self.youth_ratio = defaults['YOUTH_RATIO']
            self.adult_ratio = defaults['ADULT_RATIO']
            self.elder_ratio = defaults['ELDER_RATIO']
开发者ID:borysiasty,项目名称:inasafe,代码行数:28,代码来源:age_postprocessor.py

示例8: test_check_aggregation_single_attribute

    def test_check_aggregation_single_attribute(self):
        """Aggregation attribute is chosen correctly when there is only
        one attr available."""
        layer_path = os.path.join(
            TESTDATA, 'kabupaten_jakarta_singlepart_1_good_attr.shp')
        file_list = [layer_path]
        # add additional layers
        load_layers(file_list, clear_flag=False)
        attribute_key = get_defaults('AGGR_ATTR_KEY')

        # with 1 good aggregation attribute using
        # kabupaten_jakarta_singlepart_1_good_attr.shp
        result, message = setup_scenario(
            DOCK,
            hazard='A flood in Jakarta like in 2007',
            exposure='People',
            function_id='Flood Evacuation Function',
            aggregation_layer='kabupaten jakarta singlepart 1 good attr')
        set_jakarta_extent(dock=DOCK)
        assert result, message
        # Press RUN
        # noinspection PyCallByClass,PyTypeChecker
        DOCK.accept()
        DOCK.runtime_keywords_dialog.accept()
        print attribute_key
        print DOCK.analysis.aggregator.attributes
        attribute = DOCK.analysis.aggregator.attributes[attribute_key]
        message = (
            'The aggregation should be KAB_NAME. Found: %s' % attribute)
        self.assertEqual(attribute, 'KAB_NAME', message)
开发者ID:severinmenard,项目名称:inasafe,代码行数:30,代码来源:test_aggregator.py

示例9: __init__

    def __init__(self, iface, dock=None, parent=None):
        """Constructor for the dialog.

        :param iface: A Quantum GIS QGisAppInterface instance.
        :type iface: QGisAppInterface

        :param parent: Parent widget of this dialog
        :type parent: QWidget

        :param dock: Optional dock widget instance that we can notify of
            changes to the keywords.
        :type dock: Dock
        """

        QtGui.QDialog.__init__(self, parent)
        self.setupUi(self)
        self.setWindowTitle(self.tr('InaSAFE %s Options' % get_version()))
        # Save reference to the QGIS interface and parent
        self.iface = iface
        self.parent = parent
        self.dock = dock
        self.keyword_io = KeywordIO()
        self.defaults = get_defaults()

        # Set up things for context help
        self.help_button = self.button_box.button(QtGui.QDialogButtonBox.Help)
        # Allow toggling the help button
        self.help_button.setCheckable(True)
        self.help_button.toggled.connect(self.help_toggled)
        self.main_stacked_widget.setCurrentIndex(1)

        self.grpNotImplemented.hide()
        self.adjustSize()
        self.restore_state()
        # hack prevent showing use thread visible and set it false see #557
        self.cbxUseThread.setChecked(True)
        self.cbxUseThread.setVisible(False)

        # Set up listener for various UI
        self.custom_org_logo_checkbox.toggled.connect(
            self.set_organisation_logo)
        self.custom_north_arrow_checkbox.toggled.connect(self.set_north_arrow)
        self.custom_UseUserDirectory_checkbox.toggled.connect(
            self.set_user_dir)
        self.custom_templates_dir_checkbox.toggled.connect(
            self.set_templates_dir)
        self.custom_org_disclaimer_checkbox.toggled.connect(
            self.set_org_disclaimer)
开发者ID:dynaryu,项目名称:inasafe,代码行数:48,代码来源:options_dialog.py

示例10: test_on_rad_postprocessing_toggled

    def test_on_rad_postprocessing_toggled(self):
        """Test postprocessing radio button toggle behaviour works"""
        layer = clone_shp_layer(
            name='district_osm_jakarta',
            include_keywords=True,
            source_directory=test_data_path('boundaries'))
        defaults = get_defaults()
        dialog = KeywordsDialog(PARENT, IFACE, layer=layer)
        # Click hazard/exposure button first so that it won't take default
        # from keywords file
        dialog.radExposure.click()

        # Now click the postprocessing button
        button = dialog.radPostprocessing
        button.click()
        message = (
            'Toggling the postprocessing radio did not add a '
            'category to the keywords list.')
        self.assertEqual(
            dialog.get_value_for_key('category'), 'postprocessing', message)

        message = (
            'Toggling the postprocessing radio did not add an '
            'aggregation attribute to the keywords list.')
        self.assertEqual(
            dialog.get_value_for_key(defaults['AGGR_ATTR_KEY']),
            'KAB_NAME',
            message)

        message = (
            'Toggling the postprocessing radio did not add a '
            'female ratio attribute to the keywords list.')
        self.assertEqual(
            dialog.get_value_for_key(defaults['FEMALE_RATIO_ATTR_KEY']),
            dialog.global_default_string,
            message)

        message = (
            'Toggling the postprocessing radio did not add a '
            'female ratio default value to the keywords list.')
        self.assertEqual(
            float(dialog.get_value_for_key(defaults['FEMALE_RATIO_KEY'])),
            defaults['FEMALE_RATIO'],
            message)
开发者ID:Charlotte-Morgan,项目名称:inasafe,代码行数:44,代码来源:test_keywords_dialog.py

示例11: test_aggregation_attribute_in_keywords

    def test_aggregation_attribute_in_keywords(self):
        """Aggregation attribute is chosen correctly when present in keywords.
        """
        attribute_key = get_defaults('AGGR_ATTR_KEY')

        # with KAB_NAME aggregation attribute defined in .keyword using
        # kabupaten_jakarta_singlepart.shp
        result, message = setup_scenario(
            self.DOCK,
            hazard='Continuous Flood',
            exposure='Population',
            function_id='FloodEvacuationRasterHazardFunction',
            aggregation_layer=u"Dístríct's of Jakarta",
            aggregation_enabled_flag=True)
        set_jakarta_extent(dock=self.DOCK)
        assert result, message
        # Press RUN
        self.DOCK.accept()
        attribute = self.DOCK.analysis.aggregator.attributes[attribute_key]
        message = ('The aggregation should be KAB_NAME. Found: %s' % attribute)
        self.assertEqual(attribute, 'KAB_NAME', message)
开发者ID:codeforresilience,项目名称:inasafe,代码行数:21,代码来源:test_aggregator.py

示例12: test_aggregation_attribute_in_keywords

    def test_aggregation_attribute_in_keywords(self):
        """Aggregation attribute is chosen correctly when present in keywords.
        """
        attribute_key = get_defaults('AGGR_ATTR_KEY')

        # with KAB_NAME aggregation attribute defined in .keyword using
        # kabupaten_jakarta_singlepart.shp
        result, message = setup_scenario(
            DOCK,
            hazard='A flood in Jakarta like in 2007',
            exposure='People',
            function_id='Flood Evacuation Function',
            aggregation_layer='kabupaten jakarta singlepart',
            aggregation_enabled_flag=True)
        set_jakarta_extent(dock=DOCK)
        assert result, message
        # Press RUN
        DOCK.accept()
        DOCK.runtime_keywords_dialog.accept()
        attribute = DOCK.analysis.aggregator.attributes[attribute_key]
        message = ('The aggregation should be KAB_NAME. Found: %s' % attribute)
        self.assertEqual(attribute, 'KAB_NAME', message)
开发者ID:severinmenard,项目名称:inasafe,代码行数:22,代码来源:test_aggregator.py

示例13: test_check_aggregation_none_in_keywords

 def test_check_aggregation_none_in_keywords(self):
     """Aggregation attribute is chosen correctly when None in keywords."""
     layer_path = os.path.join(
         TESTDATA, 'kabupaten_jakarta_singlepart_with_None_keyword.shp')
     file_list = [layer_path]
     # add additional layers
     load_layers(file_list, clear_flag=False)
     attribute_key = get_defaults('AGGR_ATTR_KEY')
     # with None aggregation attribute defined in .keyword using
     # kabupaten_jakarta_singlepart_with_None_keyword.shp
     result, message = setup_scenario(
         self.DOCK,
         hazard='Continuous Flood',
         exposure='Population',
         function_id='FloodEvacuationRasterHazardFunction',
         aggregation_layer='kabupaten jakarta singlepart with None keyword')
     set_jakarta_extent(dock=self.DOCK)
     assert result, message
     # Press RUN
     self.DOCK.accept()
     attribute = self.DOCK.analysis.aggregator.attributes[attribute_key]
     message = ('The aggregation should be None. Found: %s' % attribute)
     assert attribute is None, message
开发者ID:codeforresilience,项目名称:inasafe,代码行数:23,代码来源:test_aggregator.py

示例14: test_clip_vector_with_unicode

    def test_clip_vector_with_unicode(self):
        """Test clipping vector layer with unicode attribute in feature.

        This issue is described at Github #2262 and #2233
        TODO: FIXME:
        This is a hacky fix. See above ticket for further explanation.
        To fix this, we should be able to specify UTF-8 encoding for
        QgsVectorFileWriter
        """
        # this layer contains unicode values in the
        layer_path = standard_data_path(
            'boundaries', 'district_osm_jakarta.shp')
        vector_layer = QgsVectorLayer(layer_path, 'District Jakarta', 'ogr')
        keyword_io = KeywordIO()
        aggregation_keyword = get_defaults()['AGGR_ATTR_KEY']
        aggregation_attribute = keyword_io.read_keywords(
            vector_layer, keyword=aggregation_keyword)
        source_extent = vector_layer.extent()
        extent = [source_extent.xMinimum(), source_extent.yMinimum(),
                  source_extent.xMaximum(), source_extent.yMaximum()]
        clipped_layer = clip_layer(
            layer=vector_layer,
            extent=extent,
            explode_flag=True,
            explode_attribute=aggregation_attribute)

        # cross check vector layer attribute in clipped layer
        vector_values = []
        for f in vector_layer.getFeatures():
            vector_values.append(f.attributes())

        clipped_values = []
        for f in clipped_layer.getFeatures():
            clipped_values.append(f.attributes())

        for val in clipped_values:
            self.assertIn(val, vector_values)
开发者ID:easmetz,项目名称:inasafe,代码行数:37,代码来源:test_clipper.py

示例15: setup

    def setup(self, params):
        """Concrete implementation to ensure needed parameters are initialized.

        :param params: Dict of parameters to pass to the post processor.
        :type params: dict

        """
        AbstractPostprocessor.setup(self, None)
        if self.impact_total is not None:
            self._raise_error('clear needs to be called before setup')

        self.impact_total = params['impact_total']
        try:
            # either all 3 ratio are custom set or we use defaults
            self.youth_ratio = params['youth_ratio']
            self.adult_ratio = params['adult_ratio']
            self.elderly_ratio = params['elderly_ratio']

            ratios_total = (self.youth_ratio +
                            self.adult_ratio +
                            self.elderly_ratio)
            if ratios_total > 1:
                self._raise_error(
                    'Age ratios should sum up to 1. Found: '
                    '%s + %s + %s = %s ' % (
                        self.youth_ratio,
                        self.adult_ratio,
                        self.elderly_ratio,
                        ratios_total))
        except KeyError:
            self._log_message('either all 3 age ratio are custom set or we'
                              ' use defaults')
            defaults = get_defaults()
            self.youth_ratio = defaults['YOUTH_RATIO']
            self.adult_ratio = defaults['ADULT_RATIO']
            self.elderly_ratio = defaults['ELDERLY_RATIO']
开发者ID:felix-yew,项目名称:inasafe,代码行数:36,代码来源:age_postprocessor.py


注:本文中的safe.defaults.get_defaults函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。