utils package
The utils package contains different useful but not essential scripts such as plotting scripts and scripts to compute criterias to evaluate the performance of the inference.
utils.generate_gif module
- utils.generate_gif.generate_gif(images_path='./plot/plot_all_timestep/', save_path='./plot/', file_name='output')[source]
generate a gif file from png files contained in a given directory * images_path: string, ‘./plot/plot_all_timestep/’ by default, contains the path of the directory in which the figures are * save_path: string, ‘./plot/’ by default, contains the path of the directory in which the gif file will be saved * file_name string, ‘output’ by default, name of the file in which the gif will be saved
- do:
open and concatenate in the alphabetic order the files contained in the given images’ directory
save the array of images as a gif in the given save directory
utils.geom_to_shapefile module
- utils.geom_to_shapefile.geom_to_shapefile(msh, name_file_out, path_out)[source]
method to save the geometry in a shapefile with the domain as a shapely.box for visualization
- input:
msh: object of the class MeshRect2D, the mesh containing the geometry to save
path_out: str, path to the folder in which the geometry will be saved
name_file_out: str, name of the file in which the geometry will be saved
- do:
generate a shapely.box corresponding the the domain
save the geometry contained in msh and the domain’s box in the file and folder given as input
utils.plot_colormap module
- utils.plot_colormap.plot_colormap(msh, xy_map, label, unit, cmap='jet', title=None, map_bound=None, save_path=None, file_name=None, file_format='pdf', figsize=(20, 15))[source]
Plot a given physical quantity
- input:
msh: object of the class MeshRect2D
xy_map: numpy array of shape (mesh.y.size, mesh.x.size), contains the mean value of the physical quantity in the cells
label: string, contains the label of the physical quantity, can be in LaTeX format
unit: string, contains the unit of the physical quantity, can be in LaTeX format
cmap: string, “jet” by default, contains the name of the colormap to use
title: string, None by default, contains the title of the figure, can be in LaTeX format
map_bound: tuple, contains the lower and upper boundary we want to impose to the colormap
save_path: string, None by default, contains the path to directory in which the figure is saved if not None
file_name: string, None by default, contains the name of the filein which the figure is saved if save_path is not None
file_format: string, ‘pdf’ by default, contains the format of the file in which the figure is saved if save_path is not None
figsize: tuple, (20, 15) by default, contains the size of the figure
- do:
plot on the whole domain the given physical quantity
save the figure in a file if the save_path input is not None, show the figure otherwise
- utils.plot_colormap.plot_colormap_all_timestep(msh, t, txy_map, label, unit, cmap='jet', save_path='./plot/plot_all_timestep/', figsize=(20, 15), restart_ite=0)[source]
Plot and save a given physical quantity at every time step
- input:
msh: object of the class MeshRect2D
t: numpy array, contains all the time at which the physical quantity is plotted
- txy_map:
numpy array of shape (t.size, mesh.y.size, mesh.x.size), contains the mean value of the physical quantity in the cells at every time step
label: string, contains the label of the physical quantity, can be in LaTeX format
unit: string, contains the unit of the physical quantity, can be in LaTeX format
cmap: string, “jet” by default, contains the name of the colormap to use
save_path: string, ‘./plot/plot_all_timestep/’ by default, contains the path to directory in which all the figures are saved
- do:
plot on the whole domain and at every time step the given physical quantity
save the figures in png files
utils.plot_cost module
- utils.plot_cost.plot_cost(j_obs, j_reg, norm_noise, label_reg, ls_reg, save_path=None, file_name=None, file_format='pdf', figsize=(20, 15))[source]
Plot cost
- Parameters:
j_obs (
array) – observation costj_reg (
dict of arrays) – cost of the regularization termsnorm_noise (
float) – noise levellabel_reg (
dict of strings) – labels of the regularization termsls_reg (
dict of string) – line stylessave_path (
str, optional) – Save path. Defaults to None.file_name (
str, optional) – plot file name. Defaults to None.file_format (
str, optional) – file format. Defaults to ‘pdf’.figsize (
tuple, optional) – size of the figure. Defaults to (20, 15).
- utils.plot_cost.plot_cost_obs_comparison(case_dict, save_path=None, file_name=None, file_format='pdf', figsize=(20, 15))[source]
Plot observation cost in different cases
- Parameters:
case_dict (
dict) – The different casessave_path (
str, optional) – Save path. Defaults to None.file_name (
str, optional) – File name. Defaults to None.file_format (
str, optional) – file format. Defaults to ‘pdf’.figsize (
tuple, optional) – figure size. Defaults to (20, 15).
utils.plot_ctrl module
- utils.plot_ctrl.plot_ctrl(msh, t, ctrl, ctrl_target=None, obs=None, trajectory_U=None, cmap='jet', title=None, map_bound=None, label='s', save_path=None, file_name=None, file_format='pdf', figsize=(20, 15))[source]
plot of the control
- Parameters:
msh (
mesh2D) – 2D mesht (
float) – timectrl (
array) – controlctrl_target (
array, optional) – target. Defaults to None.obs (
array, optional) – observations. Defaults to None.trajectory_U (
array, optional) – trajectory. Defaults to None.cmap (
str, optional) – color map. Defaults to “jet”.title (
str, optional) – title. Defaults to None.map_bound (
array like, optional) – boundaries. Defaults to None.label (
str, optional) – label. Defaults to ‘s’.save_path (
str, optional) – save path. Defaults to None.file_name (
str, optional) – file name. Defaults to None.file_format (
str, optional) – file format. Defaults to ‘pdf’.figsize (
tuple, optional) – figure size. Defaults to (20, 15).
- utils.plot_ctrl.plot_ctrl_all_timestep(msh, ctrl, ctrl_target=None, obs=None, label='s', cmap='jet', save_path='./plot/plot_all_timestep/')[source]
Plot and save a given physical quantity at every time step
- input:
msh: object of the class MeshRect2D
t: numpy array, contains all the time at which the physical quantity is plotted
- txy_map:
numpy array of shape (t.size, mesh.y.size, mesh.x.size), contains the mean value of the physical quantity in the cells at every time step
label: string, contains the label of the physical quantity, can be in LaTeX format
unit: string, contains the unit of the physical quantity, can be in LaTeX format
cmap: string, “jet” by default, contains the name of the colormap to use
save_path: string, ‘./plot/plot_all_timestep/’ by default, contains the path to directory in which all the figures are saved
- do:
plot on the whole domain and at every time step the given physical quantity
save the figures in png files
- utils.plot_ctrl.plot_ctrl_map(msh, t, ctrl_map, ctrl_target_map=None, obs=None, trajectory_U=None, cmap='jet', title=None, map_bound=None, label='s', save_path=None, file_name=None, file_format='pdf', figsize=(20, 15))[source]
Plot the control map
- Parameters:
msh (
mesh2D) – 2D mesht (
float) – timectrl_map (
array) – map of the controlctrl_target_map (
array, optional) – map of the target. Defaults to None.obs (
array, optional) – observations. Defaults to None.trajectory_U (
array, optional) – trajectory. Defaults to None.cmap (
str, optional) – color map. Defaults to “jet”.title (
str, optional) – title. Defaults to None.map_bound (
array like, optional) – boundaries. Defaults to None.label (
str, optional) – label. Defaults to ‘s’.save_path (
str, optional) – save path. Defaults to None.file_name (
str, optional) – file name. Defaults to None.file_format (
str, optional) – file format. Defaults to ‘pdf’.figsize (
tuple, optional) – figure size. Defaults to (20, 15).
utils.plot_ctrl_error module
- utils.plot_ctrl_error.plot_mean_error_ctrl_comparison_vs_ite(case_dict, ctrl_target, optim_iter_start=0, optim_iter_end=-1, flag_domain=None, ordre_norm=2, ylabel=None, save_path=None, file_name=None, file_format='pdf', figsize=(20, 15))[source]
Plot mean error with control, comparison with different cases
- Parameters:
case_dict (
dict of cases) – the different casesctrl_target (
dataframe) – control targetoptim_iter_start (
int, optional) – iter start. Defaults to 0.optim_iter_end (
int, optional) – iter end. Defaults to -1.flag_domain (
_type_, optional) – flag of the domain. Defaults to None.ordre_norm (
int, optional) – error norm order. Defaults to 2.ylabel (
str, optional) – ylabel. Defaults to None.save_path (
str, optional) – save path. Defaults to None.file_name (
str, optional) – file name. Defaults to None.file_format (
str, optional) – file format. Defaults to ‘pdf’.figsize (
tuple, optional) – figure size. Defaults to (20, 15).
utils.plot_env_param module
- utils.plot_env_param.plot_diffusion_tensor(msh, diffu_coeff, save_path=None, figsize=(20, 15))[source]
Plot the diffusion tensor
- input:
msh: object of the class MeshRect2D
diffu_coeff: object of the class DiffusionTensor
save_path: string, None by default, contains the path to directory in which the figure is saved if not None
figsize: tuple, (20, 15) by default, contains the size of the figure
- do:
plot on the whole domain the four component of the diffusion tensor
save the figure in a pdf file if the save_path input is not None, show the figure otherwise
- utils.plot_env_param.plot_velocity_field(msh, vel, save_path=None, file_name=None, figsize=(20, 15), space_subsampling_rate=10, scale_arrow=0.9756097560975611, width_arrow=0.2, vlim=None, title=None, format_out='pdf')[source]
Plot the velocity field
- input:
msh: object of the class MeshRect2D
vel: object of the class Velocity
save_path: string, None by default, contains the path to directory in which the figure is saved if not None
figsize: tuple, (20, 15) by default, contains the size of the figure
- do:
plot on the whole domain the velocity field with an arrow representation of the velocity vector
save the figure in a pdf file if the save_path input is not None, show the figure otherwise
utils.plot_obs module
- utils.plot_obs.plot_obs(msh, t, obs, figsize=(20, 15), cmap='jet', save_path=None, file_format='pdf', cbar_dim=[0.92, 0.15, 0.02, 0.69])[source]
Plot and save the observations at a given time step
- input:
msh: object of the class MeshRect2D
t: float, contains the time at which the observations plotted
obs: object of the class Obs, contains the observations we want to plot
cmap: string, “jet” by default, contains the name of the colormap to use
save_path: string, ‘./plot/plot_all_timestep/’ by default, contains the path to directory in which all the figures are saved
file_format: string, ‘pdf’ by default, contains the format of the file in which the figure is saved if save_path is not None
figsize: tuple, (20, 15) by default, contains the size of the figure
- do:
plot on the observations at a given time step, the points not observed are left white
save the figures in a file
utils.superlevel_set module
- utils.superlevel_set.intersection_superlevel_set(threshold, s_array)[source]
Define superlevel set intersections
- Parameters:
threshold (
float) – thresholds_array (
array) – value
- Returns:
returns point superior to the threshold
- Return type:
array
- utils.superlevel_set.superlevel_set(threshold, s)[source]
Defines the superlevel set
- Parameters:
threshold (
float) – thresholds (
array) – value
- Returns:
returns point superior to the threshold
- Return type:
array
- utils.superlevel_set.volume(domain, volume_cell)[source]
Cmpute volumem
- Parameters:
domain (
array like) – domain definitionvolume_cell (
array_like) – volume celles
- Returns:
domain volume
- Return type:
float
- utils.superlevel_set.volume_intersection_superlevel_set(threshold, s_array, volume_cell)[source]
Volume of intersection of superlevel sets
- Parameters:
threshold (
float) – thresholds_array (
array_like) – controlvolume_cell (
array_like) – volume of the cells
- Returns:
_description_
- Return type:
_type_