Example #1
0
 def copy_plane(index, src):
     p = J.call(planar_img, "getPlane", "(I)Ljava/lang/Object;", index)
     dest = J.call(p, "getCurrentStorageArray", "()Ljava/lang/Object;")
     length = np.prod(src.shape)
     src = J.get_nice_arg(src, "[D")
     J.static_call("java/lang/System", "arraycopy",
                   "(Ljava/lang/Object;ILjava/lang/Object;II)V",
                   src, 0, dest, 0, length)
Example #2
0
 def copy_plane(index, src):
     p = J.call(planar_img, "getPlane", "(I)Ljava/lang/Object;", index)
     dest = J.call(p, "getCurrentStorageArray", "()Ljava/lang/Object;")
     length = np.prod(src.shape)
     src = J.get_nice_arg(src, "[D")
     J.static_call("java/lang/System", "arraycopy",
                   "(Ljava/lang/Object;ILjava/lang/Object;II)V", src, 0,
                   dest, 0, length)
Example #3
0
 def build_extractor(self):
     '''Build a Java metadata extractor using the module settings'''
     #
     # Build a metadata extractor
     #
     script = """
     importPackage(Packages.org.cellprofiler.imageset);
     importPackage(Packages.org.cellprofiler.imageset.filter);
     extractor = new ImagePlaneMetadataExtractor();
     extractor.addImagePlaneExtractor(new OMEMetadataExtractor());
     extractor;
     """
     extractor = J.run_script(script)
     for group in self.extraction_methods:
         if group.filter_choice == F_FILTERED_IMAGES:
             fltr = J.make_instance(
                 "org/cellprofiler/imageset/filter/Filter",
                 "(Ljava/lang/String;)V", group.filter.value_text)
         else:
             fltr = None
         if group.extraction_method == X_MANUAL_EXTRACTION:
             if group.source == XM_FILE_NAME:
                 method = "addFileNameRegexp"
                 pattern = group.file_regexp.value
             elif group.source == XM_FOLDER_NAME:
                 method = "addPathNameRegexp"
                 pattern = group.folder_regexp.value
             J.call(extractor,
                    method,
                    "(Ljava/lang/String;Lorg/cellprofiler/imageset/filter/Filter;)V",
                    pattern, fltr)
         elif group.extraction_method == X_IMPORTED_EXTRACTION:
             #
             # Create the array of key pairs for the join
             #
             key_pairs = []
             for join_idx in group.csv_joiner.parse():
                 key_pair = J.make_instance(
                     'org/cellprofiler/imageset/ImportedMetadataExtractor$KeyPair',
                     '(Ljava/lang/String;Ljava/lang/String;)V',
                     join_idx[self.CSV_JOIN_NAME], 
                     join_idx[self.IPD_JOIN_NAME])
                 key_pairs.append(key_pair)
             key_pairs = J.get_nice_arg(
                 key_pairs, 
                 "[Lorg/cellprofiler/imageset/ImportedMetadataExtractor$KeyPair;")
             #
             # Open the CSV file for reading, make an ImportedMetadataExtractor
             # and install it in the big extractor
             #
             script = """
             importPackage(Packages.org.cellprofiler.imageset);
             var inputStream = new java.io.FileInputStream(csv_path);
             var rdr = new java.io.InputStreamReader(inputStream);
             var iextractor = new ImportedMetadataExtractor(rdr, key_pairs, case_insensitive);
             extractor.addImagePlaneDetailsExtractor(iextractor, fltr);
             """
             J.run_script(script, dict(
                 csv_path=group.csv_location.value,
                 key_pairs=key_pairs,
                 case_insensitive = group.wants_case_insensitive.value,
                 extractor = extractor,
                 fltr = fltr))
     #
     # Finally, we add the WellMetadataExtractor which has the inglorious
     # job of making a well name from row and column, if present.
     #
     script = """
     importPackage(Packages.org.cellprofiler.imageset);
     extractor.addImagePlaneDetailsExtractor(new WellMetadataExtractor());
     """
     J.run_script(script, dict(extractor = extractor))
     
     return extractor
Example #4
0
    def build_extractor(self):
        '''Build a Java metadata extractor using the module settings'''
        #
        # Build a metadata extractor
        #
        script = """
        importPackage(Packages.org.cellprofiler.imageset);
        importPackage(Packages.org.cellprofiler.imageset.filter);
        extractor = new ImagePlaneMetadataExtractor();
        extractor.addImagePlaneExtractor(new OMEMetadataExtractor());
        extractor;
        """
        extractor = J.run_script(script)
        for group in self.extraction_methods:
            if group.filter_choice == F_FILTERED_IMAGES:
                fltr = J.make_instance(
                    "org/cellprofiler/imageset/filter/Filter",
                    "(Ljava/lang/String;)V", group.filter.value_text)
            else:
                fltr = None
            if group.extraction_method == X_MANUAL_EXTRACTION:
                if group.source == XM_FILE_NAME:
                    method = "addFileNameRegexp"
                    pattern = group.file_regexp.value
                elif group.source == XM_FOLDER_NAME:
                    method = "addPathNameRegexp"
                    pattern = group.folder_regexp.value
                J.call(
                    extractor, method,
                    "(Ljava/lang/String;Lorg/cellprofiler/imageset/filter/Filter;)V",
                    pattern, fltr)
            elif group.extraction_method == X_IMPORTED_EXTRACTION:
                #
                # Create the array of key pairs for the join
                #
                key_pairs = []
                for join_idx in group.csv_joiner.parse():
                    key_pair = J.make_instance(
                        'org/cellprofiler/imageset/ImportedMetadataExtractor$KeyPair',
                        '(Ljava/lang/String;Ljava/lang/String;)V',
                        join_idx[self.CSV_JOIN_NAME],
                        join_idx[self.IPD_JOIN_NAME])
                    key_pairs.append(key_pair)
                key_pairs = J.get_nice_arg(
                    key_pairs,
                    "[Lorg/cellprofiler/imageset/ImportedMetadataExtractor$KeyPair;"
                )
                #
                # Open the CSV file for reading, make an ImportedMetadataExtractor
                # and install it in the big extractor
                #
                script = """
                importPackage(Packages.org.cellprofiler.imageset);
                var inputStream = new java.io.FileInputStream(csv_path);
                var rdr = new java.io.InputStreamReader(inputStream);
                var iextractor = new ImportedMetadataExtractor(rdr, key_pairs, case_insensitive);
                extractor.addImagePlaneDetailsExtractor(iextractor, fltr);
                """
                J.run_script(
                    script,
                    dict(csv_path=group.csv_location.value,
                         key_pairs=key_pairs,
                         case_insensitive=group.wants_case_insensitive.value,
                         extractor=extractor,
                         fltr=fltr))
        #
        # Finally, we add the WellMetadataExtractor which has the inglorious
        # job of making a well name from row and column, if present.
        #
        script = """
        importPackage(Packages.org.cellprofiler.imageset);
        extractor.addImagePlaneDetailsExtractor(new WellMetadataExtractor());
        """
        J.run_script(script, dict(extractor=extractor))

        return extractor