micmac.foregrounds.templates module

Module to create templates for spatial variability (spv stands for SPatial Variability)

build_empty_tree_spv(n_fgs_comp, n_betas)[source]

Create empty tree for spv config, with 0 in node nside_spv (corresponding to basic comp sep)

Parameters:
n_fgs_comp : int

number of foreground components

n_betas : int

number of betas (free parameters)

Returns:

root – root node of the tree

Return type:

anytree.Node

build_tree_from_dict(node_dict, parent=None)[source]

Recursive function to build a tree form a dict

Parameters:
node_dict : dict

dictionary with the node names and values

parent : anytree.Node

parent node

count_betas_in_tree(node)[source]

Count the number of nodes corresponding to free Bf parameters per frequency per component and per patch

Parameters:
node : anytree.Node

node of the tree

Returns:

count – number of nodes corresponding to free Bf parameters for the given node

Return type:

int

create_one_template(node, all_nsides, spv_templates, nside, print_bool=False)[source]

Create one spv template map from the tree of spv config

Parameters:
node : anytree.Node

node of the tree of spv config

all_nsides : list

list of all nsides

spv_templates : list

list of all spv templates

nside : int

nside of the output map

print_bool : bool

whether to print the nside for which the template is created

Returns:

spv_template_b – spv template map

Return type:

array[float]

create_one_template_from_bdefaultvalue(nside_b, nside, all_nsides=None, spv_templates=None, use_jax=False, print_bool=False)[source]

Create one spv (spatial variability) template map from the default value of b

Parameters:
nside_b : int

nside of the spv template map

nside : int

nside of the output map

all_nsides : list

list of all nsides

spv_templates : list

list of all spv templates

use_jax : bool

whether to use jax or not

print_bool : bool

whether to print the nside for which the template is created

Returns:

spv_template_b – spv template map

Return type:

array[float]

create_template_map(spv_nside, nside, use_jax=False, print_bool=False)[source]

Create one spv template map TODO: Currently with pure_callback, to be improved later for full jax implementation TODO: Implement the adaptive multiresolution case for any patch tempalte (not only Healpix pixelization)

Parameters:
spv_nside : int

nside of the spv template map

nside : int

nside of the output map

use_jax : bool

whether to use jax or not

print_bool : bool

whether to print the nside for which the template is created

Returns:

spv_template – spv template map

Return type:

array[float]

fill_betas(node)[source]

Check if all the b params have values, if not give them their ancestors default value (it fills all the Nones of the tree)

Parameters:
node : anytree.Node

node of the tree

get_n_patches_b(node_b, jax_use=False)[source]

Returns the number of patches for a given node b TODO: generalize to arbitrary patches distribution

Parameters:
node_b : anytree.Node

node b

jax_use : bool

whether to use jax or not

Returns:

n_patches_b – number of patches for the given node b

Return type:

int

get_nodes_b(root_tree)[source]

Returns a list of nodes b from the tree of spv config

Parameters:
root_tree : anytree.Node

root node of the tree of spv config

Returns:

nodes – list of nodes b

Return type:

list

get_values_b(nodes_b, n_frequencies, n_components)[source]

Get default values of b

Parameters:
nodes_b : list

list of nodes b

n_frequencies : int

number of frequencies

n_components : int

number of components

Returns:

values_b – array of values of b

Return type:

array[float]

print_node_with_value(node)[source]

Custom function to print node names and values if present

read_spv_config(yaml_file_path)[source]

Reads yaml file with info of spv configuration and creates a dictionary from there

Parameters:
yaml_file_path : str

path to the yaml file

Returns:

dict_params_spv – dictionary with spv configuration contained in the yaml file

Return type:

dict

select_child_with_name(parent_node, child_name)[source]

Return child with a given name

Parameters:
parent_node : anytree.Node

parent node

child_name : str

name of the child to select

Returns:

child – child with the given name

Return type:

anytree.Node

tree_spv_config(yaml_file_path, n_betas, n_fgs_comp, print_tree=False)[source]

From spv param file to tree of spv config

Parameters:
yaml_file_path : str

path to the yaml file with spv params

n_betas : int

number of betas (free parameters)

n_fgs_comp : int

number of foreground components

print_tree : bool

whether to print the tree structure or not

Returns:

root – root node of the tree of spv config

Return type:

anytree.Node