def __init__(self, lower=-10, upper=5, n_bins=1500): self.n_bins = n_bins self.n_bin_edges = self.n_bins + 1 self.lower_bin_edge = lower self.upper_bin_edge = upper self.bin_range = self.upper_bin_edge - self.lower_bin_edge # Size bins self.size_bins = initialize_bins(self.lower_bin_edge, self.upper_bin_edge, self.n_bin_edges) self.size_bins_medians = calculate_bins_medians(self.size_bins) # Volume bins self.volume_bins = calculate_volume_sphere(self.size_bins) self.volume_bins_medians = calculate_bins_medians(self.volume_bins) # Search size bins self.search_size_bins = \ initialize_bins(self.lower_bin_edge - self.bin_range, self.upper_bin_edge, self.n_bin_edges*2-1) self.search_size_bins_medians = \ calculate_bins_medians(self.search_size_bins) self.ratio_search_size_bins = \ calculate_ratio_bins(self.search_size_bins_medians) # Search volume bins self.search_volume_bins = \ calculate_volume_sphere(self.search_size_bins) self.search_volume_bins_medians = \ calculate_bins_medians(self.search_volume_bins) self.ratio_search_volume_bins = \ calculate_ratio_bins(self.search_volume_bins_medians)
def test_correct_outcome_of_radii(self, fixture_crystal_diameters): radii = fixture_crystal_diameters / 2 actual = gen.calculate_volume_sphere(fixture_crystal_diameters, diameter=False) expected = \ np.array([4.18879020e-03, 4.18879020e+03, 6.54498469e-05]) * 8 assert actual == pytest.approx(expected)
def simulate_N_crystals(self, m): """Request crystals from CSD until accounted modal volume is filled. Idea: use pdf to speed up process --> This can only be done if the CSD is converted to a 'crystal volume distribution'. From this, the number of crystals per mineral class will be known while also giving the total number of crystals (N) in 1 m³ of parent rock. """ total_volume_mineral = 0 requested_volume = self.pr_modal_volume[m] crystals = [] crystals_append = crystals.append crystals_total = 0 # crystals_total_append = crystals_total.append rs = 0 while total_volume_mineral < requested_volume: # volume that still needs to be filled with crystals diff = requested_volume - total_volume_mineral # ‘m’ represents the current mineral class # +1 so that each time at least one crystal is requested crystals_requested = \ int(diff / (self.pr_modal_mineralogy[m] * self.learning_rate)) + 1 # print(crystals_requested, end=", ") crystals_total += crystals_requested crystals_to_add = \ np.exp(self.pr_csds[m].rvs(size=crystals_requested, random_state=rs)) crystals_append(gen.calculate_volume_sphere(crystals_to_add)) total_volume_mineral += np.sum(crystals[rs]) # print(requested_volume, total_volume_mineral) rs += 1 try: crystals_array = np.concatenate(crystals) except ValueError: crystals_array = np.array(crystals) crystals_binned = \ (np.searchsorted(self.volume_bins, crystals_array) - 1).astype(np.uint16) # Capture and correct crystals that fall outside # the leftmost bin as they end up as bin 0 but since 1 gets # subtracted from all bins they end up as the highest value # of np.uint16 as negative values are not possible crystals_binned[crystals_binned > self.n_bins] = 0 return crystals_total, np.sum(crystals_total), \ total_volume_mineral, crystals_binned
def __init__(self): # Create bin matrices to capture chemical weathering self.size_bins_matrix = \ self.create_bins_matrix(self.size_bins) self.volume_bins_matrix = \ calculate_volume_sphere(self.size_bins_matrix) self.size_bins_medians_matrix = \ calculate_bins_medians(self.size_bins_matrix) self.volume_bins_medians_matrix = \ calculate_bins_medians(self.volume_bins_matrix) # Volume change matrix self.volume_change_matrix = -np.diff(self.volume_bins_medians_matrix, axis=0) # Negative bin array thresholds self.negative_volume_thresholds = \ np.argmax(self.size_bins_medians_matrix > 0, axis=2) # Create search_bins_matrix self.search_size_bins_matrix = \ self.create_bins_matrix(self.search_size_bins) self.search_volume_bins_matrix = \ calculate_volume_sphere(self.search_size_bins_matrix) # Create search_bins_medians_matrix self.search_size_bins_medians_matrix = \ calculate_bins_medians(self.search_size_bins_matrix) self.search_volume_bins_medians_matrix = \ calculate_bins_medians(self.search_volume_bins_matrix) # Create ratio_search_bins_matrix self.ratio_search_size_bins_matrix = calculate_ratio_bins( self.search_size_bins_medians_matrix) self.ratio_search_volume_bins_matrix = calculate_ratio_bins( self.search_volume_bins_medians_matrix)
def test_correct_outcome_of_diameters(self, fixture_crystal_diameters): actual = gen.calculate_volume_sphere(fixture_crystal_diameters) expected = np.array([4.18879020e-03, 4.18879020e+03, 6.54498469e-05]) assert actual == pytest.approx(expected)