Texture

AR_plot(aspect_ratio, size, auto_bins=True, bins=10, geometric=False, min_max=None, manual_lims=False, x_lims=None, y_lims=None, ax=None)

summary

Parameters:
  • aspect_ratio (_type_) –

    description

  • size (_type_) –

    description

  • auto_bins (bool, default: True ) –

    description. Defaults to True.

  • bins (int, default: 10 ) –

    description. Defaults to 10.

  • geometric (bool, default: False ) –

    description. Defaults to False.

  • min_max (_type_, default: None ) –

    description. Defaults to None.

  • manual_lims (bool, default: False ) –

    description. Defaults to False.

  • x_lims (_type_, default: None ) –

    description. Defaults to None.

  • y_lims (_type_, default: None ) –

    description. Defaults to None.

Returns:
  • _type_

    description

Source code in MinDet/Process/texture.py
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
def AR_plot(aspect_ratio, size,auto_bins = True, bins = 10, geometric = False, min_max = None, manual_lims = False, x_lims = None, y_lims = None, ax = None):
    """_summary_

    Args:
        aspect_ratio (_type_): _description_
        size (_type_): _description_
        auto_bins (bool, optional): _description_. Defaults to True.
        bins (int, optional): _description_. Defaults to 10.
        geometric (bool, optional): _description_. Defaults to False.
        min_max (_type_, optional): _description_. Defaults to None.
        manual_lims (bool, optional): _description_. Defaults to False.
        x_lims (_type_, optional): _description_. Defaults to None.
        y_lims (_type_, optional): _description_. Defaults to None.

    Returns:
        _type_: _description_
    """

    #if auto_bins is false, bins should be a set of bins, otherwise just an integer; geometric used to define how bins are generated in automatic

    #manual_lims allows user to define x and y limits themselves, otherwise will be done automatically by matplotlib

    if min_max is None:
        max_val = np.max(size)
        min_val = np.min(size)
    else:
        max_val = min_max[1]
        min_val = min_max[0]


    if auto_bins == True:
        #generate bins
        if geometric == True:
            #generate them geometrically
            b = np.logspace(min_val, max_val, num = bins)
        else:
            #generate linear bins
            b = np.linspace(min_val, max_val, num = bins)
    else:
        b = bins

    aspect_ratio_binned, aspect_ratio_sigma, bin_centres = gen_aspect_ratio_data(size, aspect_ratio, b)
    if ax is not None:
        ax.scatter(bin_centres, aspect_ratio_binned)
        ax.errorbar(bin_centres, aspect_ratio_binned, yerr=aspect_ratio_sigma, fmt = 'o')
        return None
    else:
        fig, ax = plt.subplots(1,1,figsize = (8,8))
        ax.scatter(bin_centres, aspect_ratio_binned)
        ax.errorbar(bin_centres, aspect_ratio_binned, yerr=aspect_ratio_sigma, fmt = 'o')
        return fig, ax

CSD_plot(size, auto_bins=True, bins=10, geometric=False, roi_size=1, min_max=None, manual_lims=False, x_lims=None, y_lims=None, ax=None)

summary

Parameters:
  • size (_type_) –

    description

  • auto_bins (bool, default: True ) –

    description. Defaults to True.

  • bins (int, default: 10 ) –

    description. Defaults to 10.

  • geometric (bool, default: False ) –

    description. Defaults to False.

  • min_max (_type_, default: None ) –

    description. Defaults to None.

  • manual_lims (bool, default: False ) –

    description. Defaults to False.

  • x_lims (_type_, default: None ) –

    description. Defaults to None.

  • y_lims (_type_, default: None ) –

    description. Defaults to None.

Returns:
  • _type_

    description

Source code in MinDet/Process/texture.py
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
def CSD_plot(size,auto_bins = True, bins = 10, geometric = False, roi_size = 1, min_max = None, manual_lims = False, x_lims = None, y_lims = None, ax = None):
    """_summary_

    Args:
        size (_type_): _description_
        auto_bins (bool, optional): _description_. Defaults to True.
        bins (int, optional): _description_. Defaults to 10.
        geometric (bool, optional): _description_. Defaults to False.
        min_max (_type_, optional): _description_. Defaults to None.
        manual_lims (bool, optional): _description_. Defaults to False.
        x_lims (_type_, optional): _description_. Defaults to None.
        y_lims (_type_, optional): _description_. Defaults to None.

    Returns:
        _type_: _description_
    """
    if min_max is None:
        max_val = np.max(size)
        min_val = np.min(size)
    else:
        max_val = min_max[1]
        min_val = min_max[0]


    if auto_bins == True:
        #generate bins
        if geometric == True:
            #generate them geometrically
            b = np.logspace(min_val, max_val, num = bins)
        else:
            #generate linear bins
            b = np.linspace(min_val, max_val, num = bins)
    else:
        b = bins

    counts, bin_edges = np.histogram(size, bins)
    bw = [bin_edges[i+1] - bin_edges[i] for i in range(len(bin_edges)-1)]
    counts_bwNorm = [counts[i]/bw[i] for i in range(len(counts))]

    centres = [0.5*(bin_edges[i]+bin_edges[i+1]) for i in range(len(bin_edges)-1)]

    counts, bin_edges, centres, bw, counts_bwNorm = remove_all_zero_elements(counts, bin_edges, centres, bw, counts_bwNorm)

    if ax is not None:
        ax.scatter(centres,np.log(counts_bwNorm/roi_size))
        return None
    else:
        fig, ax = plt.subplots(1,1,figsize = (8,8))
        ax.scatter(centres,np.log(counts_bwNorm/roi_size))
        ax.set_xlabel(r"Area$^{0.5}$")
        ax.set_ylabel("ln(N / bw)")
        return fig, ax

