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

Can't load .IAEAphsp data #181

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

Can't load .IAEAphsp data #181

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

Comments

@lars-mejnertsen-seetreat

Loading in PHSP data that ends in .IAEAphsp. doesn't work, and produces Exception: This data loader reads in files of extension *.phsp or *.IAEAphsp, even though the filename ends with .IAEAphsp.

Changing the file extension from .IAEAphsp to .phsp and .IAEAheader to .header does work, and the data loads in fine.

Steps to Reproduce

  1. Download Varian_TrueBeam6MV_01.IAEAphsp
  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_01.IAEAphsp")
# 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),
)

This produces the above error

Error

---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
Cell In[171], [line 20](vscode-notebook-cell:?execution_count=171&line=20)
      [5](vscode-notebook-cell:?execution_count=171&line=5) data_schema = np.dtype(
      [6](vscode-notebook-cell:?execution_count=171&line=6)     [
      [7](vscode-notebook-cell:?execution_count=171&line=7)         ("particle type", "i1"),
   (...)
     [14](vscode-notebook-cell:?execution_count=171&line=14)     ]
     [15](vscode-notebook-cell:?execution_count=171&line=15) )
     [18](vscode-notebook-cell:?execution_count=171&line=18) constants = {"weight": np.float32(1.)}
---> [20](vscode-notebook-cell:?execution_count=171&line=20) ps_data = DataLoaders.Load_IAEA(
     [21](vscode-notebook-cell:?execution_count=171&line=21)     data_schema=data_schema,
     [22](vscode-notebook-cell:?execution_count=171&line=22)     constants=constants,
     [23](vscode-notebook-cell:?execution_count=171&line=23)     input_data=file_name,
     [24](vscode-notebook-cell:?execution_count=171&line=24)     n_records=int(1e5),
     [25](vscode-notebook-cell:?execution_count=171&line=25) )

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](https://vscode-remote+ssh-002dremote-002bhpc.vscode-resource.vscode-cdn.net/home/lars/phase-spaces/~/phase-spaces/.venv/lib/python3.11/site-packages/ParticlePhaseSpace/DataLoaders.py:401) self._n_records = n_records
    [402](https://vscode-remote+ssh-002dremote-002bhpc.vscode-resource.vscode-cdn.net/home/lars/phase-spaces/~/phase-spaces/.venv/lib/python3.11/site-packages/ParticlePhaseSpace/DataLoaders.py:402) self._offset = offset
--> [403](https://vscode-remote+ssh-002dremote-002bhpc.vscode-resource.vscode-cdn.net/home/lars/phase-spaces/~/phase-spaces/.venv/lib/python3.11/site-packages/ParticlePhaseSpace/DataLoaders.py:403) super().__init__(input_data, **kwargs)

File ~/phase-spaces/.venv/lib/python3.11/site-packages/ParticlePhaseSpace/DataLoaders.py:52, in _DataLoadersBase.__init__(self, input_data, particle_type, units)
     [49](https://vscode-remote+ssh-002dremote-002bhpc.vscode-resource.vscode-cdn.net/home/lars/phase-spaces/~/phase-spaces/.venv/lib/python3.11/site-packages/ParticlePhaseSpace/DataLoaders.py:49) self._particle_type = particle_type
     [51](https://vscode-remote+ssh-002dremote-002bhpc.vscode-resource.vscode-cdn.net/home/lars/phase-spaces/~/phase-spaces/.venv/lib/python3.11/site-packages/ParticlePhaseSpace/DataLoaders.py:51) self._input_data = input_data
---> [52](https://vscode-remote+ssh-002dremote-002bhpc.vscode-resource.vscode-cdn.net/home/lars/phase-spaces/~/phase-spaces/.venv/lib/python3.11/site-packages/ParticlePhaseSpace/DataLoaders.py:52) self._check_input_data()
     [53](https://vscode-remote+ssh-002dremote-002bhpc.vscode-resource.vscode-cdn.net/home/lars/phase-spaces/~/phase-spaces/.venv/lib/python3.11/site-packages/ParticlePhaseSpace/DataLoaders.py:53) self._import_data()
     [54](https://vscode-remote+ssh-002dremote-002bhpc.vscode-resource.vscode-cdn.net/home/lars/phase-spaces/~/phase-spaces/.venv/lib/python3.11/site-packages/ParticlePhaseSpace/DataLoaders.py:54) self._check_loaded_data()

File ~/phase-spaces/.venv/lib/python3.11/site-packages/ParticlePhaseSpace/DataLoaders.py:409, in Load_IAEA._check_input_data(self)
    [407](https://vscode-remote+ssh-002dremote-002bhpc.vscode-resource.vscode-cdn.net/home/lars/phase-spaces/~/phase-spaces/.venv/lib/python3.11/site-packages/ParticlePhaseSpace/DataLoaders.py:407)     raise FileNotFoundError(f'input data file {self._import_data()} does not exist')
    [408](https://vscode-remote+ssh-002dremote-002bhpc.vscode-resource.vscode-cdn.net/home/lars/phase-spaces/~/phase-spaces/.venv/lib/python3.11/site-packages/ParticlePhaseSpace/DataLoaders.py:408) if not Path(self._input_data).suffix == '.phsp' or Path(self._input_data).suffix == '.IAEAphsp':
--> [409](https://vscode-remote+ssh-002dremote-002bhpc.vscode-resource.vscode-cdn.net/home/lars/phase-spaces/~/phase-spaces/.venv/lib/python3.11/site-packages/ParticlePhaseSpace/DataLoaders.py:409)     raise Exception('This data loader reads in files of extension *.phsp or *.IAEAphsp')
    [410](https://vscode-remote+ssh-002dremote-002bhpc.vscode-resource.vscode-cdn.net/home/lars/phase-spaces/~/phase-spaces/.venv/lib/python3.11/site-packages/ParticlePhaseSpace/DataLoaders.py:410) if self._particle_type:
    [411](https://vscode-remote+ssh-002dremote-002bhpc.vscode-resource.vscode-cdn.net/home/lars/phase-spaces/~/phase-spaces/.venv/lib/python3.11/site-packages/ParticlePhaseSpace/DataLoaders.py:411)     warnings.warn('particle type is ignored in IAEA read in')

Exception: This data loader reads in files of extension *.phsp or *.IAEAphsp
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