Last active
October 29, 2019 21:37
-
-
Save jdavies-st/17d25cb11646309f41a6f3162550655c to your computer and use it in GitHub Desktop.
serialize astropy.modeling instance to ASDF
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> from astropy.modeling import models, fitting | |
>>> import asdf | |
>>> import numpy as np | |
>>> x = np.random.random(100) | |
>>> y = np.random.random(100) | |
>>> | |
>>> mymodel = models.Polynomial1D(degree=3) | |
>>> fitter = fitting.LevMarLSQFitter() | |
>>> myfit = fitter(mymodel,x,y) | |
WARNING: Model is linear in parameters; consider using linear fitting methods. [astropy.modeling.fitting] | |
>>> | |
>>> myfit | |
<Polynomial1D(3, c0=0.55412012, c1=-1.00790666, c2=1.53229478, c3=-0.54992893)> | |
>>> tree = dict(model=myfit) | |
>>> af = asdf.AsdfFile(tree=tree) | |
>>> af.tree['model'] | |
<Polynomial1D(3, c0=0.55412012, c1=-1.00790666, c2=1.53229478, c3=-0.54992893)> | |
>>> af.write_to('mymodel.asdf') | |
>>> new = asdf.open('mymodel.asdf').tree['model'] | |
>>> new | |
<Polynomial1D(3, c0=0.55412012, c1=-1.00790666, c2=1.53229478, c3=-0.54992893)> | |
>>> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment