def view(label, image, seg_only, config): '''View a spectrogram This is a super function which provides all of the functionality to view a spectrogram, either from the database itself or recreated Args: label: The label for the file image: If not '', write image to a file named this seg_only: View segments only config: The parsed ini file for this particular run Returns: Nothing. It writes to MongoDB collection defined in the ini file Raises: FileNotFoundError: If the wavfile doesn't exist, it can't be processed ''' # Get the data, from the database or recreate init_client(config) df, spectrogram, normalization_factor = read_spectrogram(label, config) close_client() # Apply Gaussian Filter spectrogram = apply_gaussian_filter( spectrogram, config['model_fit'].getfloat('gaussian_filter_sigma')) # Either vizualize spectrogram w/ bounding boxes # -> or, segments if seg_only: gen_segs(spectrogram, df, image) else: gen_spec_with_segs(label, spectrogram, df, image)
def chunk_run_prediction(chunk, train_labels_df, predict_labels_df, config): '''Make a prediction based on a model Given a directory of data, make a prediction using a model Args: chunk: A list of columns to process train_labels_df: The training labels to run predictions from predict_labels_df: The prediction labels to make predictions on config: The parsed ini file for this run Returns: Nothing. Writes prediction data to MongoDB collection. Raises: A list of `model.predict_proba` outputs ''' init_client(config) predict_proba = [ run_prediction(col, train_labels_df, predict_labels_df, config) for col in chunk ] close_client() return predict_proba
def chunk_preprocess(chunk, config): '''Preprocess all images This is a super function which provides all of the functionality to preprocess many wav file for model fitting. Args: chunk: A chunk of files to process config: The parsed ini file for this particular run Returns: Nothing Raises: Nothing ''' # Before running the chunk, we need to initialize the global MongoDB client init_client(config) for label in chunk: preprocess(label, config) # Don't forget to close the client! close_client()
def high_cc(l, species_found, config): if len(l) != 0: init_client(config) all_file_file_statistics = generate_ff_stats(l, species_found) close_client() try: results_str = "" for idx, row in zip(l.index.values, all_file_file_statistics): highest_cc = row.max() if highest_cc >= 0.75: build_str = np.array_str(row).replace('\n', '') results_str += f"{idx}: {build_str}\n" except ValueError: pass return results_str else: return ""
def chunk_run_stats(chunk, train_labels_df, config): '''For each chunk call run_stats Run within a parallel executor to generate file and file-file Statistics for a given label. Args: chunk: A chunk of file labels labels_df: Passed through to `file_file_stats` function config: The parsed ini file for this run Returns: Nothing, writes to MongoDB Raises: Nothing. ''' init_client(config) [run_stats(label, train_labels_df, config) for label in chunk] close_client()
def chunk_build_model(chunk, labels_df, config): '''Build the lasseck2013 model Given a chunk, run build_model on each label Args: chunk: Some columns to process in parallel labels_df: The labels_df to build model with config: The parsed ini file for this run Returns: Something or possibly writes to MongoDB Raises: Nothing. ''' init_client(config) results = [build_model(col, labels_df, config) for col in chunk] close_client() return results