Esempio n. 1
0
def get_isotope_string(atom_number, atom_mass):
    """Get the isotope string in the format e.g. Ni56

    Parameters
    ----------
    atom_number : int
        Atomic number
    atom_mass : int
        Atomic mass

    Returns
    -------
    str
        Isotope string in the format e.g. Ni56
    """
    return atomic_number2element_symbol(atom_number) + str(atom_mass)
Esempio n. 2
0
    def _plot_absorption_ply(self):
        """Plot absorption part of the SDEC Plot using plotly."""
        elements_z = self.absorption_luminosities_df.columns
        nelements = len(elements_z)

        for i, atomic_num in enumerate(elements_z):
            self.fig.add_trace(
                go.Scatter(
                    x=self.absorption_luminosities_df.index,
                    # to plot absorption luminosities along negative y-axis
                    y=self.absorption_luminosities_df[atomic_num] * -1,
                    mode="none",
                    name=atomic_number2element_symbol(atomic_num),
                    fillcolor=self.to_rgb255_string(self.cmap(i / nelements)),
                    stackgroup="absorption",
                    showlegend=False,
                ))
Esempio n. 3
0
    def _show_colorbar_ply(self):
        """Show plotly colorbar with labels of elements mapped to colors."""
        # Interpolate [0, 1] range to create bins equal to number of elements
        colorscale_bins = np.linspace(0, 1, num=self.elements.size + 1)

        # Create a categorical colorscale [a list of (reference point, color)]
        # by mapping same reference points (excluding 1st and last bin edge)
        # twice in a row (https://plotly.com/python/colorscales/#constructing-a-discrete-or-discontinuous-color-scale)
        categorical_colorscale = []
        for i in range(self.elements.size):
            color = self.to_rgb255_string(self.cmap(colorscale_bins[i]))
            categorical_colorscale.append((colorscale_bins[i], color))
            categorical_colorscale.append((colorscale_bins[i + 1], color))

        coloraxis_options = dict(
            colorscale=categorical_colorscale,
            showscale=True,
            cmin=0,
            cmax=self.elements.size,
            colorbar=dict(
                title="Elements",
                tickvals=np.arange(0, self.elements.size) + 0.5,
                ticktext=[
                    atomic_number2element_symbol(atomic_num)
                    for atomic_num in self.elements
                ],
                # to change length and position of colorbar
                len=0.75,
                yanchor="top",
                y=0.75,
            ),
        )

        # Plot an invisible one point scatter trace, to make colorbar show up
        scatter_point_idx = pu.get_mid_point_idx(self.plot_wavelength)
        self.fig.add_trace(
            go.Scatter(
                x=self.plot_wavelength[scatter_point_idx],
                y=[0],
                mode="markers",
                showlegend=False,
                hoverinfo="skip",
                marker=dict(color=[0], opacity=0, **coloraxis_options),
            )
        )
Esempio n. 4
0
    def _show_colorbar_mpl(self):
        """Show matplotlib colorbar with labels of elements mapped to colors."""
        color_values = [
            self.cmap(i / self.elements.size) for i in range(self.elements.size)
        ]
        custcmap = clr.ListedColormap(color_values)
        norm = clr.Normalize(vmin=0, vmax=self.elements.size)
        mappable = cm.ScalarMappable(norm=norm, cmap=custcmap)
        mappable.set_array(np.linspace(1, self.elements.size + 1, 256))
        cbar = plt.colorbar(mappable, ax=self.ax)

        bounds = np.arange(self.elements.size) + 0.5
        cbar.set_ticks(bounds)

        elements_name = [
            atomic_number2element_symbol(atomic_num)
            for atomic_num in self.elements
        ]
        cbar.set_ticklabels(elements_name)
Esempio n. 5
0
    def _plot_emission_ply(self):
        """Plot emission part of the SDEC Plot using plotly."""
        # By specifying a common stackgroup, plotly will itself add up
        # luminosities, in order, to created stacked area chart
        self.fig.add_trace(
            go.Scatter(
                x=self.emission_luminosities_df.index,
                y=self.emission_luminosities_df.noint,
                mode="none",
                name="No interaction",
                fillcolor="black",
                stackgroup="emission",
            )
        )

        self.fig.add_trace(
            go.Scatter(
                x=self.emission_luminosities_df.index,
                y=self.emission_luminosities_df.escatter,
                mode="none",
                name="Electron Scatter Only",
                fillcolor="grey",
                stackgroup="emission",
            )
        )

        elements_z = self.emission_luminosities_df.columns[2:]
        nelements = len(elements_z)

        for i, atomic_num in enumerate(elements_z):
            self.fig.add_trace(
                go.Scatter(
                    x=self.emission_luminosities_df.index,
                    y=self.emission_luminosities_df[atomic_num],
                    mode="none",
                    name=atomic_number2element_symbol(atomic_num),
                    fillcolor=self.to_rgb255_string(self.cmap(i / nelements)),
                    stackgroup="emission",
                    showlegend=False,
                )
            )
Esempio n. 6
0
def test_atomic_number2element_symbol():
    assert atomic_number2element_symbol(14) == 'Si'
Esempio n. 7
0
def test_atomic_number2element_symbol():
    assert atomic_number2element_symbol(14) == 'Si'