-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmiscellaneous.py
More file actions
58 lines (48 loc) · 1.94 KB
/
Copy pathmiscellaneous.py
File metadata and controls
58 lines (48 loc) · 1.94 KB
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
# -*- coding: utf-8 -*-
import numpy as N
from PIL import Image
from matplotlib import pyplot as P
from colormaps import CustomColormaps
def display_density_histogram(density, percentile=0.5):
flat_d = N.sort(density.reshape(density.shape[0] * density.shape[1]))
P.figure()
b, e, coll = P.hist(N.log10(flat_d), density=True, cumulative=True, bins=500, log=True, weights=flat_d)
drop_rho = percentile / 100.0
dmin = e[:-1][b > drop_rho][0]
print("Densitéminimum : dens_min = {dmin:g} ; log(dens_min) = {ldmin:g}".format(dmin=10.0 ** dmin, ldmin=dmin))
xmin, xmax = P.xlim()
ymin, ymax = P.ylim()
P.plot([xmin, dmin], [drop_rho, drop_rho], 'k--')
P.plot([dmin, dmin], [ymin, drop_rho], 'k--')
P.plot([dmin, ], [drop_rho, ], 'r.')
P.xlabel("$log_{10}$(valeur du pixel de densité)")
P.title("Histogramme cumulé des valeurs de la carte de densité")
P.ylabel("cumul des valeurs des pixels")
P.xlim(xmin, xmax)
P.ylim(ymin, ymax)
return dmin
def display_thresholded_density_map(density, dmin):
P.figure()
P.imshow(N.log10(density.T), cmap=CustomColormaps.get_cmap("Viridis_dark"), vmin=dmin, origin="lower")
P.colorbar()
P.title("Carte de densité d'Extreme Horizon")
P.tight_layout()
def value_range(arr, drop_percentile=1.0):
values = N.sort(arr[arr > 0.0])
weights = (values - values[0]) / (values[-1] - values[0])
cumval = N.cumsum(weights)
cumval /= cumval[-1]
mask = (cumval >= drop_percentile/100.0)
vmin = values[mask][0]
return vmin, values[-1]
def pil_img(a, amin, cmap_name):
cmap = CustomColormaps.get_cmap(cmap_name)
lamin = N.log10(amin)
la = N.log10(a.T)
la[la < lamin] = lamin
lamax = la.max()
a_arr = (la-lamin)/(lamax-lamin)
ima_arr = N.clip(cmap(a_arr)*255.0, 0, 255).astype('uint8')
ima = Image.fromarray(ima_arr[:, :, :3], "RGB").transpose(Image.FLIP_TOP_BOTTOM)
return ima
__all__ = ["value_range", "pil_img"]