tests.nexus.test_build_dxtbx_models.test_get_dxtbx_spectrum_with_variants

Tags
Last edited time

delete test

tests.nexus.test_build_dxtbx_models.test_get_dxtbx_spectrum_with_variants (Age: 30)

Error Message

TypeError: can't concat str to bytes

Stacktrace

def test_get_dxtbx_spectrum_with_variants():
        # drifting gaussian bandpass with 20eV std dev
        energies = np.array([9500, 9520, 9510])
        channels = np.linspace(9400, 9600, 1000)
        weights = np.vstack([stats.norm.pdf(channels, e, 20) for e in energies])
        # calibrated energies not necessarily matching the weighted mean of the spectra
        calibrated_energies = np.array([e + 5 for e in energies])

        with h5py.File(" ", mode="w", **pytest.h5_in_memory) as f:
            beam = f.create_group("/entry/instrument/beam")
            beam.attrs["NX_class"] = "NXbeam"
            beam["incident_wavelength"] = factor_ev_angstrom / calibrated_energies
            beam["incident_wavelength"].attrs["units"] = b"angstrom"
            beam["incident_wavelength"].attrs["variant"] = b"incident_wavelength_1Dspectrum"
            beam["incident_wavelength_1Dspectrum"] = factor_ev_angstrom / channels
            beam["incident_wavelength_1Dspectrum"].attrs["units"] = b"angstrom"
            beam["incident_wavelength_1Dspectrum_weights"] = weights

            nxbeam = dxtbx.nexus.nxmx.NXbeam(f["/entry/instrument/beam"])
            beam_factory = dxtbx.nexus.CachedWavelengthBeamFactory(nxbeam)
            for i, (calibrated_energy, energy) in enumerate(
                zip(calibrated_energies, energies)
            ):
>               assert (
                    pytest.approx(beam_factory.make_beam(i).get_wavelength())
                    == factor_ev_angstrom / calibrated_energy
                )

../lib/python3.9/site-packages/dxtbx/tests/nexus/test_build_dxtbx_models.py:239:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../lib/python3.9/site-packages/dxtbx/src/dxtbx/nexus/__init__.py:78: in make_beam
    self.read_models(index)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <dxtbx.nexus.CachedWavelengthBeamFactory object at 0x10e877430>
index = 0

    def read_models(self, index: int = 0):
        # Cached model
        if self.model is not None and index == self.index:
            return

        # Get the items from the NXbeam class
        # Note it would be better if there were a general way to read weights
        # and variants from the nxmx classes
        # Seehttps://github.com/cctbx/dxtbx/issues/549
        primary_key = "incident_wavelength"
        wavelength = self.handle[primary_key]
        spectrum_wavelengths = wavelength
        spectrum_weights = self.handle.get(primary_key + "_weights")
        if spectrum_weights is None:
            # Handle deprecation:https://github.com/nexusformat/definitions/issues/837
            spectrum_weights = self.handle.get(primary_key + "_weight")

        # If the wavelength array does not represent spectra, look for spectra
        # in the variant chain
        variant_test = wavelength
        has_variant_spectra = False
        while spectrum_weights is None:
            if "variant" in variant_test.attrs:
                variant_key = variant_test.attrs["variant"]
                variant_wavelengths = self.handle[variant_key]
>               variant_weights = self.handle.get(variant_key + "_weights")
E               TypeError: can't concat str to bytes

../lib/python3.9/site-packages/dxtbx/src/dxtbx/nexus/__init__.py:110: TypeError