def_unit#
- astropy.units.def_unit(s: str | list[str], represents: UnitLike, doc: str | None = None, format: Mapping[str, str] | None = None, prefixes: bool | Iterable[UnitPrefix] = False, exclude_prefixes: Collection[str] = (), namespace: MutableMapping[str, object] | None = None) Unit[源代码]#
- astropy.units.def_unit(s: str | list[str], represents: None = None, doc: str | None = None, format: Mapping[str, str] | None = None, prefixes: bool | Iterable[UnitPrefix] = False, exclude_prefixes: Collection[str] = (), namespace: MutableMapping[str, object] | None = None) IrreducibleUnit
定义一个新单位。
该功能与直接创建单元不同
Unit或IrreducibleUnit因为它还可以在给定的命名空间中自动生成带后缀的单元。- 参数:
- s :
str或list的strPYTHON:STR或PYTHON:PYTHON列表:STR 单位名称。如果是列表,第一个元素是规范(短)名称,其余元素是别名。
- represents : astropy:unit-like ,可选AstPy:单元式,可选
此命名单元表示的单元。如果未提供,则
IrreducibleUnit创建。- doc :
str,可选Python:字符串,可选 描述单元的docstring。
- format :
dict,可选Python:Dict,可选 用于格式化此单元的特定表示形式的映射。例如,对于
Ohm单位,最好把它显示为\Omega由latex格式化程序。那样的话,format参数应设置为::{'latex': r'\Omega'}
- prefixes : bool 或 iterable 的
UnitPrefix,可选bool或pPython:UnitPreFix的可迭代性,可选 当
True,也生成该单元的所有SI后缀版本。 例如,对于给定的单位m,将产生mm,cm,km等。如果只应该创建几个带后缀的版本,那么UnitPrefix可以指定实例。默认值为False,这意味着不会生成任何带后缀的版本。此函数始终返回基本单位对象,即使创建了单位的多个缩放版本。
- exclude_prefixes :
Collectionofstr,可选Python集合:url,可选 如果需要排除任何SI后缀,则可以在此处列出它们。 例如,当定义
a,exclude_prefixes应设置为["P"]使得Pa仍然指帕斯卡。- namespace :
dict,可选Python:Dict,可选 当提供时,将单元(及其所有别名和前缀)注入给定的命名空间字典中。
- s :
- 返回:
- 加薪:
ValueError如果
represents无法作为一个单位进行解析,例如,因为它是一根畸形的弦或Quantity那不是一个纯量。