mimical 0.0.9__tar.gz → 0.1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {mimical-0.0.9 → mimical-0.1.1}/PKG-INFO +2 -2
- {mimical-0.0.9 → mimical-0.1.1}/README.md +1 -1
- {mimical-0.0.9 → mimical-0.1.1}/mimical/fitting/fitter.py +14 -8
- mimical-0.1.1/mimical/plotting/plotting.py +165 -0
- {mimical-0.0.9 → mimical-0.1.1}/mimical.egg-info/PKG-INFO +2 -2
- {mimical-0.0.9 → mimical-0.1.1}/setup.py +1 -1
- mimical-0.0.9/mimical/plotting/plotting.py +0 -87
- {mimical-0.0.9 → mimical-0.1.1}/mimical/__init__.py +0 -0
- {mimical-0.0.9 → mimical-0.1.1}/mimical/fitting/__init__.py +0 -0
- {mimical-0.0.9 → mimical-0.1.1}/mimical/fitting/prior_handler.py +0 -0
- {mimical-0.0.9 → mimical-0.1.1}/mimical/plotting/__init__.py +0 -0
- {mimical-0.0.9 → mimical-0.1.1}/mimical/utils/__init__.py +0 -0
- {mimical-0.0.9 → mimical-0.1.1}/mimical/utils/filter_set.py +0 -0
- {mimical-0.0.9 → mimical-0.1.1}/mimical.egg-info/SOURCES.txt +0 -0
- {mimical-0.0.9 → mimical-0.1.1}/mimical.egg-info/dependency_links.txt +0 -0
- {mimical-0.0.9 → mimical-0.1.1}/mimical.egg-info/requires.txt +0 -0
- {mimical-0.0.9 → mimical-0.1.1}/mimical.egg-info/top_level.txt +0 -0
- {mimical-0.0.9 → mimical-0.1.1}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mimical
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.1.1
|
|
4
4
|
Summary: Intesity modelling of multiply-imaged objects
|
|
5
5
|
Author: Struan Stevenson
|
|
6
6
|
Author-email: struan.stevenson@ed.ac.uk
|
|
@@ -17,7 +17,7 @@ Dynamic: description-content-type
|
|
|
17
17
|
Dynamic: requires-dist
|
|
18
18
|
Dynamic: summary
|
|
19
19
|
|
|
20
|
-
# Mimical (Modelling the Intensity of Multiply-Imaged
|
|
20
|
+
# Mimical (Modelling the Intensity of Multiply-Imaged Celestial Ancient Light)
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
#### Mimical is an intensity modelling code for multiply-imaged objects, performing simultaenous Bayseian inference of model parameters via the nested sampling algorithm. Mimical supports any astropy model, and supports user defined parameter polynomial depenency with image wavelength.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Mimical (Modelling the Intensity of Multiply-Imaged
|
|
1
|
+
# Mimical (Modelling the Intensity of Multiply-Imaged Celestial Ancient Light)
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
#### Mimical is an intensity modelling code for multiply-imaged objects, performing simultaenous Bayseian inference of model parameters via the nested sampling algorithm. Mimical supports any astropy model, and supports user defined parameter polynomial depenency with image wavelength.
|
|
@@ -161,10 +161,11 @@ class mimical(object):
|
|
|
161
161
|
self.success = True
|
|
162
162
|
self.samples = pd.read_csv(dir_path+'/mimical/posteriors' + f'/{self.id}.txt', delimiter=' ').to_numpy()
|
|
163
163
|
fit_dic = dict(zip((np.array((list(self.fitter_prior.keys)))+"_50").tolist(), np.median(self.samples, axis=0).tolist()))
|
|
164
|
-
print("
|
|
164
|
+
print(f"Loading existing posterior at " + dir_path + '/mimical/posteriors' + f'/{self.id}.txt')
|
|
165
165
|
print(" ")
|
|
166
166
|
return fit_dic
|
|
167
167
|
|
|
168
|
+
|
|
168
169
|
# Run sampler
|
|
169
170
|
t0 = time.time()
|
|
170
171
|
#sampler = Sampler(self.fitter_prior, self.lnlike, n_live=400, filepath= dir_path+'/bogout'+f'/{self.id}.hdf5', resume=True, pool=self.pool)
|
|
@@ -184,7 +185,7 @@ class mimical(object):
|
|
|
184
185
|
|
|
185
186
|
# Plot and save the corner plot
|
|
186
187
|
corner.corner(points, weights=np.exp(log_w), bins=20, labels=np.array(self.fitter_prior.keys), color='purple', plot_datapoints=False, range=np.repeat(0.999, len(self.fitter_prior.keys)))
|
|
187
|
-
plt.savefig(dir_path+'/mimical/plots' + f'/
|
|
188
|
+
plt.savefig(dir_path+'/mimical/plots' + f'/{self.id}_corner.pdf', bbox_inches='tight')
|
|
188
189
|
|
|
189
190
|
# Sample an appropriately weighted posterior for representative samples.
|
|
190
191
|
n_post = 10000
|
|
@@ -196,18 +197,23 @@ class mimical(object):
|
|
|
196
197
|
# Return the median-parameter model
|
|
197
198
|
fit_dic = dict(zip((np.array((list(self.fitter_prior.keys)))+"_50").tolist(), np.median(self.samples, axis=0).tolist()))
|
|
198
199
|
|
|
199
|
-
print("
|
|
200
|
+
print("Sampling finished successfully.")
|
|
200
201
|
print(" ")
|
|
201
202
|
|
|
202
203
|
return fit_dic
|
|
203
204
|
|
|
204
205
|
|
|
205
|
-
def plot_model(self):
|
|
206
|
+
def plot_model(self, type='median'):
|
|
206
207
|
if self.success != True:
|
|
207
|
-
print(f'
|
|
208
|
+
print(f'Sampling failed, cannot plot model for {self.id}.')
|
|
208
209
|
else:
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
210
|
+
if type=='median':
|
|
211
|
+
# Plot and save the median-parameter fit
|
|
212
|
+
Plotter().plot_median(self.images, self.wavs, self.convolved_models, self.samples, list(self.fitter_prior.keys), self.prior_handler, self.filter_names)
|
|
213
|
+
plt.savefig(dir_path+'/mimical/plots' + f'/{self.id}_median_model.pdf', bbox_inches='tight')
|
|
214
|
+
elif type=='median-param':
|
|
215
|
+
# Plot and save the median-parameter fit
|
|
216
|
+
Plotter().plot_median_param(self.images, self.wavs, self.convolved_models, self.samples, list(self.fitter_prior.keys), self.prior_handler, self.filter_names)
|
|
217
|
+
plt.savefig(dir_path+'/mimical/plots' + f'/{self.id}_median_param_model.pdf', bbox_inches='tight')
|
|
212
218
|
|
|
213
219
|
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import matplotlib.pyplot as plt
|
|
2
|
+
import numpy as np
|
|
3
|
+
from astropy.convolution.utils import discretize_model
|
|
4
|
+
from tqdm import tqdm
|
|
5
|
+
from matplotlib import ticker
|
|
6
|
+
|
|
7
|
+
class Plotter(object):
|
|
8
|
+
|
|
9
|
+
def plot_median_param(self, images, wavs, convolved_models, samples, fitter_keys, prior_handler, filter_names):
|
|
10
|
+
|
|
11
|
+
fig = plt.figure()
|
|
12
|
+
gs = fig.add_gridspec(nrows=4, ncols=images.shape[0]+1, width_ratios=np.append(np.ones(images.shape[0]), 0.25))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
# Get median Nautilus parameters and transalte into median model parameters.
|
|
16
|
+
param_dict = dict(zip(fitter_keys, np.median(samples, axis=0)))
|
|
17
|
+
pars = prior_handler.revert(param_dict, wavs)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
models = np.zeros_like(images)
|
|
21
|
+
for i in range(len(wavs)):
|
|
22
|
+
convolved_models[i].parameters = pars[i]
|
|
23
|
+
model = discretize_model(model=convolved_models[i],
|
|
24
|
+
x_range=[0,images[i].shape[1]],
|
|
25
|
+
y_range=[0,images[i].shape[0]],
|
|
26
|
+
mode='center')
|
|
27
|
+
models[i]=model
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
residuals = images - models
|
|
31
|
+
|
|
32
|
+
vmins = [-np.percentile(images.flatten(), q=95), -np.percentile(images.flatten(), q=95), -np.percentile(images.flatten(), q=95), min(np.percentile(residuals.flatten(), q=5), -np.percentile(residuals.flatten(), q=95))]
|
|
33
|
+
vmaxs = [np.percentile(images.flatten(), q=95), np.percentile(images.flatten(), q=95), np.percentile(images.flatten(), q=95), max(-np.percentile(residuals.flatten(), q=5), np.percentile(residuals.flatten(), q=95))]
|
|
34
|
+
cmaps = ['binary', 'binary', 'RdGy']
|
|
35
|
+
|
|
36
|
+
ax = fig.add_subplot(gs[0, 0])
|
|
37
|
+
ax.set_axis_off()
|
|
38
|
+
im1 = ax.pcolormesh(np.zeros_like(images[0]), vmax=vmaxs[0], vmin=vmins[0], cmap='RdGy')
|
|
39
|
+
cbarax1 = fig.add_subplot(gs[:3, -1])
|
|
40
|
+
cbarax1.set_yticks([])
|
|
41
|
+
cbarax1.set_xticks([])
|
|
42
|
+
cbar1 = plt.colorbar(im1, cax=cbarax1, fraction=1)
|
|
43
|
+
tick_locator = ticker.MaxNLocator(nbins=5)
|
|
44
|
+
cbar1.locator = tick_locator
|
|
45
|
+
cbar1.update_ticks()
|
|
46
|
+
|
|
47
|
+
im2 = ax.pcolormesh(np.zeros_like(images[0]), vmax=vmaxs[-1], vmin=vmins[-1], cmap='RdGy')
|
|
48
|
+
cbarax2 = fig.add_subplot(gs[3, -1])
|
|
49
|
+
cbarax2.set_yticks([])
|
|
50
|
+
cbarax2.set_xticks([])
|
|
51
|
+
cbar2 = plt.colorbar(im2, cax=cbarax2, fraction=1)
|
|
52
|
+
tick_locator = ticker.MaxNLocator(nbins=3)
|
|
53
|
+
cbar2.locator = tick_locator
|
|
54
|
+
cbar2.update_ticks()
|
|
55
|
+
|
|
56
|
+
for i in range(len(wavs)):
|
|
57
|
+
|
|
58
|
+
plotims = [images[i], models[i], residuals[i], residuals[i]]
|
|
59
|
+
|
|
60
|
+
for j in range(4):
|
|
61
|
+
|
|
62
|
+
ax = fig.add_subplot(gs[j, i])
|
|
63
|
+
im = ax.pcolormesh(plotims[j], vmax=vmaxs[j], vmin=vmins[j], cmap='RdGy')
|
|
64
|
+
ax.set_yticks([])
|
|
65
|
+
ax.set_xticks([])
|
|
66
|
+
|
|
67
|
+
if j==0:
|
|
68
|
+
ax.set_title(filter_names[i].upper())
|
|
69
|
+
|
|
70
|
+
if i==0:
|
|
71
|
+
if j==0:
|
|
72
|
+
ax.set_ylabel('Data')
|
|
73
|
+
if j==1:
|
|
74
|
+
ax.set_ylabel('Best\nModel')
|
|
75
|
+
if j==2:
|
|
76
|
+
ax.set_ylabel('Residual')
|
|
77
|
+
if j==3:
|
|
78
|
+
ax.set_ylabel('Residual\nZoom')
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
plt.subplots_adjust(hspace=0.1, wspace=0.1)
|
|
82
|
+
fig.set_size_inches(images.shape[0],4, forward=True)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def plot_median(self, images, wavs, convolved_models, samples, fitter_keys, prior_handler, filter_names):
|
|
89
|
+
|
|
90
|
+
fig = plt.figure()
|
|
91
|
+
gs = fig.add_gridspec(nrows=4, ncols=images.shape[0]+1, width_ratios=np.append(np.ones(images.shape[0]), 0.25))
|
|
92
|
+
|
|
93
|
+
models = np.zeros((samples.shape[0], *images.shape))
|
|
94
|
+
|
|
95
|
+
print("Computing median model image...")
|
|
96
|
+
for j in tqdm(range(samples.shape[0])):
|
|
97
|
+
# Get median Nautilus parameters and transalte into median model parameters.
|
|
98
|
+
param_dict = dict(zip(fitter_keys, samples[j]))
|
|
99
|
+
pars = prior_handler.revert(param_dict, wavs)
|
|
100
|
+
|
|
101
|
+
for k in range(len(wavs)):
|
|
102
|
+
convolved_models[k].parameters = pars[k]
|
|
103
|
+
model = discretize_model(model=convolved_models[k],
|
|
104
|
+
x_range=[0,images[k].shape[1]],
|
|
105
|
+
y_range=[0,images[k].shape[0]],
|
|
106
|
+
mode='center')
|
|
107
|
+
models[j,k] = model
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
models = np.median(models, axis=0)
|
|
111
|
+
residuals = images - models
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
vmins = [-np.percentile(images.flatten(), q=95), -np.percentile(images.flatten(), q=95), -np.percentile(images.flatten(), q=95), min(np.percentile(residuals.flatten(), q=5), -np.percentile(residuals.flatten(), q=95))]
|
|
115
|
+
vmaxs = [np.percentile(images.flatten(), q=95), np.percentile(images.flatten(), q=95), np.percentile(images.flatten(), q=95), max(-np.percentile(residuals.flatten(), q=5), np.percentile(residuals.flatten(), q=95))]
|
|
116
|
+
cmaps = ['binary', 'binary', 'RdGy']
|
|
117
|
+
|
|
118
|
+
ax = fig.add_subplot(gs[0, 0])
|
|
119
|
+
ax.set_axis_off()
|
|
120
|
+
im1 = ax.pcolormesh(np.zeros_like(images[0]), vmax=vmaxs[0], vmin=vmins[0], cmap='RdGy')
|
|
121
|
+
cbarax1 = fig.add_subplot(gs[:3, -1])
|
|
122
|
+
cbarax1.set_yticks([])
|
|
123
|
+
cbarax1.set_xticks([])
|
|
124
|
+
cbar1 = plt.colorbar(im1, cax=cbarax1, fraction=1)
|
|
125
|
+
tick_locator = ticker.MaxNLocator(nbins=5)
|
|
126
|
+
cbar1.locator = tick_locator
|
|
127
|
+
cbar1.update_ticks()
|
|
128
|
+
|
|
129
|
+
im2 = ax.pcolormesh(np.zeros_like(images[0]), vmax=vmaxs[-1], vmin=vmins[-1], cmap='RdGy')
|
|
130
|
+
cbarax2 = fig.add_subplot(gs[3, -1])
|
|
131
|
+
cbarax2.set_yticks([])
|
|
132
|
+
cbarax2.set_xticks([])
|
|
133
|
+
cbar2 = plt.colorbar(im2, cax=cbarax2, fraction=1)
|
|
134
|
+
tick_locator = ticker.MaxNLocator(nbins=3)
|
|
135
|
+
cbar2.locator = tick_locator
|
|
136
|
+
cbar2.update_ticks()
|
|
137
|
+
|
|
138
|
+
for i in range(len(wavs)):
|
|
139
|
+
|
|
140
|
+
plotims = [images[i], models[i], residuals[i], residuals[i]]
|
|
141
|
+
|
|
142
|
+
for j in range(4):
|
|
143
|
+
|
|
144
|
+
ax = fig.add_subplot(gs[j, i])
|
|
145
|
+
im = ax.pcolormesh(plotims[j], vmax=vmaxs[j], vmin=vmins[j], cmap='RdGy')
|
|
146
|
+
ax.set_yticks([])
|
|
147
|
+
ax.set_xticks([])
|
|
148
|
+
|
|
149
|
+
if j==0:
|
|
150
|
+
ax.set_title(filter_names[i].upper())
|
|
151
|
+
|
|
152
|
+
if i==0:
|
|
153
|
+
if j==0:
|
|
154
|
+
ax.set_ylabel('Data')
|
|
155
|
+
if j==1:
|
|
156
|
+
ax.set_ylabel('Median\nModel')
|
|
157
|
+
if j==2:
|
|
158
|
+
ax.set_ylabel('Residual')
|
|
159
|
+
if j==3:
|
|
160
|
+
ax.set_ylabel('Residual\nZoom')
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
plt.subplots_adjust(hspace=0.1, wspace=0.1)
|
|
164
|
+
fig.set_size_inches(images.shape[0],4, forward=True)
|
|
165
|
+
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mimical
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.1.1
|
|
4
4
|
Summary: Intesity modelling of multiply-imaged objects
|
|
5
5
|
Author: Struan Stevenson
|
|
6
6
|
Author-email: struan.stevenson@ed.ac.uk
|
|
@@ -17,7 +17,7 @@ Dynamic: description-content-type
|
|
|
17
17
|
Dynamic: requires-dist
|
|
18
18
|
Dynamic: summary
|
|
19
19
|
|
|
20
|
-
# Mimical (Modelling the Intensity of Multiply-Imaged
|
|
20
|
+
# Mimical (Modelling the Intensity of Multiply-Imaged Celestial Ancient Light)
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
#### Mimical is an intensity modelling code for multiply-imaged objects, performing simultaenous Bayseian inference of model parameters via the nested sampling algorithm. Mimical supports any astropy model, and supports user defined parameter polynomial depenency with image wavelength.
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import matplotlib.pyplot as plt
|
|
2
|
-
import numpy as np
|
|
3
|
-
from astropy.convolution.utils import discretize_model
|
|
4
|
-
from tqdm import tqdm
|
|
5
|
-
|
|
6
|
-
class Plotter(object):
|
|
7
|
-
|
|
8
|
-
def plot_best(self, images, wavs, convolved_models, samples, fitter_keys, prior_handler):
|
|
9
|
-
|
|
10
|
-
fig,axes=plt.subplots(3, images.shape[0], figsize=(images.shape[0],3))
|
|
11
|
-
|
|
12
|
-
# Get median Nautilus parameters and transalte into median model parameters.
|
|
13
|
-
param_dict = dict(zip(fitter_keys, np.median(samples, axis=0)))
|
|
14
|
-
pars = prior_handler.revert(param_dict, wavs)
|
|
15
|
-
|
|
16
|
-
for i in range(len(wavs)):
|
|
17
|
-
convolved_models[i].parameters = pars[i]
|
|
18
|
-
model = discretize_model(model=convolved_models[i],
|
|
19
|
-
x_range=[0,images[i].shape[1]],
|
|
20
|
-
y_range=[0,images[i].shape[0]],
|
|
21
|
-
mode='center')
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
v = np.percentile(images[-1], 99.9)
|
|
25
|
-
|
|
26
|
-
axes[0,i].imshow(images[i], vmax=v, vmin=-v)
|
|
27
|
-
axes[0,i].set_axis_off()
|
|
28
|
-
|
|
29
|
-
axes[1,i].imshow(model, vmax=v, vmin=-v)
|
|
30
|
-
axes[1,i].set_axis_off()
|
|
31
|
-
|
|
32
|
-
axes[2,i].imshow(images[i]-model, vmax=v, vmin=-v)
|
|
33
|
-
axes[2,i].set_axis_off()
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
def plot_median(self, images, wavs, convolved_models, samples, fitter_keys, prior_handler):
|
|
37
|
-
|
|
38
|
-
fig,axes=plt.subplots(3, images.shape[0], figsize=(images.shape[0],3))
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
models = np.zeros((samples.shape[0], *images.shape))
|
|
42
|
-
|
|
43
|
-
print("Computing median model image...")
|
|
44
|
-
for j in tqdm(range(samples.shape[0])):
|
|
45
|
-
# Get median Nautilus parameters and transalte into median model parameters.
|
|
46
|
-
param_dict = dict(zip(fitter_keys, samples[j]))
|
|
47
|
-
pars = prior_handler.revert(param_dict, wavs)
|
|
48
|
-
|
|
49
|
-
for k in range(len(wavs)):
|
|
50
|
-
convolved_models[k].parameters = pars[k]
|
|
51
|
-
model = discretize_model(model=convolved_models[k],
|
|
52
|
-
x_range=[0,images[k].shape[1]],
|
|
53
|
-
y_range=[0,images[k].shape[0]],
|
|
54
|
-
mode='center')
|
|
55
|
-
models[j,k] = model
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
median_models = np.median(models, axis=0)
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
if len(wavs)==1:
|
|
62
|
-
for i in range(len(wavs)):
|
|
63
|
-
v = np.percentile(images[-1], 99.9)
|
|
64
|
-
|
|
65
|
-
axes[0].imshow(images[i], vmax=v, vmin=-v)
|
|
66
|
-
axes[0].set_axis_off()
|
|
67
|
-
|
|
68
|
-
axes[1].imshow(median_models[i], vmax=v, vmin=-v)
|
|
69
|
-
axes[1].set_axis_off()
|
|
70
|
-
|
|
71
|
-
axes[2].imshow(images[i]-median_models[i], vmax=v, vmin=-v)
|
|
72
|
-
axes[2].set_axis_off()
|
|
73
|
-
|
|
74
|
-
else:
|
|
75
|
-
for i in range(len(wavs)):
|
|
76
|
-
|
|
77
|
-
v = np.percentile(images[-1], 99.9)
|
|
78
|
-
|
|
79
|
-
axes[0,i].imshow(images[i], vmax=v, vmin=-v)
|
|
80
|
-
axes[0,i].set_axis_off()
|
|
81
|
-
|
|
82
|
-
axes[1,i].imshow(median_models[i], vmax=v, vmin=-v)
|
|
83
|
-
axes[1,i].set_axis_off()
|
|
84
|
-
|
|
85
|
-
axes[2,i].imshow(images[i]-median_models[i], vmax=v, vmin=-v)
|
|
86
|
-
axes[2,i].set_axis_off()
|
|
87
|
-
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|