From 5d86fafcaa674714c803864d540052d8067bc30c Mon Sep 17 00:00:00 2001 From: "Adam L. Taylor" Date: Sat, 2 Nov 2019 20:58:48 -0400 Subject: [PATCH] Using mouselight_toolbox more --- .gitignore | 2 + delete_job_array.m | 6 -- dir_without_dot_and_dot_dot.m | 9 --- fif.m | 7 --- file_size.m | 14 ----- fraction_power_explained.m | 2 +- freeze_2018_07_02.m | 2 + get_host_name.m | 24 -------- get_scratch_folder_path.m | 12 ---- get_user_name.m | 19 ------ is_mj2_similar_to_tif.m | 2 +- mj2_from_tif.m | 67 +++++++++------------ mj2_from_tif_single.m | 6 +- mj2_from_tif_single_with_temps.m | 10 +++ mouselight_toolbox | 2 +- preverify_single_file_after_mj2_from_tif.m | 7 ++- read_16bit_grayscale_mj2.m | 15 ----- read_16bit_grayscale_tif.m | 16 ----- read_file_into_uint8_array.m | 8 --- replace_extension.m | 5 -- reset_for_test.m | 3 + results_from_job_array.m | 17 ------ simple_dir.m | 6 -- test_freezing.m | 11 ++-- touch.m | 7 --- verify_big_files_after_mj2_from_tif.m | 4 +- verify_file_sizes_after_mj2_from_tif.m | 4 +- verify_frozen_files.m | 20 ++++-- verify_single_big_file_after_mj2_from_tif.m | 7 ++- wait_on_job_array.m | 6 -- write_16bit_grayscale_mj2.m | 12 ---- 31 files changed, 88 insertions(+), 244 deletions(-) delete mode 100644 delete_job_array.m delete mode 100644 dir_without_dot_and_dot_dot.m delete mode 100644 fif.m delete mode 100644 file_size.m delete mode 100644 get_host_name.m delete mode 100644 get_scratch_folder_path.m delete mode 100644 get_user_name.m create mode 100644 mj2_from_tif_single_with_temps.m delete mode 100644 read_16bit_grayscale_mj2.m delete mode 100644 read_16bit_grayscale_tif.m delete mode 100644 read_file_into_uint8_array.m delete mode 100644 replace_extension.m create mode 100644 reset_for_test.m delete mode 100644 results_from_job_array.m delete mode 100644 simple_dir.m delete mode 100644 touch.m delete mode 100644 wait_on_job_array.m delete mode 100644 write_16bit_grayscale_mj2.m diff --git a/.gitignore b/.gitignore index ce58cf8..f4457e7 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,5 @@ mj2-from-tif-test-input-folder-virgin mj2-from-tif-test-input-folder mj2-from-tif-test-output-folder tif-from-mj2-test-input-folder +freezing-test* +thawing-test* diff --git a/delete_job_array.m b/delete_job_array.m deleted file mode 100644 index be5724c..0000000 --- a/delete_job_array.m +++ /dev/null @@ -1,6 +0,0 @@ -function delete_job_array(job_array) - job_count = length(job_array) ; - for job_index = 1 : job_count , - job_array(job_index).delete() ; - end -end \ No newline at end of file diff --git a/dir_without_dot_and_dot_dot.m b/dir_without_dot_and_dot_dot.m deleted file mode 100644 index b1cf1c0..0000000 --- a/dir_without_dot_and_dot_dot.m +++ /dev/null @@ -1,9 +0,0 @@ -function result = dir_without_dot_and_dot_dot(path) - % Like dir(), but result does not include '.' and '..'. - if ~exist('path', 'var') || isempty(path) , - path = pwd() ; - end - raw_result = dir(path) ; - is_dot_or_dot_dot = ismember({raw_result.name}, {'.', '..'}) ; - result = raw_result(~is_dot_or_dot_dot); -end diff --git a/fif.m b/fif.m deleted file mode 100644 index 8b1ccb9..0000000 --- a/fif.m +++ /dev/null @@ -1,7 +0,0 @@ -function result = fif(test, if_true, if_false) - if test , - result = if_true ; - else - result = if_false ; - end -end diff --git a/file_size.m b/file_size.m deleted file mode 100644 index 874c264..0000000 --- a/file_size.m +++ /dev/null @@ -1,14 +0,0 @@ -function result = file_size(path) - d = dir(path) ; - if isempty(d) , - error('File %s does not exist, seemingly', path) ; - elseif length(d) == 1 , - if d.isdir , - error('%s seems to be a folder, not a regular file', path) ; - else - result = d.bytes ; - end - else - error('The path %s does not seem to refer to a regular file', path) ; - end -end diff --git a/fraction_power_explained.m b/fraction_power_explained.m index 245b644..6c8f31f 100644 --- a/fraction_power_explained.m +++ b/fraction_power_explained.m @@ -14,7 +14,7 @@ % 1 in this case because we divided by 2^16-1. So PSNR = 1/MSE. So the "PNSR" % is just MSE. So 1-mse is the fraction of variance explained - result = 1 - error_power/image_power + result = 1 - error_power/image_power ; end else result = 0 ; diff --git a/freeze_2018_07_02.m b/freeze_2018_07_02.m index 8b59101..51513c9 100644 --- a/freeze_2018_07_02.m +++ b/freeze_2018_07_02.m @@ -4,4 +4,6 @@ compression_ratio = 10 ; do_verify = false ; do_run_on_cluster = true ; + mj2_from_tif(mj2_output_folder_path, tif_input_folder_path, compression_ratio, do_verify, do_run_on_cluster) +is_all_well = verify_frozen_files(mj2_output_folder_path, tif_input_folder_path, do_run_on_cluster) diff --git a/get_host_name.m b/get_host_name.m deleted file mode 100644 index ef79f35..0000000 --- a/get_host_name.m +++ /dev/null @@ -1,24 +0,0 @@ -function name = get_host_name() - % GETCOMPUTERNAME returns the name of the computer (hostname) - % name = getComputerName() - % - % WARN: output string is converted to lower case - % - % - % See also SYSTEM, GETENV, ISPC, ISUNIX - % - % m j m a r i n j (AT) y a h o o (DOT) e s - % (c) MJMJ/2007 - % MOD: MJMJ/2013 - - [ret, name] = system('hostname') ; - - if ret ~= 0, - if ispc() - name = getenv('COMPUTERNAME'); - else - name = getenv('HOSTNAME'); - end - end - name = strtrim(lower(name)); -end \ No newline at end of file diff --git a/get_scratch_folder_path.m b/get_scratch_folder_path.m deleted file mode 100644 index 244e0e5..0000000 --- a/get_scratch_folder_path.m +++ /dev/null @@ -1,12 +0,0 @@ -function result = get_scratch_folder_path() - host_name = get_host_name() ; - if ispc() , - result = tempdir() ; - elseif isequal(host_name, 'taylora-ws1') , - result = tempdir() ; - else - % We assume we're on a cluster node - user_name = get_user_name() ; - result = fullfile('/scratch', user_name) ; - end -end diff --git a/get_user_name.m b/get_user_name.m deleted file mode 100644 index d71d1ba..0000000 --- a/get_user_name.m +++ /dev/null @@ -1,19 +0,0 @@ -function name = get_user_name() - % GETCOMPUTERNAME returns the name of the computer (hostname) - % name = getComputerName() - % - % WARN: output string is converted to lower case - % - % - % See also SYSTEM, GETENV, ISPC, ISUNIX - % - % m j m a r i n j (AT) y a h o o (DOT) e s - % (c) MJMJ/2007 - % MOD: MJMJ/2013 - - if ispc() - name = getenv('username') ; % works on windows, may need to mod to work on Linux, MacOS - else - name = getenv('USER') ; % works on windows, may need to mod to work on Linux, MacOS - end -end diff --git a/is_mj2_similar_to_tif.m b/is_mj2_similar_to_tif.m index af728b2..5e4856c 100644 --- a/is_mj2_similar_to_tif.m +++ b/is_mj2_similar_to_tif.m @@ -14,7 +14,7 @@ % mean_summary_error = voxelwise_mean_relative_error_with_guard(mj2_stack, tif_stack, 1/256) ; % result = (mean_summary_error<0.1) ; % this is just intended as a gross sanity check, so use a tolerant threshold - fpe_value = fraction_power_explained(mj2_stack, tif_stack) + fpe_value = fraction_power_explained(mj2_stack, tif_stack) ; result = (fpe_value > 0.99) ; end else diff --git a/mj2_from_tif.m b/mj2_from_tif.m index 9990321..4ea971a 100644 --- a/mj2_from_tif.m +++ b/mj2_from_tif.m @@ -12,7 +12,23 @@ function mj2_from_tif(mj2_output_folder_name, tif_input_folder_name, compression if ~exist('do_run_on_cluster', 'var') || isempty(do_run_on_cluster) , do_run_on_cluster = false ; end + + % Call the helper + fprintf('Compressing .tifs to .mj2s...\n') ; + job_ids = mj2_from_tif_helper(mj2_output_folder_name, tif_input_folder_name, compression_ratio, do_verify, do_run_on_cluster, zeros(1,0)) ; + % Wait for the jobs to finish + fprintf('Waiting for mj2_from_tif() bjobs to finish...\n') ; + bwait(job_ids) ; + fprintf('mj2_from_tif() bjobs are done.\n') ; + + fprintf('Done compressing .tifs to .mj2s.\n') ; +end + + + +function job_ids = mj2_from_tif_helper(mj2_output_folder_name, tif_input_folder_name, compression_ratio, do_verify, do_run_on_cluster, initial_job_ids) + job_ids = initial_job_ids ; if ~exist(mj2_output_folder_name, 'dir') , mkdir(mj2_output_folder_name) ; end @@ -24,7 +40,7 @@ function mj2_from_tif(mj2_output_folder_name, tif_input_folder_name, compression if exist(tif_input_entity_path, 'dir') , % if a folder, recurse mj2_output_entity_path = fullfile(mj2_output_folder_name, tif_input_entity_name) ; - mj2_from_tif(mj2_output_entity_path, tif_input_entity_path, compression_ratio, do_verify, do_run_on_cluster) ; + job_ids = mj2_from_tif_helper(mj2_output_entity_path, tif_input_entity_path, compression_ratio, do_verify, do_run_on_cluster, job_ids) ; else % if a normal file, convert to .mj2 if it's a .tif, or just % copy otherwise @@ -32,45 +48,20 @@ function mj2_from_tif(mj2_output_folder_name, tif_input_folder_name, compression if isequal(ext, '.tif') , mj2_output_entity_path = fullfile(mj2_output_folder_name, replace_extension(tif_input_entity_name, '.mj2')) ; if ~exist(mj2_output_entity_path, 'file') , - fprintf('Converting %s...\n', tif_input_entity_path); - tic_id = tic() ; - scratch_folder_path = get_scratch_folder_path() ; - temporary_tif_input_file_path = [tempname(scratch_folder_path) '.tif'] ; - temporary_mj2_output_file_path = [tempname(scratch_folder_path) '.mj2'] ; % risky, but VideoWriter is dumb and always adds this anyway - if do_run_on_cluster , - command_line = ... - sprintf(['matlab -nojvm ' ... - '-batch ' ... - '"mj2_output_entity_path = ''%s''; tif_input_entity_path = ''%s''; do_verify = %s; ' ... - 'compression_ratio = %s; ' ... - 'temporary_tif_input_file_path = ''%s''; temporary_mj2_output_file_path = ''%s''; ' ... - 'copyfile(tif_input_entity_path, temporary_tif_input_file_path); ' ... - 'mj2_from_tif_single(temporary_mj2_output_file_path, temporary_tif_input_file_path, compression_ratio, do_verify); ' ... - 'copyfile(temporary_mj2_output_file_path, mj2_output_entity_path); ' ... - 'delete(temporary_tif_input_file_path); ' ... - 'delete(temporary_mj2_output_file_path);"'], ... - mj2_output_entity_path, ... - tif_input_entity_path, ... - fif(do_verify, 'true', 'false'), ... - num2str(compression_ratio, '%.18g') , ... - temporary_tif_input_file_path, ... - temporary_mj2_output_file_path) ; - fprintf('Command line: %s\n', command_line) ; - if do_verify , - core_count_to_request = 4 ; - else - core_count_to_request = 1 ; - end - bsub_command_line = ... - sprintf('bsub -n%d -P mouselight -oo /dev/null -eo /dev/null -W 59 -J freeze %s', core_count_to_request, command_line) ; - %bsub_command_line = sprintf('bsub -n%d -P mouselight %s', core_count_to_request, command_line) ; - fprintf('bsub Command line: %s\n', bsub_command_line) ; - system(bsub_command_line) ; + if do_verify , + core_count_to_request = 4 ; else - mj2_from_tif_single(mj2_output_entity_path, tif_input_entity_path, compression_ratio, do_verify) ; + core_count_to_request = 1 ; end - duration = toc(tic_id) ; - fprintf('Took %g seconds\n', duration) ; + bsub_options = sprintf('-n%d -P mouselight -W 59 -J freeze', core_count_to_request) ; + job_id = bsub(do_run_on_cluster, ... + bsub_options, ... + @mj2_from_tif_single_with_temps, ... + mj2_output_entity_path, ... + tif_input_entity_path, ... + compression_ratio, ... + do_verify) ; + job_ids = horzcat(job_ids, job_id) ; %#ok end else mj2_output_entity_path = fullfile(mj2_output_folder_name, tif_input_entity_name) ; % input not really a tif, output not really a .mj2 diff --git a/mj2_from_tif_single.m b/mj2_from_tif_single.m index 765a284..71d54f1 100644 --- a/mj2_from_tif_single.m +++ b/mj2_from_tif_single.m @@ -28,12 +28,12 @@ function mj2_from_tif_single(mj2_output_file_name, tif_input_file_name, compress % without error. if do_verify , - ticId = tic() ; + %ticId = tic() ; mj2_stack = read_16bit_grayscale_mj2(mj2_output_file_name) ; if ~is_mj2_similar_to_tif(mj2_stack, tif_stack) , error('%s is not sufficiently similar to %s\n', mj2_output_file_name, tif_input_file_name) ; end - elapsed_time = toc(ticId) ; - fprintf('Time to verify was %g seconds.\n', elapsed_time) ; + %elapsed_time = toc(ticId) ; + %fprintf('Time to verify was %g seconds.\n', elapsed_time) ; end end diff --git a/mj2_from_tif_single_with_temps.m b/mj2_from_tif_single_with_temps.m new file mode 100644 index 0000000..06f9bb6 --- /dev/null +++ b/mj2_from_tif_single_with_temps.m @@ -0,0 +1,10 @@ +function mj2_from_tif_single_with_temps(mj2_output_file_path, tif_input_file_path, compression_ratio, do_verify) + scratch_folder_path = get_scratch_folder_path() ; + temporary_tif_input_file_path = [tempname(scratch_folder_path) '.tif'] ; + temporary_mj2_output_file_path = [tempname(scratch_folder_path) '.mj2'] ; % risky, but VideoWriter is dumb and always adds this anyway + copyfile(tif_input_file_path, temporary_tif_input_file_path); + mj2_from_tif_single(temporary_mj2_output_file_path, temporary_tif_input_file_path, compression_ratio, do_verify); + copyfile(temporary_mj2_output_file_path, mj2_output_file_path); + delete(temporary_tif_input_file_path); + delete(temporary_mj2_output_file_path); +end diff --git a/mouselight_toolbox b/mouselight_toolbox index 6bd3f64..5d73d0f 160000 --- a/mouselight_toolbox +++ b/mouselight_toolbox @@ -1 +1 @@ -Subproject commit 6bd3f644ef17b02b1a2199cba79fb2c733c1cc0a +Subproject commit 5d73d0f71916c490a6303a6e0e3e494437640084 diff --git a/preverify_single_file_after_mj2_from_tif.m b/preverify_single_file_after_mj2_from_tif.m index 1f1053f..9b6dba4 100644 --- a/preverify_single_file_after_mj2_from_tif.m +++ b/preverify_single_file_after_mj2_from_tif.m @@ -1,9 +1,10 @@ function preverify_single_file_after_mj2_from_tif(tif_file_path, tif_root_folder_name, mj2_root_folder_name) % Checks that the mj2 is similar to the .tif, and outputs a .similar-mj2-exists file in the % tif folder if the are similar. If unable to verify, writes nothing. - relative_file_path = relpath(tif_file_path, tif_root_folder_name) ; - mj2_file_path = fullfile(mj2_root_folder_name, relative_file_path) ; - check_file_path = horzcat(tif_file_path, '.similar-mj2-exists') ; + relative_file_path_of_tif = relpath(tif_file_path, tif_root_folder_name) ; + relative_file_path_of_mj2 = replace_extension(relative_file_path_of_tif, '.mj2') ; + mj2_file_path = fullfile(mj2_root_folder_name, relative_file_path_of_mj2) ; + check_file_path = horzcat(mj2_file_path, '.is-similar-to-tif') ; if exist(check_file_path, 'file') , return end diff --git a/read_16bit_grayscale_mj2.m b/read_16bit_grayscale_mj2.m deleted file mode 100644 index 94e9fcc..0000000 --- a/read_16bit_grayscale_mj2.m +++ /dev/null @@ -1,15 +0,0 @@ -function stack = read_16bit_grayscale_mj2(file_name) - input_file = VideoReader(file_name) ; - n_rows = input_file.Height ; - n_cols = input_file.Width ; - n_pages_approx = ceil(input_file.FrameRate * input_file.Duration) ; % hopefully big enough - stack = zeros([n_rows n_cols n_pages_approx], 'uint16') ; - frame_index = 0 ; - while input_file.hasFrame() , - frame_index = frame_index + 1 ; - frame = input_file.readFrame() ; - stack(:,:,frame_index) = frame ; - end - n_pages = frame_index ; - stack = stack(:,:,1:n_pages) ; -end diff --git a/read_16bit_grayscale_tif.m b/read_16bit_grayscale_tif.m deleted file mode 100644 index 42b99ad..0000000 --- a/read_16bit_grayscale_tif.m +++ /dev/null @@ -1,16 +0,0 @@ -function stack = read_16bit_grayscale_tif(file_name) - info = imfinfo(file_name, 'tif') ; - n_pages = length(info) ; - if n_pages>0 , - first_frame_info = info(1) ; - n_cols = first_frame_info.Width; - n_rows = first_frame_info.Height; - else - n_cols = 0 ; - n_rows = 0 ; - end - stack = zeros([n_rows n_cols n_pages], 'uint16'); - for i = 1:n_pages , - stack(:,:,i) = imread(file_name, 'Index', i, 'Info', info) ; - end -end diff --git a/read_file_into_uint8_array.m b/read_file_into_uint8_array.m deleted file mode 100644 index 22b0b04..0000000 --- a/read_file_into_uint8_array.m +++ /dev/null @@ -1,8 +0,0 @@ -function result = read_file_into_uint8_array(file_name) - fid = fopen(file_name, 'rb') ; - if fid<0 , - error('Unable to open file %s for reading', file_name) ; - end - cleaner = onCleanup(@()(fclose(fid))) ; - result = fread(fid, inf, 'uint8=>uint8') ; -end diff --git a/replace_extension.m b/replace_extension.m deleted file mode 100644 index e970c67..0000000 --- a/replace_extension.m +++ /dev/null @@ -1,5 +0,0 @@ -function result = replace_extension(file_name, new_extension) - % Replace the extension of the given file_name with the new_extension - [path_to_parent, base_name, ~] = fileparts(file_name) ; - result = fullfile(path_to_parent, horzcat(base_name, new_extension)) ; -end diff --git a/reset_for_test.m b/reset_for_test.m new file mode 100644 index 0000000..115e182 --- /dev/null +++ b/reset_for_test.m @@ -0,0 +1,3 @@ +function reset_for_test(output_folder_path) + system(sprintf('rm -rf %s', output_folder_path)) ; +end diff --git a/results_from_job_array.m b/results_from_job_array.m deleted file mode 100644 index 24571da..0000000 --- a/results_from_job_array.m +++ /dev/null @@ -1,17 +0,0 @@ -function result = results_from_job_array(job_array) - job_count = length(job_array) ; - if job_count == 0 , - result = {} ; - else - result = cell(1, job_count) ; - for job_index = 1 : job_count , - job = job_array(job_index) ; - try - c = job.fetchOutputs() ; - catch err %#ok - c = cell(1,0) ; - end - result{job_index} = c ; - end - end -end diff --git a/simple_dir.m b/simple_dir.m deleted file mode 100644 index d2461e8..0000000 --- a/simple_dir.m +++ /dev/null @@ -1,6 +0,0 @@ -function file_names = simple_dir(folder_name) - % Does what I wish dir() did: just return a cell array of the directory - % entries, without all the other stuff. - s = dir(folder_name) ; - file_names = {s.name} ; -end diff --git a/test_freezing.m b/test_freezing.m index 392a6f3..54465b8 100644 --- a/test_freezing.m +++ b/test_freezing.m @@ -1,8 +1,11 @@ path_to_this_script = mfilename('fullpath') ; path_to_this_folder = fileparts(path_to_this_script) ; -mj2_output_folder_path = fullfile(path_to_this_folder, 'mj2-from-tif-test-output-folder') ; -tif_input_folder_path = fullfile(path_to_this_folder, 'mj2-from-tif-test-input-folder') ; +mj2_output_folder_path = fullfile(path_to_this_folder, 'freezing-test-output-folder') ; +tif_input_folder_path = fullfile(path_to_this_folder, 'freezing-test-input-folder') ; compression_ratio = 10 ; -do_verify = true ; -do_run_on_cluster = false ; +do_verify = false ; +do_run_on_cluster = true ; + +reset_for_test(mj2_output_folder_path) ; mj2_from_tif(mj2_output_folder_path, tif_input_folder_path, compression_ratio, do_verify, do_run_on_cluster) +is_all_well = verify_frozen_files(mj2_output_folder_path, tif_input_folder_path, do_run_on_cluster) diff --git a/touch.m b/touch.m deleted file mode 100644 index 2d80a1c..0000000 --- a/touch.m +++ /dev/null @@ -1,7 +0,0 @@ -function touch(file_name) - fid = fopen(file_name, 'wb') ; - if fid<0 , - error('Unable to open file %s for touching', file_name) ; - end - fclose(fid) ; -end diff --git a/verify_big_files_after_mj2_from_tif.m b/verify_big_files_after_mj2_from_tif.m index ba0cc5a..14929b7 100644 --- a/verify_big_files_after_mj2_from_tif.m +++ b/verify_big_files_after_mj2_from_tif.m @@ -1,6 +1,6 @@ -function is_all_well = verify_big_files_after_mj2_from_tif(tif_root_folder_path) +function is_all_well = verify_big_files_after_mj2_from_tif(tif_root_folder_path, mj2_root_folder_path) % Makes sure there's a .similar-mj2-exists for each .tif file in % tif_root_folder_path. - is_all_well = find_and_verify(tif_root_folder_path, '^\d\d\d\d\d-ngc.\d.tif$', @verify_single_big_file_after_mj2_from_tif) ; + is_all_well = find_and_verify(tif_root_folder_path, @does_match_raw_tile_tif_name, @verify_single_big_file_after_mj2_from_tif, tif_root_folder_path, mj2_root_folder_path) ; end \ No newline at end of file diff --git a/verify_file_sizes_after_mj2_from_tif.m b/verify_file_sizes_after_mj2_from_tif.m index 16807bf..0a3e4ec 100644 --- a/verify_file_sizes_after_mj2_from_tif.m +++ b/verify_file_sizes_after_mj2_from_tif.m @@ -30,7 +30,7 @@ function verify_file_sizes_after_mj2_from_tif(mj2_output_folder_name, tif_input_ mj2_output_entity_path = fullfile(mj2_output_folder_name, replace_extension(tif_input_entity_name, '.mj2')) ; if exist(mj2_output_entity_path, 'file') , tif_file_size = tif_input_entity.bytes ; - mj2_file_size = file_size(mj2_output_entity_path) ; + mj2_file_size = get_file_size(mj2_output_entity_path) ; desired_mj2_file_size = round(tif_file_size/compression_ratio) ; if mj2_file_size == desired_mj2_file_size , % do nothing, this is fine and good, and should handle zero-length files @@ -53,7 +53,7 @@ function verify_file_sizes_after_mj2_from_tif(mj2_output_folder_name, tif_input_ mj2_output_entity_path = fullfile(mj2_output_folder_name, tif_input_entity_name) ; % input not really a tif, output not really a .mj2 if exist(mj2_output_entity_path, 'file') , tif_file_size = tif_input_entity.bytes ; - mj2_file_size = file_size(mj2_output_entity_path) ; + mj2_file_size = get_file_size(mj2_output_entity_path) ; if mj2_file_size == tif_file_size , % do nothing, this is fine and good else diff --git a/verify_frozen_files.m b/verify_frozen_files.m index 781c971..b3ef978 100644 --- a/verify_frozen_files.m +++ b/verify_frozen_files.m @@ -1,5 +1,17 @@ -function result = verify_frozen_files(mj2_root_folder_path, tif_root_folder_path) - batch_preverify_big_files_after_mj2_from_tif(mj2_root_folder_path, tif_root_folder_path) - is_all_well_with_big_files = verify_big_files_after_mj2_from_tif(tif_root_folder_path) ; - result = is_all_well_with_big_files && verify_small_files_after_mj2_from_tif(mj2_root_folder_path, tif_root_folder_path) ; +function result = verify_frozen_files(mj2_root_folder_path, tif_root_folder_path, do_submit) + fprintf('Doing batch preverification of large files...\n') ; + batch_preverify_big_files_after_mj2_from_tif(mj2_root_folder_path, tif_root_folder_path, do_submit) + fprintf('Done with batch preverification of large files.\n') ; + + fprintf('Doing verification of large files...\n') ; + is_all_well_with_big_files = verify_big_files_after_mj2_from_tif(tif_root_folder_path, mj2_root_folder_path) ; + fprintf('Done with verification of large files.\n') ; + + if is_all_well_with_big_files, + fprintf('Doing verification of small files...\n') ; + result = verify_small_files_after_mj2_from_tif(mj2_root_folder_path, tif_root_folder_path) ; + fprintf('Done with verification of small files.\n') ; + else + result = false ; + end end diff --git a/verify_single_big_file_after_mj2_from_tif.m b/verify_single_big_file_after_mj2_from_tif.m index dff5e7f..f963582 100644 --- a/verify_single_big_file_after_mj2_from_tif.m +++ b/verify_single_big_file_after_mj2_from_tif.m @@ -1,4 +1,7 @@ -function result = verify_single_big_file_after_mj2_from_tif(tif_file_path) - check_file_path = horzcat(tif_file_path, '.similar-mj2-exists') ; +function result = verify_single_big_file_after_mj2_from_tif(tif_file_path, tif_root_folder_path, mj2_root_folder_path) + relative_file_path_of_tif = relpath(tif_file_path, tif_root_folder_path) ; + relative_file_path_of_mj2 = replace_extension(relative_file_path_of_tif, '.mj2') ; + mj2_file_path = fullfile(mj2_root_folder_path, relative_file_path_of_mj2) ; + check_file_path = horzcat(mj2_file_path, '.is-similar-to-tif') ; result = logical( exist(check_file_path, 'file') ) ; end diff --git a/wait_on_job_array.m b/wait_on_job_array.m deleted file mode 100644 index e51786d..0000000 --- a/wait_on_job_array.m +++ /dev/null @@ -1,6 +0,0 @@ -function wait_on_job_array(job_array) - job_count = length(job_array) ; - for job_index = 1 : job_count , - job_array(job_index).wait() ; - end -end \ No newline at end of file diff --git a/write_16bit_grayscale_mj2.m b/write_16bit_grayscale_mj2.m deleted file mode 100644 index 63ffce2..0000000 --- a/write_16bit_grayscale_mj2.m +++ /dev/null @@ -1,12 +0,0 @@ -function write_16bit_grayscale_mj2(file_name, stack, compression_ratio) - %fprintf('Nominal file name in write_16bit_grayscale_mj2(): %s\n', file_name) ; - [row_count, column_count, page_count] = size(stack) ; - stack_for_video_writer = reshape(stack, [row_count, column_count 1 page_count]) ; - % VideoWriter supports RGB, so have time in 4th dimension to disambiguate. - vw = VideoWriter(file_name, 'Motion JPEG 2000') ; - vw.CompressionRatio = compression_ratio ; - vw.MJ2BitDepth = 16 ; - vw.open() ; - vw.writeVideo(stack_for_video_writer) ; - vw.close() ; -end