|
4 | 4 |
|
5 | 5 | import numpy as np |
6 | 6 |
|
7 | | -from ..modeling.core import Fittable1DModel, Fittable2DModel |
8 | | - |
| 7 | +from ..modeling.core import FittableModel, custom_model |
9 | 8 |
|
10 | 9 | __all__ = ['discretize_model'] |
11 | 10 |
|
@@ -74,12 +73,16 @@ def add_kernel_arrays_2D(array_1, array_2): |
74 | 73 |
|
75 | 74 | def discretize_model(model, x_range, y_range=None, mode='center', factor=10): |
76 | 75 | """ |
77 | | - Function to evaluate analytical models on a grid. |
| 76 | + Function to evaluate analytical model functions on a grid. |
| 77 | +
|
| 78 | + So far the function can only deal with pixel coordinates. |
78 | 79 |
|
79 | 80 | Parameters |
80 | 81 | ---------- |
81 | | - model : `~astropy.modeling.FittableModel` |
82 | | - Model to be evaluated. |
| 82 | + model : `~astropy.modeling.FittableModel` or callable. |
| 83 | + Analytic model function to be discretized. Callables, which are not an |
| 84 | + instances of `~astropy.modeling.FittableModel` are passed to |
| 85 | + `~astropy.modeling.custom_model` and then evaluated. |
83 | 86 | x_range : tuple |
84 | 87 | x range in which the model is evaluated. |
85 | 88 | y_range : tuple, optional |
@@ -135,27 +138,37 @@ def discretize_model(model, x_range, y_range=None, mode='center', factor=10): |
135 | 138 |
|
136 | 139 |
|
137 | 140 | """ |
138 | | - if isinstance(model, Fittable2DModel) and y_range is None: |
139 | | - raise Exception("Please specify y range.") |
| 141 | + if not callable(model): |
| 142 | + raise TypeError('Model must be callable.') |
| 143 | + if not isinstance(model, FittableModel): |
| 144 | + model = custom_model(model)() |
| 145 | + ndim = model.n_inputs |
| 146 | + if ndim > 2: |
| 147 | + raise ValueError('discretize_model only supports 1-d and 2-d models.') |
| 148 | + |
| 149 | + if ndim == 2 and y_range is None: |
| 150 | + raise ValueError("y range not specified, but model is 2-d") |
| 151 | + if ndim == 1 and y_range is not None: |
| 152 | + raise ValueError("y range specified, but model is only 1-d.") |
140 | 153 | if mode == "center": |
141 | | - if isinstance(model, Fittable1DModel): |
| 154 | + if ndim == 1: |
142 | 155 | return discretize_center_1D(model, x_range) |
143 | | - if isinstance(model, Fittable2DModel): |
| 156 | + elif ndim == 2: |
144 | 157 | return discretize_center_2D(model, x_range, y_range) |
145 | 158 | elif mode == "linear_interp": |
146 | | - if isinstance(model, Fittable1DModel): |
| 159 | + if ndim == 1: |
147 | 160 | return discretize_linear_1D(model, x_range) |
148 | | - if isinstance(model, Fittable2DModel): |
| 161 | + if ndim == 2: |
149 | 162 | return discretize_bilinear_2D(model, x_range, y_range) |
150 | 163 | elif mode == "oversample": |
151 | | - if isinstance(model, Fittable1DModel): |
| 164 | + if ndim == 1: |
152 | 165 | return discretize_oversample_1D(model, x_range, factor) |
153 | | - if isinstance(model, Fittable2DModel): |
| 166 | + if ndim == 2: |
154 | 167 | return discretize_oversample_2D(model, x_range, y_range, factor) |
155 | 168 | elif mode == "integrate": |
156 | | - if isinstance(model, Fittable1DModel): |
| 169 | + if ndim == 1: |
157 | 170 | return discretize_integrate_1D(model, x_range) |
158 | | - if isinstance(model, Fittable2DModel): |
| 171 | + if ndim == 2: |
159 | 172 | return discretize_integrate_2D(model, x_range, y_range) |
160 | 173 | else: |
161 | 174 | raise DiscretizationError('Invalid mode.') |
|
0 commit comments