Geometric Data

The database can be used to store simple geometric structures, which are usually used as regions of interests. This structures must be defined in a concrete coordinates system. There is one main table which stores general information about the structure (roi), and a table for each roi type which stores its concrete data for each subject.

ROIs

roi_name_exists(name)[source]

Check if a ROI with the given name exists

Parameters:name (str) – ROI name
Returns:True if a ROI with the given name exists in the database, False otherwise.
get_roi_id(roi_name)[source]

Find the id of a ROI

Parameters:roi_name (str) – ROI Name
Returns:ROI id in the database
get_roi_name(roi_id)[source]

Find the name of a ROI

Parameters:roi_id (int) – ROI id
Returns:ROI name
get_roi_type(name=None, roi_id=None)[source]

Get the type of a ROI

Only one of the two arguments is required, roi_id is preferred

Parameters:
  • name (str) – ROI name
  • roi_id (int) – ROI id
Returns:

ROI type as a string, see create_roi() for options

get_roi_space(name=None, roi_id=None)[source]

Retrieve the coordinate systems of a ROI

Only one of the two arguments is required, roi_id is preferred

Parameters:
  • name (str) – ROI name
  • roi_id (int) – ROI id
Returns:

coordinate system as a string, see create_roi() for options

create_roi(*args, **kwargs)[source]

Creates a new ROI

Parameters:
  • name (str) – ROI Name
  • roi_type (str) –

    ROI type, current options are

    • sphere
    • line_sagital
    • line_coronal
    • line_axial
    • line_free
  • coords (str) –

    coordinate system, options are

    • subject
    • talairach
    • dartel
  • desc (str) – ROI description
Returns:

Id of ROI in the database

recursive_delete_roi(*args, **kwargs)[source]

Removes a ROI from the database, including all its values.

Warning

This may delete large amounts of information and can’t be reversed

Parameters:roi_id (int) – ROI id

Spheres

Spheres are saved as a center (x,y,z) and a radius.

load_sphere(sphere_id, subject)[source]

Loads a sphere for a subject

Parameters:
  • sphere_id (int) – ROI id
  • subject – subject id
Returns:

(r,x,y,z) where r is the radius of the sphere and (x,y,z) is its center.

get_available_spheres_df(space=None)[source]

Get available spheres

Parameters:space (str) – Optional, filter to only rois in a certain space
Returns:DataFrame with columns for sphere id, and number of subjects with the ROI defined; indexed by name
get_all_spheres(sphere_id)[source]

Get a DataFrame of all the subjects spheres with a given id

Parameters:sphere_id (int) – ROI id
Returns:pandas.DataFrame with columns for radius, center x, center y and center z; indexed by subject
subjects_with_sphere(sphere_id)[source]

Get subjects who have a certain sphere defined

Parameters:sphere_id (int) – ROI id
Returns:A set of subjects with the sphere defined
save_sphere(*args, **kwargs)[source]

Save a sphere for a given subject into the database

Parameters:
  • sphere_id (int) – ROI id
  • subject – subject id
  • radius (float) – sphere radius in mm.
  • center (tuple) – The three coordinates for the sphere center in mm.
copy_spheres(*args, **kwargs)[source]

Copies spheres from one ROI to another

Copies the definitions of spheres for each subject from one ROI to another ROI

Parameters:
  • origi_id (int) – ROI id of the source spheres
  • dest_id (int) – ROI id into which the spheres will be copied

Lines

Lines are saved as a starting point (xo,yo,zo) and an end point (xf,yf,zf)

load_line(line_id, subject)[source]

Retrieves a line for a given subject

Parameters:
  • line_id (int) – ROI id
  • subject – subject id
Returns
(xo,yo,zo,xf,yf,zf) where (xo,yo,zo) is the line origin and (xf,yf,zf) is the end.
get_available_lines_df()[source]

Get available lines

Returns:DataFrame with columns for line id, and number of subjects with the ROI defined; indexed by name
subjects_with_line(line_id)[source]

Get subjects who have a certain line defined

Parameters:sphere_id (int) – ROI id
Returns:A set of subjects with the line defined
save_line(*args, **kwargs)[source]

Save a line from a given subject into the database

Parameters:
  • line_id (int) – ROI id
  • subject – subject id
  • point1 (tuple) – coordinates (xo,yo,zo) of the line origin
  • point2 (tuple) – coordinates (xf,yf,zf) of the line end