-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added formatting function to export APLOSE formatted result to Raven and json format * added formatting function to export APLOSE formatted result to Raven and json format * added a test to aplose2raven function and added some more comments in docstring * changed some variables for more explicit names in `test_aplose2raven` * syntax fix * docstring update * docstring update 2 * docstring update 3
- Loading branch information
1 parent
c527c9f
commit 6ac7558
Showing
2 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import pandas as pd | ||
|
||
|
||
def aplose2raven(df: pd.DataFrame) -> pd.DataFrame: | ||
"""Export an APLOSE formatted result file to Raven formatted DataFrame | ||
Parameters | ||
---------- | ||
df: APLOSE formatted result DataFrame | ||
Returns | ||
------- | ||
df2raven: Raven formatted DataFrame | ||
Example of use | ||
-------------- | ||
aplose_file = Path("path/to/aplose/result/file") | ||
df = ( | ||
pd.read_csv(aplose_file, parse_dates=["start_datetime", "end_datetime"]) | ||
.sort_values("start_datetime") | ||
.reset_index(drop=True) | ||
) | ||
df_raven = aplose2raven(df) | ||
# export to Raven format | ||
df2raven.to_csv('path/to/result/file.txt', sep='\t', index=False) # Raven export tab-separated files with a txt extension | ||
""" | ||
start_time = [ | ||
(st - df["start_datetime"][0]).total_seconds() for st in df["start_datetime"] | ||
] | ||
end_time = [st + dur for st, dur in zip(start_time, df["end_time"])] | ||
|
||
df2raven = pd.DataFrame() | ||
df2raven["Selection"] = list(range(1, len(df) + 1)) | ||
df2raven["View"], df2raven["Channel"] = [1] * len(df), [1] * len(df) | ||
df2raven["Begin Time (s)"] = start_time | ||
df2raven["End Time (s)"] = end_time | ||
df2raven["Low Freq (Hz)"] = df["start_frequency"] | ||
df2raven["High Freq (Hz)"] = df["end_frequency"] | ||
|
||
return df2raven |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters