gaia-dpci / GaiaXPy

Gaia BP/RP spectra package
BSD 3-Clause "New" or "Revised" License
36 stars 9 forks source link

Error reading an additional systems directory when one of the system names is a substring of another (GaiaXPy 2.1.1) #102

Closed druzm closed 4 months ago

druzm commented 4 months ago

When passing a directory to load_additional_systems, the systems in the directory will fail to load if one (or more) of the system names in the directory is a substring of another system name.

For example in the following structure:

├── ABC
│   ├── ABC.gaiaXPy_dr3_v1.xml
│   ├── ABC1.gaiaXPy_dr3_v1.xml
│   └── DEF.gaiaXPy_dr3_v1.xml
└── XYZ.gaiaXPy_dr3_v1.xml

System name ABC is a substring of ABC1. The files in this directory will be rejected.

To reproduce simply run:

from gaiaxpy import load_additional_systems, PhotometricSystem

PhotometricSystem = load_additional_systems('path/to/dir/')  # where dir contains files like the ones described

GaiaXPy should be able to correctly load the systems in these files.

Trace:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/userhome/gaiaxpy/lib/python3.10/site-packages/gaiaxpy/generator/photometric_system.py", line 107, in load_additional_systems
    updated_enum = __load_additional_systems(_systems_path, _CFG_FILE_PATH)
  File "/userhome/gaiaxpy/lib/python3.10/site-packages/gaiaxpy/generator/photometric_system.py", line 133, in __load_additional_systems
    return AutoName('PhotometricSystem', _get_system_tuples())
  File "/userhome/gaiaxpy/lib/python3.10/site-packages/gaiaxpy/generator/photometric_system.py", line 81, in _get_system_tuples
    return [(s, create_system(s, None)) if _is_built_in_system(s) else (s, create_system(s, _CFG_FILE_PATH)) for s in
  File "/userhome/gaiaxpy/lib/python3.10/site-packages/gaiaxpy/generator/photometric_system.py", line 81, in <listcomp>
    return [(s, create_system(s, None)) if _is_built_in_system(s) else (s, create_system(s, _CFG_FILE_PATH)) for s in
  File "/userhome/gaiaxpy/lib/python3.10/site-packages/gaiaxpy/generator/photometric_system.py", line 62, in create_system
    else RegularPhotometricSystem(name, systems_path)
  File "/userhome/gaiaxpy/lib/python3.10/site-packages/gaiaxpy/generator/regular_photometric_system.py", line 19, in __init__
    super().__init__(name, config_file)
  File "/userhome/gaiaxpy/lib/python3.10/site-packages/gaiaxpy/generator/internal_photometric_system.py", line 31, in __init__
    self._set_file(bp_model=bp_model, rp_model=rp_model)
  File "/userhome/gaiaxpy/lib/python3.10/site-packages/gaiaxpy/generator/internal_photometric_system.py", line 148, in _set_file
    raise ValueError(f'More than one system named {self.label.replace(f"{ADDITIONAL_SYSTEM_PREFIX}_", "")}'
ValueError: More than one system named ABC were found. System names in the given directory should be unique. Operation aborted.
druzm commented 4 months ago

Fixed by commit a67a512a06fa54c2a6a6d714b52fd4a26727109d