{"id":952495,"date":"2024-12-27T01:32:04","date_gmt":"2024-12-26T17:32:04","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/952495.html"},"modified":"2024-12-27T01:32:06","modified_gmt":"2024-12-26T17:32:06","slug":"python%e5%a6%82%e4%bd%95fits%e6%96%87%e4%bb%b6","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/952495.html","title":{"rendered":"python\u5982\u4f55fits\u6587\u4ef6"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25090322\/15cfaf92-b0db-4f79-9897-b5a6c68cc757.webp\" alt=\"python\u5982\u4f55fits\u6587\u4ef6\" \/><\/p>\n<p><p> <strong>Python\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528Astropy\u5e93\u6765\u5904\u7406FITS\u6587\u4ef6\u3001Astropy\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u5929\u6587\u5b66\u8ba1\u7b97\u5e93\u3001\u5b83\u63d0\u4f9b\u4e86\u5904\u7406\u548c\u5206\u6790FITS\u6587\u4ef6\u7684\u5de5\u5177\u3002\u4f7f\u7528Astropy\u5e93\u53ef\u4ee5\u65b9\u4fbf\u5730\u8bfb\u53d6\u3001\u64cd\u4f5c\u548c\u5199\u5165FITS\u6587\u4ef6\u3002<\/strong><\/p>\n<\/p>\n<p><p>Astropy\u5e93\u662f\u4e00\u4e2a\u4e13\u95e8\u4e3a\u5929\u6587\u5b66\u6570\u636e\u5904\u7406\u800c\u8bbe\u8ba1\u7684Python\u5e93\uff0c\u5b83\u7684<code>astropy.io.fits<\/code>\u6a21\u5757\u63d0\u4f9b\u4e86\u5904\u7406FITS\u6587\u4ef6\u7684\u529f\u80fd\u3002\u901a\u8fc7\u8be5\u6a21\u5757\uff0c\u4f60\u53ef\u4ee5\u65b9\u4fbf\u5730\u8bfb\u53d6FITS\u6587\u4ef6\u4e2d\u7684\u6570\u636e\u548c\u5934\u4fe1\u606f\uff0c\u5e76\u5c06\u5176\u8f6c\u5316\u4e3aPython\u5bf9\u8c61\u8fdb\u884c\u64cd\u4f5c\u3002\u6b64\u5916\uff0cAstropy\u8fd8\u652f\u6301\u5c06\u4fee\u6539\u540e\u7684\u6570\u636e\u548c\u5934\u4fe1\u606f\u5199\u56de\u5230FITS\u6587\u4ef6\u4e2d\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528Astropy\u5e93\u6765\u5904\u7406FITS\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u5b89\u88c5Astropy\u5e93<\/p>\n<\/p>\n<p><p>\u5728\u5f00\u59cb\u4e4b\u524d\uff0c\u9700\u8981\u786e\u4fdd\u5df2\u7ecf\u5b89\u88c5\u4e86Astropy\u5e93\u3002\u5982\u679c\u6ca1\u6709\u5b89\u88c5\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install astropy<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u5728Python\u4e2d\u5bfc\u5165Astropy\u5e93\u5e76\u5f00\u59cb\u5904\u7406FITS\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001\u8bfb\u53d6FITS\u6587\u4ef6<\/p>\n<\/p>\n<p><p>Astropy\u63d0\u4f9b\u4e86\u4e00\u4e2a\u540d\u4e3a<code>fits<\/code>\u7684\u6a21\u5757\uff0c\u7528\u4e8e\u8bfb\u53d6FITS\u6587\u4ef6\u3002\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5bfc\u5165\u8be5\u6a21\u5757\uff0c\u7136\u540e\u4f7f\u7528<code>fits.open()<\/code>\u51fd\u6570\u6253\u5f00FITS\u6587\u4ef6\u3002\u8fd9\u4e2a\u51fd\u6570\u8fd4\u56de\u4e00\u4e2a<code>HDUList<\/code>\u5bf9\u8c61\uff0c\u8be5\u5bf9\u8c61\u662f\u4e00\u4e2a\u5305\u542b\u6240\u6709HDU\uff08Header\/Data Unit\uff09\u7684\u5217\u8868\u3002\u6bcf\u4e2aHDU\u5305\u542b\u4e86\u6570\u636e\u548c\u5934\u4fe1\u606f\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from astropy.io import fits<\/p>\n<h2><strong>\u6253\u5f00FITS\u6587\u4ef6<\/strong><\/h2>\n<p>hdulist = fits.open(&#39;example.fits&#39;)<\/p>\n<h2><strong>\u67e5\u770bFITS\u6587\u4ef6\u4e2d\u7684HDU\u5217\u8868<\/strong><\/h2>\n<p>print(hdulist.info())<\/p>\n<h2><strong>\u8bbf\u95ee\u7b2c\u4e00\u4e2aHDU\u7684\u6570\u636e\u548c\u5934\u4fe1\u606f<\/strong><\/h2>\n<p>data = hdulist[0].data<\/p>\n<p>header = hdulist[0].header<\/p>\n<h2><strong>\u5173\u95edFITS\u6587\u4ef6<\/strong><\/h2>\n<p>hdulist.close()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c<code>fits.open()<\/code>\u51fd\u6570\u6253\u5f00\u4e86\u4e00\u4e2a\u540d\u4e3a<code>example.fits<\/code>\u7684FITS\u6587\u4ef6\uff0c\u5e76\u8fd4\u56de\u4e00\u4e2a<code>HDUList<\/code>\u5bf9\u8c61\u3002\u901a\u8fc7\u8c03\u7528<code>hdulist.info()<\/code>\uff0c\u6211\u4eec\u53ef\u4ee5\u67e5\u770bFITS\u6587\u4ef6\u4e2d\u7684HDU\u5217\u8868\u4ee5\u53ca\u6bcf\u4e2aHDU\u7684\u57fa\u672c\u4fe1\u606f\u3002\u968f\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7<code>hdulist[0].data<\/code>\u548c<code>hdulist[0].header<\/code>\u8bbf\u95ee\u7b2c\u4e00\u4e2aHDU\u7684\u6570\u636e\u548c\u5934\u4fe1\u606f\u3002<\/p>\n<\/p>\n<p><p>\u4e09\u3001\u64cd\u4f5cFITS\u6570\u636e<\/p>\n<\/p>\n<p><p>\u8bfb\u53d6FITS\u6587\u4ef6\u4e2d\u7684\u6570\u636e\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u5bf9\u6570\u636e\u8fdb\u884c\u5404\u79cd\u64cd\u4f5c\uff0c\u4f8b\u5982\u8fdb\u884c\u7edf\u8ba1\u5206\u6790\u3001\u6570\u636e\u5904\u7406\u3001\u56fe\u50cf\u663e\u793a\u7b49\u3002\u4ee5\u4e0b\u662f\u51e0\u4e2a\u5e38\u89c1\u7684\u64cd\u4f5c\uff1a<\/p>\n<\/p>\n<ol>\n<li><strong>\u7edf\u8ba1\u5206\u6790<\/strong><\/li>\n<\/ol>\n<p><p>\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528NumPy\u5e93\u6765\u5bf9FITS\u6570\u636e\u8fdb\u884c\u7edf\u8ba1\u5206\u6790\u3002NumPy\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u6570\u503c\u8ba1\u7b97\u5e93\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u5bf9\u591a\u7ef4\u6570\u7ec4\u8fdb\u884c\u64cd\u4f5c\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\uff0c\u8ba1\u7b97FITS\u6570\u636e\u7684\u5e73\u5747\u503c\u548c\u6807\u51c6\u5dee\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u8ba1\u7b97\u6570\u636e\u7684\u5e73\u5747\u503c\u548c\u6807\u51c6\u5dee<\/strong><\/h2>\n<p>mean_value = np.mean(data)<\/p>\n<p>std_dev = np.std(data)<\/p>\n<p>print(f&quot;Mean: {mean_value}, Standard Deviation: {std_dev}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u56fe\u50cf\u663e\u793a<\/strong><\/li>\n<\/ol>\n<p><p>\u5bf9\u4e8e\u4e8c\u7ef4\u56fe\u50cf\u6570\u636e\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Matplotlib\u5e93\u8fdb\u884c\u53ef\u89c6\u5316\u3002Matplotlib\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u7ed8\u56fe\u5e93\uff0c\u80fd\u591f\u751f\u6210\u9ad8\u8d28\u91cf\u7684\u56fe\u5f62\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\uff0c\u663e\u793aFITS\u56fe\u50cf\u6570\u636e\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u663e\u793a\u56fe\u50cf\u6570\u636e<\/strong><\/h2>\n<p>plt.imshow(data, cmap=&#39;gray&#39;, origin=&#39;lower&#39;)<\/p>\n<p>plt.colorbar()<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528<code>plt.imshow()<\/code>\u51fd\u6570\u663e\u793aFITS\u6570\u636e\uff0c\u5e76\u4f7f\u7528\u7070\u5ea6\u989c\u8272\u6620\u5c04\uff08<code>cmap=&#39;gray&#39;<\/code>\uff09\u548c\u5de6\u4e0b\u89d2\u4e3a\u539f\u70b9\uff08<code>origin=&#39;lower&#39;<\/code>\uff09\u3002<code>plt.colorbar()<\/code>\u7528\u4e8e\u5728\u56fe\u50cf\u65c1\u8fb9\u663e\u793a\u989c\u8272\u6761\u3002<\/p>\n<\/p>\n<p><p>\u56db\u3001\u4fee\u6539FITS\u6587\u4ef6<\/p>\n<\/p>\n<p><p>\u6211\u4eec\u8fd8\u53ef\u4ee5\u4fee\u6539FITS\u6587\u4ef6\u4e2d\u7684\u6570\u636e\u548c\u5934\u4fe1\u606f\uff0c\u7136\u540e\u5c06\u5176\u4fdd\u5b58\u56deFITS\u6587\u4ef6\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\uff0c\u4fee\u6539FITS\u6587\u4ef6\u4e2d\u7684\u5934\u4fe1\u606f\u5e76\u4fdd\u5b58\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u4fee\u6539\u5934\u4fe1\u606f<\/p>\n<p>header[&#39;OBSERVER&#39;] = &#39;John Doe&#39;<\/p>\n<p>header[&#39;COMMENT&#39;] = &#39;This is a modified FITS file.&#39;<\/p>\n<h2><strong>\u4fdd\u5b58\u4fee\u6539\u540e\u7684FITS\u6587\u4ef6<\/strong><\/h2>\n<p>hdulist.writeto(&#39;modified_example.fits&#39;, overwrite=True)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u4fee\u6539\u4e86\u5934\u4fe1\u606f\u4e2d\u7684<code>OBSERVER<\/code>\u5b57\u6bb5\uff0c\u5e76\u6dfb\u52a0\u4e86\u4e00\u6761<code>COMMENT<\/code>\u3002\u7136\u540e\uff0c\u6211\u4eec\u4f7f\u7528<code>hdulist.writeto()<\/code>\u51fd\u6570\u5c06\u4fee\u6539\u540e\u7684\u6570\u636e\u548c\u5934\u4fe1\u606f\u5199\u5165\u5230\u4e00\u4e2a\u65b0\u7684FITS\u6587\u4ef6\u4e2d\u3002\u8bbe\u7f6e<code>overwrite=True<\/code>\u8868\u793a\u5982\u679c\u6587\u4ef6\u5df2\u5b58\u5728\uff0c\u5c06\u8986\u76d6\u8be5\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><p>\u4e94\u3001\u521b\u5efa\u65b0\u7684FITS\u6587\u4ef6<\/p>\n<\/p>\n<p><p>\u9664\u4e86\u8bfb\u53d6\u548c\u4fee\u6539\u73b0\u6709\u7684FITS\u6587\u4ef6\uff0c\u6211\u4eec\u8fd8\u53ef\u4ee5\u4f7f\u7528Astropy\u5e93\u521b\u5efa\u65b0\u7684FITS\u6587\u4ef6\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\uff0c\u521b\u5efa\u4e00\u4e2a\u5305\u542b\u968f\u673a\u6570\u636e\u7684FITS\u6587\u4ef6\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from astropy.io import fits<\/p>\n<p>import numpy as np<\/p>\n<h2><strong>\u521b\u5efa\u968f\u673a\u6570\u636e<\/strong><\/h2>\n<p>random_data = np.random.random((100, 100))<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2aPrimaryHDU\u5bf9\u8c61<\/strong><\/h2>\n<p>hdu = fits.PrimaryHDU(data=random_data)<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2aHDUList\u5bf9\u8c61<\/strong><\/h2>\n<p>hdulist = fits.HDUList([hdu])<\/p>\n<h2><strong>\u5199\u5165\u5230FITS\u6587\u4ef6<\/strong><\/h2>\n<p>hdulist.writeto(&#39;new_example.fits&#39;, overwrite=True)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u521b\u5efa\u4e86\u4e00\u4e2a\u5305\u542b\u968f\u673a\u6570\u636e\u7684NumPy\u6570\u7ec4\u3002\u7136\u540e\uff0c\u4f7f\u7528<code>fits.PrimaryHDU()<\/code>\u521b\u5efa\u4e00\u4e2a<code>PrimaryHDU<\/code>\u5bf9\u8c61\uff0c\u5e76\u5c06\u6570\u636e\u4f20\u5165\u5176\u4e2d\u3002\u63a5\u4e0b\u6765\uff0c\u521b\u5efa\u4e00\u4e2a<code>HDUList<\/code>\u5bf9\u8c61\uff0c\u5c06<code>PrimaryHDU<\/code>\u5bf9\u8c61\u6dfb\u52a0\u5230\u5176\u4e2d\u3002\u6700\u540e\uff0c\u4f7f\u7528<code>hdulist.writeto()<\/code>\u51fd\u6570\u5c06\u6570\u636e\u5199\u5165\u5230\u4e00\u4e2a\u65b0\u7684FITS\u6587\u4ef6\u4e2d\u3002<\/p>\n<\/p>\n<p><p>\u516d\u3001\u5904\u7406\u591aHDU\u7684FITS\u6587\u4ef6<\/p>\n<\/p>\n<p><p>\u6709\u4e9bFITS\u6587\u4ef6\u5305\u542b\u591a\u4e2aHDU\uff0c\u6bcf\u4e2aHDU\u53ef\u80fd\u5305\u542b\u4e0d\u540c\u7684\u6570\u636e\u548c\u5934\u4fe1\u606f\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u904d\u5386<code>HDUList<\/code>\u5bf9\u8c61\u6765\u8bbf\u95ee\u548c\u5904\u7406\u6bcf\u4e2aHDU\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\uff0c\u904d\u5386\u591aHDU\u7684FITS\u6587\u4ef6\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u6253\u5f00\u591aHDU\u7684FITS\u6587\u4ef6<\/p>\n<p>hdulist = fits.open(&#39;multi_hdu_example.fits&#39;)<\/p>\n<h2><strong>\u904d\u5386\u6bcf\u4e2aHDU<\/strong><\/h2>\n<p>for hdu in hdulist:<\/p>\n<p>    print(hdu.header)<\/p>\n<p>    print(hdu.data)<\/p>\n<h2><strong>\u5173\u95edFITS\u6587\u4ef6<\/strong><\/h2>\n<p>hdulist.close()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528<code>fits.open()<\/code>\u51fd\u6570\u6253\u5f00\u4e00\u4e2a\u5305\u542b\u591a\u4e2aHDU\u7684FITS\u6587\u4ef6\u3002\u7136\u540e\uff0c\u901a\u8fc7\u904d\u5386<code>HDUList<\/code>\u5bf9\u8c61\u4e2d\u7684\u6bcf\u4e2aHDU\uff0c\u6211\u4eec\u53ef\u4ee5\u8bbf\u95ee\u548c\u6253\u5370\u6bcf\u4e2aHDU\u7684\u5934\u4fe1\u606f\u548c\u6570\u636e\u3002<\/p>\n<\/p>\n<p><p>\u4e03\u3001\u603b\u7ed3<\/p>\n<\/p>\n<p><p>Astropy\u5e93\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u5de5\u5177\u6765\u5904\u7406FITS\u6587\u4ef6\uff0c\u4f7f\u5f97\u8bfb\u53d6\u3001\u64cd\u4f5c\u548c\u5199\u5165FITS\u6587\u4ef6\u53d8\u5f97\u7b80\u5355\u800c\u9ad8\u6548\u3002\u901a\u8fc7\u4f7f\u7528Astropy\u5e93\uff0c\u6211\u4eec\u53ef\u4ee5\u65b9\u4fbf\u5730\u8fdb\u884c\u6570\u636e\u7684\u7edf\u8ba1\u5206\u6790\u3001\u56fe\u50cf\u663e\u793a\u548c\u6587\u4ef6\u4fee\u6539\u7b49\u64cd\u4f5c\u3002\u6b64\u5916\uff0cAstropy\u8fd8\u652f\u6301\u5904\u7406\u591aHDU\u7684FITS\u6587\u4ef6\uff0c\u5141\u8bb8\u6211\u4eec\u8bbf\u95ee\u548c\u64cd\u4f5c\u6bcf\u4e2aHDU\u4e2d\u7684\u6570\u636e\u548c\u5934\u4fe1\u606f\u3002\u65e0\u8bba\u662f\u5929\u6587\u5b66\u7814\u7a76\u8fd8\u662f\u5176\u4ed6\u79d1\u5b66\u9886\u57df\u7684\u6570\u636e\u5904\u7406\uff0cAstropy\u90fd\u662f\u4e00\u4e2a\u5f3a\u5927\u4e14\u7075\u6d3b\u7684\u5de5\u5177\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u8bfb\u53d6FITS\u6587\u4ef6\uff1f<\/strong><br \/>\u53ef\u4ee5\u4f7f\u7528Astropy\u5e93\u6765\u8bfb\u53d6FITS\u6587\u4ef6\u3002\u9996\u5148\uff0c\u786e\u4fdd\u5df2\u5b89\u88c5Astropy\u5e93\u3002\u901a\u8fc7<code>pip install astropy<\/code>\u8fdb\u884c\u5b89\u88c5\u3002\u7136\u540e\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u6253\u5f00\u5e76\u8bfb\u53d6FITS\u6587\u4ef6\u7684\u5185\u5bb9\uff1a<\/p>\n<pre><code class=\"language-python\">from astropy.io import fits\n\n# \u6253\u5f00FITS\u6587\u4ef6\nwith fits.open(&#39;your_file.fits&#39;) as hdul:\n    hdul.info()  # \u67e5\u770b\u6587\u4ef6\u4fe1\u606f\n    data = hdul[0].data  # \u8bfb\u53d6\u6570\u636e\n<\/code><\/pre>\n<p><strong>\u4f7f\u7528Python\u5904\u7406FITS\u6587\u4ef6\u6709\u4ec0\u4e48\u4f18\u70b9\uff1f<\/strong><br \/>\u4f7f\u7528Python\u5904\u7406FITS\u6587\u4ef6\u7684\u4f18\u70b9\u5305\u62ec\u5f3a\u5927\u7684\u6570\u636e\u5904\u7406\u80fd\u529b\u3001\u4e30\u5bcc\u7684\u5e93\u652f\u6301\u548c\u6d3b\u8dc3\u7684\u793e\u533a\u3002Astropy\u5e93\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u529f\u80fd\u6765\u5904\u7406\u5929\u6587\u6570\u636e\uff0c\u5305\u62ec\u6570\u636e\u8bfb\u53d6\u3001\u8f6c\u6362\u548c\u5206\u6790\u3002\u6b64\u5916\uff0cPython\u7684\u53ef\u89c6\u5316\u5e93\uff08\u5982Matplotlib\uff09\u53ef\u4ee5\u65b9\u4fbf\u5730\u5bf9FITS\u6570\u636e\u8fdb\u884c\u53ef\u89c6\u5316\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\u5982\u4f55\u5199\u5165FITS\u6587\u4ef6\uff1f<\/strong><br \/>\u60a8\u53ef\u4ee5\u4f7f\u7528Astropy\u5e93\u5c06\u6570\u636e\u5199\u5165FITS\u6587\u4ef6\u3002\u521b\u5efa\u4e00\u4e2a\u65b0\u7684FITS\u6587\u4ef6\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u4ee3\u7801\u5b9e\u73b0\uff1a<\/p>\n<pre><code class=\"language-python\">from astropy.io import fits\nimport numpy as np\n\n# \u521b\u5efa\u6570\u636e\ndata = np.zeros((100, 100))  # \u793a\u4f8b\u6570\u636e\n\n# \u521b\u5efa\u4e00\u4e2a\u65b0\u7684HDU\uff08Header\/Data Unit\uff09\nhdu = fits.PrimaryHDU(data)\n\n# \u5c06HDU\u5199\u5165FITS\u6587\u4ef6\nhdu.writeto(&#39;new_file.fits&#39;, overwrite=True)\n<\/code><\/pre>\n<p><strong>\u5728\u5904\u7406FITS\u6587\u4ef6\u65f6\uff0c\u5e38\u89c1\u7684\u9519\u8bef\u6709\u54ea\u4e9b\uff1f<\/strong><br \/>\u5e38\u89c1\u7684\u9519\u8bef\u5305\u62ec\u6587\u4ef6\u8def\u5f84\u9519\u8bef\u3001\u6587\u4ef6\u683c\u5f0f\u4e0d\u6b63\u786e\u548c\u6743\u9650\u95ee\u9898\u3002\u786e\u4fddFITS\u6587\u4ef6\u7684\u8def\u5f84\u6b63\u786e\uff0c\u5e76\u4e14\u6587\u4ef6\u683c\u5f0f\u7b26\u5408\u6807\u51c6\u3002\u6743\u9650\u95ee\u9898\u53ef\u80fd\u5bfc\u81f4\u65e0\u6cd5\u8bfb\u53d6\u6216\u5199\u5165\u6587\u4ef6\uff0c\u68c0\u67e5\u6587\u4ef6\u7684\u8bbf\u95ee\u6743\u9650\u8bbe\u7f6e\u662f\u89e3\u51b3\u6b64\u7c7b\u95ee\u9898\u7684\u597d\u65b9\u6cd5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528Astropy\u5e93\u6765\u5904\u7406FITS\u6587\u4ef6\u3001Astropy\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u5929\u6587\u5b66\u8ba1\u7b97\u5e93\u3001\u5b83\u63d0\u4f9b\u4e86\u5904 [&hellip;]","protected":false},"author":3,"featured_media":952496,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/952495"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=952495"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/952495\/revisions"}],"predecessor-version":[{"id":952497,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/952495\/revisions\/952497"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/952496"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=952495"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=952495"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=952495"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}