Пример #1
0
    def create_settings(self):
        self.input_type = cps.Choice("Select the type of input",
                                     [IF_IMAGE, IF_OBJECTS], IF_IMAGE)

        self.image_name = cps.ImageNameSubscriber("Select the image to save",
                                                  cps.NONE,
                                                  doc="""
            <i>(Used only if "%(IF_IMAGE)s", "%(IF_MASK)s" or "%(IF_CROPPING)s" are selected to save)</i><br>
            Select the image you want to save.""" % globals())

        self.input_object_name = cps.ObjectNameSubscriber(
            "Select the objects to save", cps.NONE)

        self.objects_name = cps.ObjectNameSubscriber(
            "Select the objects to crop and save",
            cps.NONE,
            doc="""
            Select the objects that you want to save.""" % globals())

        self.file_name_method = cps.Choice(
            "Select method for constructing file names", [
                FN_FROM_IMAGE,
            ],
            doc="""
            Several choices are available for constructing the image file name:
            <ul>
            <li><i>%(FN_FROM_IMAGE)s:</i> The filename will be constructed based
            on the original filename of an input image specified in <b>NamesAndTypes</b>.
            You will have the opportunity to prefix or append
            additional text.
            <p>If you have metadata associated with your images, you can append an text
            to the image filename using a metadata tag. This is especially useful if you
            want your output given a unique label according to the metadata corresponding
            to an image group. The name of the metadata to substitute can be provided for
            each image for each cycle using the <b>Metadata</b> module.
            %(USING_METADATA_TAGS_REF)s%(USING_METADATA_HELP_REF)s.</p></li>
            </ul>""" % globals())

        self.file_image_name = cps.FileImageNameSubscriber(
            "Select image name for file prefix",
            cps.NONE,
            doc="""
            <i>(Used only when "%(FN_FROM_IMAGE)s" is selected for contructing the filename)</i><br>
            Select an image loaded using <b>NamesAndTypes</b>. The original filename will be
            used as the prefix for the output filename.""" % globals())

        self.wants_file_name_suffix = cps.Binary(
            "Append a suffix to the image file name?",
            False,
            doc="""
            Select <i>%(YES)s</i> to add a suffix to the image's file name.
            Select <i>%(NO)s</i> to use the image name as-is.""" % globals())

        self.file_name_suffix = cps.Text("Text to append to the image name",
                                         "",
                                         metadata=True,
                                         doc="""
            <i>(Used only when constructing the filename from the image filename)</i><br>
            Enter the text that should be appended to the filename specified above."""
                                         )

        self.file_format = cps.Choice("Saved file format", [FF_TIFF],
                                      value=FF_TIFF,
                                      doc="""
            <i>(Used only when saving non-movie files)</i><br>
            Select the image or movie format to save the image(s). Most common
            image formats are available; MAT-files are readable by MATLAB.""")

        self.pathname = SaveImagesDirectoryPath("Output file location",
                                                self.file_image_name,
                                                doc="""
            <i>(Used only when saving non-movie files)</i><br>
            This setting lets you choose the folder for the output
            files. %(IO_FOLDER_CHOICE_HELP_TEXT)s
            <p>An additional option is the following:
            <ul>
            <li><i>Same folder as image</i>: Place the output file in the same folder
            that the source image is located.</li>
            </ul></p>
            <p>%(IO_WITH_METADATA_HELP_TEXT)s %(USING_METADATA_TAGS_REF)s.
            For instance, if you have a metadata tag named
            "Plate", you can create a per-plate folder by selecting one the subfolder options
            and then specifying the subfolder name as "\g&lt;Plate&gt;". The module will
            substitute the metadata values for the current image set for any metadata tags in the
            folder name.%(USING_METADATA_HELP_REF)s.</p>
            <p>If the subfolder does not exist when the pipeline is run, CellProfiler will
            create it.</p>
            <p>If you are creating nested subfolders using the sub-folder options, you can
            specify the additional folders separated with slashes. For example, "Outlines/Plate1" will create
            a "Plate1" folder in the "Outlines" folder, which in turn is under the Default
            Input/Output Folder. The use of a forward slash ("/") as a folder separator will
            avoid ambiguity between the various operating systems.</p>""" %
                                                globals())

        self.bit_depth = cps.Choice(
            "Image bit depth", [BIT_DEPTH_8, BIT_DEPTH_16, BIT_DEPTH_FLOAT],
            doc="""
            <i>(Used only when saving files in a non-MAT format)</i><br>
            Select the bit-depth at which you want to save the images.
            <i>%(BIT_DEPTH_FLOAT)s</i> saves the image as floating-point decimals
            with 32-bit precision in its raw form, typically scaled between
            0 and 1.
            <b>%(BIT_DEPTH_16)s and %(BIT_DEPTH_FLOAT)s images are supported only
            for TIF formats. Currently, saving images in 12-bit is not supported.</b>"""
            % globals())

        self.object_extension = cps.Integer("Object extension",
                                            value=1,
                                            doc="""
            How many pixels should the bounding box of the objects be extended
                                            before cropping""")

        self.overwrite = cps.Binary(
            "Overwrite existing files without warning?",
            False,
            doc="""
            Select <i>%(YES)s</i> to automatically overwrite a file if it already exists.
            Select <i>%(NO)s</i> to be prompted for confirmation first.
            <p>If you are running the pipeline on a computing cluster,
            select <i>%(YES)s</i> since you will not be able to intervene and answer the confirmation prompt.</p>"""
            % globals())

        self.when_to_save = cps.Choice("When to save", [WS_FIRST_CYCLE],
                                       doc="""<a name='when_to_save'>
            <i>(Used only when saving non-movie files)</i><br>
            Specify at what point during pipeline execution to save file(s). </a>
            <ul>
            <li><i>%(WS_EVERY_CYCLE)s:</i> Useful for when the image of interest is created every cycle and is
            not dependent on results from a prior cycle.</li>
            </ul> """ % globals())

        self.update_file_names = cps.Binary(
            "Record the file and path information to the saved image?",
            False,
            doc="""
            Select <i>%(YES)s</i> to store filename and pathname data for each of the new files created
            via this module as a per-image measurement.
            <p>Instances in which this information may be useful include:
            <ul>
            <li>Exporting measurements to a database, allowing
            access to the saved image. If you are using the machine-learning tools or image
            viewer in CellProfiler Analyst, for example, you will want to enable this setting if you want
            the saved images to be displayed along with the original images.</li>
            <li>Allowing downstream modules (e.g., <b>CreateWebPage</b>) to access
            the newly saved files.</li>
            </ul></p>""" % globals())

        self.create_subdirectories = cps.Binary(
            "Create subfolders in the output folder?",
            False,
            doc="""
            Select <i>%(YES)s</i> to create subfolders to match the input image folder structure."""
            % globals())

        self.root_dir = cps.DirectoryPath("Base image folder",
                                          doc="""
            <i>Used only if creating subfolders in the output folder</i>
            In subfolder mode, <b>SaveImages</b> determines the folder for
            an image file by examining the path of the matching input file.
            The path that SaveImages uses is relative to the image folder
            chosen using this setting. As an example, input images might be stored
            in a folder structure of "images%(sep)s<i>experiment-name</i>%(sep)s
            <i>date</i>%(sep)s<i>plate-name</i>". If the image folder is
            "images", <b>SaveImages</b> will store images in the subfolder,
            "<i>experiment-name</i>%(sep)s<i>date</i>%(sep)s<i>plate-name</i>".
            If the image folder is "images%(sep)s<i>experiment-name</i>",
            <b>SaveImages</b> will store images in the subfolder,
            <i>date</i>%(sep)s<i>plate-name</i>".
            """ % dict(sep=os.path.sep))
    def create_settings(self):
        '''Create the settings for the module's UI'''
        self.warning = cps.Divider(
            "This module allows you to rename (overwrite) your files. Please "
            "see the help for this module for warnings.")

        self.image_name = cps.FileImageNameSubscriber('Select the input image',
                                                      cps.NONE,
                                                      doc="""
            Select the images associated with the files
            you want to rename. This should be an image loaded by the
            <b>Input</b> modules.
            Be very careful because you will be renaming these files!""")

        self.number_characters_prefix = cps.Integer(
            "Number of characters to retain at start of file name",
            6,
            minval=0,
            doc="""
            Number of characters at the start of the old
            file name that will be copied over verbatim to the new file name. For
            instance, if this setting is "6" and the file name is 
            "Image-734.tif", the output file name will also start with 
            "Image-".""")

        self.number_characters_suffix = cps.Integer(
            "Number of characters to retain at the end of file name",
            4,
            minval=0,
            doc="""
            Number of characters at the end of the old
            file name that will be copied over verbatim to the new file name. For
            instance, if this setting is "4" and the file name is
            "Image-734.tif", the output file name will also end with ".tif"."""
        )

        self.action = cps.Choice("Handling of remaining characters",
                                 [A_RENUMBER, A_DELETE],
                                 doc="""
            You can either treat the characters between the start and
            end as numbers or you can delete them. If you treat them as numbers,
            you will be given the opportunity to pad the numbers with zeros
            so that all of your file names will have a uniform length. For
            instance, if you were to renumber the highlighted portion of the
            file "Image-<u>734</u>.tif" using four digits, the result would
            be "Image-0734.tif".""")

        self.number_digits = cps.Integer("Number of digits for numbers",
                                         4,
                                         minval=0,
                                         doc="""
            <i>(Used only if %(A_RENUMBER)s is selected)</i><br>
            Use this setting to pad numbers with zeros so that they
            all have a uniform number of characters. For instance, padding
            with four digits has the following result:<br>
            <code><table>
            <tr><th>Original</th><th>Padded</th></tr>
            <tr><td>1</td><td>0001</td></tr>
            <tr><td>10</td><td>0010</td></tr>
            <tr><td>100</td><td>0100</td></tr>
            <tr><td>1000</td><td>1000</td></tr>
            </table></code>""" % globals())

        self.wants_text = cps.Binary("Add text to the file name?",
                                     False,
                                     doc="""
            Select <i>%(YES)s</i> if you want to add text
            to the file name. If you had chosen <i>%(A_RENUMBER)s</i> above,
            the module will add the text after your number.
            If you had chosen <i>%(A_DELETE)s</i>, the module will replace
            the deleted text with the text you enter here.""" % globals())

        self.text_to_add = cps.Text("Replacement text",
                                    "",
                                    doc="""
            <i>(Used only if you chose to add text to the file name)</i><br>
            Enter the text that you want to add to each file name.""")

        self.wants_to_replace_spaces = cps.Binary("Replace spaces?",
                                                  False,
                                                  doc="""
            Select <i>%(YES)s</i> to replace spaces in the final
            version of the file name with some other text. 
            <p>Select <i>%(NO)s</i> if the file name can have spaces 
            or if none of the file names have spaces.</p>""" % globals())

        self.space_replacement = cps.Text("Space replacement",
                                          "_",
                                          doc="""
            This is the text that will be substituted for spaces
            in your file name.""")
