Closed laldoroty closed 3 months ago
Test code, seems to work.
v1 = np.array([3.12])
v2 = np.array([3.22])
v3 = np.array([3.33])
v4 = np.array([3.1])
vecs = np.hstack([v1,v2,v3,v4])
n = 4
N = int(n*(n-1)/2)
print('N, n:')
print(N, n)
dv1 = v1-v2
dv2 = v1-v3
dv3 = v1-v4
dv4 = v2-v3
dv5 = v2-v4
dv6 = v3-v4
A = np.hstack([dv1,dv2,dv3,dv4,dv5,dv6])
print(A)
print('A shape:')
print(A.shape)
C = np.diagflat([0.1,0.12,0.2,0.14,0.16,0.09])
print('C shape:')
print(C.shape)
i, j = np.triu_indices(n, k=1)
X = np.zeros((N,n))
print('X shape:')
print(X.shape)
np.put_along_axis(X, i[:, None], 1, axis=1)
np.put_along_axis(X, j[:, None], -1, axis=1)
XTCXXT = np.linalg.lstsq(X.T @ np.linalg.inv(C) @ X, X.T, rcond=None)
print('XTCXXT shape')
print(XTCXXT[0].shape)
v = XTCXXT[0] @ np.linalg.inv(C) @ A
print('SOLUTION:')
print(vecs - v)
Output:
SOLUTION:
[3.1925 3.1925 3.1925 3.1925]
@wmwv when you're back from vacation, can you take a look at the above and confirm the right idea is there? Particularly with the solution being an n-length vector instead of a scalar. I expect that for real data, (vecs-v) will not contain all identical values.
I am going to close this issue. I am not working on it and the branch is littered with other stuff. I will re-open a new issue for sorting out the photometry.
Merged to new branch associated with issue #20. Closing.
I think I should rewrite to use Masao's suggested approach, which is: do single-epoch DIA on each image N times, where N is the number of template images. Then, coadd the difference images at the end. So, I would not coadd anything until the very end. It is more computationally expensive, but it builds on code that already works, and I think I'm wasting a lot of time trying to hunt this down. I could also simultaneously rewrite so that I rotate the reference to match the science instead of the other way around (like I'm currently doing).
To make the science image where I get the ZPT (i.e., the science image that's un-subtracted but has been cross-convolved with the reference and the decorrelation kernel applied), I could just make N of these, do photometry on the stars in all N images, and take the median exactly as I was doing before. This also may allow for SFFT on smaller stamp sizes (1K)--the issue with making the stamps smaller was there weren't enough stars in the stamps to get a ZPT. This would multiply the number of stars by N.
Thoughts?
Originally posted by @laldoroty in https://github.com/laldoroty/phrosty/issues/12#issuecomment-2246186857
Then, @wmwv responded:
So, going to rewrite code to use this method. Rewrote code structure plan: https://github.com/Roman-Supernova-PIT/diff-img/discussions/14