Exemplo n.º 1
0
def convert_dir(in_path):
    out_path = in_path + "_utf8"
    all_paths = []
    path_cats, cats = tools.get_paths(in_path)
    for path_i, cat_i in zip(path_cats, cats):
        text_paths, names = tools.get_paths(path_i)
        all_paths += text_paths
    tools.make_dir(out_path)
    for dir_i in path_cats:
        dir_i = dir_i.replace(in_path, out_path)
        tools.make_dir(dir_i)
    for in_path_i in all_paths:
        out_path_i = in_path_i.replace(in_path, out_path)
        to_utf8(in_path_i, out_path_i)
    print(all_paths)
Exemplo n.º 2
0
    source_dir = ''
    output_dir = './'
    infile = sys.argv[1]
    
else:
    # Use hardcoded file
    root_dir = '/home/kyager/ppl/AtikurRahman/layered_BCPs_01/'
    data_dir = 'L-36/'
    #data_dir = 'normal/'
    
    protocol = 'local_avg_realspace'
    #protocol = 'thumbnails'
    source_dir = os.path.join( root_dir, 'raw', data_dir )
    output_dir = os.path.join( root_dir, 'ImAnalysis', data_dir )
    
    tools.make_dir(output_dir)
    
    #infile = 'L-36-3cyc_L-74-3-cyc_O2-at-end_1_q01.tif'
    
    import glob
    #infiles = glob.glob(source_dir + '*.tif')
    infiles = glob.glob(source_dir + 'L-36-3cyc_L-74-3-cyc_O2-at-end_1_q01.tif')
    
    #infiles = glob.glob(source_dir + '6.tif')
    #infiles = glob.glob(source_dir + '2012-09-25 Lam Blend01-2p5KRPM_q02.tif')
    
    infiles.sort()
    


if True:
Exemplo n.º 3
0
environment_init.install_init()

# install init_package
os.chdir(base['tar_base'])
for soft in init_package:
	tools.extract_file(soft)
	folder_name = tools.filter(soft)
	tools.pak_configure(folder_name,folder_name,base['soft_path'],base['tar_base'])
	tools.pak_make(folder_name,base['tar_base'])

# install mysql
# extract mysql.tar
tools.extract_file(mysql_package)
# configure options
for dir in ['data','etc']
	tools.make_dir(dir,mysql_path)

options = 
"""
-DMYSQL_DATADIR=%s \
-DSYSCONFDIR=%s \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_READLINE=1 \
-DWITH_DEBUG=0 \
-DWITH_EMBEDDED_SERVER=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1
""" % (os.path.join(mysql_path,'data'),os.path.join(mysql_path,'etc'))
Exemplo n.º 4
0
# configure
tools.pak_configure(base['soft_name'],tools.filter(nginx_package),base['soft_path'],base['tar_path'],options)

# change the Makefile to tend to adjust the init
makefile_fix = os.path.join(base['tar_path'],nginx_package,'/objs')
makefile = tools.read_file('makefile_fix' + '/Makefile')
result_1 = re.sub(r'./configure','./configure --prefix=/opt/lnmp/app/init',makefile)
result = re.sub(r'./configure --prefix=/opt/lnmp/app/init --disable-shared','./configure --prefix=/opt/lnmp/app/init',result_1)
tools.write_file(makefile_fix,result)

# make
tools.pak_make(tools.filter(nginx_package),base['tar_path'])

# config
for dir in ['sites-enabled','sites-available']:
	tools.make_dir(dir,os.path.join(nginx_path,'conf'))
tools.make_dir('bin',nginx_path)


for file in ['nginx.conf','nginx.sh','herouser_virtualhost']:
	temp_content = tools.read_file(cwd + '/' + file)
	if 'conf' in file:
		temp_file = os.path.join(nginx_path, 'conf') + '/' + file
	elif 'sh' in file:
		temp_file = os.path.join(nginx_path, 'bin') + '/' + file
	elif 'virtualhost' in file:
		temp_file = os.path.join(nginx_path, 'conf', 'sites-available') + '/' + file
	tools.write_file(temp_file, temp_content)
	os.chmod(temp_file,stat.S_IRWXU + stat.S_IRWXG)