gen_aspect_ratio_data(size, aspect_ratio, bin_edges)

Generator for aspect ratio data with given bin edges.

Parameters:
  • size (ndarray) –

    description

  • aspect_ratio (ndarray) –

    description

  • bin_edges (ndarray) –

    description

Returns:
  • aspect_ratio_binned

  • aspect_ratio_sigma

  • bin_centres

Source code in MinDet/Process/texture.py
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
def gen_aspect_ratio_data(size, aspect_ratio, bin_edges):
    """Generator for aspect ratio data with given bin edges.

    Args:
        size (ndarray): _description_
        aspect_ratio (ndarray): _description_
        bin_edges (ndarray): _description_

    Returns:
        aspect_ratio_binned
        aspect_ratio_sigma
        bin_centres
    """

    aspect_ratio_binned = []
    aspect_ratio_sigma = []
    bin_centres = []

    for i in range(len(bin_edges)-1):
        n = i+1

        above_lower_edge = size >= bin_edges[i]
        new_size = size[above_lower_edge]
        new_aspect = np.asarray(aspect_ratio)[above_lower_edge]

        below_upper = new_size < bin_edges[n]
        binned_aspect = new_aspect[below_upper]

        aspect_ratio_binned.append(np.mean(binned_aspect))
        aspect_ratio_sigma.append(np.std(binned_aspect))
        bin_centres.append(0.5*(bin_edges[i]+bin_edges[n]))

    return aspect_ratio_binned, aspect_ratio_sigma, bin_centres

remove_all_zero_elements(counts, bins, bin_centres, bw, counts_bwNorm)

summary

Parameters:
  • counts (_type_) –

    description

  • bins (_type_) –

    description

  • bin_centres (_type_) –

    description

  • bw (_type_) –

    description

  • counts_bwNorm (_type_) –

    description

Returns:
  • _type_

    description

Source code in MinDet/Process/texture.py
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
def remove_all_zero_elements(counts, bins, bin_centres, bw, counts_bwNorm):
    """_summary_

    Args:
        counts (_type_): _description_
        bins (_type_): _description_
        bin_centres (_type_): _description_
        bw (_type_): _description_
        counts_bwNorm (_type_): _description_

    Returns:
        _type_: _description_
    """
    bins = np.asarray(bins)
    counts = np.asarray(counts)
    new_bins = bins[:bins.shape[0]-1]
    index = counts >0

    new_bins = new_bins[index]
    counts = counts[index]
    bin_centres = np.asarray(bin_centres)
    bin_centres = bin_centres[index]
    bw = np.asarray(bw)
    bw = bw[index]
    counts_bwNorm = np.asarray(counts_bwNorm)
    counts_bwNorm = counts_bwNorm[index]

    return counts, new_bins, bin_centres, bw, counts_bwNorm

remove_zero_elements(counts, bins, bin_centres=None)

summary

Parameters:
  • counts (_type_) –

    description

  • bins (_type_) –

    description

  • bin_centres (_type_, default: None ) –

    description. Defaults to None.

Returns:
  • _type_

    description

Source code in MinDet/Process/texture.py
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
def remove_zero_elements(counts, bins, bin_centres = None):
    """_summary_

    Args:
        counts (_type_): _description_
        bins (_type_): _description_
        bin_centres (_type_, optional): _description_. Defaults to None.

    Returns:
        _type_: _description_
    """
    bins = np.asarray(bins)
    counts = np.asarray(counts)
    new_bins = bins[:bins.shape[0]-1]
    index = counts >0

    new_bins = new_bins[index]
    counts = counts[index]
    if bin_centres is not None:
        bin_centres = np.asarray(bin_centres)
        bin_centres = bin_centres[index]

        return counts, new_bins, bin_centres
    else:
        return counts, new_bins