def generate_incremental_foldername(folderpath='.', n_digit=4, create_dir=True): folderpath = os.path.abspath(folderpath) if create_dir: ensure_dir(folderpath) found_folders = list_folders(folderpath) current_max = -1 for f in found_folders: basename = File(f, folderpath).filebasename if basename.isdigit(): count = int(basename) if count > current_max: current_max = count fname = generate_n_digit_name(current_max + 1, n_digit) return os.path.join(folderpath, fname)
def run(self): self.interrupted.acquire() while self.interrupted.locked(): folders = filetools.list_folders(self.folder_to_watch) folders.sort() for folder in folders: if folder not in self.processed_folder: param_file = os.path.join(folder, self.param_filename) ignore_file = os.path.join(folder, self.ignore_filename) if os.path.exists( param_file) and not os.path.exists(ignore_file): if self.verbose: print 'Adding {} to manager queue'.format( param_file) XP_dict = read_XP_from_file(param_file) self.manager.add_XP(XP_dict) self.processed_folder.append(folder) time.sleep(SLEEP_TIME)
def check_xps_to_do(gen_path: str) -> list: """Checks for experiments to do in the current generation Checks for missing UV and IR spectra in each folder If missing, add to list Args: gen_path (str): Path to the current generation Returns: list: List of XP filepaths to execute """ xps = [] for xp_folder in sorted(filetools.list_folders(gen_path)): xp_files = [f for f in filetools.list_files(xp_folder)] uv_file = get_spectra_filenames(xp_folder) if not uv_file in xp_files: xps.append(xp_folder) return xps
def parse_xp_folders(self, generation_path): """ Parses all experiments in a generation to get their fitnesses Args: generation_path (str): Path of the current generation folder Returns: fitnesses (List): List of all the fitnesses for a generation """ fitnesses = [] xp_folders = filetools.list_folders(generation_path) for xp in sorted(xp_folders): # Do not process the ideal experiment for fitness if "ideal" in xp: continue print(f"Experiment: {xp}") fitness = self.parse_uv_for_fitness(xp) print(f"Fitness: {fitness}") self.write_fitness_to_file(xp, fitness) fitnesses.append(fitness) return fitnesses
problem_names = ['circle', 'sinus'] method_names = [ 'random', 'uncertainty_batch', 'uncertainty_single', 'uncertainty_batch_no_repulsion' ] results = {} for problem_name in problem_names: results[problem_name] = {} for method_name in method_names: refpath = os.path.join(HERE_PATH, 'plot', problem_name, method_name) folders = filetools.list_folders(refpath) for subfolders in folders: source_folders = filetools.list_folders(subfolders) for source_folder in source_folders: print source_folder fname = 'video.avi' video_filename = os.path.join(source_folder, fname) if 'model' in source_folder: fps = 1 else: fps = 5 make_video_from_folder(source_folder, video_filename,
# process_config = copy.deepcopy(DEFAULT_PROCESS_CONFIG) # process_config['dish_detect_config'] = { # 'minDist': np.inf, # 'hough_config': {}, # 'dish_center': None, # 'dish_radius': 180 # } # # videofilename = '/home/group/orkney1/0-Images/Laurie Points/LJP4-28/For Jonathan/2 Minute Videos/29.35 mm/C/My Movie 2.mp4' # video_out = '/home/group/orkney1/0-Images/Laurie Points/LJP4-28/For Jonathan/2 Minute Videos/29.35 mm/C/analysed2.avi' # # droplet_info = process_video(videofilename, process_config=process_config, video_out=video_out, debug=True, deep_debug=False) # # elapsed = time.time() - start_time # print 'It took {} seconds to analyse one video'.format(elapsed) #parallel start_time = time.time() droptracker = PoolSimpleDropletTracker() folder_list = filetools.list_folders('simple_videos') folder_list.sort() for folder in folder_list: droptracker.add_task(create_default_simple_tracker_config_from_folder(folder)) # need an abspath droptracker.wait_until_idle() elapsed = time.time() - start_time print 'It took {} seconds to analyse {} videos in parallel'.format(elapsed, len(folder_list))
import sys import filetools if len(sys.argv) != 2: print 'Please specify a root folder as argument' # seed seed = int(sys.argv[1]) random.seed(seed) np.random.seed(seed) # root_folder = os.path.join(HERE_PATH, sys.argv[1]) folders = filetools.list_folders(root_folder) folders.sort() last_folder = folders[-1] last_folder_int = int(os.path.basename(last_folder)) # load data current_datafile = os.path.join(last_folder, 'data.csv') X, y = read_data(current_datafile) # check everything is fine np.testing.assert_array_almost_equal(np.sum(X, axis=1), TOTAL_VOLUME_IN_ML, decimal=N_DECIMAL_EQUAL) # X = proba_normalize_row(X) # clf = train_classifier(X, y)
def count_XP_in_pool_folder(pool_folder): # a pool folder must contain only XP folder, so we just count the number of folder if os.path.exists(pool_folder): return len(filetools.list_folders(pool_folder)) else: return 0