-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcompute_rca_results.py
71 lines (55 loc) · 1.99 KB
/
compute_rca_results.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Compute RCA solutions for each test case using optimal parameters found by compute_rca_opt_param.py.
"""
import os
import glob
import copy
import numpy as np
from rca import RCA
from rca.utils import rca_format
# Define standard integer sampling grid -wp ... wp
wp = 7
# Common noise level
slct_noise = 1.0
# Paths to data files
rcainpath = 'data/rca_input'
rsltpath = 'data/rca_results'
# Get optimal parameters found via brute-force search
prmfile = os.path.join(rsltpath, 'rca_opt_param.npz')
prm = dict(np.load(prmfile, allow_pickle=True)['results'].item())
# Iterate over test images
for starfile in sorted(glob.glob(os.path.join(rcainpath, 'rca_stars_*.npy'))):
basename = os.path.basename(starfile)
fncmpnt = basename.split('_')
posfile = os.path.join(rcainpath, '_'.join(
(['rca', 'pos'] + fncmpnt[2:])))
shape = fncmpnt[-1][0:-4]
noise = float(fncmpnt[-2][1:])
if noise != slct_noise:
continue
pps = int(fncmpnt[-3][1:])
basename = '%s_d%03d_n%7.1e.npz' % (shape, pps, noise)
rsltfile = os.path.join(rsltpath, basename)
if not os.path.exists(rsltfile):
print('Computing %s' % rsltfile)
stars = np.load(starfile)
pos = np.load(posfile)
optprm = prm[basename]['sprm']
n_comp, ksig, n_scales, ksig_init, psf_size, n_eigenvects = optprm
n_comp = int(n_comp)
n_scales = int(n_scales)
n_eigenvects = int(n_eigenvects)
try:
rca = RCA(n_comp=n_comp, ksig=ksig, n_scales=n_scales,
ksig_init=ksig_init, verbose=0)
S, A = rca.fit(rca_format(stars), pos,
psf_size=psf_size,
n_eigenvects=n_eigenvects)
psf = rca.estimate_psf(pos[0:1]).squeeze()
except:
psf = None
if psf is not None:
np.savez(rsltfile, noise=noise, shape=shape,
pixperstar=pps, optprm=optprm, psf=psf)