windows上用anaconda安装marvin包并读取本地cube文件

说在前面:
anaconda最好在安装的时候就加入环境变量!
make sure to check both the “Add Anaconda to my PATH environment variable” and “Register Anaconda as my default Python 3.6”
虽然不添加好像也能运行,但是会出一堆warning,原因见Installation — Marvin 2.8.0 documentation  Marvin on Windows

安装marvin步骤:

1.新建环境python 3.8,命令行输入:conda create -n marvin python=3.8

2.激活环境,命令行输入:conda activate marvin

3.安装marvin,命令行输入:pip install sdss-marvin

4.找一个地方放marvin的HOME环境,比如D:\\marvin,并在该目录放入一个.netrc格式的文件,文件名随便,不需要写内容,然后在每个用到marvin包的程序开头加入下面几行:
import os
os.environ['HOME'] = 'D:\\marvin'
os.environ['SAS_BASE_DIR'] = os.path.join(os.getenv("HOME"), 'sas')

5.用pip uninstall卸载并更换下面版本的包

a.问题:ImportError: cannot import name 'escape' from 'jinja2’
   解决:安装jinja2版本小于3.1,命令行输入:pip install -U "jinja2>3,<3.1"
https://github.com/sdss/marvin/issues/791

b.问题:cannot import name 'json' from 'itsdangerous’
   解决:安装itsdangerous版本,命令行输入:pip install itsdangerous==2.0.1
https://github.com/sdss/marvin/issues/815

c.问题:drpall-v3_1_1.fits cannot be found. Setting drpall to None.
   解决:python程序中开头加入:
from marvin import config
config.switchSasUrl(sasmode='mirror')
config.mode = 'local'
https://github.com/sdss/marvin/issues/816https://github.com/sdss/marvin/issues/810#issuecomment-2176729494

注意:其他的包packaging版本为20.9,werkzeug版本为2.0.3,其他默认

6.更改C:\Users\XX\anaconda3\envs\marvin\lib\site-packages\marvin\tools\cube.py中的第180和181行代码:
将180行with gunzip(self.filename) as gg:注释掉,改为#with gunzip(self.filename) as gg:
将181行self.data = fits.open(self.filename)向前缩进,改为self.data = fits.open(self.filename)

7.最终一个可以读取本地manga数据cube的marvin程序开头如下:
import os
os.environ['HOME'] = 'D:\\marvin'
os.environ['SAS_BASE_DIR'] = os.path.join(os.getenv("HOME"), 'sas')
from marvin import config
config.switchSasUrl(sasmode='mirror')
config.mode = 'local'
from marvin.tools import Cube
directory='目录\\manga-7443-12703-LOGCUBE.fits.gz'
cube = Cube(filename=directory)

最后:本来第5步弄完应该就可以了,但是用Cube读取本地fits文件的时候说找不到文件:
OSError: filename XX\\XX\\manga-7443-12703-LOGCUBE.fits.gz' cannot be found: [Errno 13] Permission denied: 'C:\\Users\\XX\\AppData\\Local\\Temp\\tmp4ys03e44'
网上查了一堆说是临时文件产生不了,可能是临时文件读写权限有问题,但是用管理员运行spyder或者anaconda也解决不了,更高级的办法不知道,看了下报错的代码有一行是源代码读取本地数据的函数,也就是第6步那里cube.py文件的180和181行有问题,里面用了个gunzip什么玩意好像要解压文件,明明astropy的fits.open就能直接读取.gz的压缩fits文件,为什么还要多此一举解压一遍还要再Temp里搞个临时文件,然后还没有权限,服了。

注:以上情况适用于2024.10.28以前2.8.0的marvin安装,测试可以在21H2和24H2的win11上运行,anaconda版本为2.6.3,anaconda最好在安装的时候就加入环境变量,不加好像也能用,但是有warning报错。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值