def test_simple_structure_file_catches_mixed_indents(self, tmpdir): with open(os.path.join(str(tmpdir), "simple.txt"), "w", encoding= "utf-8") as f: f.write("""DATA pics: Photos sounds: sound audio: recording.wav ANALYSIS srcid: SRCID.txt""") with pytest.raises(ValueError): ds = iyore.Dataset(os.path.join(str(tmpdir), "simple.txt"))
def test_simple_structure_file_tabs(self, tmpdir): with open(os.path.join(str(tmpdir), "simple.txt"), "w", encoding= "utf-8") as f: f.write("""DATA pics: Photos sounds: sound audio: recording.wav ANALYSIS srcid: SRCID.txt""") ds = iyore.Dataset(os.path.join(str(tmpdir), "simple.txt")) self.assert_simple_structure(ds)
def test_simple_structure_file_allow_comment_lines(self, tmpdir): with open(os.path.join(str(tmpdir), "simple.txt"), "w", encoding= "utf-8") as f: f.write(""" # first line comment DATA pics: Photos # indented comment sounds: sound audio: recording.wav #comment no preceding space ANALYSIS srcid: SRCID.txt #extra indented comment""") ds = iyore.Dataset(os.path.join(str(tmpdir), "simple.txt")) self.assert_simple_structure(ds)
def dataset(self): return iyore.Dataset(os.path.join(base, structureFile))
def datafiles_endpoint(self, request, makeTestTree): if request.param == "manual": return datafiles else: return iyore.Dataset(os.path.join(base, structureFile)).datafiles
def code_to_splat(file, code, outputdir): # import the output of event extraction flight_events = pd.read_csv(file, sep=",") # extract the times of closest approach for each event flight_events["ClosestApch"] = pd.to_datetime(flight_events["ClosestApch"]) print("Transcribing columns for " + code) # create an empty srcid dataframe srcid = pd.DataFrame() # column 1: nvsplDate flight_events["ClosestApch_date"] = flight_events["ClosestApch"].apply( lambda x: x.date()) srcid['nvsplDate'] = flight_events["ClosestApch_date"] # column 2: hr flight_events["ClosestApch_time"] = flight_events["ClosestApch"].apply( lambda x: x.time()) srcid['hr'] = flight_events["ClosestApch_time"].apply(lambda x: x.hour) # column 3: secs flight_events["ClosestApch_mins"] = flight_events["ClosestApch"].apply( lambda x: x.time()) flight_events["ClosestApch_mins"] = flight_events["ClosestApch"].apply( lambda x: x.minute) flight_events["ClosestApch_secs"] = flight_events["ClosestApch"].apply( lambda x: x.time()) flight_events["ClosestApch_secs"] = flight_events["ClosestApch"].apply( lambda x: x.second) # convert minutes to seconds flight_events["ClosestApch_mins"] = flight_events[ "ClosestApch_mins"].apply(lambda x: 60 * x) # add seconds from above step to seconds srcid['secs'] = flight_events["ClosestApch_mins"] + flight_events[ "ClosestApch_secs"] # column 4: len srcid['len'] = 60 # column 5: srcID srcid['srcID'] = flight_events["EventID"].apply( lambda x: "1." + str(x).zfill(3)) #column 6 srcid['Hz_L'] = 12.5 #column 6 srcid['Hz_U'] = 2000 #column 7 srcid['MaxSPL'] = 0 #column 8 srcid['SEL'] = 0 #column 9 srcid['MaxSPLt'] = 0 #column 10 srcid['SELt'] = 0 #column 11 srcid['userName'] = "******" #column 9 srcid['tagDate'] = "1000-01-01 00:00:01" # column for sound data presence/absence -> will be populated after all processing srcid['data'] = 1 # store initial frame length framelength = len(srcid) ############### ################ # Check for audio data ############### print("Removing points without available audio for " + code) failure_count = 0 ds = iyore.Dataset("Y:") # for every event in the srcid list for i in srcid.index: # extract time data ymd = srcid.iat[i, 0] hour = srcid.iat[i, 1] year = ymd.year month = ymd.month day = ymd.day #check availablity of a given event in the soundDB database available = [ e for e in ds.nvspl( site=code, year=year, month=month, day=day, hour=hour) ] # if nothing is available, set avaialable field to zero if (len(available) == 0): srcid.ix[i, 13] = 0 failure_count = failure_count + 1 # generate the file name filename = "SRCID_DENA" + str(flight_events.iloc[0, 0]) + "eventExtractor.txt" print("Sorting and extracting data.") #sort the dataframe by date/time srcid = srcid.sort_values("nvsplDate") srcid = srcid.loc[srcid["data"] == 1] srcid = srcid.drop("data", axis=1) # export to csv with correct naming convention based on station code srcid.to_csv(outputdir + "SRCID_DENA" + code + ".txt", sep="\t", index=False) # function for adding header lines to files def prepend(path, text): with open(path, 'r+') as f: body = f.read() f.seek(0) f.write(text + body) # add the splat format version header to the file prepend(outputdir + "SRCID_DENA" + code + ".txt", "%% SRCID file v20111005" + "\n") print("") print( str(framelength - failure_count) + " of " + str(framelength) + " points had matching data for station id " + code + ".")
# In[6]: import sys sys.path.append(r"C:\Program Files (x86)\ArcGIS\Desktop10.5\arcpy") sys.path.append(r"C:\Program Files (x86)\ArcGIS\Desktop10.5\bin") import os import datetime import numpy as np import pandas as pd import soundDB import iyore ds = iyore.Dataset("K:") import matplotlib.pyplot as plt # SPLAT_append combines a srcID file output by Flight_Event_to_SRCID with the output of the flight_event_extractor # script. The srcID file should contain both the output of the Flight_Event_to_SRCID script and the events manually # annotated in SPLAT. # # # The resulting csv file contains a list of all overflight events with associated flight data, such as flight number, elevation, # climb/descent rate, ground speed, etc. # # example function call: SPLAT_append("C:/overflights","UWBT_overflights.csv","SRCID_DENAUWBT.txt") # # # change display options to make all rows and columns visible for debugging