def costfunc(x, *args):
    (y, dt, i_deg, phi_deg) = x
    (grad_t, grad_mag_n, t0) = args
    # grad_time
    global nn

    (tmp, grad_disk_fit) = exorings.ring_grad_line(grad_t, y, dt, i_deg, phi_deg)

    # lazy way of calculating the time midpoint of the light curve
    rmintime = np.arange(np.min(grad_t), np.max(grad_t), 0.01)
    (tmp, rminline) = exorings.ring_grad_line(rmintime, y, dt, i_deg, phi_deg)
    rmint = rmintime[np.argmin(rminline)]

    # make a cost function
    delta = grad_disk_fit - grad_mag_n

    # if delta is positive, keep it
    # if delta is negative, make it positive and multiply by 50
    delta[np.where(delta < 0)] = -delta[np.where(delta < 0)] * 50.

    # dean is penalty to clamp rmint
    dean = np.abs(rmint - t0)

    cost = np.sum(delta) + (dean * 20)
    nn += 1
    return cost
dataset/ETHPy150Open mkenworthy/exorings/disk_sim.py/costfunc/original