class BaseScanParameters: def __init__(self, job_config): dynamical_system_dict = job_config['dynamical_system'] self.dynamical_system = DynamicalSystem( *dynamical_system_dict.values()) intg_precision_exp10 = job_config['trajectory_integration'][ 'precision'] self.intg_precision = 10**intg_precision_exp10 self.intg_limit = job_config['trajectory_integration']['limit'] scan_resolution_exp10 = job_config['phase_space_scan']['resolution'] self.scan_resolution = 10**scan_resolution_exp10 scan_min_x = job_config['phase_space_scan']['min_x'] scan_max_x = job_config['phase_space_scan']['max_x'] scan_min_y = job_config['phase_space_scan']['min_y'] scan_max_y = job_config['phase_space_scan']['max_y'] self.scan_space = DiscretePlane(scan_min_x, scan_max_x, self.scan_resolution, scan_min_y, scan_max_y, self.scan_resolution) self.scan_range = self.scan_space.range() self.total_iterations = self.compute_total_iterations() def compute_total_iterations(self): initial_positions = self.scan_space.range() # cannot reuse the attribute cause iterables can only be traversed once! return sum([1 for xy in initial_positions])
def __init__(self, scan_params): map_resolution = 10**-2 min_x, max_x, min_y, max_y = scan_params.scan_space.extent() self.map_space = DiscretePlane(min_x, max_x, map_resolution, min_y, max_y, map_resolution) # inbound is marked as 0, outbound is marked as 1. self.tendency_map = np.zeros(self.map_space.dimension(), dtype=int) # to normalize at the end. self.counts_map = np.zeros(self.map_space.dimension(), dtype=int)
def from_dict(cls, dict): if '__heatmap__' not in dict: raise RuntimeError('not a Heatmap dict') restored_heatmap = cls.__new__(cls) restored_heatmap.map_space = DiscretePlane.from_dict(dict['map_space']) restored_heatmap.incidence_map = np.array(dict['incidence_map']) return restored_heatmap
def from_dict(cls, dict): if '__interloop_scan_map__' not in dict: raise RuntimeError('not an InterloopScanMap dict') restored_scan_map = cls.__new__(cls) restored_scan_map.map_space = DiscretePlane.from_dict( dict['map_space']) restored_scan_map.tendency_map = np.array(dict['tendency_map']) restored_scan_map.counts_map = np.array(dict['counts_map']) return restored_scan_map
def __init__(self, job_config): dynamical_system_dict = job_config['dynamical_system'] self.dynamical_system = DynamicalSystem( *dynamical_system_dict.values()) intg_precision_exp10 = job_config['trajectory_integration'][ 'precision'] self.intg_precision = 10**intg_precision_exp10 self.intg_limit = job_config['trajectory_integration']['limit'] scan_resolution_exp10 = job_config['phase_space_scan']['resolution'] self.scan_resolution = 10**scan_resolution_exp10 scan_min_x = job_config['phase_space_scan']['min_x'] scan_max_x = job_config['phase_space_scan']['max_x'] scan_min_y = job_config['phase_space_scan']['min_y'] scan_max_y = job_config['phase_space_scan']['max_y'] self.scan_space = DiscretePlane(scan_min_x, scan_max_x, self.scan_resolution, scan_min_y, scan_max_y, self.scan_resolution) self.scan_range = self.scan_space.range() self.total_iterations = self.compute_total_iterations()
def __init__(self, job_config): super().__init__(job_config) projection_min_x = job_config['heatmap']['min_x'] projection_max_x = job_config['heatmap']['max_x'] resolution_x_exp10 = job_config['heatmap']['resolution_x'] projection_res_x = 10 ** resolution_x_exp10 projection_min_y = job_config['heatmap']['min_y'] projection_max_y = job_config['heatmap']['max_y'] resolution_y_exp10 = job_config['heatmap']['resolution_y'] projection_res_y = 10 ** resolution_y_exp10 self.projection_space = DiscretePlane( projection_min_x, projection_max_x, projection_res_x, projection_min_y, projection_max_y, projection_res_y )
class InterloopScanMap: def __init__(self, scan_params): map_resolution = 10**-2 min_x, max_x, min_y, max_y = scan_params.scan_space.extent() self.map_space = DiscretePlane(min_x, max_x, map_resolution, min_y, max_y, map_resolution) # inbound is marked as 0, outbound is marked as 1. self.tendency_map = np.zeros(self.map_space.dimension(), dtype=int) # to normalize at the end. self.counts_map = np.zeros(self.map_space.dimension(), dtype=int) def project(self, x, y, bit): #logging.info(f'{x}, {y}: {bit}') coordinates = self.map_space.projection_coordinates(x, y) if coordinates is not None: map_x, map_y = coordinates self.tendency_map[map_x, map_y] += bit self.counts_map[map_x, map_y] += 1 def to_dict(self): return { '__interloop_scan_map__': True, 'map_space': self.map_space.to_dict(), 'tendency_map': self.tendency_map.tolist(), 'counts_map': self.counts_map.tolist() } @classmethod def from_dict(cls, dict): if '__interloop_scan_map__' not in dict: raise RuntimeError('not an InterloopScanMap dict') restored_scan_map = cls.__new__(cls) restored_scan_map.map_space = DiscretePlane.from_dict( dict['map_space']) restored_scan_map.tendency_map = np.array(dict['tendency_map']) restored_scan_map.counts_map = np.array(dict['counts_map']) return restored_scan_map def plot(self, save_path=""): averaged_map = np.divide(self.tendency_map, self.counts_map) im = plt.imshow(averaged_map.transpose(), cmap='viridis', aspect='auto', origin='lower', extent=self.map_space.extent()) plt.xlabel('x') plt.ylabel('y') plt.colorbar(im) if save_path: plt.savefig(save_path) else: plt.show()