Skip to content

fermipy should accept pathlib.Path objects #654

@HealthyPear

Description

@HealthyPear

also easy to add checks on existence and enforce directory structure within an analysis

currently, gta.GTAnalysis() fails even starting with

---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
Cell In[14], [line 1](vscode-notebook-cell:?execution_count=14&line=1)
----> [1](vscode-notebook-cell:?execution_count=14&line=1) gta = GTAnalysis(paths.data / "Fermi_LAT" / "fermipy_config_baseline.yml", logging={'verbosity' : 5})
      2 gta.setup()

File ~/Data/projects/W51_FermiLAT_baseline/.snakemake/conda/91ff16a64e21ea2415c95ceb35b74ee7_/lib/python3.11/site-packages/fermipy/gtanalysis.py:294, in GTAnalysis.__init__(self, config, roi, **kwargs)
    291 validate = kwargs.pop('validate', True)
    292 self._loglevel = kwargs.pop('loglevel', logging.INFO)
--> [294](https://file+.vscode-resource.vscode-cdn.net/Users/michele/Data/projects/W51_FermiLAT_baseline/src/scripts/~/Data/projects/W51_FermiLAT_baseline/.snakemake/conda/91ff16a64e21ea2415c95ceb35b74ee7_/lib/python3.11/site-packages/fermipy/gtanalysis.py:294) super(GTAnalysis, self).__init__(config, validate=validate,
    295                                  **kwargs)
    297 self._projtype = self.config['binning']['projtype']
    298 self._tmin = self.config['selection']['tmin']

File ~/Data/projects/W51_FermiLAT_baseline/.snakemake/conda/91ff16a64e21ea2415c95ceb35b74ee7_/lib/python3.11/site-packages/fermipy/config.py:219, in Configurable.__init__(self, config, **kwargs)
    217     raise Exception('Invalid path to configuration file: %s' % config)
    218 else:
--> [219](https://file+.vscode-resource.vscode-cdn.net/Users/michele/Data/projects/W51_FermiLAT_baseline/src/scripts/~/Data/projects/W51_FermiLAT_baseline/.snakemake/conda/91ff16a64e21ea2415c95ceb35b74ee7_/lib/python3.11/site-packages/fermipy/config.py:219)     raise Exception('Invalid config argument.')
    221 self.configure(config_dict, **kwargs)
    223 if self.configdir and 'fileio' in self.config and \
    224         self.config['fileio']['outdir'] is None:

Exception: Invalid config argument.

unless using str(path_to_config)

The error itself is not informative for the user (see #617) and might lead to people opening issues for every small mistake.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions