Skip to content

Commit

Permalink
Using mouselight_toolbox more
Browse files Browse the repository at this point in the history
  • Loading branch information
adamltaylor committed Nov 3, 2019
1 parent adedd6a commit 5d86faf
Show file tree
Hide file tree
Showing 31 changed files with 88 additions and 244 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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*
6 changes: 0 additions & 6 deletions delete_job_array.m

This file was deleted.

9 changes: 0 additions & 9 deletions dir_without_dot_and_dot_dot.m

This file was deleted.

7 changes: 0 additions & 7 deletions fif.m

This file was deleted.

14 changes: 0 additions & 14 deletions file_size.m

This file was deleted.

2 changes: 1 addition & 1 deletion fraction_power_explained.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 ;
Expand Down
2 changes: 2 additions & 0 deletions freeze_2018_07_02.m
Original file line number Diff line number Diff line change
Expand Up @@ -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)
24 changes: 0 additions & 24 deletions get_host_name.m

This file was deleted.

12 changes: 0 additions & 12 deletions get_scratch_folder_path.m

This file was deleted.

19 changes: 0 additions & 19 deletions get_user_name.m

This file was deleted.

2 changes: 1 addition & 1 deletion is_mj2_similar_to_tif.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
67 changes: 29 additions & 38 deletions mj2_from_tif.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -24,53 +40,28 @@ 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
[~,~,ext] = fileparts(tif_input_entity_path) ;
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<AGROW>
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
Expand Down
6 changes: 3 additions & 3 deletions mj2_from_tif_single.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 10 additions & 0 deletions mj2_from_tif_single_with_temps.m
Original file line number Diff line number Diff line change
@@ -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
7 changes: 4 additions & 3 deletions preverify_single_file_after_mj2_from_tif.m
Original file line number Diff line number Diff line change
@@ -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
Expand Down
15 changes: 0 additions & 15 deletions read_16bit_grayscale_mj2.m

This file was deleted.

16 changes: 0 additions & 16 deletions read_16bit_grayscale_tif.m

This file was deleted.

8 changes: 0 additions & 8 deletions read_file_into_uint8_array.m

This file was deleted.

5 changes: 0 additions & 5 deletions replace_extension.m

This file was deleted.

3 changes: 3 additions & 0 deletions reset_for_test.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function reset_for_test(output_folder_path)
system(sprintf('rm -rf %s', output_folder_path)) ;
end
17 changes: 0 additions & 17 deletions results_from_job_array.m

This file was deleted.

6 changes: 0 additions & 6 deletions simple_dir.m

This file was deleted.

11 changes: 7 additions & 4 deletions test_freezing.m
Original file line number Diff line number Diff line change
@@ -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)
7 changes: 0 additions & 7 deletions touch.m

This file was deleted.

4 changes: 2 additions & 2 deletions verify_big_files_after_mj2_from_tif.m
Original file line number Diff line number Diff line change
@@ -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

4 changes: 2 additions & 2 deletions verify_file_sizes_after_mj2_from_tif.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Loading

0 comments on commit 5d86faf

Please sign in to comment.