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

Max gamut #180

Merged
merged 5 commits into from Feb 3, 2020
Merged

Max gamut #180

merged 5 commits into from Feb 3, 2020

Conversation

Bisaloo
Copy link
Collaborator

@Bisaloo Bisaloo commented Nov 20, 2019

fix #66

This is something that I have been wanting to do for a long time and that I now have to do for a manuscipt in revision: I need to compute the maximum theoretical gamut given a visual system and illuminant.

This is a first pass at trying to do this but I'm not entirely sure it's the best way. I also really need to refactorize dispace()/trispace()/tcspace() at some point (plus address #102 and #179 while I'm at it) but I don't know if I will manage to do it in this PR.

An example of what it produces with triplot():

Rplot

@thomased
Copy link
Collaborator

Related #66 — would be awesome.

@Bisaloo
Copy link
Collaborator Author

Bisaloo commented Nov 20, 2019

Quality check: cie monochromatic loci

data(sicalis)
vis_sicalis <- vismodel(sicalis, visual = "cie10", illum = "D65")
tri_sicalis <- trispace(vis_sicalis)
plot(tri_sicalis, gamut = TRUE)

Rplot

@Bisaloo Bisaloo marked this pull request as ready for review Jan 14, 2020
@Bisaloo
Copy link
Collaborator Author

Bisaloo commented Jan 14, 2020

Currently stuck at: vismodel() creates -Inf values for qcatch = "fi". I need to figure out what we're supposed to do with Fechner's law when Qi = 0.

@thomased
Copy link
Collaborator

This looks awesome.

Yeah the Qi = 0 and Qi < 1 cases for log-transforming are longstanding. I don't have a clean answer, no-one seems to mention it which has made me think I'm missing something obvious...

@Bisaloo Bisaloo force-pushed the max-gamut branch 2 times, most recently from a914785 to e4dc01d Compare Jan 17, 2020
@Bisaloo Bisaloo requested a review from thomased Jan 17, 2020
@thomased
Copy link
Collaborator

thomased commented Jan 18, 2020

This is super cool. Couple of quick Q's while I'm playing around:

  • (1) Points should always fall inside the gamut right? Unless I'm misunderstanding how it works. e.g. centre
    gamuts
  • (2) It's not currently implemented for qcatch = 'fi' just yet correct? Because of the above Qi = 0 issue.

EDIT: Right, I see 687f18c, ignore (2)

@Bisaloo
Copy link
Collaborator Author

Bisaloo commented Jan 18, 2020

No, you're right, points should not fall outside. It's likely a bug. Could you share the code you used to produce these graphs please?

On a related note, the first graph is strange because the max gamut should always be convex and it's not the case here.

@thomased
Copy link
Collaborator

Lazy code:

data(flowers)

vis_a <- sensmodel(c(350, 450, 550))
names(vis_a) <- c('wl', 's', 'm', 'l')
mod_a <- vismodel(flowers, vis_a)
tri_a <- colspace(mod_a)

vis_b <- sensmodel(c(340, 530, 550))
names(vis_b) <- c('wl', 's', 'm', 'l')
mod_b <- vismodel(flowers, vis_b)
tri_b <- colspace(mod_b)

vis_c <- sensmodel(c(330, 340, 660))
names(vis_c) <- c('wl', 's', 'm', 'l')
mod_c <- vismodel(flowers, vis_c)
tri_c <- colspace(mod_c)

par(mfrow = c(1, 3))
plot(tri_a, gamut = TRUE)
plot(tri_b, gamut = TRUE)
plot(tri_c, gamut = TRUE)

@Bisaloo
Copy link
Collaborator Author

Bisaloo commented Jan 18, 2020

Random thought while trying to debug this: should we provide a method for identify() for colspace objects?

@Bisaloo
Copy link
Collaborator Author

Bisaloo commented Jan 19, 2020

Okay, the gamut for trispace objects is now correct. The bug was not present for dispace and tcspace objects.

Rplot02

On a related note, what is the best way to figure the gamut in plots?

@Bisaloo
Copy link
Collaborator Author

Bisaloo commented Jan 25, 2020

Issue: conversion to relative qcatches when all qcatches are zero (e.g. CIE between 300 and 390 nm) creates NaN.

@thomased
Copy link
Collaborator

This is looking awesome. Couple of quick things:

(1) Uninformative error atm when trying to use transformed qcatches

data(flowers)
vis.flowers <- vismodel(flowers, qcatch = 'Ei', visual = "apis", scale = 10000)
tri.flowers <- colspace(vis.flowers)
plot(tri.flowers, gamut = TRUE)
Error in convhulln(coords_mono) : 
The first argument should not contain any NAs 

(2) Not sure what your thoughts are, but if it'll be a while before before we solve/implement it with transformed qcatches it's probably worth mentioning that in the docs (...currently only possible when qcatch = Qi or something).

(3) For tetrachromats, the volume when plotted looks like it's basically ~100%. Is that right? My intuition might just be mis-calibrated, but I would've thought the effect of the minor overlaps in sensitivity should be larger. (Maybe not though, one of the benefits of tetrachromacy...).

vis.flowers <- vismodel(flowers, visual = 'bluetit')
tcs.flowers <- colspace(vis.flowers)
summary(tcs.flowers)
plot(tcs.flowers, gamut = TRUE)

tcs

@Bisaloo
Copy link
Collaborator Author

Bisaloo commented Jan 31, 2020

All very good points:

  1. Fixed by tryCatch() in 7a6be24
  2. Updated the docs of triplot(), tetraplot() and tcsplot() in edd2c85
  3. I think the code is correct. From a theoretical point of view (and actually one reviewer said the same thing), I agree but because of their oil droplets (this is the main reason I think), most birds have very little overlap. Below are the blue tit's photoreceptor sensitivity profiles:

Rplot

The only case where it's impossible to excite only one receptor is for m (because there is always another receptor overlapping) and notice how it's the only place where the max gamut doesn't reach the corner in the tcs plot.

Let's try again with sensmodel(c(350, 450, 550, 650)), which generates a lot of overlap:

Rplot01

vis.flowers <- vismodel(flowers, sensmodel(c(350, 450, 550, 650)))
tcs.flowers <- colspace(vis.flowers)
summary(tcs.flowers)
plot(tcs.flowers, gamut = TRUE)

Rplot02

@thomased
Copy link
Collaborator

Cool - all looks good to go from my perspective then. Guess my intuition was just off re: birds, but it makes sense. Benefits of a finely tuned tetrachromat!

@Bisaloo Bisaloo merged commit 2622bbe into rmaia:master Feb 3, 2020
@Bisaloo Bisaloo deleted the max-gamut branch Feb 3, 2020
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

Successfully merging this pull request may close these issues.

Monochromatic loci
2 participants