看板 Python 關於我們 聯絡資訊
import os import fabio import numpy as np def generate_tiff_files(fn, path, prefix, compress): """ Generate tiff files from a hdf file. :param fn, metadata, path, prefix: :return: - """ print('Generating TIFF Files...') with fabio.open(fn) as fabio_img: # create_tiff(fabio_img.data, metadata, path, prefix, 1) create_tiff(fabio_img, path, prefix, 1, compress) if fabio_img.nframes > 1: for i in range(2, fabio_img.nframes + 1): fabio_img = fabio_img.next() # create_tiff(fabio_img.data, metadata, path, prefix, i) create_tiff(fabio_img, path, prefix, i, compress) log_progress(i, fabio_img.nframes) print('Completed') generate_tiff_files(r'C:\Users\wayne\OneDrive\Desktop\Test_hdf5_to_tiff\rat8_trabec1_225_data_000001.h5', r'rat8_trabec1_225_data_000001.h5', r'C:\Users\wayne\OneDrive\Desktop\Test_hdf5_to_tiff', False) 這段程式碼是我在這個網站上找到的, 他寫說是可以把 h5轉成tiff檔. Convert HDF5 file to TIFF files — MuscleX 1.15.7 documentation Source code在這: https://github.com/biocatiit/musclex/blob/master/musclex/utils/hdf5_to_tiffs.py 我嘗試要把h5的檔案轉成tiff檔,, 裝了Fabio 的 package 後試著跑了第二段的程式碼但卻跑出下面的錯誤訊息, 嘗試在stack overflow 上找過了可是大部分都說是因為檔案受損導致,我用確定沒受損的檔案也照樣會跑出錯誤訊息. 小妹我嘗試用關鍵字找但還是不知道為什麼fabio沒辦法讀h5檔, 我是這學期才剛開始學python, 還不是很熟悉. 請問我到底要怎麼辦才能讓fabio正常讀我想要的h5檔? 錯誤訊息: Generating TIFF Files... Traceback (most recent call last): File "C:\Users\wayne\OneDrive\Desktop\Test_hdf5_to_tiff\hdf5_to_tiffs.py", line 120, in <module> generate_tiff_files(r'C:\Users\wayne\OneDrive\Desktop\Test_hdf5_to_tiff\rat8_trabec1_225_data_000001.h5', r'rat8_trabec1_225_data_000001.h5', r'C:\Users\wayne\OneDrive\Desktop\Test_hdf5_to_tiff', False) File "C:\Users\wayne\OneDrive\Desktop\Test_hdf5_to_tiff\hdf5_to_tiffs.py", line 51, in generate_tiff_files with fabio.open(fn) as fabio_img: File "C:\Users\wayne\AppData\Local\Programs\Python\Python310\lib\site-packages\fabio\openimage.py", line 180, in openimage obj = obj.read(obj.filename, frame) File "C:\Users\wayne\AppData\Local\Programs\Python\Python310\lib\site-packages\fabio\eigerimage.py", line 159, in read self._data = self.dataset[0][self.currentframe,:,:] File "h5py\_objects.pyx", line 54, in h5py._objects.with_phil.wrapper File "h5py\_objects.pyx", line 55, in h5py._objects.with_phil.wrapper File "C:\Users\wayne\AppData\Local\Programs\Python\Python310\lib\site-packages\h5py\_hl\dataset.py", line 741, in __getitem__ return self._fast_reader.read(args) File "h5py\_selector.pyx", line 370, in h5py._selector.Reader.read OSError: Can't read data (can't open directory) ----- Sent from JPTT on my iPhone -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 223.139.237.229 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1669201094.A.92F.html
DavisX: 你的.h5檔是dectris eiger detector吐的嗎? 11/23 22:51
DavisX: 如果是 -> 他的dataset是有lz4壓縮過的 11/23 22:51
DavisX: 如果沒幾張 -> 建議你去dectris網站抓albula viewer 11/23 22:52
DavisX: 用這viewer去另存tiff就好 11/23 22:52
DavisX: 如果想自己弄 -> 建議裝 h5py 和 hdf5plugin (用pip) 11/23 22:53
lycantrope: 單純是output path給錯 11/24 08:59
lycantrope: source code命名爛,fn的path是輸出的folder 11/24 09:03
lycantrope: prefix則是輸出的tiff的prefix 11/24 09:03
afreet: 感謝樓上兩位,裝了hdf5plugin就解決了 11/24 09:53
※ 編輯: afreet (123.194.170.161 臺灣), 08/18/2023 04:19:52