diff --git a/Project.toml b/Project.toml index 5407d17..8605a06 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "AdriaArrayGeometryPicker" uuid = "10cbbe04-4d51-483e-8de5-7c05df3150f1" -authors = ["Marcel Thielmann"] version = "1.0.0-DEV" +authors = ["Marcel Thielmann"] [deps] Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" @@ -9,8 +9,12 @@ DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab" FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549" GLMakie = "e9467ef8-e4e7-5192-8a1a-b1aee30e663a" GeophysicalModelGenerator = "3700c31b-fa53-48a6-808a-ef22d5a84742" +GridLayoutBase = "3955a311-db13-416c-9275-1d80ed98e5e9" +Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59" JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819" +Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a" NativeFileDialog = "e1fe445b-aa65-4df4-81c1-2041507f0fd4" +Revise = "295af30f-e4ad-537b-8983-00126c2a3abe" [compat] Dates = "1.10.0 - 1.11.0" @@ -19,7 +23,10 @@ FileIO = "1.17.0" GLMakie = "0.8 - 0.11, 0.13" GeophysicalModelGenerator = "0.7.14" JLD2 = "0.5.15, 0.6" +GridLayoutBase = "0.11.2" +Interpolations = "0.15.2" NativeFileDialog = "0.2.1" +Revise = "3.12.3" julia = "1.9" [extras] diff --git a/src/AdA_VizPickTool_V1.jl b/src/AdA_VizPickTool_V1.jl index aa6d29d..8d5cc04 100644 --- a/src/AdA_VizPickTool_V1.jl +++ b/src/AdA_VizPickTool_V1.jl @@ -10,6 +10,9 @@ include("utils.jl") # this file contains some utility functions include("FileIO/fileIO_utils.jl") # this file contains the functions to load and save data include("Controls/layout_main_controls.jl") # this file contains the layour for the main controls +using Interpolations + + ############################################################### # main function to start the tool @@ -131,21 +134,17 @@ function start_AdA_Picker(;data=nothing) ############################################################ # SET THE CONTROL PANEL + + # FIELD DATA: THIS PANEL MORE OR LESS REMAINS THE SAME, ONLY SOME OF THE CONTENTS CHANGE - # VOLUME DATA CONTROLS + # set up the panel, box and label field_data_panel = panel_plot_controls[1, 1] = GridLayout(tellheight = false, halign = :left) field_data_box = Box(field_data_panel[1, 1:5], color = :steelblue1,strokecolor = :steelblue1, cornerradius = 3); - Label(field_data_panel[1, 1:5], "Field data (Tomographies etc.)", fontsize = 16,halign = :left,width = nothing) + Label(field_data_panel[1, 1:5], "Field data (Tomographies etc.)", fontsize = 16,halign = :left,width = nothing) - menu_field_data = Menu(field_data_panel[2,1:5]) - menu_field_data.options = field_names[1:end-2] # the last one is empty, so we remove it - Label(field_data_panel[3, 1], "Colormap", fontsize = 14,halign = :left,width=nothing) menu_field_colormap = Menu(field_data_panel[3,2:5], options = [:seismic,:roma,:glasgow,:lipari,:vik,:managua,:lajolla,:inferno,:plasma,:magma,:RdBu,:RdYlBu], fontsize = 12) - - #Label(field_data_panel[4, 1], "Clim", fontsize = 12,halign = :left,width=nothing) colorrange_slider = IntervalSlider(field_data_panel[4,2:4],linewidth = 20,range = colrange) - # text for the label of the colorbar colrange_text = lift(colorrange_slider.interval) do int string(round.(int,digits = 2)) @@ -160,6 +159,10 @@ function start_AdA_Picker(;data=nothing) rowgap!(field_data_panel,2) + # set the menu for field data selection + menu_field_data = Menu(field_data_panel[2,1:5]) + menu_field_data.options = field_names[1:end-2] # the last one is empty, so we remove it + # SURFACE DATA CONTROLS surf_data_panel = panel_plot_controls[2, 1] = GridLayout(tellheight = false, halign = :left,tellwidth = false) surf_data_box = Box(surf_data_panel[1, 1:5], color = :steelblue1,strokecolor = :steelblue1, cornerradius = 3); @@ -421,8 +424,8 @@ function start_AdA_Picker(;data=nothing) println("Picks loaded") # add these picks as a dashed line - #lines!(ax1, x_pick,y_pick, color = :white,linewidth = 3,visible = @lift($(surf_toggles[isurf].active) ? true : false)) # white background line - pp = lines!(ax1, x_pick,y_pick,color=:black,linewidth=3,linestyle=:dash,visible = @lift($(compare_toggle.active) ? true : false)) # black main line + lines!(ax1, x_pick,y_pick, color = :white,linewidth = 3,visible = @lift($(compare_toggle.active) ? true : false)) # white background line + pp = lines!(ax1, x_pick,y_pick,color=:red,linewidth=2,linestyle=(:dot,:dense),visible = @lift($(compare_toggle.active) ? true : false)) # black main line #push!(comppick_plot,pp) #push!(comppick_label,data_picks["user_name"]) @@ -465,14 +468,35 @@ function start_AdA_Picker(;data=nothing) filetype = split(fn_save,".")[end] # get the ending # save depending on file ending if filetype == "jld2" - # file should contain: profile information, picker information, picks - profile_info = (start_lonlat = data.start_lonlat,end_lonlat = data.end_lonlat) + # file should contain: profile information, picker information, picks, lat and lon of the picked points + profile_info = (start_lonlat = data.start_lonlat,end_lonlat = data.end_lonlat) # profile information + println("profile information generated") + # interpolate the lat and lon from the profile end points to the picked points + xtmp = [minimum(data.VolData.fields.x_profile), maximum(data.VolData.fields.x_profile)] + println("xtmp generated") + lontmp = [data.start_lonlat[1], data.end_lonlat[1]] + println("lontmp generated") + lattmp = [data.start_lonlat[2], data.end_lonlat[2]] + println("lattmp generated") + + interp_linear_lon = linear_interpolation(xtmp, lontmp) + interp_linear_lat = linear_interpolation(xtmp, lattmp) + println("interpolators generated") + lon_pick = interp_linear_lon(pickarray[:,1]) + lat_pick = interp_linear_lat(pickarray[:,1]) + println("lon and lat generated") + + # add lon and lat to the pickarray + pickarray = hcat(pickarray,lon_pick,lat_pick) + println("lon and lat added to pickarray") + + # save as jld2 file jldsave(fn_save; picks=pickarray, profile_info=profile_info, user_name=pick_name.stored_string[], date=now()) println(fn_save*" saved") elseif filetype == "csv" println("Saving as csv is not implemented yet") else - println("This is not a valid pick file format. Picks are saved as jld2 file.") + println("This is not a valid pick file format. Picks should be saved as jld2 files.") end end # get the file ending diff --git a/src/test_playground.jl b/src/test_playground.jl new file mode 100644 index 0000000..2869903 --- /dev/null +++ b/src/test_playground.jl @@ -0,0 +1,56 @@ + +using GLMakie + +# function to clear a GridLayout unit (I call it panel) by recursively deleting all its children +function clear_panel!(panel::GridLayout) + for child in panel.children + if child isa GridLayout + clear_panel!(child) + end + delete!(panel, child) + end + return nothing +end + +function CreateFigure() +# create figure +fig = Figure(backgroundcolor = RGBf(0.98, 0.98, 0.98),size = (1000, 600)) +# create panels +panel_clear = fig[1,1] = GridLayout(tellheight = false) +panel_main_menu = fig[2,1] = GridLayout(tellheight = false) +panel_plots = fig[2,2:3] = GridLayout(tellheight = false) + +# create subpanels in main menu +panel1 = panel_main_menu[1,1] = GridLayout(tellheight = false) # for logo +panel2 = panel_main_menu[2,1] = GridLayout(tellheight = false) # for toggles + +# add text to panel1 + Label(panel1[1, 1], "Field data (Tomographies etc.)", fontsize = 16,halign = :left,width = nothing) +# add toggles to panel2 + toggle1 = Toggle(panel2[1,1],active=false,buttoncolor = RGBf(0.9, 0.9, 0.9), framecolor_inactive = RGBf(0.5, 0.1, 0.1), framecolor_active = RGBf(0.1, 0.5, 0.1)) + toggle2 = Toggle(panel2[1,2],active=false,buttoncolor = RGBf(0.9, 0.9, 0.9), framecolor_inactive = RGBf(0.5, 0.1, 0.1), framecolor_active = RGBf(0.1, 0.5, 0.1)) + +# add a button to clear panel_plots + btn_clear = Button(panel_clear[1,1], label = "Clear Plots", width = 100) + #on(btn_clear.clicks) do _ + # clear_panel!(panel_plots) + #end + + # add a button to clear panel_main_menu + btn_clear_main = Button(panel_clear[1,2], label = "Clear Main Menu", width = 150) + #on(btn_clear_main.clicks) do _ + # clear_panel!(panel_main_menu) + #end + +# create a line plot and a heatmap in panel_plots +ax1 = Axis(panel_plots[1,1],title = "Line Plot Example") +l = lines!(ax1, 1:10, rand(10), color = :blue) +ax2 = Axis(panel_plots[2,1],title = "Heatmap Example") +hm = heatmap!(ax2, rand(10,10), colormap = :viridis) + +return fig,ax1,ax2,hm,l +end + + + + diff --git a/src/utils.jl b/src/utils.jl index bcea239..6ada73e 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -27,3 +27,13 @@ # return nothing # end +# # function to clear a GridLayout unit (I call it panel) by recursively deleting all its children +# function clear_panel!(panel::GridLayout) +# for child in panel.children +# if child isa GridLayout +# clear_panel!(child) +# end +# delete!(panel, child) +# end +# return nothing +# end \ No newline at end of file