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

Issue with loading Varian_TrueBeam6MV_02 #182

Open
lars-mejnertsen-seetreat opened this issue Sep 16, 2024 · 0 comments
Open

Issue with loading Varian_TrueBeam6MV_02 #182

lars-mejnertsen-seetreat opened this issue Sep 16, 2024 · 0 comments

Comments

@lars-mejnertsen-seetreat

Trying to load Varian_TrueBeam6MV_02 (and header file) produces TypeError: unknown particle code -3 error. I was able to load Varian_TrueBeam6MV_01 with no issues.

I did change the file extensions to overcome #181.

Steps to Reproduce

  1. Download Varian_TrueBeam6MV_02
  2. Run the example from Reading IAEA phase space:
from ParticlePhaseSpace import PhaseSpace, DataLoaders
from pathlib import Path
import numpy as np


# get data file:
file_name = Path("Varian_TrueBeam6MV_02.phsp")
# read in
data_schema = np.dtype(
    [
        ("particle type", "i1"),
        ("Ek", "f4"),
        ("x", "f4"),
        ("y", "f4"),
        ("z", "f4"),
        ("Cosine X", "f4"),
        ("Cosine Y", "f4"),
    ]
)

constants = {"weight": np.float32(1.)}

ps_data = DataLoaders.Load_IAEA(
    data_schema=data_schema,
    constants=constants,
    input_data=file_name,
    n_records=int(1e5),
)

Error

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[2], line 19
      4 data_schema = np.dtype(
      5     [
      6         (\"particle type\", \"i1\"),
   (...)
     13     ]
     14 )
     17 constants = {\"weight\": np.float32(1.)}
---> 19 ps_data = DataLoaders.Load_IAEA(
     20     data_schema=data_schema,
     21     constants=constants,
     22     input_data=file_name,
     23     n_records=int(1e5),
     24 )

File ~/phase-spaces/.venv/lib/python3.11/site-packages/ParticlePhaseSpace/DataLoaders.py:403, in Load_IAEA.__init__(self, data_schema, constants, input_data, n_records, offset, **kwargs)
    401 self._n_records = n_records
    402 self._offset = offset
--> 403 super().__init__(input_data, **kwargs)

File ~/phase-spaces/.venv/lib/python3.11/site-packages/ParticlePhaseSpace/DataLoaders.py:53, in _DataLoadersBase.__init__(self, input_data, particle_type, units)
     51 self._input_data = input_data
     52 self._check_input_data()
---> 53 self._import_data()
     54 self._check_loaded_data()

File ~/phase-spaces/.venv/lib/python3.11/site-packages/ParticlePhaseSpace/DataLoaders.py:435, in Load_IAEA._import_data(self)
    431             self.data[self._columns[constant]] = pd.Series(self._constants[constant] *
    432                                                            np.ones(self.data.shape[0]), dtype=\"category\")
    434 # OK; add the fields I assume is not in the data
--> 435 particle_types_pdg = self._iaea_types_to_pdg(data['particle type'])
    436 self._check_n_particles_in_header(particle_types_pdg)
    437 self.data[self._columns['particle type']] = particle_types_pdg

File ~/phase-spaces/.venv/lib/python3.11/site-packages/ParticlePhaseSpace/DataLoaders.py:483, in Load_IAEA._iaea_types_to_pdg(self, varian_types)
    481 for type in np.unique(varian_types):
    482     if not type in [1, 2, 3, 4, 5]:
--> 483         raise TypeError(f'unknown particle code {type}')
    484 pdg_types[varian_types==1] = 22  # gammas
    485 pdg_types[varian_types == 2] = 11  # electrons

TypeError: unknown particle code -3
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

1 participant