def drive_fit(expid, params={}, weights={}, skip_fit=False): params_default = {'analytic': True, 'number_sample': 0, 'verbose': True, 'num_bins': 1} params_default.update(param_default_kils(expid)) params_default.update(params) params = params_default model = Digestor().digest_directory( params['data_directory'], file_type=params['data_name']) if params['number_sample'] > 0: rows = np.random.choice(model.index.values, params['number_sample'], replace=False) model = model.ix[rows] # guess rzero rzero = r0_guess(model['e0'].min()) rzeros_float = np.array([0.08 + 0.01 * i for i in xrange(15)]) rzeros = ['{0:.2f}'.format(0.08 + 0.01 * i) for i in xrange(15)] # always want the rzero one above so that we underestimate it # note that this also implies that we want a dc component for e0 in # addition to e1 and e2 rzero_i = np.searchsorted(rzeros_float, rzero) rzero_key = rzeros[rzero_i] model['rzero'] = rzero # get the PSF_Interpolator PSF_Interpolator = Mesh_Interpolator(mesh_name=params['mesh_name'], directory=params['mesh_directory']) if params['analytic']: PSF_Evaluator = Zernike_Evaluator(*np.load(params['analytic_coeffs']).item()[rzero_key]) WF = DECAM_Analytic_Wavefront(rzero=rzero, PSF_Interpolator=PSF_Interpolator, PSF_Evaluator=PSF_Evaluator, num_bins=params['num_bins'], model=model) else: WF = DECAM_Model_Wavefront(PSF_Interpolator=PSF_Interpolator, num_bins=params['num_bins'], model=model) misalignment = translate_misalignment_to_arguments({}) # fix some keys pop_keys = ['rzero', 'delta1', 'delta2', 'zeta1', 'zeta2'] for pop_key in pop_keys: _ = misalignment.pop(pop_key) if skip_fit: return WF minuit, chi2, plane = do_fit(WF, misalignment=misalignment, verbose=params['verbose'], weights=weights) return minuit, chi2, plane, WF
# data wavefront will be either analytic or decam_model_wavefront with a model # paraemter passed in that is the data of the assessed fits files if __name__ == '__main__': import matplotlib.pyplot as plt from WavefrontPSF.psf_interpolator import Mesh_Interpolator from WavefrontPSF.wavefront import Wavefront from WavefrontPSF.digestor import Digestor from WavefrontPSF.analytic_interpolator import DECAM_Analytic_Wavefront, r0_guess from WavefrontPSF.donutengine import DECAM_Model_Wavefront model = Digestor().digest_directory( '/Users/cpd/Projects/WavefrontPSF/meshes/00253794/', file_type='_selpsfcat.fits') # guess rzero model['rzero'] = r0_guess(model['e0'].min()) mesh_directory = '/Users/cpd/Projects/WavefrontPSF/meshes/Science-20140212s2-v1i2' mesh_name = 'Science-20140212s2-v1i2_All' PSF_Interpolator = Mesh_Interpolator(mesh_name=mesh_name, directory=mesh_directory) #from astropy.stats import mad_std WF = DECAM_Model_Wavefront(PSF_Interpolator=PSF_Interpolator, num_bins=1, model=model)#, reducer=mad_std) # WF.plot_field('e0') # naieve = WF(WF.data) # WF.plot_colormap(naieve, 'x', 'y', 'e0', num_bins=1)