tools.make_dir('www/herouser',nginx_path)
Exemplo n.º 5
0
    def _do_registration(self, modality, fiji_path, registration_script,
                         registration_params, input_folder,
                         input_filenames_prefix, output_folder, num_images,
                         orig_image_size, pixels_per_mm, info_description,
                         info_parameters):
        # modality is 'EM' or 'LM'

        # Ensure that folder exists, if not create it and its parent folders.
        tools.make_dir(output_folder)

        # Tell Fiji to execute a macro that (i) reads the LM/EM images, (ii) merges them into a stack,
        # (iii) saves the stack to TIFF, (iv) aligns the slices in this stack
        # and (v) saves the aligned stack to TIFF.
        # Registration happens either with Fiji's Plugins > Registration > Linear Stack Alignment with SIFT, or with Plugins > StackReg.

        busy_string = "Registering {} images...".format(modality)

        print(busy_string)
        print(
            'Starting a headless Fiji and calling the image registration plugin. Please be patient...'
        )
        script_args = "srcdir='{}',dstdir='{}',prefix='{}',method='{}',numimages='{}',do_invert='{}',do_enhance_contrast='{}',do_crop='{}',roi_x='{}',roi_y='{}',roi_width='{}',roi_height='{}'".format(
            input_folder, output_folder, input_filenames_prefix,
            registration_params['method'], num_images,
            registration_params["invert"],
            registration_params["enhance_contrast"],
            registration_params["crop"], registration_params["roi"][0],
            registration_params["roi"][1], registration_params["roi"][2],
            registration_params["roi"][3])

        # Note: info about headless ImageJ: https://imagej.net/Headless#Running_macros_in_headless_mode
        wait = wx.BusyInfo(busy_string)
        retcode, out, err = tools.commandline_exec([
            fiji_path, "-Dpython.console.encoding=UTF-8", "--ij2",
            "--headless", "--console", "--run", registration_script,
            script_args
        ])

        print('Headless Fiji retcode={}\nstdout=\n{}\nstderr={}\n'.format(
            retcode, out, err))
        del wait

        # # # # # # # # # # BEGIN EXPERIMENTAL CODE

        update_offsets = True

        output_filename = '{}_aligned_stack.tif'.format(
            registration_params['method'])
        registration_correct = wx.MessageBox(
            'Please check the registration result {}.\n'
            'Are all images aligned correctly?'.format(
                os.path.join(output_folder,
                             output_filename)), 'Registration successful?',
            wx.YES_NO | wx.ICON_QUESTION, self)  # "Yes" is selected by default
        if registration_correct == wx.NO:
            print('User feedback: registration is not correct.')
            with RegistrationImportDialog(output_folder, None, wx.ID_ANY,
                                          "Import Registration Output") as dlg:
                if dlg.ShowModal() == wx.ID_OK:
                    print('Using manual registration output')
                    out = dlg.get_registration_output()
                    info_description = info_description + ' (Manual)'
                else:
                    print('User feedback: do not use manual registration')
                    update_offsets = False
        else:
            print('User feedback: registration is correct.')

        # # # # # # # # # # END EXPERIMENTAL CODE

        if update_offsets:
            # Parse the output of the registration plugin and extract
            # the transformation matrices to register each slice onto the next.
            print(
                'Extracting transformation matrices from registration plugin output'
            )
            registration_matrices = tools.extract_registration_matrices(
                registration_params['method'], out)
            print(registration_matrices)

            registration_offsets_microns = self.calculate_registration_offsets(
                registration_matrices, orig_image_size, pixels_per_mm,
                registration_params)
            print(
                'Registration corrected point-of-interest offsets [micrometer]: '
                + repr(registration_offsets_microns))

            # Combine (=sum) existing offsets with this new one
            assert self._model.combined_offsets_microns is not None
            assert len(self._model.combined_offsets_microns) == len(
                registration_offsets_microns)
            self._model.combined_offsets_microns = map(
                operator.add, self._model.combined_offsets_microns,
                registration_offsets_microns)
            print('Combined offsets [micrometer]: ' +
                  repr(self._model.combined_offsets_microns))

            # Append offset correction to "history" of existing offsets.
            self._model.all_offsets_microns.append({
                'name':
                info_description,
                'parameters':
                info_parameters,
                'offsets':
                registration_offsets_microns
            })
        else:
            print('Registration plugin output NOT used.')
            print('Slice offsets NOT updated with corrections.')

        #
        self._do_save_poi_info(output_folder)

        # For debugging / validation: display the offsets table.
        tools.show_offsets_table(self._model.all_offsets_microns,
                                 self._model.combined_offsets_microns)