def __init__(self, g_parameters, image_renderer, snr):
        self.g_parameters = g_parameters
        self.snr = snr
        self.model = galfun.getGalaxiesModels(g_parameters=self.g_parameters)
        self.image_renderer = image_renderer

        #we do not want to mask or crop the images used to obtain the partials. 
        self.image_renderer_partials = galfun.ImageRenderer(stamp=self.image_renderer.stamp)
        self.image = self.image_renderer.getImage(self.model)
        _, self.var_noise = galfun.addNoise(self.image, self.snr, 0)

        self.steps = defaults.getSteps(self.g_parameters, self.image_renderer)
        self.param_names = g_parameters.ordered_fit_names
        self.num_params = len(self.param_names)
        self.num_galaxies = self.g_parameters.num_galaxies

        self.derivatives_images = self.derivativesImages()
        self.second_derivatives_images = self.secondDerivativesImages()
        self.fisher_matrix_images = self.fisherMatrixImages()
        self.fisher_matrix = self.fisherMatrix()
        self.covariance_matrix = self.covarianceMatrix()
        self.correlation_matrix = self.correlationMatrix()
        self.bias_matrix_images = self.biasMatrixImages()
        self.bias_matrix = self.biasMatrix()
        self.bias_images = self.biasImages()
        self.biases = self.getBiases()

        self.fisher_condition_number = self.fisherConditionNumber()
def main(argv):
    current_fit_number, snr, project, existing_fits = (
        int(argv[1]), float(argv[2]), argv[3], int(argv[4]))

    noise_seed = current_fit_number + existing_fits

    if not os.path.isdir(os.path.join(project, defaults.RESULTS_DIR)):
        os.mkdir(os.path.join(project, defaults.RESULTS_DIR))

    g_parameters = galfun.GParameters(project)
    image_renderer = galfun.ImageRenderer(pixel_scale=defaults.PIXEL_SCALE,nx=defaults.NX,ny=defaults.NY)
    fish = fisher.Fisher(g_parameters=g_parameters,image_renderer=image_renderer, snr=snr)
    orig_image = deepcopy(fish.image)
    mins = defaults.getMinimums(g_parameters, orig_image)
    maxs = defaults.getMaximums(g_parameters, orig_image)
    init_values = defaults.getInitialValuesFit(g_parameters)
    nfit_params = g_parameters.nfit_params
    noisy_image, variance_noise = galfun.addNoise(orig_image, snr, noise_seed)

    fit_params = lmfit.Parameters()
    for param in g_parameters.fit_params:
        fit_params.add(param,
                       value=init_values[param],
                       min=mins[param],
                       max=maxs[param])

    results = lmfit.minimize(objFunc, fit_params, kws=dict(image_renderer=image_renderer,
                                                           data=noisy_image,
                                                           variance_noise=(variance_noise),
                                                           **nfit_params))
    

    filename = ''.join([defaults.RESULTS_DIR, str(noise_seed), '.csv'])
    result_filename = os.path.join(project, defaults.RESULTS_DIR, filename)

    # write results of fits into a file,
    with open(result_filename, 'w') as csvfile:
        row_to_write = fit_params.valuesdict()
        row_to_write['chi2'] = results.chisqr
        row_to_write['success'] = results.success
        row_to_write['errorbars'] = results.errorbars
        row_to_write['nfev'] = results.nfev
        row_to_write['nvarys'] = results.nvarys
        row_to_write['ndata'] = results.ndata
        row_to_write['nfree'] = results.nfree
        row_to_write['redchi'] = results.redchi
        writer = csv.DictWriter(csvfile, fieldnames=row_to_write.keys())
        writer.writeheader()
        writer.writerow(row_to_write)