- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有一个约 50GB 的适合文件,包含多个 HDU,它们都具有相同的格式:一个 (1E5 x 1E6) 数组,包含 1E5 个对象和 1E6 个时间戳。 HDU 描述了不同的物理属性,例如 Flux、RA、DEC 等。我只想从每个 HDU 中读取 5 个对象(即 (5 x 1E6) 数组)。
python 2.7,天体1.0.3,Linux x86_64
到目前为止,我尝试了很多我发现的建议,但没有任何效果。我最好的方法仍然是:
#the five objects I want to read out
obj_list = ['Star1','Star15','Star700','Star2000','Star5000']
dic = {}
with fits.open(fname, memmap=True, do_not_scale_image_data=True) as hdulist:
# There is a special HDU 'OBJECTS' which is an (1E5 x 1) array and contains the info which index in the fits file corresponds to which object.
# First, get the indices of the rows that describe the objects in the fits file (not necessarily in order!)
ind_objs = np.in1d(hdulist['OBJECTS'].data, obj_list, assume_unique=True).nonzero()[0] #indices of the candidates
# Second, read out the 5 object's time series
dic['FLUX'] = hdulist['FLUX'].data[ind_objs] # (5 x 1E6) array
dic['RA'] = hdulist['RA'].data[ind_objs] # (5 x 1E6) array
dic['DEC'] = hdulist['DEC'].data[ind_objs] # (5 x 1E6) array
此代码适用于最大约 20 GB 的文件,运行良好且速度很快,但对于更大的文件会耗尽内存(更大的文件只包含更多的对象,而不是更多的时间戳)。我不明白为什么 - 据我所知,astropy.io.fits 本质上使用 mmap 并且应该只将 (5x1E6) 数组加载到内存中?与文件大小无关,我想要读出的内容始终具有相同的大小。
编辑 - 这是错误信息:
dic['RA'] = hdulist['RA'].data[ind_objs] # (5 x 1E6) array
File "/usr/local/python/lib/python2.7/site-packages/astropy-1.0.3-py2.7-linux-x86_64.egg/astropy/utils/decorators.py", line 341, in __get__
val = self._fget(obj)
File "/usr/local/python/lib/python2.7/site-packages/astropy-1.0.3-py2.7-linux-x86_64.egg/astropy/io/fits/hdu/image.py", line 239, in data
data = self._get_scaled_image_data(self._data_offset, self.shape)
File "/usr/local/python/lib/python2.7/site-packages/astropy-1.0.3-py2.7-linux-x86_64.egg/astropy/io/fits/hdu/image.py", line 585, in _get_scaled_image_data
raw_data = self._get_raw_data(shape, code, offset)
File "/usr/local/python/lib/python2.7/site-packages/astropy-1.0.3-py2.7-linux-x86_64.egg/astropy/io/fits/hdu/base.py", line 523, in _get_raw_data
return self._file.readarray(offset=offset, dtype=code, shape=shape)
File "/usr/local/python/lib/python2.7/site-packages/astropy-1.0.3-py2.7-linux-x86_64.egg/astropy/io/fits/file.py", line 248, in readarray
shape=shape).view(np.ndarray)
File "/usr/local/python/lib/python2.7/site-packages/numpy/core/memmap.py", line 254, in __new__
mm = mmap.mmap(fid.fileno(), bytes, access=acc, offset=start)
mmap.error: [Errno 12] Cannot allocate memory
编辑 2:谢谢,我现在包含了建议,它使我能够处理最大 50GB 的适合文件。新代码:
#the five objects I want to read out
obj_list = ['Star1','Star15','Star700','Star2000','Star5000']
dic = {}
with fits.open(fname, mode='denywrite', memmap=True, do_not_scale_image_data=True) as hdulist:
# There is a special HDU 'OBJECTS' which is an (1E5 x 1) array and contains the info which index in the fits file corresponds to which object.
# First, get the indices of the rows that describe the objects in the fits file (not necessarily in order!)
ind_objs = np.in1d(hdulist['OBJECTS'].data, obj_list, assume_unique=True).nonzero()[0] #indices of the candidates
# Second, read out the 5 object's time series
dic['FLUX'] = hdulist['FLUX'].data[ind_objs] # (5 x 1E6) array
del hdulist['FLUX'].data
dic['RA'] = hdulist['RA'].data[ind_objs] # (5 x 1E6) array
del hdulist['RA'].data
dic['DEC'] = hdulist['DEC'].data[ind_objs] # (5 x 1E6) array
del hdulist['DEC'].data
mode='denywrite'
没有引起任何变化。
memmap=True
确实不是默认的,需要手动设置。
del hdulist['FLUX'].data
etc 现在允许我读取 50GB 而不是 20GB 的文件
新问题:任何大于 50GB 的内容仍然会导致相同的内存错误 - 但是,现在直接在第一行。
dic['FLUX'] = hdulist['FLUX'].data[ind_objs] # (5 x 1E6) array
最佳答案
您似乎遇到过这个问题:https://github.com/astropy/astropy/issues/1380
这里的问题是,即使它使用的是 mmap,它也是在写时复制模式下使用 mmap,这意味着您的系统需要能够分配足够大的虚拟内存区域,原则上可以容纳与 mmap 大小一样多的数据,以防您将数据写回 mmap。
如果您将 mode='denywrite'
传递给 fits.open()
它应该可以工作。任何修改数组的尝试都会导致错误,但如果您只想读取数据,那也没关系。
如果你仍然无法让它工作,你也可以试试 fitsio更好地支持以较小的 block 读取文件的模块。
关于python - astropy.io.fits 从具有多个 HDU 的大型拟合文件中读取行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35759713/
gnuplot 中拟合函数的正确方法是什么 f(x)有下一个表格吗? f(x) = A*exp(x - B*f(x)) 我尝试使用以下方法将其拟合为任何其他函数: fit f(x) "data.txt
(1)首先要建立数据集 ? 1
测量显示一个信号,其形式类似于具有偏移量和因子的平方根函数。如何找到系数并在一个图中绘制原始数据和拟合曲线? require(ggplot2) require(nlmrt) # may be thi
我想将以下函数拟合到我的数据中: f(x) = Offset+Amplitudesin(FrequencyT+Phase), 或根据 Wikipedia : f(x) = C+alphasin(ome
我正在尝试使用与此工具相同的方法在 C# 中拟合 Akima 样条曲线:https://www.mycurvefit.com/share/4ab90a5f-af5e-435e-9ce4-652c95c
问题:开放层适合 map ,只有在添加特征之后(视觉),我该如何避免这种情况? 我在做这个 第 1 步 - 创建特征 var feature = new ol.Feature({...}); 第 2
我有一个数据变量,其中包含以下内容: [Object { score="2.8", word="Blue"}, Object { score="2.8", word="Red"}, Objec
我正在尝试用中等大小的 numpy float 组来填充森林 In [3]: data.shape Out[3]: (401125, 5) [...] forest = forest.fit(data
我想用洛伦兹函数拟合一些数据,但我发现当我使用不同数量级的参数时拟合会出现问题。 这是我的洛伦兹函数: function [ value ] = lorentz( x,x0,gamma,amp )
我有一些数据,我希望对其进行建模,以便能够在与数据相同的范围内获得相对准确的值。 为此,我使用 polyfit 来拟合 6 阶多项式,由于我的 x 轴值,它建议我将其居中并缩放以获得更准确的拟合。 但
我一直在寻找一种方法来使数据符合 beta 二项分布并估计 alpha 和 beta,类似于 VGAM 库中的 vglm 包的方式。我一直无法找到如何在 python 中执行此操作。有一个 scipy
我将 scipy.optimize.minimize ( https://docs.scipy.org/doc/scipy/reference/tutorial/optimize.html ) 函数与
在过去的几天里,我一直在尝试使用 python 绘制圆形数据,方法是构建一个范围从 0 到 2pi 的圆形直方图并拟合 Von Mises 分布。我真正想要实现的是: 具有拟合 Von-Mises 分
我有一个简单的循环,它在每次迭代中都会创建一个 LSTM(具有相同的参数)并将其拟合到相同的数据。问题是迭代过程中需要越来越多的时间。 batch_size = 10 optimizer = opti
我有一个 Python 系列,我想为其直方图拟合密度。问题:是否有一种巧妙的方法可以使用 np.histogram() 中的值来实现此结果? (请参阅下面的更新) 我目前的问题是,我执行的 kde 拟
我有一个简单的 keras 模型(正常套索线性模型),其中输入被移动到单个“神经元”Dense(1, kernel_regularizer=l1(fdr))(input_layer) 但是权重从这个模
我正在尝试解决 Boston Dataset 上的回归问题在random forest regressor的帮助下.我用的是GridSearchCV用于选择最佳超参数。 问题一 我是否应该将 Grid
使用以下函数,可以在输入点 P 上拟合三次样条: def plotCurve(P): pts = np.vstack([P, P[0]]) x, y = pts.T i = np.aran
我有 python 代码可以生成数字 x、y 和 z 的三元组列表。我想使用 scipy curve_fit 来拟合 z= f(x,y)。这是一些无效的代码 A = [(19,20,24), (10,
我正在尝试从 this answer 中复制代码,但是我在这样做时遇到了问题。我正在使用包 VGAM 中的gumbel 发行版和 fitdistrplus . 做的时候出现问题: fit = fi
我是一名优秀的程序员,十分优秀!