我想加快一些分析天文数据所需的脚本。我有为每个单独的图像文件(以.fits文件格式)独立运行的脚本。我试图使用Multiprocessing.Pool()
和地图一次启动多个文件。我的代码如下所示:
def sextract(name):
# creates a class instance and calls the method
astro = astrometry(name, *some_more_args)
astro.sextract()
arguments = ['PART1_cal.fits', 'PART2_cal.fits', 'PART3_cal.fits',
'PART4_cal.fits', 'PART5_cal.fits']
with closing(Pool()) as pool:
pool.map(sextract, arguments)
pool.terminate()
,astrometry.sextract方法如下所示:
def sextract(self):
sex = 'sextractor'
headerlist = ['JD-START', 'OBSERVER', 'DATE', 'TM-START', 'OBJECT',
'FLTRNAME', 'RA', 'DEC', 'AIRMASS',
'EXP_TIME']
calib = self._from
# calls the SourceExtrator in the shell with a config-file and
# the file name
os.system(sex + ' -c ' + self.sexpath + ' ' + calib)
# copies the extracted file to a folder on an external HDD
shutil.copy2(self.ext_path, self._to + '/' +
calib.split('/')[-1])
# opens the old .fits image and extracts the header
old = fits.open(calib)
o = old[0].header
# opens the new(copied) .fits image and extracts the header
# this produces the error
extr = fits.open(self._to + '/' + calib.split('/')[-1],
mode='update')
e = extr[1].header
# goes through the old header entries and copies all entries
# in the to the new header
for g in headerlist:
e[g] = o[g]
# saves the new header to the new(copied) file and closes both
# files
extr[1].header = e
extr.flush()
extr.close()
old.close()
每次运行此代码时,我都会得到一个IOError: Header missing END card.
,这是由我打开新.fits并将其放入变量extr
的行所引发的。起初我认为这会发生,因为复制过程需要太长时间,并且python尝试在文件完成复制之前访问该文件。我插入time.sleep(10)
来检查,但错误仍然出现。
我尝试使用pool.apply()
和普通map()
,在这两种情况下我都没有收到错误。使用pool.apply()
时,map()
的情况几乎和<select id="sltFont" onchange="changeFont(this.valueOf);">
<option selected disabled>Select a Font</option>
<option value=”Arial” style="font-family:arial;">Arial</option>
<option value=”Calibri” style="font-family:Calibri;">Calibri</option>
<option value=”Candara” style="font-family:Candara;">Candara</option>
<option value=”ComicSansMS” style="font-family:'Comic Sans MS';">Comic Sans MS</option>
<option value=”FranklinGothicMedium” style="font-family:'Franklin Gothic Medium';">Franklin Gothic Medium</option>
<option value=”FrenchScriptMT” style="font-family:'French Script MT';">French Script MT</option>
<option value=”Impact” style="font-family:Impact;">Impact</option>
<option value=”JuiceITC” style="font-family:'Juice ITC';">Juice ITC </option>
<option value=”KristenITC” style="font-family:'Kristen ITC';">Kristen ITC</option>
<option value=”LucidaHandwriting” style="font-family:'Lucida Handwriting';">Lucida Handwriting</option>
</select>
一样长,所以我还没有真正做到这一点。
我知道这是一个非常具体的问题,但我希望有人可能知道我的问题在哪里,或者已经有类似的工作了。