GithubHelp home page GithubHelp logo

makieorg / topoplots.jl Goto Github PK

View Code? Open in Web Editor NEW
26.0 26.0 7.0 104.45 MB

Makie topo plot recipes, for neuro-science, geo plots and anyone needing surface plots from unstructured data

License: MIT License

Julia 100.00%

topoplots.jl's Issues

Convert from x/y/z to eeg_topoplot positions

I converted some MNE code to convert form x/y/z to eeg_topoplot coordinates.

Now the big question is, can/should this be included here in TopoPlots.jl, or somehwere else?

using CoordinateTransformations

	"""
		convert x/y/z electrode montage positions to spherical coordinate representation. output is a matrix
	"""
	function cart3d_to_spherical(x,y,z)
		sph = SphericalFromCartesian().(SVector.(x,y,z))
		sph = [vcat(s.r,s.θ,π/2 - s.ϕ) for s in sph] 
		sph = hcat(sph...)'
		return sph
	end

		
"""
Projects 3D electrode positions to a 2D layout.

Re-implementation of the MNE algorithm.

If you put sphere to 
"""
function pos3D_to_layout(x,y,z;sphere=[0,0,0.])
	#cart3d_to_spherical(x,y,z)
	
# translate to sphere origin
	x .-= sphere[1]
	y .-= sphere[2]
	z .-= sphere[3]
	
	# convert to spherical coordinates
	sph = cart3d_to_spherical(x,y,z)

	# get rid of of the radius for now
	pol_a = sph[:,3]
	pol_b = sph[:,2]
	
	# use only theta & phi, convert back to cartesian coordinates
	p_x = pol_a .* cos.(pol_b)
	p_y = pol_a .* sin.(pol_b)

	# scale by the radius
	p_x .*= sph[:,1] .//2)
	p_y .*= sph[:,1] .//2)

	# move back by the sphere coordinates
	p_x .+= sphere[1]
	p_y .+= sphere[2]

  return Point2f.(p_x,p_y)
end
		  		



	  

grafik


(for full reproducibility)

begin
using CSV
	using LinearAlgebra
	using HTTP
	using CoordinateTransformations
	using WGLMakie
using StaticArrays
using DataFrames
end
begin
pos3d = CSV.read(download("https://raw.githubusercontent.com/lrkrol/SEREEGA/b5dec01e8b98260904906cc19c38853bfbb2ff19/leadfield/hartmut/chanlocs-hartmut-NYhead_small.xyz"),DataFrame,header=false)
rename!(pos3d,:Column1=>:ix,:Column2=>:x,:Column3=>:y,:Column4=>:z,:Column5=>:label)

	# remove some whitespace in the labels
transform!(pos3d,:label=>(x->strip.(x))=>:label)

	# remove some weird channels
	subset!(pos3d,:label=>ByRow(l -> l  ["Nk1","Nk2","Nk3","Nk4"]));

out =   pos3D_to_layout(pos3d.x,pos3d.y,pos3d.z)

eeg_topoplot(1:size(out,1),pos3d.label;positions=out, interpolation=NullInterpolator(),label_text=true,enlarge=0.5)
end;

Strange interpolation at boundary

Hi,
I am plotting some EEG topographies together with @behinger. We observed strange interpolation at the top boundary. This is with the default interpolator ClaughTochter
image

DelaunyMesh has same issue
image

Any ideas? Has it to do with the fill-value?
Cheers,
Vladimir & Bene

TagBot trigger issue

This issue is used to trigger TagBot; feel free to unsubscribe.

If you haven't already, you should update your TagBot.yml to include issue comment triggers.
Please see this post on Discourse for instructions and more details.

If you'd like for me to do this for you, comment TagBot fix on this issue.
I'll open a PR within a few hours, please be patient!

multiple layout arrangements

Currently, if I do data, positions = TopoPlots.example_data() I have only opportunity to get 64 channel position.
But if I want 32, or 128 channels layout? Would be nice to have such arrangements too.

Plotting broken for subset of chanels (and no labels)

Has anyone used this recently? I'm pretty sure it used to work at some point, but now it seems quite broken:

using TopoPlots
labels = ["cz", "fp1", "fp2", "fz"]
TopoPlots.eeg_topoplot(ones(length(labels)), labels; label_text=true, label_scatter=(markersize=10, strokewidth=2, strokecolor=:white))

