Tidy up
[?]
AEj8dahVWy718uSSFPe9VSRJ5qX5G8pC2zvFzJJ8yzBd
Nov 10, 2024, 2:50 AM
7KO4BAOG5HYRSQOFMJTT3AD4K4OPOICXTTVO7K3UPPA24TACMLUACDependencies
- [2]
QA2TJZRAripped ML out into the SkraakML repo, compiles quicker now - [3]
JYCKLP2Echanges to clips and predict - [4]
EDYR5C55fixed ConstructPrimaryDataSet, licence date, Readme, re-arranged Predict.jl - [5]
RQ56K2G4minor work on train and predict - [6]
L7G33K4Cfixed a comment problem in Clips, and upgraded, now it compiles on Mac again - [7]
PQ6OQCBQwork on construct primary dataset - [8]
2UBDFCJHnew files tracked - [9]
E3Y55MPRadded perceptual colour maps and changed get_image_from_sample - [10]
MMG2PLXKnew functiion to make clips of downloaded bisd calls - [11]
OFTU77S5first commit - [12]
FY7CEMM2mac work on train.jl - [13]
YODTMMPTadded a whole bunch of functions to Labels.jl for working with raven and avians labels - [14]
U46LDPL7added model, CUDA works again now on ubuntu - [15]
NV7FXZ5Qfirst commit - [16]
PHGT4YMBextended Skraak.dddict, and work on all the functions that call it or make it - [17]
NMQCXLNGcatch up commit, about to do some work on prediction loop - [18]
AQWXGGE3mod to clips.jl - [19]
X54TLSYEcatch up commit, train now working with julia 1.10.5 but not 1.11 - [20]
BOPNWZL4refactored Skraak.jl into sub files, tidy now - [21]
3FAESP6Ncatch up with changes, mainly construct primary dataset - [22]
ROFI4OLAcatch up, working on colour images - [23]
WOSKMRI4added module Base and module ML - [*]
QPBH7QWCadded MLBaste for confusion matrix, f1, roc, must still remove freq tables
Change contents
- replacement in src/Utility.jl at line 3
export check_png_wav_both_present, resize_image!, move_one_hour!, utc_to_nzdt!export dawn_dusk_of_sunrise_sunset,get_sunrise_sunset_utc,make_spectro_from_file,move_one_hour!,resample_to_16000hz,resample_to_8000hz,resize_image!,utc_to_nzdt!,check_png_wav_both_present - edit in src/Utility.jl at line 90[3.325555]→[3.325555:325601](∅→∅),[3.325601]→[3.340835:340898](∅→∅),[3.340898]→[3.325601:325864](∅→∅),[3.325601]→[3.325601:325864](∅→∅),[3.325864]→[2.329:382](∅→∅),[2.382]→[3.325906:325984](∅→∅),[3.325906]→[3.325906:325984](∅→∅),[3.325984]→[3.340899:340945](∅→∅),[3.340945]→[3.326031:326133](∅→∅),[3.326031]→[3.326031:326133](∅→∅),[3.326133]→[3.78:131](∅→∅),[3.131]→[2.383:451](∅→∅),[3.131]→[3.326185:326189](∅→∅),[2.451]→[3.326185:326189](∅→∅),[3.326185]→[3.326185:326189](∅→∅),[3.341009]→[3.326189:326406](∅→∅),[3.326189]→[3.326189:326406](∅→∅),[3.326406]→[3.132:238](∅→∅),[3.238]→[3.326458:327092](∅→∅),[3.326458]→[3.326458:327092](∅→∅)
end"""twilight_tuple_local_time(dt::Date)#deprecated now have a big sunset_sunrise_utc.csv to work fromTakes a date and returns a tuple with local time twilight times. Use to make a Dataframe then csv.Queries api.sunrise-sunset.orgwas using civil_twilight_end, civil_twilight_begin, changed to sunrise, sunsetUse like this:Using CSV, Dates, DataFrames, Skraakdf = DataFrames.DataFrame(Date=[], Dawn=[], Dusk=[])dr = Dates.Date(2019,01,01):Dates.Day(1):Dates.Date(2024,12,31)for day in drq = Skraak.twilight_tuple_local_time(day)isempty(q) ? println("fail $day") : push!(df, q)sleep(5)endCSV.write("dawn_dusk.csv", df)using CSV, DataFrames, Dates, HTTP, JSON3, TimeZones#####deprecated now have a big sunset_sunrise_utc.csv to work from"""function twilight_tuple_local_time(dt::Date)# C05 co-ordinates hard coded into functionresp1 = HTTP.get("https://api.sunrise-sunset.org/json?lat=-45.50608&lng=167.47822&date=$dt&formatted=0",)#resp2 = String(resp1.body) |> JSON.Parser.parseresp2 = String(resp1.body) |> x -> JSON3.read(x)resp3 = get(resp2, "results", "missing")dusk_utc = get(resp3, "sunset", "missing")dusk_utc_zoned = ZonedDateTime(dusk_utc, "yyyy-mm-ddTHH:MM:SSzzzz")dusk_local = astimezone(dusk_utc_zoned, tz"Pacific/Auckland")dusk_string = Dates.format(dusk_local, "yyyy-mm-ddTHH:MM:SS")dawn_utc = get(resp3, "sunrise", "missing")dawn_utc_zoned = ZonedDateTime(dawn_utc, "yyyy-mm-ddTHH:MM:SSzzzz")dawn_local = astimezone(dawn_utc_zoned, tz"Pacific/Auckland")dawn_string = Dates.format(dawn_local, "yyyy-mm-ddTHH:MM:SS")date = Dates.format(dt, "yyyy-mm-dd")return (date, dawn_string, dusk_string) - edit in src/Utility.jl at line 273
end# Convert mp3's with: for file in *.mp3; do ffmpeg -i "${file}" -ar 16000 "${file%.*}.wav"; done# Requires 16000hz wav's, works in current folder, need ffmpeg to convert mp3's to wavs at 16000hz#=wavs = Glob.glob("*.wav")for wav in wavsSkraak.make_spectro_from_file(wav) - edit in src/Utility.jl at line 282[2.1019]
=#function make_spectro_from_file(file::String)signal, freq = WAV.wavread("$file")freq = freq |> Float32partitioned_signal = Iterators.partition(signal, 80000) #5s clipsfor (index, part) in enumerate(partitioned_signal)length(part) > 50000 && beginoutfile = "$(chop(file, head=0, tail=4))__$(index)"image = Skraak.get_image_from_sample(part, freq)PNGFiles.save("$outfile.png", image)endendend - replacement in src/Labels.jl at line 3
export aggregate_labels, audiodata_db, raven_of_avianz, avianz_of_raven, label_summaryexport actual_from_folders,aggregate_labels,audiodata_db,avianz_file_of_dict,avianz_of_raven,check_change_avianz_species!,df_of_avianz_dict,dict_of_avianz_file,label_summary,prepare_df_for_raven,raven_of_avianz,raven_of_avianz - edit in src/Labels.jl at line 56
- replacement in src/Labels.jl at line 89
This function takes the csv output from my hand classification and ouputs a df, and csv for insertion into AudioData.duckdb using the duckdb cli or using DFto.audiodata_db()This function takes the csv output from my hand classification and ouputs a df, and csv for insertion into AudioData.duckdb using the duckdb cli or using audiodata_db() - replacement in src/ConstructPrimaryDataset.jl at line 3
using DataFrames, CSV, Globusing DataFramesMeta: @transform!, @byrow #, @subset!, @passmissingusing DataFrames, CSV, Glob, DataFramesMeta - replacement in src/ConstructPrimaryDataset.jl at line 5
function make_dataset(input_file::String, output_path::String="/media/david/SSD2/PrimaryDataset/kiwi_set/")function make_skraak_dataset(input_file::String,output_path::String = "/media/david/SSD2/PrimaryDataset/kiwi_set/",) - replacement in src/ConstructPrimaryDataset.jl at line 10
move_files(input_file, output_path) |>x -> save_pngs(x, output_path)move_files(input_file, output_path) |> x -> save_pngs(x, output_path) - replacement in src/ConstructPrimaryDataset.jl at line 23[3.2951]→[3.394:415](∅→∅),[3.415]→[3.5082:5106](∅→∅),[3.5082]→[3.5082:5106](∅→∅),[3.5106]→[3.416:440](∅→∅),[3.440]→[3.5178:5180](∅→∅),[3.5178]→[3.5178:5180](∅→∅)
function move_files(input_file::String,output_path::String)function move_files(input_file::String, output_path::String) - replacement in src/ConstructPrimaryDataset.jl at line 54
function save_pngs(df::DataFrame,output_path::String)function save_pngs(df::DataFrame, output_path::String) - replacement in src/ConstructPrimaryDataset.jl at line 67
duration = length_signal ÷ freqduration = length_signal ÷ freq - replacement in src/ConstructPrimaryDataset.jl at line 92[3.7628]→[3.7628:7659](∅→∅),[3.7659]→[3.781:856](∅→∅),[3.856]→[3.7742:7786](∅→∅),[3.1126]→[3.7742:7786](∅→∅),[3.7742]→[3.7742:7786](∅→∅)
PNGFiles.save("$output_path$folder/K/$folder-$start-$(start+4).png",plot,)PNGFiles.save("$output_path$folder/K/$folder-$start-$(start+4).png", plot) - replacement in src/ConstructPrimaryDataset.jl at line 96[3.7958]→[3.7958:7989](∅→∅),[3.7989]→[3.857:932](∅→∅),[3.932]→[3.8072:8116](∅→∅),[3.1190]→[3.8072:8116](∅→∅),[3.8072]→[3.8072:8116](∅→∅)
PNGFiles.save("$output_path$folder/N/$folder-$start-$(start+4).png",plot,)PNGFiles.save("$output_path$folder/N/$folder-$start-$(start+4).png", plot) - replacement in src/ConstructPrimaryDataset.jl at line 117
s=(st*freq)-freq+1en*freq <= len ? e=en*freq : e=lenreturn s, es = (st * freq) - freq + 1en * freq <= len ? e = en * freq : e = lenreturn s, e - replacement in src/Clips.jl at line 3
export make_clips, move_clips_to_foldersexport make_clips, make_clips_generic, move_clips_to_folders - edit in src/Clips.jl at line 323[3.22022]→[3.205:430](∅→∅),[3.430]→[2.5863:5889](∅→∅),[2.5889]→[3.451:559](∅→∅),[3.451]→[3.451:559](∅→∅),[3.559]→[2.5890:5930](∅→∅),[2.5930]→[3.595:850](∅→∅),[3.595]→[3.595:850](∅→∅),[3.850]→[2.5931:5992](∅→∅),[2.5992]→[3.904:953](∅→∅),[3.904]→[3.904:953](∅→∅)
endendend# Convert mp3's with: for file in *.mp3; do ffmpeg -i "${file}" -ar 16000 "${file%.*}.wav"; done# Requires 16000hz wav's, works in current folder, need ffmpeg to convert mp3's to wavs at 16000hz#=wavs = Glob.glob("*.wav")for wav in wavsSkraak.make_spectro_from_file(wav)end=#function make_spectro_from_file(file::String)signal, freq = WAV.wavread("$file")freq = freq |> Float32partitioned_signal = Iterators.partition(signal, 80000) #5s clipsfor (index, part) in enumerate(partitioned_signal)length(part) > 50000 && beginoutfile = "$(chop(file, head=0, tail=4))__$(index)"image = Skraak.get_image_from_sample(part, freq)PNGFiles.save("$outfile.png", image) - replacement in src/Clips.jl at line 328
For making colour images using GLMakie (moved on but may be useful one day), not wired up into skraak yet.Using for 24/7 and 250kHZ data.using Glob, Skraak, CSV, DataFrames, Dates, PNGFiles - replacement in src/Clips.jl at line 330
using DSP, GLMakie, PNGFilesfunction get_colour_image_from_sample(sample, f)dims = 224 #pxS = DSP.spectrogram(sample[:, 1], 400, 2; fs = f)f = GLMakie.Figure(resolution = (dims, dims), figure_padding = 0)ax = GLMakie.Axis(f[1, 1], spinewidth = 0)GLMakie.hidedecorations!(ax)GLMakie.heatmap!(ax, (DSP.pow2db.(S.power))', colormap = :inferno)a=Glob.glob("*/*/preds-2024-08-29.csv")b=Glob.glob("*/*/*/preds-2024-08-29.csv")c=Glob.glob("*/*/*/*/preds-2024-08-29.csv")predictions = [a ; b ; c]## orpredictions = Glob.glob("*/*/preds-2024-10-21.csv") - replacement in src/Clips.jl at line 337
@assert size(f) == (dims, dims) "Wrong size"return ffor file in predictionstrymake_clips_generic(file)catch xprintln(x) - edit in src/Clips.jl at line 343
function save_colour_image(f, outfile)tryPNGFiles.save("$outfile.png", f)catch err@info "Saving $outfile.png failed\n$err"end - replacement in src/Clips.jl at line 345[3.2150]→[3.2150:2173](∅→∅),[3.2173]→[2.5993:6074](∅→∅),[2.6074]→[3.2239:2553](∅→∅),[3.2239]→[3.2239:2553](∅→∅)
#=For Kahurangi Dataa=Glob.glob("*/*/*.csv")b=Glob.glob("*/*/*/*.csv")c=Glob.glob("*/*/*/*/*.csv")list=[a ; b ; c]# to delete empty preds.csv filesfor file in listsize = stat(file).sizeif size < 10println("Deleting $file - $size")rm(file)endend## change date on preds below (no longer required at 25/10/24)function make_clips_kahurangi(preds_path::String, label::Int = 1)function make_clips_generic(preds_path::String, label::Int = 1) - replacement in src/Clips.jl at line 383
p=chop(pth, tail=1) |> x -> replace(x, "/" => "---") #delete trailing / then replace / with ---p = chop(pth, tail = 1) |> x -> replace(x, "/" => "---") #delete trailing / then replace / with --- - edit in src/Clips.jl at line 401[3.4863]→[3.4863:4918](∅→∅),[3.4918]→[2.6272:6398](∅→∅),[2.6398]→[3.5029:5061](∅→∅),[3.5029]→[3.5029:5061](∅→∅),[3.5061]→[2.6399:6451](∅→∅),[2.6451]→[3.5108:5191](∅→∅),[3.5108]→[3.5108:5191](∅→∅),[3.5191]→[3.1062:1064](∅→∅),[3.709]→[3.1062:1064](∅→∅)
using Glob, Skraak, CSV, DataFrames, Dates, PNGFilesa=Glob.glob("*/*/preds-2024-08-29.csv")b=Glob.glob("*/*/*/preds-2024-08-29.csv")c=Glob.glob("*/*/*/*/preds-2024-08-29.csv")predictions = [a ; b ; c]## orpredictions = Glob.glob("*/*/preds-2024-10-21.csv")for file in predictionstrymake_clips_kahurangi(file)catch xprintln(x)endend=# - replacement in Manifest.toml at line 3
julia_version = "1.10.6"julia_version = "1.11.1" - edit in Manifest.toml at line 17
[[deps.Adapt]]deps = ["LinearAlgebra", "Requires"]git-tree-sha1 = "cde29ddf7e5726c9fb511f340244ea3481267608"uuid = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"version = "3.7.2"weakdeps = ["StaticArrays"][deps.Adapt.extensions]AdaptStaticArraysExt = "StaticArrays" - replacement in Manifest.toml at line 30
version = "1.1.1"version = "1.1.2" - edit in Manifest.toml at line 40
version = "1.11.0" - edit in Manifest.toml at line 56
version = "1.11.0" - edit in Manifest.toml at line 238
version = "1.11.0" - edit in Manifest.toml at line 254
version = "1.11.0" - edit in Manifest.toml at line 345
version = "1.11.0" - edit in Manifest.toml at line 362
version = "1.11.0" - edit in Manifest.toml at line 533
version = "1.11.0" - replacement in Manifest.toml at line 536
deps = ["AxisAlgorithms", "ChainRulesCore", "LinearAlgebra", "OffsetArrays", "Random", "Ratios", "Requires", "SharedArrays", "SparseArrays", "StaticArrays", "WoodburyMatrices"]git-tree-sha1 = "00a19d6ab0cbdea2978fc23c5a6482e02c192501"deps = ["Adapt", "AxisAlgorithms", "ChainRulesCore", "LinearAlgebra", "OffsetArrays", "Random", "Ratios", "Requires", "SharedArrays", "SparseArrays", "StaticArrays", "WoodburyMatrices"]git-tree-sha1 = "721ec2cf720536ad005cb38f50dbba7b02419a15" - replacement in Manifest.toml at line 539
version = "0.14.0"version = "0.14.7" - edit in Manifest.toml at line 628
version = "1.11.0" - replacement in Manifest.toml at line 643
version = "8.4.0+0"version = "8.6.0+0" - edit in Manifest.toml at line 648
version = "1.11.0" - replacement in Manifest.toml at line 653
version = "1.6.4+0"version = "1.7.2+0" - edit in Manifest.toml at line 662
version = "1.11.0" - edit in Manifest.toml at line 679[3.10270613][25.3728]
version = "1.11.0" - edit in Manifest.toml at line 705
version = "1.11.0" - edit in Manifest.toml at line 733
version = "1.11.0" - replacement in Manifest.toml at line 744
version = "2.28.2+1"version = "2.28.6+0" - edit in Manifest.toml at line 760
version = "1.11.0" - replacement in Manifest.toml at line 776
version = "2023.1.10"version = "2023.12.12" - edit in Manifest.toml at line 804
weakdeps = ["Adapt"] - edit in Manifest.toml at line 808
[deps.OffsetArrays.weakdeps]Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" - replacement in Manifest.toml at line 818
version = "0.3.23+4"version = "0.3.27+1" - replacement in Manifest.toml at line 897
deps = ["Artifacts", "Dates", "Downloads", "FileWatching", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "Serialization", "TOML", "Tar", "UUIDs", "p7zip_jll"]deps = ["Artifacts", "Dates", "Downloads", "FileWatching", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "Random", "SHA", "TOML", "Tar", "UUIDs", "p7zip_jll"] - replacement in Manifest.toml at line 899
version = "1.10.0"version = "1.11.0"weakdeps = ["REPL"][deps.Pkg.extensions]REPLExt = "REPL" - edit in Manifest.toml at line 956
version = "1.11.0" - replacement in Manifest.toml at line 989
deps = ["InteractiveUtils", "Markdown", "Sockets", "Unicode"]deps = ["InteractiveUtils", "Markdown", "Sockets", "StyledStrings", "Unicode"] - edit in Manifest.toml at line 991
version = "1.11.0" - edit in Manifest.toml at line 996
version = "1.11.0" - edit in Manifest.toml at line 1076
version = "1.11.0" - edit in Manifest.toml at line 1087
version = "1.11.0" - edit in Manifest.toml at line 1114
version = "1.11.0" - replacement in Manifest.toml at line 1125
version = "1.10.0"version = "1.11.0" - replacement in Manifest.toml at line 1160
deps = ["LinearAlgebra", "SparseArrays"]deps = ["LinearAlgebra"]git-tree-sha1 = "ae3bb1eb3bba077cd276bc5cfc337cc65c3075c0" - replacement in Manifest.toml at line 1163
version = "1.10.0"version = "1.11.1"weakdeps = ["SparseArrays"][deps.Statistics.extensions]SparseArraysExt = ["SparseArrays"] - edit in Manifest.toml at line 1193
[[deps.StyledStrings]]uuid = "f489334b-da3d-4c2e-b8f0-e476e12c162b"version = "1.11.0" - replacement in Manifest.toml at line 1200
version = "7.2.1+1"version = "7.7.0+0" - edit in Manifest.toml at line 1245
version = "1.11.0" - edit in Manifest.toml at line 1282
version = "1.11.0" - edit in Manifest.toml at line 1291
version = "1.11.0" - replacement in Manifest.toml at line 1384
version = "1.52.0+1"version = "1.59.0+0"