首页 > 解决方案 > 如何忽略 astropy 3.2 中的弃用警告?

问题描述

我最近将 Astropy 更新到了新的 3.2(.1) 版本。突然很多 AstropyDeprecationWarnings 开始出现。我曾经以这种方式处理它们:

from astropy.utils.exceptions import AstropyDeprecationWarning
import warnings
warnings.simplefilter('ignore', category = AstropyDeprecationWarning)

然而,有了这个新的 Astropy 版本,过滤器基本上被忽略了,并且警告不断显示。这不是一个至关重要的问题,代码当然可以工作,但我想摆脱它们,因为它们使输出更难阅读。有没有办法解决这个问题?难道我做错了什么?

谢谢!

编辑:

我经常看到的两个警告是:

WARNING: AstropyDeprecationWarning: astropy.extern.six will be removed in 4.0, use the six module directly if it is still needed [astropy.extern.six]
WARNING: AstropyDeprecationWarning: Composition of model classes will be removed in 4.0 (but composition of model instances is not affected) [astropy.modeling.core]

我认为第二个警告出现是因为这行代码我结合了高斯模型+背景:

    model = models.Gaussian1D(amplitude = flux.max()*0.9, mean = 0., stddev = size) \
            + models.Const1D(amplitude = flux.min()*0.9)

我不知道第一个警告来自哪里。我没有明确导入 astropy.extern.six (我实际上不知道它是什么),所以它可能与第二个警告或第三方代码有关。

编辑 v2:

我对此进行了更多调查,因为模型的组合并不像我最初想到的那样对警告负责。显然 astropy.extern.six 警告来自:

from astroquery.ned import Ned

而模型类警告的组成来自:

import photutils as ph

标签: python-3.xastropy

解决方案


推荐阅读