示例#1
0
 def test_do_calculation_calculation_process(self, tmpdir, data_test_dir):
     plan = self.create_calculation_plan3()
     file_path = os.path.join(data_test_dir, "stack1_components",
                              "stack1_component1.tif")
     calc = Calculation(
         [file_path],
         base_prefix=data_test_dir,
         result_prefix=data_test_dir,
         measurement_file_path=os.path.join(tmpdir, "test3.xlsx"),
         sheet_name="Sheet1",
         calculation_plan=plan,
         voxel_size=(1, 1, 1),
     )
     calc_process = CalculationProcess()
     res = calc_process.do_calculation(FileCalculation(file_path, calc))
     assert isinstance(res, list)
     assert isinstance(res[0], ResponseData)
示例#2
0
def do_calculation(file_info: Tuple[int, str],
                   calculation: BaseCalculation) -> WrappedResult:
    """
    Main function which will be used for run calculation.
    It create :py:class:`.CalculationProcess` and call it method
    :py:meth:`.CalculationProcess.do_calculation`

    :param file_info: index and path to file which should be processed
    :param calculation: calculation description
    """
    calc = CalculationProcess()
    index, file_path = file_info
    try:
        return index, calc.do_calculation(
            FileCalculation(file_path, calculation))
    except Exception as e:
        # traceback.print_exc()
        return index, [prepare_error_data(e)]
示例#3
0
def do_calculation(file_info: Tuple[int, str],
                   calculation: BaseCalculation) -> WrappedResult:
    """
    Main function which will be used for run calculation.
    It create :py:class:`.CalculationProcess` and call it method
    :py:meth:`.CalculationProcess.do_calculation`

    :param file_info: index and path to file which should be processed
    :param calculation: calculation description
    """
    SimpleITK.ProcessObject_SetGlobalDefaultNumberOfThreads(1)
    calc = CalculationProcess()
    index, file_path = file_info
    try:
        return index, calc.do_calculation(
            FileCalculation(file_path, calculation))
    except Exception as e:
        return index, [prepare_error_data(e)]
示例#4
0
 def test_do_calculation_save(self, tmpdir, data_test_dir, file_name,
                              root_type, save_method: SaveBase):
     save_desc = Save("_test", "", save_method.get_name(),
                      save_method.get_short_name(),
                      save_method.get_default_values())
     plan = self.create_simple_plan(root_type, save_desc)
     file_path = os.path.join(data_test_dir, file_name)
     calc = Calculation(
         [file_path],
         base_prefix=os.path.dirname(file_path),
         result_prefix=tmpdir,
         measurement_file_path=os.path.join(tmpdir, "test3.xlsx"),
         sheet_name="Sheet1",
         calculation_plan=plan,
         voxel_size=(1, 1, 1),
     )
     calc_process = CalculationProcess()
     res = calc_process.do_calculation(FileCalculation(file_path, calc))
     assert isinstance(res, list)
     assert isinstance(res[0], ResponseData)
示例#5
0
 def test_full_pipeline_base(self, tmpdir, data_test_dir, monkeypatch):
     monkeypatch.setattr(batch_backend, "CalculationProcess",
                         MockCalculationProcess)
     plan = self.create_calculation_plan()
     file_pattern = os.path.join(data_test_dir, "stack1_components",
                                 "stack1_component*[0-9].tif")
     file_paths = sorted(glob(file_pattern))
     assert os.path.basename(file_paths[0]) == "stack1_component1.tif"
     calc = Calculation(
         file_paths,
         base_prefix=data_test_dir,
         result_prefix=data_test_dir,
         measurement_file_path=os.path.join(tmpdir, "test.xlsx"),
         sheet_name="Sheet1",
         calculation_plan=plan,
         voxel_size=(1, 1, 1),
     )
     calc_process = CalculationProcess()
     for file_path in file_paths:
         res = calc_process.do_calculation(FileCalculation(file_path, calc))
         assert isinstance(res, list)
         assert isinstance(res[0], ResponseData)