1313import shutil
1414import sys
1515
16+ from bdv .util .source .fused import AlphaFusedResampledSource
1617from ch .epfl .biop .scijava .command .spimdata import (
1718 FuseBigStitcherDatasetIntoOMETiffCommand ,
1819)
2122from .. import pathtools
2223from ..log import LOG as log
2324
24-
2525# internal template strings used in string formatting (note: the `"""@private"""`
2626# pseudo-decorator is there to instruct [pdoc] to omit those variables when generating
2727# API documentation):
@@ -902,6 +902,7 @@ def define_dataset_manual(
902902 image_file_pattern ,
903903 dataset_organisation ,
904904 definition_opts = None ,
905+ list_files = None ,
905906):
906907 """Run "Define Multi-View Dataset" using the "Manual Loader" option.
907908
@@ -920,20 +921,26 @@ def define_dataset_manual(
920921 Looks like "timepoints_=%s-%s channels_=0-%s tiles_=%s-%s"
921922 definition_opts : dict
922923 Dictionary containing the details about the file repartitions.
924+ list_files : list of str, optional
925+ If provided, a list of file names to pass directly to the manual
926+ loader in "show_list" mode. When `list_files` is given the
927+ function will include the filenames in the options string instead
928+ of relying on a file pattern; items should be either basenames or
929+ paths appropriate for the selected ``image_file_directory``.
930+
923931 """
924932
925- xml_filename = project_filename + ".xml"
933+ # xml_filename = project_filename + ".xml"
926934
927935 if definition_opts is None :
928- definition_opts = DefinitionOptions ()
936+ definition_opts = bdv . DefinitionOptions ()
929937
930- temp = os .path .join (source_directory , project_filename + "_temp" )
931- os .path .join (temp , project_filename )
938+ show_list_options = "" if not list_files else "show_list " + " " .join (list_files )
932939
933940 options = (
934941 "define_dataset=[Manual Loader (Bioformats based)] "
935942 + "project_filename=["
936- + xml_filename
943+ + project_filename
937944 + "] "
938945 + "_____"
939946 + definition_opts .fmt_acitt_options ()
@@ -943,11 +950,12 @@ def define_dataset_manual(
943950 + " "
944951 + "image_file_pattern="
945952 + image_file_pattern
953+ + " "
946954 + dataset_organisation
947955 + " "
948956 + "calibration_type=[Same voxel-size for all views] "
949957 + "calibration_definition=[Load voxel-size(s) from file(s)] "
950- # + "imglib2_data_container=[ArrayImg (faster)]"
958+ + show_list_options
951959 )
952960
953961 log .debug ("Manual dataset definition options: <%s>" , options )
@@ -991,7 +999,7 @@ def resave_as_h5(
991999 """
9921000
9931001 if not processing_opts :
994- processing_opts = ProcessingOptions ()
1002+ processing_opts = bdv . ProcessingOptions ()
9951003
9961004 if use_deflate_compression :
9971005 use_deflate_compression_arg = "use_deflate_compression "
@@ -1032,7 +1040,7 @@ def resave_as_h5(
10321040 )
10331041
10341042 log .debug ("Resave as HDF5 options: <%s>" , options )
1035- IJ .run ("As HDF5" , str (options ))
1043+ IJ .run ("Resave as HDF5 (local) " , str (options ))
10361044
10371045
10381046def flip_axes (source_xml_file , x = False , y = True , z = False ):
@@ -1593,58 +1601,100 @@ def fuse_dataset(
15931601def fuse_dataset_bdvp (
15941602 project_path ,
15951603 command ,
1596- processing_opts = None ,
15971604 result_path = None ,
1598- compression = "LZW" ,
1605+ n_resolution_levels = 5 ,
1606+ use_lzw_compression = True ,
1607+ fusion_method = "SMOOTH " + AlphaFusedResampledSource .AVERAGE ,
15991608):
16001609 """Export a BigDataViewer project using the BIOP Kheops exporter.
16011610
1602- Use the BIOP Kheops exporter to convert a BigDataViewer project into
1603- OME-TIFF files, with optional compression.
1611+ Convert a BigDataViewer project into OME-TIFF files using the BIOP
1612+ Kheops exporter. This wraps the Scijava export command and allows
1613+ setting the output directory, compression and number of resolution
1614+ levels.
16041615
16051616 Parameters
16061617 ----------
16071618 project_path : str
16081619 Full path to the BigDataViewer XML project file.
16091620 command : CommandService
16101621 The Scijava CommandService instance to execute the export command.
1611- processing_opts : ProcessingOptions, optional
1612- Options defining which parts of the dataset to process. If None, default
1613- processing options will be used (process all angles, channels, etc.).
16141622 result_path : str, optional
1615- Path where to store the exported files. If None, files will be saved in
1616- the same directory as the input project.
1617- compression : str, optional
1618- Compression method to use for the TIFF files. Default is "LZW".
1623+ Path where to store the exported files. If ``None``, files will be
1624+ saved in the same directory as the input project.
1625+ n_resolution_levels : int, optional
1626+ Number of resolution levels to export (default 5).
1627+ use_lzw_compression : bool, optional
1628+ Whether to use LZW compression for the output TIFFs (default True).
1629+ fusion_method : str, optional
1630+ Fusion method to use for exporting (default ``"SMOOTH AVERAGE"``).
16191631
16201632 Notes
16211633 -----
1622- This function requires the PTBIOP update site to be enabled in Fiji/ImageJ.
1634+ This function requires the PTBIOP update site to be enabled in Fiji/
1635+ ImageJ.
1636+
16231637 """
1624- if processing_opts is None :
1625- processing_opts = ProcessingOptions ()
16261638
16271639 file_info = pathtools .parse_path (project_path )
1640+
16281641 if not result_path :
16291642 result_path = file_info ["path" ]
1630- # if not os.path.exists(result_path):
1631- # os.makedirs(result_path)
16321643
16331644 command .run (
16341645 FuseBigStitcherDatasetIntoOMETiffCommand ,
1635- True ,
1636- "image " ,
1646+ False ,
1647+ "xml_bigstitcher_file " ,
16371648 project_path ,
1638- "output_dir " ,
1649+ "output_path_directory " ,
16391650 result_path ,
1640- "compression" ,
1641- compression ,
1642- "subset_channels" ,
1643- "" ,
1644- "subset_slices" ,
1645- "" ,
1646- "subset_frames" ,
1647- "" ,
1648- "compress_temp_files" ,
1649- False ,
1650- )
1651+ "n_resolution_levels" ,
1652+ n_resolution_levels ,
1653+ "use_lzw_compression" ,
1654+ use_lzw_compression ,
1655+ "fusion_method" ,
1656+ fusion_method ,
1657+ ).get ()
1658+
1659+
1660+ def join_files_with_channel_suffix (files , nchannels ):
1661+ """Join filenames and append channel-suffixed copies.
1662+
1663+ For each filename in ``files``, return a list where original filenames
1664+ appear first followed by copies with suffixes ``_0`` .. ``_{n-2}``
1665+ (inserted before the file extension). This is suitable for passing
1666+ to Bioformats/Jython in ``show_list`` mode when each channel is stored
1667+ as a separate file.
1668+
1669+ Parameters
1670+ ----------
1671+ files : list or tuple
1672+ List or tuple of filename strings.
1673+ nchannels : int
1674+ Number of channels (>=1). If ``nchannels`` is 1 no suffixed copies
1675+ are added.
1676+
1677+ Returns
1678+ -------
1679+ list of str
1680+ Ordered list of filenames (originals then suffixed copies).
1681+ """
1682+ import os
1683+
1684+ if not files :
1685+ return ""
1686+ try :
1687+ x = range (int (nchannels ) - 1 )
1688+ except Exception :
1689+ x = [0 ]
1690+ suff = "_" + str (x )
1691+ out = []
1692+ # keep original order, then add suffixed copies
1693+ for f in files :
1694+ out .append (f )
1695+ for i in x :
1696+ suff = "_" + str (i )
1697+ for f in files :
1698+ base , ext = os .path .splitext (f )
1699+ out .append (base + suff + ext )
1700+ return out
0 commit comments