Example #1
0
# load annotations
annot = Annotation()
annot.from_netcdf(annotation_file)

# load detections
detec = Measurement()
detec.from_netcdf(detection_file)
print(detec)

freq_ovp = True # default True
dur_factor_max = None # default None
dur_factor_min = 0.1 # default None
ovlp_ratio_min = 0.3 # defaulkt None
remove_duplicates = True # dfault - False
inherit_metadata = True # default False
filter_deploymentID = False # default True

detec.filter_overlap_with(annot,
                          freq_ovp=freq_ovp,
                          dur_factor_max=dur_factor_max,
                          dur_factor_min=dur_factor_min,
                          ovlp_ratio_min=ovlp_ratio_min,
                          remove_duplicates=remove_duplicates,
                          inherit_metadata=inherit_metadata,
                          filter_deploymentID=filter_deploymentID,
                          inplace=True
                          )
print(detec)
detec.to_netcdf(outfile)
Example #2
0
min_threshold = 0.7
noise_label = 'NN'

# load names of file and start/stop times where false alarms have been manually
# identified
df = pd.read_excel(xls_file, header=None)

for idx in range(0, len(df)):
    # file name to load
    wav_file_name = df[0][idx]
    tmin_sec = df[1][idx]
    tmax_sec = df[2][idx]
    print(wav_file_name, tmin_sec, tmax_sec)
    detec_file_path = os.path.join(in_dir, wav_file_name + '.nc')
    # load detection/measurement file
    meas = Measurement()
    meas.from_netcdf(detec_file_path)
    data_df = meas.data
    # Only keep fish detections above the given confidence threshold and times
    data_df_filt = data_df[(data_df.label_class == fish_label)
                           & (data_df.confidence >= min_threshold)
                           & (data_df.time_min_offset >= tmin_sec)
                           & (data_df.time_max_offset <= tmax_sec)]
    data_df_filt.reset_index(inplace=True, drop=True)
    meas.data = data_df_filt
    # Change fish labels to noise labels
    meas.insert_values(label_class=noise_label)
    # Save to new nc file
    meas.to_netcdf(os.path.join(out_dir, wav_file_name + str(idx)))

print('done')
Example #3
0
deployment_file = r'C:\Users\xavier.mouy\Documents\PhD\Projects\Dectector\datasets\UVIC_mill-bay_2019\deployment_info.csv'
data_dir = r'C:\Users\xavier.mouy\Documents\PhD\Projects\Dectector\datasets\UVIC_mill-bay_2019\audio_data'

# load meta data
operator_name = platform.uname().node
dep_info = DeploymentInfo()
dep_info.read(deployment_file)

#list files
files = ecosound.core.tools.list_files(indir,
                                       ext,
                                       recursive=False,
                                       case_sensitive=True)

for idx, file in enumerate(files):
    print(str(idx) + r'/' + str(len(files)) + ': ' + file)
    meas = Measurement()
    meas.from_netcdf(file)

    meas.insert_metadata(deployment_file)

    file_name = os.path.splitext(os.path.basename(file))[0]
    meas.insert_values(
        operator_name=platform.uname().node,
        audio_file_name=os.path.splitext(os.path.basename(file_name))[0],
        audio_file_dir=data_dir,
        audio_file_extension='.wav',
        audio_file_start_date=ecosound.core.tools.filename_to_datetime(
            file_name)[0])
    meas.to_netcdf(os.path.join(outdir, file_name + '.nc'))
            data.dropna(subset=features,
                        axis=0,
                        how='any',
                        thresh=None,
                        inplace=True)
            n2 = len(data)
            print('Deleted observations (due to NaNs): ' + str(n1 - n2))
            # Classification - predictions
            X = data[features]
            X = (X - Norm_mean) / Norm_std
            pred_class = model.predict(X)
            pred_prob = model.predict_proba(X)
            pred_prob = pred_prob[range(0, len(pred_class)), pred_class]
            # Relabel
            for index, row in classes_encoder.iterrows():
                pred_class = [
                    row['label'] if i == row['ID'] else i for i in pred_class
                ]
            # update measurements
            data['label_class'] = pred_class
            data['confidence'] = pred_prob
            # sort detections by ascending start date/time
            data.sort_values('time_min_offset',
                             axis=0,
                             ascending=True,
                             inplace=True)
            # save result as NetCDF file
            print('Saving')
            meas.data = data
            meas.to_netcdf(os.path.join(outdir, file))