Skip to content

Commit 024c3e0

Browse files
committed
Update Manifest.toml and refactor scalebar functionality in MakieRecipes.jl
- Downgraded Julia version from 1.11.3 to 1.11.1. - Updated ElectroPhysiology dependency version from 0.5.40 to 0.5.45 and adjusted git-tree-sha1. - Refactored scalebar functionality to improve parameter handling and documentation, enhancing usability in plot visualizations. - Revised test script to reflect changes in scale bar parameters and data loading for improved clarity in experimental analysis.
1 parent 4c05280 commit 024c3e0

File tree

4 files changed

+71
-89
lines changed

4 files changed

+71
-89
lines changed

Manifest.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This file is machine-generated - editing it directly is not advised
22

3-
julia_version = "1.11.3"
3+
julia_version = "1.11.1"
44
manifest_format = "2.0"
55
project_hash = "264a14f240d43fd1743b9a93abff69dec12397af"
66

@@ -299,9 +299,9 @@ version = "1.6.0"
299299

300300
[[deps.ElectroPhysiology]]
301301
deps = ["CurveFit", "DSP", "Dates", "FileIO", "ImageMagick", "Images", "OffsetArrays", "Polynomials", "ProgressMeter", "Requires", "SparseArrays", "Statistics", "TimeZones"]
302-
git-tree-sha1 = "dfb4f67fbb08b55046a29b780c045d78c0d42c7a"
302+
git-tree-sha1 = "d6410f4992c0de040aaac703b254787ebb7734c9"
303303
uuid = "da7a9670-f599-43ac-b818-143f8bf87d45"
304-
version = "0.5.40"
304+
version = "0.5.45"
305305

306306
[[deps.ExprTools]]
307307
git-tree-sha1 = "27415f162e6028e81c72b82ef756bf321213b6ec"

src/PhysMakie/MakieRecipes.jl

Lines changed: 56 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -294,24 +294,27 @@ end
294294
export stimulustiming!
295295

296296
"""
297-
@recipe(ScaleBar)
297+
scalebar!(ax; origin=(0.0, 0.0), length_x=nothing, length_y=nothing,
298+
color=:black, linewidth=2.0, text_color=:black, fontsize=12,
299+
x_label=nothing, y_label=nothing, offset_x_ratio=0.02, offset_y_ratio=0.02)
298300
299-
A recipe for adding scale bars to plots. This recipe adds:
301+
Add scale bars to a plot. This function adds:
300302
1. An optional x-scale bar (horizontal)
301303
2. An optional y-scale bar (vertical)
302304
303-
# Attributes
304-
- `start_x`: Starting x-position for the x-scale bar (default: nothing, meaning no x-scale bar)
305-
- `length_x`: Length of the x-scale bar in data units (default: 1.0)
306-
- `start_y`: Starting y-position for the y-scale bar (default: nothing, meaning no y-scale bar)
307-
- `length_y`: Length of the y-scale bar in data units (default: 1.0)
305+
# Arguments
306+
- `ax`: The axis to add scale bars to
307+
- `origin`: (x,y) position where the scale bars will start (default: (0.0, 0.0))
308+
- `length_x`: Length of the x-scale bar in data units (default: nothing, meaning no x-scale bar)
309+
- `length_y`: Length of the y-scale bar in data units (default: nothing, meaning no y-scale bar)
308310
- `color`: Color of the scale bars (default: :black)
309311
- `linewidth`: Width of the scale bars (default: 2.0)
310312
- `text_color`: Color of the scale bar labels (default: :black)
311313
- `fontsize`: Size of the scale bar labels (default: 12)
312314
- `x_label`: Label for the x-scale bar (default: nothing, will use length_x value)
313315
- `y_label`: Label for the y-scale bar (default: nothing, will use length_y value)
314-
- `offset_ratio`: Ratio of axis range to use for text offset (default: 0.02)
316+
- `offset_x_ratio`: Ratio of x-axis range to use for text offset (default: 0.02)
317+
- `offset_y_ratio`: Ratio of y-axis range to use for text offset (default: 0.02)
315318
316319
# Example
317320
```julia
@@ -320,84 +323,63 @@ ax = Axis(fig[1,1])
320323
# First plot your data
321324
lines!(ax, x, y)
322325
# Then add scale bars
323-
scale_bar!(ax, start_x=0.1, length_x=10.0, start_y=0.1, length_y=5.0)
326+
scalebar!(ax, origin=(0.1, 0.1), length_x=10.0, length_y=5.0)
324327
```
325328
"""
326-
@recipe(ScaleBar) do scene
327-
Attributes(
328-
start_x = nothing,
329-
length_x = 1.0,
330-
start_y = nothing,
331-
length_y = 1.0,
332-
color = :black,
333-
linewidth = 2.0,
334-
text_color = :black,
335-
fontsize = 12,
336-
x_label = nothing,
337-
y_label = nothing,
338-
offset_ratio = 0.02
339-
)
340-
end
341-
342-
"""
343-
Makie.plot!(sb::ScaleBar)
344-
345-
Internal plotting function for ScaleBar recipe. Adds scale bars to the current plot
346-
based on the specified positions and lengths.
347-
"""
348-
function Makie.plot!(sb::ScaleBar)
349-
# Get the parent axis
350-
ax = sb.parent
351-
352-
# Get current axis limits
353-
xlims = ax.finallimits[].origin[1], ax.finallimits[].origin[1] + ax.finallimits[].widths[1]
354-
ylims = ax.finallimits[].origin[2], ax.finallimits[].origin[2] + ax.finallimits[].widths[2]
355-
356-
# Calculate offsets based on axis ranges
357-
x_range = xlims[2] - xlims[1]
358-
y_range = ylims[2] - ylims[1]
359-
offset = sb.offset_ratio[] * min(x_range, y_range)
329+
function scalebar!(ax;
330+
origin = (0.0, 0.0),
331+
length_x = nothing,
332+
length_y = nothing,
333+
color = :black,
334+
linewidth = 2.0,
335+
text_color = :black,
336+
fontsize = 12,
337+
x_label = nothing,
338+
y_label = nothing,
339+
offset_x_ratio = 10.0,
340+
offset_y_ratio = 0.2
341+
)
342+
x_start, y_start = origin
360343

