|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +""" |
| 3 | +Created on 201102 |
| 4 | +
|
| 5 | +@author: stepp |
| 6 | +
|
| 7 | +Application to read a h5 file and save a tif from it at 2Hz to test the |
| 8 | +watchdog on lebpc20 |
| 9 | +""" |
| 10 | + |
| 11 | +import time |
| 12 | +import numpy as np |
| 13 | +import matplotlib.pyplot as plt |
| 14 | +import h5py |
| 15 | +from skimage import io |
| 16 | +import os |
| 17 | + |
| 18 | +data_path = 'C:/Users/stepp/Documents/data_raw/SmartMito/' # nb: begin with / |
| 19 | +print('data_path : ', data_path) |
| 20 | +print() |
| 21 | +input_data_filename1 = data_path + 'Mito.h5' # Mito |
| 22 | +input_data_filename2 = data_path + 'Drp1.h5' # Drp1 |
| 23 | + |
| 24 | +input_data_filename1 = data_path + 'cell_8_Pos1_mito_741.tif' # Mito |
| 25 | +input_data_filename2 = data_path + 'cell_8_Pos1_drp1_741.tif' # Drp1 |
| 26 | + |
| 27 | +# input_data_filename1 = data_path + 'cell_8_mito_1024.tif' # Mito |
| 28 | +# input_data_filename2 = data_path + 'cell_8_drp1_1024.tif' # Drp1 |
| 29 | + |
| 30 | +# input_data_filename1 = data_path + 'cell_8_mito.tif' # Mito |
| 31 | +# input_data_filename2 = data_path + 'cell_8_drp1.tif' # Drp1 |
| 32 | + |
| 33 | +# input_data_filename1 = data_path + 's3_c6_mito.tif' # Mito |
| 34 | +# input_data_filename2 = data_path + 's3_c6_drp1.tif' # Drp1 |
| 35 | + |
| 36 | +mito = [] |
| 37 | +drp = [] |
| 38 | + |
| 39 | +if input_data_filename1[-3:] == '.h5': |
| 40 | + hf = h5py.File(input_data_filename1, 'r') |
| 41 | + mito = hf.get('Mito') # Mito |
| 42 | +else: |
| 43 | + mito = io.imread(input_data_filename1) |
| 44 | + |
| 45 | +print(mito.dtype) |
| 46 | +print('Input : ', mito.shape) |
| 47 | +print('Input : ', np.shape(mito)[0]) |
| 48 | + |
| 49 | +if input_data_filename2[-3:] == '.h5': |
| 50 | + hf = h5py.File(input_data_filename2, 'r') |
| 51 | + drp = hf.get('Drp1') |
| 52 | +else: |
| 53 | + drp = io.imread(input_data_filename2) |
| 54 | + |
| 55 | +print(drp.dtype) |
| 56 | +print('Input : ', drp.shape) |
| 57 | +print('Input : ', np.shape(drp)[0]) |
| 58 | + |
| 59 | +nas_path = '//lebnas1.epfl.ch/microsc125/Watchdog/python_saver/' |
| 60 | + |
| 61 | +i = 0 |
| 62 | +for item in range(200, 213): |
| 63 | + # for item in range(1, 2002, 1000): # [1, 208]: # range(150, 210): |
| 64 | + t1 = time.perf_counter() |
| 65 | + print(item) |
| 66 | + mito_path = nas_path + 'img_channel000_position000_time' + \ |
| 67 | + str((i*2)).zfill(9) + '_z000.tiff' |
| 68 | + drp_path = nas_path + 'img_channel000_position000_time' + \ |
| 69 | + str((i*2 + 1)).zfill(9) + '_z000.tiff' |
| 70 | + |
| 71 | + # First write mito then drp as watchdog waits for drp image |
| 72 | + io.imsave(mito_path, mito[item, :, :].astype(np.uint16), |
| 73 | + check_contrast=False) |
| 74 | + time.sleep(0.05) |
| 75 | + io.imsave(drp_path, drp[item, :, :].astype(np.uint16), |
| 76 | + check_contrast=False) |
| 77 | + t2 = time.perf_counter() |
| 78 | + time.sleep(np.max([0, .45 - (t2 - t1)])) |
| 79 | + i = i + 1 |
| 80 | + |
| 81 | +time.sleep(3) |
| 82 | + |
| 83 | +# Clear the folder completely to have the same situation always |
| 84 | +for f in os.listdir(nas_path): |
| 85 | + if not f.endswith(".tiff"): |
| 86 | + continue |
| 87 | + os.remove(os.path.join(nas_path, f)) |
0 commit comments