def compute_kappa(config): """ Returns the computed kappa corresponding to the given configuration. Parameters ---------- config : Config Must contain the following attributes: * gammas : str (path) * mask : str (path) * method : str * niter : int * bconstraint : int or str * reduced : bool Returns Image Image with both modes of the computed kappa maps. """ config = copy.deepcopy(config) # Copy of the configuration gammas = Image.from_fits(config['gammas']) # Loads gamma from fits file mask = Image.from_fits(config['mask']) # Loads mask from fits file g1map = gammas.get_layer(0) g2map = gammas.get_layer(1) # Estimates kappa maps kE, kB = iterative(config['method'], g1map, g2map, mask.get_layer(), config['niter'], config['bconstraint'], config['reduced']) data = np.array([kE, kB]) header = config._config header.update({'NAME': "computed kappa"}) return Image(data, header)
class Machine: def __init__(self, scr, sprites): self.scr = scr box = sprites["machine_base"] self.box = Image(scr, box, 400, 350) self.x, self.y, self.w, self.h = self.box.get_rekt() # make two different handles for the machine because I am a moron # that can't use transformations handle = sprites["handle_idle"] self.non_active_handle = Image_Button(scr, handle, 700, 500, self.click) handle = sprites["handle_active"] self.active_handle = Image_Button(scr, handle, 700, 370, self.click) self.active = False return def click(self): # haha money machine go brrrrr self.active = not self.active # reset both handles bc they are the same button self.active_handle.last_click = time() self.non_active_handle.last_click = time() return def blit(self): if self.active: handle = self.active_handle elif self.active == False: handle = self.non_active_handle handle.blit() self.box.blit() return pass
def get_ms(index, scr): out = [] # content = get_sprites()[f"ms_{index}"] content = get_sprites()["ms_ex"] paper = get_sprites()["ms_paper"] paper = Image(scr, paper, 50, 50 + 500) out.append(paper) out.append(Image(scr, content, 200, 100 + 500)) x, y, w, h = paper.get_rekt() out.append(Rect_Button(scr, BLACK,x, y, w, h, delay_time=0)) return out
def __init__(self, scr, sprites): self.scr = scr box = sprites["machine_base"] self.box = Image(scr, box, 400, 350) self.x, self.y, self.w, self.h = self.box.get_rekt() # make two different handles for the machine because I am a moron # that can't use transformations handle = sprites["handle_idle"] self.non_active_handle = Image_Button(scr, handle, 700, 500, self.click) handle = sprites["handle_active"] self.active_handle = Image_Button(scr, handle, 700, 370, self.click) self.active = False return
def __init__(self, game, scr, key, letter_smol, letter_big, unlocks): self.unlock = unlocks self.game = game self.key = key self.scr = scr self.small = True self.big = False self.x = 1150 self.y = 650 _, _, w, h = Image(scr, letter_smol, self.x, self.y).get_rekt() self.small_button = Rect_Button(scr, BLACK, 1150 - w / 2, 650 - h / 2, w, h, resp=self.click) self.smol = letter_smol self.big_letter = letter_big self.big_button = Rect_Button(scr, BLACK, 200, 100, 1156, 561) self.angle = 0 self.t = 0.5 self.angle_max = 20 self.base_factor = self.angle_max / self.t self.factor = self.base_factor self.active_letter = self.smol self.done = 1500 self.yps = 0.05 return
def process_image_form(db, bookID, imageID, description, height, width, targetImageURL, ARImageURLs, links, title, videoURL): books_ref = db.collection(u"books").document(bookID).collection("images").document(imageID) image = Image(imageID, description, height, width, targetImageURL, ARImageURLs, links, title, videoURL) print(image.to_dict()) return books_ref.set(image.to_dict())
def k2g_fits(k_path, g_path, mask_path=None, noise_path=None): """ Computes gamma maps from kappa maps in fits file. Parameters ---------- k_path : str Path to the kappa map fits file. g_path : str Path to save the gamma map fits file. mask_path : str, optional Path to the mask map fits file. noise_path : str Path to the noise map fits file. Return ------ None Notes ----- * The noise is added to the gamma maps. * If the noise fits file contains only one noise map,the noise will be added to both gamma maps. * Else (2 noise maps) the first (resp. second) willbe added to the first (res. second) gamma map. * The mask is applied over each gamma map. """ # Loads kappa maps from fits file. kappa = Image.from_fits(k_path) if mask_path: # Loads mask from fits file if given. mask = Image.from_fits(mask_path).get_layer() else: mask = 1 if noise_path: # Loads noise map from fits file if given. noises = Image.from_fits(noise_path) if noises.layers == 2: n1, n2 = noises.get_layer(0), noises.get_layer(1) elif noises.layers == 1: n1 = n2 = noises.get_layer(0) else: print("Cannot handle noise with more than 2 layers.") return else: n1, n2 = 0, 0 # Getting E-mode and B-mode kappa maps if kappa.layers == 1: k1map = kappa.get_layer() k2map = k1map * 0 elif kappa.layers == 2: k1map, k2map = kappa.get_layer(0), kappa.get_layer(1) else: print("Cannot handle kappa with more than 2 layers.") return # Evaluates gamma maps g1map, g2map = ks93inv(k1map, k2map) # Apply the mask and noise over the compute gamma maps... gamma = Image(np.array([(g1map + n1) * mask, (g2map + n2) * mask])) # ... Then it is stored in a fits file under the given name gamma.save(g_path)
def compute_errors(computed_kappa_path, gnd_truth_path, output_path=None): """ Evaluates both errors (E and B), then stores the values in the computed kappa header and in a global results register. Parameters ---------- computed_kappa_path : str Path toward the computed kappa fits file. gnd_truth_path : str Path toward the ground truth map fits file. output_path : str, optional Path toward the file in which the results register will be stored. Return ------ Image Image of the difference between the computed and the ground truth kappa maps for both modes. """ # Loads data from the computed kappa file. computed_kappa = ComputedKappa.from_fits(computed_kappa_path) # Loads data from the ground truth kappa file gnd_truth = Image.from_fits(gnd_truth_path) # Loads the mask used to compute the estimated kappa map. mask = Image.from_fits(computed_kappa.mask_path) # Check if there is a B mode to consider in the error computation. layers_truth = gnd_truth.layers if layers_truth == 1: # If there is only the E-mode, then B-mode is zero... gndB = gnd_truth.get_layer() * 0 # ... and we compute the B-mode error according to the E-mode. denomB = gnd_truth.get_layer() elif layers_truth == 2: # If there is a B-mode... gndB = gnd_truth.get_layer(1) if norm(gndB): # ... and non zero, then we compute the B-mode error according to it, ... denomB = gndB else: # else we compute the B-mode error according to the E-mode. denomB = gnd_truth.get_layer() else: print('Cannot handle ground truth with more than 2 layers') return # E-mode difference. diff = computed_kappa.get_layer(0) - gnd_truth.get_layer(0) diffB = computed_kappa.get_layer(1) - gndB # B-mode difference. computed_kappa.header['ERROR_E'] = get_error( diff[mask.get_layer().astype(bool)], gnd_truth.get_layer()[mask.get_layer().astype(bool)]) computed_kappa.header['ERROR_B'] = get_error( diffB[mask.get_layer().astype(bool)], denomB[mask.get_layer().astype(bool)]) computed_kappa.save() if not output_path: output_path = gnd_truth_path.replace('inputs', 'outputs').replace( '.fits', '.json') rr = ResultRegister(output_path) rr.set_error(computed_kappa.method, computed_kappa.niter, computed_kappa.bconstraint, computed_kappa.header['ERROR_E'], 'e') rr.set_error(computed_kappa.method, computed_kappa.niter, computed_kappa.bconstraint, computed_kappa.header['ERROR_B'], 'b') rr.save() return Image(np.array([diff, diffB]))