... does neither prodcue correct sensor locations (look at Cz) nor does it plot any text for me:

image

I believe this is related to: #18, so it seems to be an unfortunate consequence of some design decisions. Nevertheless, I think this warrants fixing as the current behavior is extremely surprising.

Arbitrary topoplot types

Would it make sense to add a plottype kwarg to TopoPlot, which would allow any HeatmapLike plot to be used in place of contourf? I would love to use surface or even contour, for example.

EEG TopoPlot colorrange issue with data type

Hi, I noticed a small problem when setting the 'colorrange' attribute for the eeg_topoplot() function. The colors inside the circles that indicate channel locations are unaffected by the new colorrange if the data is passed as Vector{Any} instead of Vector{Float32}.

colorrange

Data description is missing

Nowhere in the documentation is there a description of the data dimensions for this code:
data, positions = TopoPlots.example_data().
It has three dimensions: 64×400×3. But what do they represent?
Specifying this will greatly improve the usability of the package, especially for new users.

EEG TopoPlot Head misalignment

Hello,
we noticed a weird behavior with the head position in a eeg_topoplot when the data points are asymmetrical or only in one corner.
edc110d6-c020-48b5-ac4a-d10a7dc0a6f1
In the image we are drawing two eeg topoplots with points in the top right and bottom left and our expected behavior was to see both heads overlap and contain all points instead of two smaller local heads.
This is the code used to draw them:

f = Figure()
axis = Axis(f[1, 1], aspect = 1)
xlims!(low = -2, high = 2)
ylims!(low = -2, high = 2)

data = [0, 0, 0]
pos1 = [Point2f(-1, -1), Point2f(-1.0, 0.0), Point2f(0, -1)]
pos2 = [Point2f(1, 1), Point2f(1.0, 0.0), Point2f(0, 1)]

eeg_topoplot!(axis, data, positions=pos1)
eeg_topoplot!(axis, data, positions=pos2)

Is there some workaround to keep the head location and size independent from the point locations ?
Or would it be possible to either add a way to set a position and size for the head or expose the draw_ear_nose! function ?

Thank you very much and kind regards,
Daniel, Sören, Niklas

Unused line / define defaults?

I didnt fully understand this line of code - do we need it?

It seems to be a stub to use the default values. params is not used though?

params = Iterators.filter(((k, v),) -> !(v isa Nothing), Dict(:tol => ct.tol, :maxiter => ct.maxiter, :rescale => ct.rescale))

Context:

function (ct::ClaughTochter)(
xrange::LinRange, yrange::LinRange,
positions::AbstractVector{<: Point{2}}, data::AbstractVector{<:Number})
params = Iterators.filter(((k, v),) -> !(v isa Nothing), Dict(:tol => ct.tol, :maxiter => ct.maxiter, :rescale => ct.rescale))
interp = SciPy.interpolate.CloughTocher2DInterpolator(
Tuple.(positions), data;
tol=ct.tol, maxiter=ct.maxiter, rescale=ct.rescale)
return collect(interp(xrange' .* ones(length(yrange)), ones(length(xrange))' .* yrange)')

eeg_topoplot: labels need to be specified twice

labels = ["cz", "fp1", "fp2", "fz"]
TopoPlots.eeg_topoplot(1:length(labels),labels;                        label_text = true) # doesnt work
TopoPlots.eeg_topoplot(1:length(labels),labels; labels=labels, label_text = true) # works

is necessary. The reason most likely is that in the recipe label is used as this "named"-input

@recipe(EEG_TopoPlot, data, labels) do scene

later it is referenced in the plot! function via

tplot = topoplot!(plot, Attributes(plot), plot.data, positions; labels=plot.labels)

not sure why the first case, labels seem to not be picked up correctly. Maybe a hint: Attributes(plot) is used, and in there, labels = nothing. Even though plot.labels is correctly showing the Array. - I dont know enough to understand this

maybe @SimonDanisch any insights?

(This was not the case in topoplots 1.3, with pre 0.20 makie (didnt test all iterations))

pinging @marcpabst for pushing me to this issue

Deactivate Interpolator

I think we should allow
interpolation = False

This would allow to plot things like:
grafik
and
grafik

Should be straight forward to add another if interpolation == False catch where we select for Delauny/Splines Interpolations, right?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.