|
| 1 | +function check_tiles(sample_date_as_string, do_show_progress) |
| 2 | + if ~exist('do_show_progress', 'var') || isempty(do_show_progress) , |
| 3 | + do_show_progress = false ; |
| 4 | + end |
| 5 | + |
| 6 | + raw_tile_folder_path_template = '/groups/mousebrainmicro/mousebrainmicro/data/%s/Tiling' ; |
| 7 | + raw_tile_folder_path = sprintf(raw_tile_folder_path_template, sample_date_as_string) ; |
| 8 | + % Sometimes they use a "Tiling" folder, sometimes not... |
| 9 | + if ~exist(raw_tile_folder_path, 'file') , |
| 10 | + raw_tile_folder_path_template = '/groups/mousebrainmicro/mousebrainmicro/data/acquisition/%s' ; |
| 11 | + raw_tile_folder_path = sprintf(raw_tile_folder_path_template, sample_date_as_string) ; |
| 12 | + end |
| 13 | + pipeline_output_folder_path_template_from_stage_index = {raw_tile_folder_path_template, ... |
| 14 | + '/nrs/mouselight/pipeline_output/%s/stage_1_line_fix_output', ... |
| 15 | + '/nrs/mouselight/pipeline_output/%s/stage_2_classifier_output', ... |
| 16 | + '/nrs/mouselight/pipeline_output/%s/stage_3_descriptor_output', ... |
| 17 | + '/nrs/mouselight/pipeline_output/%s/stage_4_point_match_output'} ; |
| 18 | + stage_name_from_index = {'raw', 'line-fix', 'classifier', 'descriptor', 'point-match'} ; |
| 19 | + |
| 20 | + % Get a list of all the raw tiles for channel 0. |
| 21 | + % Each tile is represented by its relative path within raw_tile_folder_path |
| 22 | + fprintf('Scanning filesystem for raw tile folders...\n') ; |
| 23 | + raw_tile_folder_relative_paths = collect_raw_tile_folder_relative_paths(raw_tile_folder_path) ; |
| 24 | + fprintf('Done scanning filesystem for raw tile folders.\n') ; |
| 25 | + |
| 26 | + % Report the number of tiles |
| 27 | + raw_tile_count = length(raw_tile_folder_relative_paths) ; |
| 28 | + fprintf('Raw tile folder count: %d\n', raw_tile_count) ; |
| 29 | + if raw_tile_count==0 , |
| 30 | + error('There are no raw tiles!') ; |
| 31 | + end |
| 32 | + |
| 33 | + % Get the tile shape |
| 34 | + first_raw_tile_folder_relative_path = raw_tile_folder_relative_paths{1} ; |
| 35 | + [~,first_raw_tile_folder_leaf_name] = fileparts2(first_raw_tile_folder_relative_path) ; |
| 36 | + first_raw_tile_channel_0_file_relative_path = fullfile(first_raw_tile_folder_relative_path, sprintf('%s-ngc.0.tif', first_raw_tile_folder_leaf_name)) ; |
| 37 | + first_raw_tile_channel_0_file_absolute_path = fullfile(raw_tile_folder_path, first_raw_tile_channel_0_file_relative_path) ; |
| 38 | + stack = read_16bit_grayscale_tif(first_raw_tile_channel_0_file_absolute_path) ; |
| 39 | + nominal_tile_shape_yxz = size(stack) ; |
| 40 | + nominal_raw_tif_file_size = get_file_size(first_raw_tile_channel_0_file_absolute_path) ; |
| 41 | + fprintf('Nominal tile shape (yxz) is: [%d %d %d]\n', nominal_tile_shape_yxz) ; |
| 42 | + fprintf('Nominal uncompressed tiff file size is: %d\n', nominal_raw_tif_file_size) ; |
| 43 | + |
| 44 | + stage_count = length(stage_name_from_index) ; |
| 45 | + for stage_index = 1 : stage_count , |
| 46 | + stage_name = stage_name_from_index{stage_index} ; |
| 47 | + pipeline_output_folder_path_template = pipeline_output_folder_path_template_from_stage_index{stage_index} ; |
| 48 | + stage_pipeline_output_tile_folder_path = sprintf(pipeline_output_folder_path_template, sample_date_as_string) ; |
| 49 | + problematic_stage_output_file_relative_paths = cell(1,0) ; |
| 50 | + problematic_stage_output_file_messages = cell(1,0) ; |
| 51 | + fprintf('\n') |
| 52 | + fprintf('Checking stage %s...\n', stage_name) ; |
| 53 | + if do_show_progress , |
| 54 | + progress_bar = progress_bar_object(raw_tile_count) ; |
| 55 | + end |
| 56 | + for raw_tile_index = 1 : raw_tile_count , |
| 57 | + raw_tile_folder_relative_path = raw_tile_folder_relative_paths{raw_tile_index} ; |
| 58 | + [~,leaf_folder_name] = fileparts2(raw_tile_folder_relative_path) ; |
| 59 | + if isequal(stage_name, 'classifier') , |
| 60 | + putative_stage_output_tile_file_name_template = sprintf('%s-prob.%%d.h5', leaf_folder_name) ; |
| 61 | + are_channels = true ; |
| 62 | + elseif isequal(stage_name, 'descriptor') , |
| 63 | + putative_stage_output_tile_file_name_template = sprintf('%s-desc.%%d.txt', leaf_folder_name) ; |
| 64 | + are_channels = true ; |
| 65 | + elseif isequal(stage_name, 'point-match') , |
| 66 | + %putative_stage_output_tile_file_name_template = 'match-Z.mat' ; |
| 67 | + putative_stage_output_tile_file_name_template = 'channel-%d-match-Z.mat' ; |
| 68 | + are_channels = true ; |
| 69 | + else |
| 70 | + putative_stage_output_tile_file_name_template = sprintf('%s-ngc.%%d.tif', leaf_folder_name) ; |
| 71 | + are_channels = true ; |
| 72 | + end |
| 73 | + if are_channels , |
| 74 | + for channel_index = 0:1 , |
| 75 | + putative_stage_output_tile_file_name = sprintf(putative_stage_output_tile_file_name_template, channel_index) ; |
| 76 | + putative_stage_output_tile_relative_path = fullfile(raw_tile_folder_relative_path, ... |
| 77 | + putative_stage_output_tile_file_name) ; |
| 78 | + putative_stage_output_tile_absolute_path = fullfile(stage_pipeline_output_tile_folder_path, ... |
| 79 | + putative_stage_output_tile_relative_path) ; |
| 80 | + if exist(putative_stage_output_tile_absolute_path, 'file') , |
| 81 | + if isequal(stage_name, 'raw') , |
| 82 | + [problematic_stage_output_file_relative_paths, problematic_stage_output_file_messages] = ... |
| 83 | + check_raw_tile(stage_pipeline_output_tile_folder_path, ... |
| 84 | + putative_stage_output_tile_relative_path, ... |
| 85 | + nominal_raw_tif_file_size, ... |
| 86 | + nominal_tile_shape_yxz, ... |
| 87 | + problematic_stage_output_file_relative_paths, ... |
| 88 | + problematic_stage_output_file_messages) ; |
| 89 | + elseif isequal(stage_name, 'classifier') , |
| 90 | + [problematic_stage_output_file_relative_paths, problematic_stage_output_file_messages] = ... |
| 91 | + check_classifier_tile(stage_pipeline_output_tile_folder_path, ... |
| 92 | + putative_stage_output_tile_relative_path, ... |
| 93 | + nominal_raw_tif_file_size, ... |
| 94 | + nominal_tile_shape_yxz, ... |
| 95 | + problematic_stage_output_file_relative_paths, ... |
| 96 | + problematic_stage_output_file_messages) ; |
| 97 | + end |
| 98 | + else |
| 99 | + problematic_stage_output_file_relative_paths = ... |
| 100 | + horzcat(problematic_stage_output_file_relative_paths, ... |
| 101 | + putative_stage_output_tile_relative_path) ; %#ok<AGROW> |
| 102 | + problematic_stage_output_file_messages = ... |
| 103 | + horzcat(problematic_stage_output_file_messages, ... |
| 104 | + sprintf('%s is missing', putative_stage_output_tile_relative_path)) ; %#ok<AGROW> |
| 105 | + end |
| 106 | + end |
| 107 | + else |
| 108 | + % If no channels for this stage, the name is jus the |
| 109 | + % template |
| 110 | + putative_stage_output_tile_file_name = putative_stage_output_tile_file_name_template ; |
| 111 | + putative_stage_output_tile_relative_path = fullfile(raw_tile_folder_relative_path, ... |
| 112 | + putative_stage_output_tile_file_name) ; |
| 113 | + putative_stage_output_tile_absolute_path = fullfile(stage_pipeline_output_tile_folder_path, ... |
| 114 | + putative_stage_output_tile_relative_path) ; |
| 115 | + if ~exist(putative_stage_output_tile_absolute_path, 'file') , |
| 116 | + problematic_stage_output_file_relative_paths = ... |
| 117 | + horzcat(problematic_stage_output_file_relative_paths, ... |
| 118 | + putative_stage_output_tile_relative_path) ; %#ok<AGROW> |
| 119 | + problematic_stage_output_file_messages = ... |
| 120 | + horzcat(problematic_stage_output_file_messages, ... |
| 121 | + sprintf('%s is missing', putative_stage_output_tile_relative_path)) ; %#ok<AGROW> |
| 122 | + end |
| 123 | + end |
| 124 | + |
| 125 | + % Update the progress bar |
| 126 | + if do_show_progress , |
| 127 | + progress_bar.update(raw_tile_index) |
| 128 | + end |
| 129 | + end |
| 130 | + |
| 131 | + problematic_file_count = length(problematic_stage_output_file_relative_paths) ; |
| 132 | + fprintf('\n') ; |
| 133 | + fprintf('Problematic %s file count: %d\n', stage_name, problematic_file_count) ; |
| 134 | + problematic_files_to_show_count = min(problematic_file_count,inf) ; |
| 135 | + for index = 1 : problematic_files_to_show_count , |
| 136 | + problematic_stage_output_file_relative_path = problematic_stage_output_file_relative_paths{index} ; |
| 137 | + problematic_stage_output_file_message = problematic_stage_output_file_messages{index} ; |
| 138 | + % if stage_name == 'raw': |
| 139 | + % problematic_stage_output_tile_absolute_path = os.path.join(raw_tile_folder_path, |
| 140 | + % problematic_stage_output_tile_relative_path) |
| 141 | + % shape = get_tiff_shape(problematic_stage_output_tile_absolute_path) |
| 142 | + % print(' problematic: %s, shape (zyx) is %s' % (problematic_stage_output_tile_relative_path, shape) ) |
| 143 | + % else: |
| 144 | + fprintf(' problematic: %s: %s\n', problematic_stage_output_file_relative_path, problematic_stage_output_file_message) ; |
| 145 | + end |
| 146 | + if problematic_files_to_show_count < problematic_file_count , |
| 147 | + problematic_files_now_shown_count = problematic_file_count - problematic_files_to_show_count ; |
| 148 | + fprintf(' problematic: (%d more files)\n', problematic_files_now_shown_count) ; |
| 149 | + end |
| 150 | + end |
| 151 | +end |
| 152 | + |
| 153 | + |
0 commit comments