pomme.model

class pomme.model.GeneralModel(model)

Bases: object

General model class.

get_abundance(model, l)

Getter for the abundance distribution (for the line produce species of line l). Has to be implemented by the user!

get_boundary_condition(model, frequency)

Getter for the boundary condition. Has to be implemented by the user!

get_temperature(model)

Getter for the temperature distribution. Has to be implemented by the user!

get_turbulence(model)

Getter for the turbulence distribution. Has to be implemented by the user!

get_velocity(model)

Getter for the velocity field. Has to be implemented by the user!

image(lines, frequencies)

Create synthetic image of the given general model.

Parameters:
  • lines (list) – List of Line objects for which to create the synthetic image.

  • frequencies (list)

Returns:

Iss – The synthetic image of the model.

Return type:

torch.Tensor

class pomme.model.SphericalModel(rs, model_1D, r_star=0.0)

Bases: object

Spherically symmetric model. Convenience class to simplify creating spherically symmetic models.

diff_r(arr, rs)

Derivative along the radial direction.

Parameters:
  • arr (torch.Tensor) – The array for which to compute the derivative.

  • rs (torch.Tensor) – The radii of the spherical model.

Returns:

diff_r – The derivative along the radial direction.

Return type:

torch.Tensor

get_abundance(model_1D)

Getter for the abundance distribution. Has to be implemented by the user!

get_boundary_condition(model_1D, frequency, b)

Getter for the boundary condition at the impact parameter b. Has to be implemented by the user!

get_temperature(model_1D)

Getter for the temperature distribution. Has to be implemented by the user!

get_turbulence(model_1D)

Getter for the turbulence distribution. Has to be implemented by the user!

get_velocity(model_1D)

Getter for the velocity field. Has to be implemented by the user!

image(lines, frequencies, r_max=inf, step=5)

Create synthetic image of the given spherically symmetric model.

Parameters:
  • lines (list) – List of Line objects for which to create the synthetic image.

  • frequencies (list) – List of frequencies at which to compute the synthetic image.

  • r_max (float (optional)) – Maximum radius at which to compute the synthetic image.

  • step (int (optional)) – Step size for the impact parameters at which to trace a ray.

Returns:

Iss – The synthetic image of the model.

Return type:

torch.Tensor

image_ray_tracer()

Ray tracer for the spherical model.

plot(keys=None, exclude=[])

Plot the model parameters.

class pomme.model.TensorModel(sizes, shape, keys=[], dtau_warning_threshold=0.5)

Bases: object

A (deterministic) model in which every variable is represented by a PyTorch tensor.

apply(func, exclude=[], include=[])

Apply the given functional to all model variables.

Parameters:
  • func (function) – The function to be applied to the model variables.

  • exclude (list (optional)) – List of keys to exclude from the application of the function.

  • include (list (optional)) – List of variables to include in the application of the function.

Returns:

res – The result of the application of the function to the model variables.

Return type:

torch.Tensor

apply_to_fields(func, exclude=[], include=[])

Apply the given functional to all model fields.

Parameters:
  • func (function) – The function to be applied to the model fields.

  • exclude (list (optional)) – List of keys to exclude from the application of the function.

  • include (list (optional)) – List of variables to include in the application of the function.

Returns:

res – The result of the application of the function to the model fields.

Return type:

torch.Tensor

deepcopy()

Create a deep copy of the TensorModel.

diff(arr, axis=-1)

Derivative along an axis.

Parameters:
  • arr (torch.Tensor) – The array for which to compute the derivative.

  • axis (int (optional)) – The axis along which to compute the derivative.

Returns:

diff – The derivative along the specified axis.

Return type:

torch.Tensor

diff_x(arr)

Derivtive along x axis.

Parameters:

arr (torch.Tensor) – The array for which to compute the derivative.

Returns:

diff_x – The derivative along the x axis.

Return type:

torch.Tensor

diff_y(arr)

Derivtive along y axis.

Parameters:

arr (torch.Tensor) – The array for which to compute the derivative.

