NuGrid 的 Python 工具
项目描述
NuGridPy
NuGridPy是 NuGrid Python 包,提供工具来访问和分析(例如绘图)来自 NuGrid 代码(mppnp 和 ppn)的各种输出格式(包括NuGrid hdf5-based se 格式)和使用NuGrid mesa_h5 MESA 扩展的 MESA 恒星演化代码. 原则上,如果NuGrid se 库用于输出,NuGridPy 包可以用于任何恒星进化代码 输出。mesa.py 模块将使用 LOGS目录中的 MESA ASCII 输出。
使用 NuGridPy
NuGridPy 模块在编写时考虑到了交互式工作模式,或者
利用交互式 ipython 会话,或
在 jupyter ipython 笔记本中。一旦您的会话开始从 NuGridPy 包中导入模块,例如mesa、nugridse或ppn(取决于您使用的数据类型),例如:
from nugridpy import mesa as ms
示例会话
可以在NuGrid 数据交互 (WENDI)的 Web 探索服务器上执行的 jupyter 笔记本中的典型示例会话如下所示:
转到https://wendi.nugridstars.org并使用您的 github ID 登录(会话将定期筛选 > 几个小时,如果您想在此试用期之后使用此服务,请向 uvic 的 fherwig 发送消息.ca)
启动 Python 3 ipython 笔记本
加载 NuGridPy 包并初始化数据源:
%pylab # loading packages from nugridpy import nugridse as nuse from nugridpy import mesa #setting data path for mesa and nuse data_dir='/data/nugrid_vos' # data_dir='/data/nugrid_apod2/' # alternative data store # do ! ls /data/nug* to check for other alternative data stores mesa.set_nugrid_path(data_dir) nuse.set_nugrid_path(data_dir)
创建 see 和 ppd 实例
# see: Stellar Evolution and Explosion data # ppd: Post-Processing Data m2z02_ppd=nuse.se(mass=2,Z=0.02) m2z02_see=mesa.history_data(mass=2,Z=0.02)
绘制 Hertzsprung-Russel 图或 Kippenhahn 图
m2z02_see.hrd_new()
m2z02_see.kip_cont()
查询文档字符串,从 ppd data_dir 绘制丰度分布图
m2z02_see.plot?
figure(11) m2z02_ppd.plot('mass','Ba-138',fname=33500,logy=True,shape='-',\ linewidth=2,limits=[0.5882, 0.5889,-7.8, -3.2])species=['H-1','C-12','C-13','N-14','Fe-56','Sr-86','Ba-138','Pb-206'] ifig=121;close(ifig);figure(ifig) m2z02_ppd.abu_profile(isos=species, ifig=ifig, fname=45500, logy=True, colourblind=True) ylim(-9,0) xlim(0.603,0.6033) title("Formation of the $^\mathsf{13}\mathsf{C}$ pocket: the partial H-$^\mathsf{12}\mathsf{C}$ zone")
文档
每个模块、类、函数在模块中都有(或应该有!)合理的文档字符串。阅读文档字符串:help(ms) , m2z02_see.plot?
文档字符串也可在文档网页上找到。
如果您进行了测试和调试改进,我们很高兴了解它们。在 github 上提出拉取请求。此类改进包括文档。
这里提供的工具对我们很有用,但当然还有很多需要注意和改进的地方。请在 github repo 上添加提交 问题以获取改进的想法并报告错误。如果您想在这些方面提供帮助,请告诉我们。拉请求和新问题是最受欢迎的!
安装
有几种方法可以安装 NuGridPy。
派皮
PyPI 的主要版本:
pip install nugridpy
从 github 发布:
有时您想安装特定版本。转到NuGridPy 发布页面并确定所需发布的标签。如果标签是v0.7.2 ,请使用以下命令使用 pip 安装该版本(您可以为 egg 名称选择其他名称):
pip install -e git://github.com/NuGrid/NuGridPy.git@v0.7.4#egg=nugridpy
如果您只想使用 github 安装 github 上的最新提交,您可以执行以下操作:
pip install git+https://github.com/NuGrid/NuGridPy.git
克隆和 PYTHONPATH
特别是对于开发 NuGridPy,您可能想要使用 pip,但可以更好地控制安装的位置,更改 repo 并提交回来。在这种情况下,您可以克隆此 repo,例如:
cd ; mkdir src; cd src git clone https://github.com/NuGrid/NuGridPy.git
并将PYTHONPATH变量指向 NuGridPy 存储库目录。
在 jupyter notebook 中,您可以通过以下方式设置路径:
import sys
sys.path.append('/home/user/src/NuGridPy')
所需的软件包
所有模块都应与 python 发行版推荐的 NuGridDoc python 发行版一起使用,还有一个额外的包,未来需要额外安装的包。
NuGridPy 具有以下 python 依赖项: numpy scipy matplotlib h5py xlrd future
有关所需软件包、依赖项和手动安装的更多详细信息,请查阅 Wiki。