361-
# Plot x-scale bar if start_x is specified
362-
if !isnothing(sb.start_x[])
363-
x_start = sb.start_x[]
364-
x_end = x_start + sb.length_x[]
365-
y_pos = sb.start_y[] === nothing ? ylims[1] + offset : sb.start_y[]
344+
# Plot x-scale bar if length_x is specified
345+
if !isnothing(length_x)
346+
x_end = x_start + length_x
366347

367-
lines!(sb, [x_start, x_end], [y_pos, y_pos],
368-
color = sb.color[],
369-
linewidth = sb.linewidth[]
348+
lines!(ax, [x_start, x_end], [y_start, y_start],
349+
color = color,
350+
linewidth = linewidth
370351
)
371352

372-
x_label_text = isnothing(sb.x_label[]) ? "$(sb.length_x[])" : sb.x_label[]
373-
text!(sb, x_label_text,
374-
position = (x_start + sb.length_x[]/2, y_pos - offset),
375-
align = (:center, :top),
376-
color = sb.text_color[],
377-
fontsize = sb.fontsize[]
353+
x_label_text = isnothing(x_label) ? "$(length_x)" : x_label
354+
text!(ax, x_label_text,
355+
position = (x_start + length_x/2, y_start - y_start/offset_x_ratio),
356+
align = (:center, :center),
357+
color = text_color,
358+
fontsize = fontsize
378359
)
379360
end
380361

381-
# Plot y-scale bar if start_y is specified
382-
if !isnothing(sb.start_y[])
383-
y_start = sb.start_y[]
384-
y_end = y_start + sb.length_y[]
385-
x_pos = sb.start_x[] === nothing ? xlims[1] + offset : sb.start_x[]
362+
# Plot y-scale bar if length_y is specified
363+
if !isnothing(length_y)
364+
y_end = y_start + length_y
386365

387-
lines!(sb, [x_pos, x_pos], [y_start, y_end],
388-
color = sb.color[],
389-
linewidth = sb.linewidth[]
366+
lines!(ax, [x_start, x_start], [y_start, y_end],
367+
color = color,
368+
linewidth = linewidth
390369
)
391370

392-
y_label_text = isnothing(sb.y_label[]) ? "$(sb.length_y[])" : sb.y_label[]
393-
text!(sb, y_label_text,
394-
position = (x_pos - offset, y_start + sb.length_y[]/2),
395-
align = (:right, :center),
396-
color = sb.text_color[],
397-
fontsize = sb.fontsize[],
398-
rotation = -pi/2 # Makie uses radians for rotation
371+
y_label_text = isnothing(y_label) ? "$(length_y)" : y_label
372+
text!(ax, y_label_text,
373+
position = (x_start - x_start/offset_y_ratio, y_start + length_y/2),
374+
align = (:center, :center),
375+
color = text_color,
376+
fontsize = fontsize,
377+
rotation = pi/2 # Makie uses radians for rotation
399378
)
400379
end
401380

402-
return sb
403-
end
381+
return ax
382+
end
383+
384+
# Export the function
385+
export scalebar!

test/Manifest.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,11 +1509,11 @@ version = "0.5.3"
15091509

15101510
[[deps.PhysiologyAnalysis]]
15111511
deps = ["CSV", "Colors", "DataFrames", "Dates", "ElectroPhysiology", "FileIO", "GLMakie", "HypothesisTests", "ImageFiltering", "ImageMagick", "Images", "Interpolations", "LinearAlgebra", "LsqFit", "OffsetArrays", "Peaks", "Polynomials", "ProgressMeter", "Requires", "SparseArrays", "Statistics", "StatsBase"]
1512-
git-tree-sha1 = "f933db47eabc577f1620757a79cc39e6986a6863"
1512+
git-tree-sha1 = "ed78c25f59a444d783271c7b7ba648e5d9408647"
15131513
repo-rev = "main"
15141514
repo-url = "https://github.com/mattar13/PhysiologyAnalysis.jl.git"
15151515
uuid = "69cbc4a0-077e-48a7-9b45-fa8b7014b5ca"
1516-
version = "0.6.42"
1516+
version = "0.6.44"
15171517

15181518
[[deps.Pixman_jll]]
15191519
deps = ["Artifacts", "CompilerSupportLibraries_jll", "JLLWrappers", "LLVMOpenMP_jll", "Libdl"]

test/revision.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,33 @@ using Pkg; Pkg.activate("test")
66
using GLMakie
77
using PhysiologyAnalysis
88
#using Pkg; Pkg.activate("test")
9-
9+
1010
#Loading data for 10mM Dopamine
1111
img_da_10mM_fn = raw"F:\Data\Two Photon\2025-05-19-nirCAT-STR-DPUFF\nirCAT_s2_10mM_mq010.tif"
1212
stim_da_10mM_fn = raw"F:\Data\Patching\2025-05-19-nirCAT-str\25519016.abf"
13-
da_10mM_data = load_puffing_data(img_da_10mM_fn, stim_da_10mM_fn, split_channel = false, main_channel = :red)
13+
da_10mM_data = load_puffing_data(img_da_10mM_fn, stim_da_10mM_fn, split_channel = true, main_channel = :red)
1414

15+
#%%
16+
PhysiologyPlotting.__init__()
1517
fig_roi = plot_roi_analysis(da_10mM_data["experiment"], stim_idx = 2)
1618

1719
experiment = da_10mM_data["experiment"]
1820
getStimulusProtocol(experiment)
1921
fig, ax = twophotonprojection(experiment, dims = (1, 2))
2022
stimulustiming!(ax, experiment)
2123

22-
2324
scalebar!(ax,
24-
start_x = 40.0, # Start at 40 seconds
25+
origin = (0.5, 0.01), # Start at 40 seconds
2526
length_x = 25.0, # 25 second scale bar
26-
start_y = 0.005, # Start at 0.005 intensity
27-
length_y = 0.1, # 0.1 intensity scale bar
27+
length_y = 0.001, # 0.1 intensity scale bar
2828
x_label = "25 s",
29-
y_label = "0.1"
29+
y_label = "1% df/f"
3030
)
3131
fig
3232

3333
#%%
34-
fig = plot_roi_analysis(data2P, stim_idx = 2)
35-
display(fig)
36-
save(raw"H:\Data\Analysis\fig_roi_analysis_striatum_elec.png", fig)
34+
# fig = plot_roi_analysis(data2P, stim_idx = 2)
35+
# display(fig)
36+
# save(raw"H:\Data\Analysis\fig_roi_analysis_striatum_elec.png", fig)
3737

3838
# Save the ROI analysis figure

0 commit comments

Comments
 (0)