Returns:

diff_y – The derivative along the y axis.

Return type:

torch.Tensor

diff_z(arr)

Derivtive along z axis.

Parameters:

arr (torch.Tensor) – The array for which to compute the derivative.

Returns:

diff_z – The derivative along the z axis.

Return type:

torch.Tensor

dim()

Getter for the dimension of the TensorModel.

dx(i)

Return the size of a model element.

Parameters:

i (int) – Index of the dimension.

Returns:

dx – Size of the model element along axis or dimension i.

Return type:

float

fix(keys)

“Fixes” the variables that should not be adjusted in optimistation. (and hence do not require a gradient.)

Parameters:

keys (str or list) – The key(s) of the variable(s) that should be fixed.

fix_all()

Makes all model variables fixed.

free(keys)

“Frees” the variables that should be adjusted in optimistation. (and hence require a gradient.)

Parameters:

keys (str or list) – The key(s) of the variable(s) that should be freed.

free_all()

Makes all model variables free.

free_parameters()

Return a list of all “free” variables in the TensorModel.

get_coords(origin='centre')

Getter for the coordinates of each tensor location.

Parameters:

origin (array_like) – Indices of the origin of the coordinate system (can be float). The dimension of the origin should match the dimension of the model. If ‘centre’, the origin is set to the centre of the model.

Returns:

coords – coordinates of each location in the tensor model.

Return type:

numpy array

get_detached_clone()

Returns a copy of the model, detached from this model.

get_radial_direction(origin='centre')

Getter for the radial direction of the model.

Parameters:

origin (array_like (optional)) – indices of the origin of the coordinate system (can be float). The dimension of the origin should match the dimension of the model.

Returns:

direction – radial directions of each element in the model.

Return type:

numpy array

get_radius(origin='centre')

Getter for the radial cooridnate of each location.

Parameters:

origin (array_like) – indices of the origin of the coordinate system (can be float). The dimension of the origin should match the dimension of the model. If ‘centre’, the origin is set to the centre of the model.

Returns:

radius – radial coordinate of each location in the tensor model.

Return type:

numpy array

info()

Print info about the TensorModel.

integrate(var, axis=0)

Integrate a variable along an axis of the model box.

integrate_out(var, axis=0)

Integrate a variable out along an axis of the model box.

interpolate_from_model(model, detach=True)

Interpolate the varialbles of another model into this model.

Parameters:
  • model (TensorModel) – The model from which to interpolate the variables.

  • detach (bool (optional)) – If True, the interpolated tensors in this model will be detached from the PyTorch compute graph.

is_field(key)

Check if the key corresponds to a field (i.e. a variable defined at each model element).

Parameters:

key (str) – The key of the variable.

Returns:

is_field – True if the key corresponds to a field, False otherwise.

Return type:

bool

keys()

Return the variable keys.

static load(fname)

Load a TensorModel from an HDF5 file.

Parameters:

fname (str) – The name of the file from which the TensorModel is loaded.

Returns:

model – The loaded TensorModel

Return type:

TensorModel

origin_as_index_array(origin)

Convert origin to a numpy array.

Parameters:

origin (array_like or str) – Indices of the origin of the coordinate system (can be float). The dimension of the origin should match the dimension of the model. If ‘centre’, the origin is set to the centre of the model.

Returns:

origin – indices of the origin of the coordinate system.

Return type:

numpy array

parameters()

Return a list of all variables in the TensorModel.

static print_diff(model_1, model_2)

Print info about the difference between two models.

Parameters:
save(fname)

Save the TensorModel to disk as an HDF5 file.

Parameters:

fname (str) – The name of the file to which the TensorModel is saved.

reserved_keys = ['shape', 'sizes', 'free']
pomme.model.make_object_with_len(obj)

Turn object into a tuple if it does not have a __len__ attribute.

Parameters:

obj (object) – Object to be turned into a tuple if it does not have a __len__ attribute.

Returns:

obj – Object turned into a tuple if it does not already had a __len__ attribute.

Return type:

object