Пример #3
0
    def create_settings(self):
        self.directory = cps.DirectoryPath("Output file location",
                                           dir_choices=[
                                               ABSOLUTE_FOLDER_NAME,
                                               DEFAULT_OUTPUT_FOLDER_NAME,
                                               DEFAULT_OUTPUT_SUBFOLDER_NAME,
                                               DEFAULT_INPUT_FOLDER_NAME,
                                               DEFAULT_INPUT_SUBFOLDER_NAME
                                           ],
                                           doc="""
            This setting lets you choose the folder for the output
            files. %(IO_FOLDER_CHOICE_HELP_TEXT)s
            
            <p>%(IO_WITH_METADATA_HELP_TEXT)s %(USING_METADATA_TAGS_REF)s<br>
            For instance, if you have a metadata tag named 
            "Plate", you can create a per-plate folder by selecting one of the subfolder options
            and then specifying the subfolder name as "\g&lt;Plate&gt;". The module will 
            substitute the metadata values for the current image set for any metadata tags in the 
            folder name. %(USING_METADATA_HELP_REF)s.</p>""" % globals())
        self.directory.dir_choice = DEFAULT_OUTPUT_FOLDER_NAME

        self.wants_overwrite_without_warning = cps.Binary(
            "Overwrite without warning?",
            False,
            doc="""This setting either prevents or allows overwriting of
            old .txt files by <b>ExportToACC</b> without confirmation.
            Select <i>%(YES)s</i> to overwrite without warning any .txt file 
            that already exists. Select <i>%(NO)s</i> to prompt before overwriting
            when running CellProfiler in the GUI and to fail when running
            headless.""" % globals())

        self.nan_representation = cps.Choice("Representation of Nan/Inf",
                                             [NANS_AS_NANS, NANS_AS_NULLS],
                                             doc="""
            This setting controls the output for numeric fields
            if the calculated value is infinite (<i>Inf</i>) or undefined (<i>NaN</i>).
            CellProfiler will produce Inf or NaN values under certain rare
            circumstances, for instance when calculating the mean intensity
            of an object within a masked region of an image.
            <ul>
            <li><i>%(NANS_AS_NULLS)s:</i> Output these values as empty fields.</li>
            <li><i>%(NANS_AS_NANS)s:</i> Output them as the strings "NaN", "Inf" or "-Inf".</li>
            </ul>
            """ % globals())

        self.pick_columns = cps.Binary("Select the measurements to export",
                                       False,
                                       doc="""
            Select <i>%(YES)s</i> to provide a button that allows you to select which measurements you want to export.
            This is useful if you know exactly what measurements you want included in the final spreadheet(s). """
                                       % globals())

        self.columns = cps.MeasurementMultiChoice(
            "Press button to select measurements to export",
            doc="""
            <i>(Used only when selecting the columns of measurements to export)</i><br>
            This setting controls the columns to be exported. Press
            the button and check the measurements or categories to export.""")

        self.file_image_name = cps.FileImageNameSubscriber(
            "Select image name for file prefix",
            cps.NONE,
            doc="""
            Select an image loaded using <b>NamesAndTypes</b>. The original filename will be
            used as the prefix for the output filename.""" % globals())