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


Python core.AttribDict类代码示例

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


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

示例1: test_setitem

 def test_setitem(self):
     """
     Tests __setitem__ method of AttribDict class.
     """
     # 1
     ad = AttribDict()
     ad['test'] = 'NEW'
     self.assertEqual(ad['test'], 'NEW')
     self.assertEqual(ad.test, 'NEW')
     self.assertEqual(ad.get('test'), 'NEW')
     self.assertEqual(ad.__getattr__('test'), 'NEW')
     self.assertEqual(ad.__getitem__('test'), 'NEW')
     self.assertEqual(ad.__dict__['test'], 'NEW')
     self.assertEqual(ad.__dict__.get('test'), 'NEW')
     self.assertIn('test', ad)
     self.assertIn('test', ad.__dict__)
     # 2
     ad = AttribDict()
     ad.__setitem__('test', 'NEW')
     self.assertEqual(ad['test'], 'NEW')
     self.assertEqual(ad.test, 'NEW')
     self.assertEqual(ad.get('test'), 'NEW')
     self.assertEqual(ad.__getattr__('test'), 'NEW')
     self.assertEqual(ad.__getitem__('test'), 'NEW')
     self.assertEqual(ad.__dict__['test'], 'NEW')
     self.assertEqual(ad.__dict__.get('test'), 'NEW')
     self.assertIn('test', ad)
     self.assertIn('test', ad.__dict__)
开发者ID:3rdcycle,项目名称:obspy,代码行数:28,代码来源:test_util_attribdict.py

示例2: get_model_info

    def get_model_info(self, model_name):
        """
        Get some information about a particular model.

        .. rubric:: Example

        >>> from obspy.clients.syngine import Client
        >>> c = Client()
        >>> db_info = c.get_model_info(model_name="ak135f_5s")
        >>> print(db_info.period)
        5.125

        :param model_name: The name of the model. Case insensitive.
        :type model_name: str
        :returns: A dictionary with more information about any model.
        :rtype: :class:`obspy.core.util.attribdict.AttribDict`
        """
        model_name = model_name.strip().lower()
        r = self._download(self._get_url("info"),
                           params={"model": model_name})
        info = AttribDict(get_json(r))
        # Convert slip and sliprate into numpy arrays for easier handling.
        info.slip = np.array(info.slip, dtype=np.float64)
        info.sliprate = np.array(info.sliprate, dtype=np.float64)
        return info
开发者ID:calum-chamberlain,项目名称:obspy,代码行数:25,代码来源:client.py

示例3: test_setitem

 def test_setitem(self):
     """
     Tests __setitem__ method of AttribDict class.
     """
     # 1
     ad = AttribDict()
     ad["test"] = "NEW"
     self.assertEqual(ad["test"], "NEW")
     self.assertEqual(ad.test, "NEW")
     self.assertEqual(ad.get("test"), "NEW")
     self.assertEqual(ad.__getattr__("test"), "NEW")
     self.assertEqual(ad.__getitem__("test"), "NEW")
     self.assertEqual(ad.__dict__["test"], "NEW")
     self.assertEqual(ad.__dict__.get("test"), "NEW")
     self.assertTrue("test" in ad)
     self.assertTrue("test" in ad.__dict__)
     # 2
     ad = AttribDict()
     ad.__setitem__("test", "NEW")
     self.assertEqual(ad["test"], "NEW")
     self.assertEqual(ad.test, "NEW")
     self.assertEqual(ad.get("test"), "NEW")
     self.assertEqual(ad.__getattr__("test"), "NEW")
     self.assertEqual(ad.__getitem__("test"), "NEW")
     self.assertEqual(ad.__dict__["test"], "NEW")
     self.assertEqual(ad.__dict__.get("test"), "NEW")
     self.assertTrue("test" in ad)
     self.assertTrue("test" in ad.__dict__)
开发者ID:gauteh,项目名称:obspy,代码行数:28,代码来源:test_util_attribdict.py

示例4: test_init

 def test_init(self):
     """
     Tests initialization of AttribDict class.
     """
     ad = AttribDict({'test': 'NEW'})
     self.assertEqual(ad['test'], 'NEW')
     self.assertEqual(ad.test, 'NEW')
     self.assertEqual(ad.get('test'), 'NEW')
     self.assertEqual(ad.__getattr__('test'), 'NEW')
     self.assertEqual(ad.__getitem__('test'), 'NEW')
     self.assertEqual(ad.__dict__['test'], 'NEW')
     self.assertEqual(ad.__dict__.get('test'), 'NEW')
     self.assertIn('test', ad)
     self.assertIn('test', ad.__dict__)
开发者ID:3rdcycle,项目名称:obspy,代码行数:14,代码来源:test_util_attribdict.py

