Skip to content

Commit 38a85e6

Browse files
committed
cclosure clipping exception bug
1 parent e148c3e commit 38a85e6

File tree

3 files changed

+62
-3
lines changed

3 files changed

+62
-3
lines changed

closig/expansion.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def _covector(pt, ptau):
188188
def clip_cclosures(p_range, basis, cclosures, axis=0):
189189
# returns basis and cclosures array clipped to p_range of acquisitions
190190
# axis: axis of cclosures spanning elements of closure basis
191-
if p_range[0] > basis.P or p_range[1] > basis.P or p_range[0] <=0:
191+
if p_range[0] > basis.P or p_range[1] > basis.P or p_range[0] <0:
192192
raise ValueError("Invalid p_range")
193193
P_clip = p_range[1] - p_range[0]
194194
basis_clip = type(basis)(P_clip)

closig/visualization/triangle.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,6 @@ def triangle_plot(
9494
_cbar = plt.colorbar(im, ax=ax, cax=cax, ticks=[vabs, 0, -vabs])
9595
_cbar.solids.set_rasterized(True)
9696
_cbar.solids.set_edgecolor('face')
97-
return ax
97+
return ax, _cbar
98+
else:
99+
return ax

scripts/speckle_triangle_plot.py

+58-1
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,67 @@ def speckle_plot(fnout=None):
6262
if fnout is None:
6363
plt.show()
6464
else:
65-
fig.savefig(fnout)
65+
fig.savefig(fnout, dpi=450)
66+
67+
def speckle_bias_plot(fnout=None):
68+
from matplotlib.cm import ScalarMappable
69+
from matplotlib.colors import Normalize
70+
71+
P = 91
72+
P_year = 30
73+
N_samples = 1024
74+
L = 169
75+
xticks_year = (0, 1, 2, 3)
76+
model = model_catalog('decorrsoil', P_year=P_year, band='C')
77+
ylabels = [
78+
('small step', '$\\tau$ [yr]'), ('two hop', '$ \\tau$ [yr]')]
79+
aspect = 0.75
80+
triangleparms = [
81+
(180, cmap_cyclic, ['$-\\pi$', '0', '$\\pi$']),
82+
(45, cmap_clipped, ['$-\\pi/4$', '0', '$\\pi/4$'])]
83+
fig, axs = prepare_figure(
84+
nrows=2, ncols=1, figsize=(0.85, 0.66), sharey='row', sharex='col', top=0.98, left=0.07,
85+
wspace=0.20, hspace=0.16, bottom=0.17, right=0.90)
86+
for ax in axs.flatten():
87+
ax.set_box_aspect(aspect)
88+
extent = (0, (P + 1) / P_year) * 2
89+
90+
ex = CutOffExperiment(model, dps=[P_year], P=P, P_year=P_year)
91+
C_obs = ex.observed_covariance((N_samples,), L, seed=98765)
92+
93+
for jBasis, Basis in enumerate((SmallStepBasis, TwoHopBasis)):
94+
basis = Basis(P)
95+
cclosures = basis.evaluate_covariance(C_obs, compl=True)
96+
cclosures_m = np.mean(cclosures, axis=1)
97+
triangle_plot(
98+
basis, cclosures_m, ax=axs[jBasis], show_xticklabels=False, extent=extent,
99+
show_yticklabels=True, vabs=triangleparms[0][0], cmap=triangleparms[0][1], cbar=False,
100+
aspect=aspect, ticks=xticks_year, ticklabels=xticks_year)
101+
ax = axs[-1]
102+
ax.set_xticklabels(xticks_year)
103+
ax.text(0.5, -0.35, '$t$ [yr]', ha='center', va='baseline', transform=ax.transAxes)
104+
for jax, ax in enumerate(axs):
105+
ylabell, ylabelr = ylabels[jax]
106+
ax.text(-0.37, 0.50, ylabell, ha='right', va='center', transform=ax.transAxes, rotation=90)
107+
ax.text(-0.22, 0.50, ylabelr, ha='right', va='center', transform=ax.transAxes, rotation=90)
108+
cax_limits = [1.17, 0.1, 0.10, 0.80]
109+
for jax, ax in enumerate(axs):
110+
cax = ax.inset_axes(cax_limits)
111+
vabs = triangleparms[jax][0] / 180 * np.pi
112+
cbar = plt.colorbar(
113+
ScalarMappable(norm=Normalize(vmin=-vabs, vmax=vabs), cmap=triangleparms[jax][1]), cax,
114+
shrink=0.5, orientation='vertical', ticks=[-vabs, 0, vabs])
115+
cbar.set_ticklabels(triangleparms[jax][2])
116+
if fnout is None:
117+
plt.show()
118+
else:
119+
fig.savefig(fnout, dpi=450)
66120

67121
if __name__ == '__main__':
68122

69123
pathfig = Path('/home/simon/Work/closig/figures')
70124
fnout = pathfig / 'triangle_speckle.pdf'
71125
speckle_plot(fnout)
126+
127+
fnout = pathfig / 'triangle_speckle_mean.pdf'
128+
# speckle_bias_plot(fnout)

0 commit comments

Comments
 (0)