Skip to content

Instantly share code, notes, and snippets.

View nden's full-sized avatar

Nadia Dencheva nden

  • Space Telescope Science Institute
View GitHub Profile
@nden
nden / sip-transformations.py
Last active August 29, 2015 14:00
SIP transformations
'''
Definitions:
SIP forward transformation:
'''
foc_X = (px_x - crpix1) + Forward_SIP_X((px_x - crpix1), (px_y - crpix2))
foc_Y = (px_y - crpix2) + Forward_SIP_Y((px_x - crpix1), (px_y - crpix2))
# SIP inverse transformation:
@nden
nden / line_fitter.py
Last active August 29, 2015 13:56
Fitting a straight line example
import numpy as np
from astropy.modeling.fitting import (_validate_model, _fitter_to_model_params, Fitter, _convert_input)
from astropy.modeling.optimizers import *
def chi_line(measured_vals, updated_model, x_sigma, y_sigma, x):
"""
Chi^2 statistic for fitting a straight line with uncertainties in x and y.
Parameters
----------
@nden
nden / gist:7028218
Last active December 25, 2015 19:29
subclass_model
from astropy.modeling.core import Model
from astropy.modeling.parameters import Parameter
class MyModel1(Model):
param_names = ['a']
def __init__(self, a):
self._a = Parameter('a', a, self, 1)
@nden
nden / gist:6808601
Created October 3, 2013 11:51
gaussian2d_example.py
from astropy.modeling import models, fitting
import numpy as np
from scipy.optimize import leastsq
def gaussian2d(p, x, y):
amplitude, x_mean, y_mean, x_stddev, y_stddev, theta = p[:]
a = 0.5 * ((np.cos(theta) / x_stddev) ** 2 + (np.sin(theta) / y_stddev) ** 2)
b = 0.5 * (np.cos(theta) * np.sin(theta) * (1. / x_stddev ** 2 - 1. / y_stddev ** 2))
c = 0.5 * ((np.sin(theta) / x_stddev) ** 2 + (np.cos(theta) / y_stddev) ** 2)
return amplitude * np.exp(-a * (x - x_mean) ** 2 - b * (x - x_mean) * (y - y_mean) - c * (y - y_mean) ** 2)
@nden
nden / newfitter.py
Last active September 5, 2018 18:56
Example of creating a new fitter
from astropy.models.fitting import Fitter
import numpy as np
from scipy import optimize
class SLSQPFitter(Fitter):
def __init__(self):
super().__init__(optimizer=SLSQP, statistic=leastsquare)
def errorfunc(self, fps, *args):
model = args[0]
@nden
nden / models_TODO_list
Last active December 16, 2015 05:09
Proposed new features in astropy.models
This page lists features to be added to astropy.models. It was compiled from suggestions in the initial astropy.models PR#493. Feel free to add to this list. Please make a note if you are interested in working on any of them. This list is not prioritized.
* Add spline models and fitters.
* Write a general `Model.inverse()` method.
This is intended to be used in models for which an analytical inverse is not available.
* Add a `CompositeModel.simplify` method, similar to AST.