示例5: test_init

 def test_init(self):
     """
     Tests initialization of AttribDict class.
     """
     ad = AttribDict({"test": "NEW"})
     self.assertEqual(ad["test"], "NEW")
     self.assertEqual(ad.test, "NEW")
     self.assertEqual(ad.get("test"), "NEW")
     self.assertEqual(ad.__getattr__("test"), "NEW")
     self.assertEqual(ad.__getitem__("test"), "NEW")
     self.assertEqual(ad.__dict__["test"], "NEW")
     self.assertEqual(ad.__dict__.get("test"), "NEW")
     self.assertTrue("test" in ad)
     self.assertTrue("test" in ad.__dict__)
开发者ID:gauteh,项目名称:obspy,代码行数:14,代码来源:test_util_attribdict.py

示例6: test_popitem

 def test_popitem(self):
     """
     Tests pop method of AttribDict class.
     """
     ad = AttribDict()
     ad['test2'] = 'test'
     # removing via popitem
     temp = ad.popitem()
     self.assertEqual(temp, ('test2', 'test'))
     self.assertFalse('test2' in ad)
     self.assertFalse('test2' in ad.__dict__)
     self.assertFalse(hasattr(ad, 'test2'))
     # popitem for empty AttribDict raises a KeyError
     self.assertRaises(KeyError, ad.popitem)
开发者ID:3rdcycle,项目名称:obspy,代码行数:14,代码来源:test_util_attribdict.py

示例7: test_popitem

 def test_popitem(self):
     """
     Tests pop method of AttribDict class.
     """
     ad = AttribDict()
     ad["test2"] = "test"
     # removing via popitem
     temp = ad.popitem()
     self.assertEquals(temp, ("test2", "test"))
     self.assertFalse("test2" in ad)
     self.assertFalse("test2" in ad.__dict__)
     self.assertFalse(hasattr(ad, "test2"))
     # popitem for empty AttribDict raises a KeyError
     self.assertRaises(KeyError, ad.popitem)
开发者ID:gauteh,项目名称:obspy,代码行数:14,代码来源:test_util_attribdict.py

示例8: test_clear

 def test_clear(self):
     """
     Tests clear method of AttribDict class.
     """
     ad = AttribDict()
     ad.test = 1
     ad['test2'] = 'test'
     # removing via pop
     ad.clear()
     self.assertFalse('test' in ad)
     self.assertFalse('test2' in ad)
     self.assertFalse('test' in ad.__dict__)
     self.assertFalse('test2' in ad.__dict__)
     self.assertFalse(hasattr(ad, 'test'))
     self.assertFalse(hasattr(ad, 'test2'))
     # class attributes should be still present
     self.assertTrue(hasattr(ad, 'readonly'))
     self.assertTrue(hasattr(ad, 'defaults'))
开发者ID:3rdcycle,项目名称:obspy,代码行数:18,代码来源:test_util_attribdict.py

示例9: test_pop

 def test_pop(self):
     """
     Tests pop method of AttribDict class.
     """
     ad = AttribDict()
     ad.test = 1
     ad['test2'] = 'test'
     # removing via pop
     temp = ad.pop('test')
     self.assertEqual(temp, 1)
     self.assertFalse('test' in ad)
     self.assertIn('test2', ad)
     self.assertFalse('test' in ad.__dict__)
     self.assertIn('test2', ad.__dict__)
     self.assertFalse(hasattr(ad, 'test'))
     self.assertTrue(hasattr(ad, 'test2'))
     # using pop() for not existing element raises a KeyError
     self.assertRaises(KeyError, ad.pop, 'test')
开发者ID:3rdcycle,项目名称:obspy,代码行数:18,代码来源:test_util_attribdict.py

示例10: test_pop

 def test_pop(self):
     """
     Tests pop method of AttribDict class.
     """
     ad = AttribDict()
     ad.test = 1
     ad["test2"] = "test"
     # removing via pop
     temp = ad.pop("test")
     self.assertEquals(temp, 1)
     self.assertFalse("test" in ad)
     self.assertTrue("test2" in ad)
     self.assertFalse("test" in ad.__dict__)
     self.assertTrue("test2" in ad.__dict__)
     self.assertFalse(hasattr(ad, "test"))
     self.assertTrue(hasattr(ad, "test2"))
     # using pop() for not existing element raises a KeyError
     self.assertRaises(KeyError, ad.pop, "test")
开发者ID:gauteh,项目名称:obspy,代码行数:18,代码来源:test_util_attribdict.py

示例11: test_delete

 def test_delete(self):
     """
     Tests delete method of AttribDict class.
     """
     ad = AttribDict()
     ad.test = 1
     ad['test2'] = 'test'
     # deleting test using dictionary
     del ad['test']
     self.assertFalse('test' in ad)
     self.assertIn('test2', ad)
     self.assertFalse('test' in ad.__dict__)
     self.assertIn('test2', ad.__dict__)
     self.assertFalse(hasattr(ad, 'test'))
     self.assertTrue(hasattr(ad, 'test2'))
     # deleting test2 using attribute
     del ad.test2
     self.assertFalse('test2' in ad)
     self.assertFalse('test2' in ad.__dict__)
     self.assertFalse(hasattr(ad, 'test2'))
开发者ID:3rdcycle,项目名称:obspy,代码行数:20,代码来源:test_util_attribdict.py

示例12: test_delete

 def test_delete(self):
     """
     Tests delete method of AttribDict class.
     """
     ad = AttribDict()
     ad.test = 1
     ad["test2"] = "test"
     # deleting test using dictionary
     del ad["test"]
     self.assertFalse("test" in ad)
     self.assertTrue("test2" in ad)
     self.assertFalse("test" in ad.__dict__)
     self.assertTrue("test2" in ad.__dict__)
     self.assertFalse(hasattr(ad, "test"))
     self.assertTrue(hasattr(ad, "test2"))
     # deleting test2 using attribute
     del ad.test2
     self.assertFalse("test2" in ad)
     self.assertFalse("test2" in ad.__dict__)
     self.assertFalse(hasattr(ad, "test2"))
开发者ID:gauteh,项目名称:obspy,代码行数:20,代码来源:test_util_attribdict.py

示例13: test_defaults

 def test_defaults(self):
     """
     Tests default of __getitem__/__getattr__ methods of AttribDict class.
     """
     # 1
     ad = AttribDict()
     ad['test'] = 'NEW'
     self.assertEqual(ad.__getitem__('test'), 'NEW')
     self.assertEqual(ad.__getitem__('xxx', 'blub'), 'blub')
     self.assertEqual(ad.__getitem__('test', 'blub'), 'NEW')
     self.assertEqual(ad.__getattr__('test'), 'NEW')
     self.assertEqual(ad.__getattr__('xxx', 'blub'), 'blub')
     self.assertEqual(ad.__getattr__('test', 'blub'), 'NEW')
     # should raise KeyError without default item
     self.assertRaises(KeyError, ad.__getitem__, 'xxx')
     self.assertRaises(AttributeError, ad.__getattr__, 'xxx')
     # 2
     ad2 = AttribDict(defaults={'test2': 'NEW'})
     self.assertEqual(ad2.__getitem__('test2'), 'NEW')
     self.assertRaises(KeyError, ad2.__getitem__, 'xxx')
开发者ID:3rdcycle,项目名称:obspy,代码行数:20,代码来源:test_util_attribdict.py

示例14: _read_SES3D

def _read_SES3D(fh, headonly=False):
    """
    Internal SES3D parsing routine.
    """
    # Import here to avoid circular imports.
    from obspy.core import AttribDict, Trace, Stream

    # Read the header.
    component = fh.readline().split()[0].lower()
    npts = int(fh.readline().split()[-1])
    delta = float(fh.readline().split()[-1])
    # Skip receiver location line.
    fh.readline()
    rec_loc = fh.readline().split()
    rec_x, rec_y, rec_z = map(float, [rec_loc[1], rec_loc[3], rec_loc[5]])
    # Skip the source location line.
    fh.readline()
    src_loc = fh.readline().split()
    src_x, src_y, src_z = map(float, [src_loc[1], src_loc[3], src_loc[5]])

    # Read the data.
    if headonly is False:
        data = np.array(map(float, fh.readlines()),
                        dtype="float32")
    else:
        data = np.array([])

    ses3d = AttribDict()
    ses3d.receiver_latitude = rotations.colat2lat(rec_x)
    ses3d.receiver_longitude = rec_y
    ses3d.receiver_depth_in_m = rec_z
    ses3d.source_latitude = rotations.colat2lat(src_x)
    ses3d.source_longitude = src_y
    ses3d.source_depth_in_m = src_z

    header = {
        "delta": delta,
        "channel": COMPONENT_MAP[component],
        "ses3d": ses3d,
        "npts": npts
    }

    # Setup Obspy Stream/Trace structure.
    tr = Trace(data=data, header=header)

    # Small check.
    if headonly is False and npts != tr.stats.npts:
        msg = "The sample count specified in the header does not match " + \
            "the actual data count."
        warnings.warn(msg)
    return Stream(traces=[tr])
开发者ID:Phlos,项目名称:LASIF,代码行数:51,代码来源:ses3d_file_parser.py

示例15: test_defaults

 def test_defaults(self):
     """
     Tests default of __getitem__/__getattr__ methods of AttribDict class.
     """
     # 1
     ad = AttribDict()
     ad["test"] = "NEW"
     self.assertEqual(ad.__getitem__("test"), "NEW")
     self.assertEqual(ad.__getitem__("xxx", "blub"), "blub")
     self.assertEqual(ad.__getitem__("test", "blub"), "NEW")
     self.assertEqual(ad.__getattr__("test"), "NEW")
     self.assertEqual(ad.__getattr__("xxx", "blub"), "blub")
     self.assertEqual(ad.__getattr__("test", "blub"), "NEW")
     # should raise KeyError without default item
     self.assertRaises(KeyError, ad.__getitem__, "xxx")
     self.assertRaises(KeyError, ad.__getattr__, "xxx")
开发者ID:gauteh,项目名称:obspy,代码行数:16,代码来源:test_util_attribdict.py


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