added check_change_avianz_species! function to Labels.jl

[?]
AEj8dahVWy718uSSFPe9VSRJ5qX5G8pC2zvFzJJ8yzBd
Nov 8, 2024, 9:18 PM
YXAKJSDTRZXBQLFL6VLB7QTLA2QAXZNS6CY3K4XAKFGCL2XM6EOQC

Dependencies

  • [2] 2O6SHIVY added avianz_of_raven function to Labels.jl
  • [3] 2UBDFCJH new files tracked

Change contents

  • replacement in src/Labels.jl at line 5
    [3.54][3.54:111]()
    using CSV, DataFrames, Glob, Random, DBInterface, DuckDB
    [3.54]
    [3.111]
    using CSV, DataFrames, Glob, Random, DBInterface, DuckDB, JSON3
  • replacement in src/Labels.jl at line 168
    [2.272][2.272:398]()
    df=DataFrame(CSV.File(f))
    data=Any[Dict([("Operator", "D"), ("Reviewer", "D"), ("Duration", 60.0)])]
    labels=Any[]
    [2.272]
    [2.398]
    df = DataFrame(CSV.File(f))
    data = Any[Dict([("Operator", "D"), ("Reviewer", "D"), ("Duration", 60.0)])]
    labels = Any[]
  • replacement in src/Labels.jl at line 172
    [2.425][2.425:724]()
    label=
    [
    row."Begin Time (s)",
    row."End Time (s)",
    floor(Int, row."Low Freq (Hz)"),
    ceil(Int, row."High Freq (Hz)"),
    [
    Dict([("filter", "M"), ("species", row.Species), ("certainty", 100)])
    ]
    [2.425]
    [2.724]
    label = [
    row."Begin Time (s)",
    row."End Time (s)",
    floor(Int, row."Low Freq (Hz)"),
    ceil(Int, row."High Freq (Hz)"),
    [Dict([("filter", "M"), ("species", row.Species), ("certainty", 100)])],
  • replacement in src/Labels.jl at line 182
    [2.797][2.797:821]()
    avianzf=f * ".data"
    [2.797]
    [2.821]
    avianzf = f * ".data"
  • replacement in src/Labels.jl at line 188
    [2.938][3.4517:4520](),[3.4517][3.4517:4520]()
    end
    [2.938]
    end
    # Check then mutate all AviaNZ .data labels (Species column)
    # using JSON3
    # a=glob("*.WAV.data")
    # check_and_change_labels!(a, "somethning", "something")
    function check_change_avianz_species!(list::Vector{String}, wrong::String, right::String)
    function mutate_avianz_dict!(dct, wrong::String, right::String)
    didmutate = false
    data = copy(dct)
    for (index1, item1) in enumerate(data[2:end])
    for (index2, item2) in enumerate(item1[5])
    if item2[:species] == wrong
    data[index1+1][5][index2][:species] = right
    didmutate = true
    end
    end
    end
    return (didmutate, data)
    end
    function read_avianz_data(f)
    json_string = read(f, String)
    x = JSON3.read(json_string)
    return x
    end
    function write_new_file!(f, payload)
    cp(f, "$f.backup")
    open(f, "w") do io
    JSON3.write(io, payload)
    end
    end
    for file in list
    x = read_avianz_data(file)
    if length(x) >= 2 #ignores empty .data files
    didmutate, payload = mutate_avianz_dict!(x, wrong, right)
    if didmutate == true
    try
    write_new_file!(file, payload)
    catch
    @warn "Could not write file or backup: $file"
    end
    end
    end
    end
    end