def null_detection(self, time, gas_field): """ Every detection method shares the same null_detection method defined here Inputs: time a time object (Defined in simulation_classes) gas_field a gas_field object (Defined in simulation_classes) """ # print("{}: Null detection: Chance of fixing each leak: {}".format( # self.name, gas_field.null_repair_rate * time.delta_t)) n_repaired = np.random.poisson( len(self.leaks.flux) * gas_field.null_repair_rate * time.delta_t) if n_repaired > len(self.leaks.flux): n_repaired = len(self.leaks.flux) if n_repaired > 0: # msg = "{}: Randomly found {} leaks on day {}! Remaining leaks: {}" # print(msg.format(self.name, n_repaired, time.current_time, len(self.leaks.flux) - # n_repaired)) index_repaired = np.random.choice(n_repaired, n_repaired, replace=False) else: index_repaired = [] for ind in index_repaired: self.null_repaired.append(self.leaks.flux[ind]) self.leaks.delete_leaks(index_repaired) self.repair_cost[time.time_index] += sum( sample_wr(gas_field.repair_cost_dist.repair_costs, n_repaired))
def null_detection(self, time, gas_field): """ Every detection method shares the same null_detection method defined here Inputs: time a time object (Defined in simulation_classes) gas_field a gas_field object (Defined in simulation_classes) """ n_repaired = np.random.poisson( len(self.leaks.flux) * gas_field.null_repair_rate * time.delta_t) index_repaired = random.sample(list(range(0, len(self.leaks.flux))), n_repaired) for ind in index_repaired: self.null_repaired.append(self.leaks.flux[ind]) self.leaks.delete_leaks(index_repaired) self.repair_cost[time.time_index] += sum( sample_wr(gas_field.repair_cost_dist.repair_costs, n_repaired))
def detection(self, time, gas_field, atm): """ Determines which leaks are detected at each timestep Inputs: time: object of type Time defining the time variables in the simulation gas_field: object of type GasField defining gas field parameters atm: object of type Atmosphere defining wind speed, direction and atmospheric stability """ self.null_detection(time, gas_field) # Periodically repair all detected leaks if time.current_time % self.repair_interval < time.delta_t and time.current_time != 0: # countFound is a temporary variable to ease notation count_found = sum(self.leaks.leaks_detected) # account for the np.cost of locating the leaks self.find_cost[time.time_index] = self.location_cost * count_found # calculate the repair np.cost self.repair_cost[time.time_index] += sum( sample_wr(gas_field.repair_cost_dist.repair_costs, int(count_found))) # update leaksFound and leakStruct if count_found > 0: # Identify indexes of leaks to delete ind = np.where(self.leaks.leaks_detected == 1)[0] self.leaks_found.extend(self.leaks.flux[ind]) self.leaks.delete_leaks([ind]) # Convert coordinates so that x is measured in the direction of the wind wind_dir_rad = np.radians(atm.wind_direction[time.time_index]) detector_x, detector_y = helper_functions.coord_transform( wind_dir_rad, self.x, self.y) x_save, y_save = helper_functions.coord_transform( wind_dir_rad, self.leaks.x, self.leaks.y) # At each time step, iterate through each leak to see if it can be detected indexes = np.where(self.leaks.leaks_detected == 0)[0] # check if each detector detects the leak phi = simulation_functions.gauss_leak_model(self.x, self.y, self.z, self.leaks, atm, time.time_index, index=indexes) for ind in range(0, self.n_sniff): found_indexes = np.where(phi[ind, :] > self.sensitivity)[0] self.leaks.leaks_detected[indexes[found_indexes]] = 1 self.leaks.x, self.leaks.y, self.x, self.y = x_save, y_save, detector_x, detector_y
def detection(self, time, gas_field, atm): """ Inputs: time an object of type Time (defined in feast_classes) gas_field an object of type GasField (defined in feast_classes) atm an object of type Atmosphere (defined in feast_classes) Note: atm is not currently used by this method, but it is accepted as an argument for consistency with other detection methods """ self.null_detection(time, gas_field) # Take no action unless a survey interval is ending if time.current_time % self.survey_interval < time.delta_t: # Repair all leaks self.repair_cost[time.time_index] += \ sum(sample_wr(gas_field.repair_cost_dist.repair_costs, len(self.leaks.flux))) self.leaks_found.extend(self.leaks.flux) self.leaks.delete_leaks(indexes_to_delete="all") return
def detection(self, time, gas_field, atm): """ Determines which leaks are detected at each timestep Inputs: time: object of type Time defining the time variables in the simulation gas_field: object of type GasField defining gas field parameters atm: object of type Atmosphere defining wind speed, direction and atmospheric stability """ self.null_detection(time, gas_field) if self.leaks.n_leaks < 0: print("WARN: why are there less than zero leaks") # Periodically repair all detected leaks if time.current_time % self.survey_interval < time.delta_t: # print("AD Flight: Day {}".format(time.current_time)) # print("num_leaks", self.leaks.n_leaks) # print("len flux", len(self.leaks.flux)) if self.leaks.n_leaks < 0: print("WARN: why are there less than zero leaks") self.leaks.n_leaks = len(self.leaks.flux) # TODO still a hack flux_nonzero = self.leaks.flux[:self.leaks.n_leaks] detected = np.zeros(self.leaks.n_leaks, dtype=int) detection_probs = self.get_detection_probabilities(flux_nonzero) finding_luck = np.random.rand(self.leaks.n_leaks) detected[finding_luck <= detection_probs] = 1 detected_ndxs = np.where(detected)[0] # print("det ndx", detected_ndxs) # print("det type", detected.dtype) num_found = np.sum(detected) if num_found > 0: self.repair_cost[time.time_index] += \ sum(sample_wr(gas_field.repair_cost_dist.repair_costs, len(detected_ndxs))) self.leaks_found.extend(flux_nonzero[detected_ndxs]) # Delete found leaks self.leaks.delete_leaks(detected_ndxs)