Skip to content

Instantly share code, notes, and snippets.

@nden
Created August 8, 2017 13:16
Show Gist options
  • Save nden/987d3315a8deaf0a62fcbdea4628d786 to your computer and use it in GitHub Desktop.
Save nden/987d3315a8deaf0a62fcbdea4628d786 to your computer and use it in GitHub Desktop.
parameters can be models
from astropy.modeling.core import Model
from astropy.modeling.models import Polynomial2D, Polynomial1D
from astropy.modeling.parameters import Parameter
class MyModel(Model):
inputs = ('x', 'y', 't')
outputs = ('z',)
def __init__(self, c0, c1, **kwargs):
'''
c0, c1 are Poly models
'''
self.c0 = c0 # poly1d(degree=1)
self.c1 = c1 # deg = 2
super(MyModel, self).__init__(**kwargs)
def evaluate(self, x, y, t):
"""
x, y = coordinates
t - order
"""
p2 = Polynomial2D(1, c0_0=self.c0(t), c0_1=self.c1(t), c1_0=1)
return p2(x,y)
c0 = Polynomial1D(1, c0=1, c1=2)
c1 = Polynomial1D(2, c0=1, c1=2, c2=3)
m = MyModel(c0, c1)
m(1, 2, 1)
# 16
m(1, 2, 2)
#40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment