@@ -51,21 +51,22 @@ def get_xija_model_spec(
51
51
"""
52
52
Get Xija model specification for the specified ``model_name``.
53
53
54
- Supported model names include (but are not limited to): ``'aca'``,
55
- ``'acisfp'``, ``'dea'``, ``'dpa'``, ``'psmc'``, ``'minusyz'``, and
56
- ``'pftank2t'``.
54
+ This gets the model specification from the Ska chandra_models repository, looking
55
+ for ``*.json`` files in the ``chandra_models/xija`` directory of the repository.
57
56
58
- Use ``get_xija_model_names()`` for the full list.
57
+ The ``model_name`` can be provided in two ways:
58
+ - Short like ``'acisfp'`` which looks for ``acisfp_spec.json`` (tried first).
59
+ - Full like ``'acisfp_spec_matlab'`` which looks for ``acisfp_spec_matlab.json``.
59
60
60
61
Examples
61
62
--------
62
- Get the latest version of the ``acisfp `` model spec from the local Ska data
63
+ Get the latest version of the ``acisfp_spec `` model spec from the local Ska data
63
64
directory ``$SKA/data/chandra_models``, checking that the version matches
64
65
the latest release tag on GitHub.
65
66
66
67
>>> import xija
67
68
>>> from xija.get_model_spec import get_xija_model_spec
68
- >>> model_spec, version = get_xija_model_spec('acisfp ', check_version=True)
69
+ >>> model_spec, version = get_xija_model_spec('acisfp_spec ', check_version=True)
69
70
>>> model = xija.XijaModel('acisfp', model_spec=model_spec,
70
71
... start='2020:001', stop='2020:010')
71
72
>>> model.make()
@@ -81,7 +82,7 @@ def get_xija_model_spec(
81
82
Parameters
82
83
----------
83
84
model_name : str
84
- Name of model
85
+ Name of model or model spec file (e.g. 'acisfp' or 'acisfp_spec_matlab')
85
86
version : str, None
86
87
Tag, branch or commit of chandra_models to use (default=latest tag from
87
88
repo)
@@ -120,17 +121,21 @@ def _get_xija_model_spec(
120
121
if not models_path .exists ():
121
122
raise FileNotFoundError (f"xija models directory { models_path } does not exist" )
122
123
123
- file_glob = str (models_path / "*" / f"{ model_name .lower ()} _spec.json" )
124
- try :
125
- # get_globfiles() default requires exactly one file match and returns a list
126
- file_name = get_globfiles (file_glob )[0 ]
127
- except ValueError :
128
- names = get_xija_model_names (repo_path )
129
- raise ValueError (
130
- f'no models matched { model_name } . Available models are: { ", " .join (names )} '
131
- )
132
-
133
- model_spec = json .load (open (file_name , "r" ))
124
+ file_path = None
125
+ for suffix in ["_spec.json" , ".json" ]:
126
+ file_paths = list (models_path .glob (f"*/{ model_name } { suffix } " ))
127
+ if len (file_paths ) == 1 :
128
+ file_path = file_paths [0 ]
129
+ break
130
+ elif len (file_paths ) > 1 :
131
+ raise ValueError (
132
+ f"Multiple files found for { model_name } in { models_path } : { file_paths } "
133
+ )
134
+
135
+ if file_path is None :
136
+ raise ValueError (f"no model spec files matched { model_name } " )
137
+
138
+ model_spec = json .load (open (file_path , "r" ))
134
139
135
140
# Get version and ensure that repo is clean and tip is at latest tag
136
141
if version is None :
0 commit comments