Skip to content

Conversation

@GarethCabournDavies
Copy link
Contributor

As we are now making plots with difference coincidences on one chart, I thought we should make a consistent chart to refer to each detector combination.

Standard information about the request

This is a new feature

This change changes result presentation / plotting

This change follows style guidelines (See e.g. PEP8), has been proposed using the contribution guidelines

Contents

Add a dictionary of colour choices and a function to wrap it.

How this is made is probably the more interesting thing:

This was made from combining the _ifo_color_map colors and generating a maximally-distinct colour based on a few things.
I set this up by starting with an IFO-precedence list: H1 L1 V1 K1 I1 G1
I then created coincidences containing the most-preferred IFOs and extended the color palette using glasbey to maximise the distinctness of the new color(s).

In words:

  • From H (red) and L (blue) colors, I got the maximally distinct color (lime green) for HL
  • I then added in V, and got the maximally-distinct set of colors which would extend H, L, V and HL's already-defined colorset, and used it to get the HV, LV and HLV colours
  • This is repeated in turn for K, I and then G
  • I then asked github copilot to name all the colors (though I don't really know what 'olive drab' and 'rosy brown' are)

The code I ran is here:

def generate_precedence_color_map(n_ifos=None):
    # Create a color map which adds in the coincidences containing ifos in the order of ifo_precedence
    # This means that the coincs containing the most preferred IFOs will be colored first, and the less preferred IFOs will be colored last
    # As a result the most-used combinations will be maximally distinguishable
    if n_ifos == 1:
        # Single-IFO "coincs" just use the color of the ifo from the original _ifo_color_map
        return {ifo_precedence[0]: _ifo_color_map[ifo_precedence[0]]}
    
    n_ifos = n_ifos if n_ifos is not None else len(ifo_precedence)
    # Generate the color map for the IFOs up to the IFO before this one
    color_map = generate_precedence_color_map(n_ifos=n_ifos-1)
    # Now we add the coincidences formed with the 
    new_coincs = []
    for k in list(color_map.keys()) + ['']:
        # Add the new IFO into the key in alphabetical order
        # split the string into each IFO, these will be 2 characters long
        ifos = [k[i:i+2] for i in range(0, len(k), 2)]
        # Add the new IFO into the list, put it into alpabetical order, and rejoin the string
        new_coinc = ''.join(sorted(ifos + [ifo_precedence[n_ifos-1]]))
        if new_coinc in _ifo_color_map:
            color_map[new_coinc] = _ifo_color_map[new_coinc]
        else:
            new_coincs.append(new_coinc)

    new_palette = glasbey.extend_palette(list(color_map.values()), palette_size=len(new_coincs) + len(color_map))
    color_map.update({s: new_palette[i + len(color_map)] for i, s in enumerate(new_coincs)})=
    return color_map

precedence_cmap = generate_precedence_color_map()
# Remove the single-ifo combinations
precedence_cmap = {k: v for k, v in precedence_cmap.items() if k not in _ifo_color_map}

I didn't want to add the code directly because

  1. It can take a while to run the same thing every time
  2. I didn't want to add a new dependency

Right now, nothing links to this function/dictionary, so I expect all tests to pass, but we can use this for different coincs on the same plot

  • The author of this pull request confirms they will adhere to the code of conduct

@GarethCabournDavies
Copy link
Contributor Author

Adding a few plots so that we can actually see teh changes:
Full map (including singles):
image

HLV network:
image

All 2-ifo coincs:
image

Coincs and Singles:
image

@GarethCabournDavies
Copy link
Contributor Author

GarethCabournDavies commented Feb 18, 2025

No longer Requires #5041

@GarethCabournDavies GarethCabournDavies added the long term This is a long term issue minor thing to address label May 1, 2025
@GarethCabournDavies
Copy link
Contributor Author

Updated given #5041 closure, whitespace removed and docstring clarified. I think this is ready for review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

long term This is a long term issue minor thing to address

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant