Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clim kwarg in expressionPalette or expressionColors #14

Open
gszep opened this issue Jan 26, 2021 · 5 comments
Open

clim kwarg in expressionPalette or expressionColors #14

gszep opened this issue Jan 26, 2021 · 5 comments

Comments

@gszep
Copy link

gszep commented Jan 26, 2021

I would like to more precisely control the dynamic range of the expressionPalette. For example my expressions range from -2 to 7, but the interesting region lies from -1 to 1. I want to adjust my colour range so any expression values outside of the limits [-1,1] are clipped to the boundary colours.

It is possible to to this by pre-processing the input data, which would re-calculate the inputs each time I change the colour range which doesn't seem to be necessary. It makes more sense to have to colour representation change, not the underlying data.

As you can imagine, this will eventually be used in an interactive figure :)

@gszep
Copy link
Author

gszep commented Jan 26, 2021

maybe with using the cgrad method? https://docs.juliaplots.org/latest/generated/colorschemes/

@gszep
Copy link
Author

gszep commented Jan 26, 2021

palette = cgrad(:viridis)
scale(x::Number,y::StepRangeLen) = ( x - minimum(y) )/( maximum(y) - minimum(y) )
color = map( x->palette[scale(x,channelRange)], fcsdata[!,channel] )

@exaexa
Copy link
Collaborator

exaexa commented Jan 26, 2021

Yes, this would help a lot. The scaling is now (partially) done by scaleMinMax (see README examples). Perhaps the easiest way to have that working would be to supply kwargs min/max to the scaleMinMax function that set the bounds properly. Would that work for you?

See https://github.com/LCSB-BioCore/GigaScatter.jl/blob/master/src/colors.jl#L114 for scaleMinMax.

I didn't know about cgrad, I guess I can replace a bit of the code with that, e.g. this https://github.com/LCSB-BioCore/GigaScatter.jl/blob/master/src/colors.jl#L28 .

@gszep
Copy link
Author

gszep commented Jan 26, 2021

I realised that calling palette(::Float64) is 10x slower than palette(::Int64) and therefore it makes sense to pre-compute color indexes for each event. Here is the snippet I am working with:

channelRange, nlevels = range(-2,7,length=50), 10
palette = cgrad(:viridis,nlevels,categorical=true)

channels = names(fcsdata)
channel = Observable(first(channels))

function toIndex(x::AbstractVector{<:Number})
    min,max = extrema(channelRange)
    scaled = ( x .- min ) / ( max - min )
    
    @. scaled[scaled<0] = 0
    @. scaled[1<scaled] = 1
    
    return @. trunc(Int,nlevels*scaled) + 1
end

colorIndex = combine(fcsdata,[ col => toIndex => col for col  names(fcsdata) ] )
color = Observable(palette[ colorIndex[!,channel[]] ])

############################# update on channel change
on(channel) do channel
    color[] = palette[ colorIndex[!,channel] ]
end

here color[] is a Vector{RGBA{Float64}} which is a good input for the color kwarg in Makie.jl. Is it also suitable for GigaScatter.jl?

@exaexa
Copy link
Collaborator

exaexa commented Jan 26, 2021

the slowness is quite likely because the float version is doing the interpolation with all colors; I guess I can do the same with our ColorPalette. I'll likely get to it tomorrow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants