This is no longer maintained and has been superseded by datajoint-company/datajoint-docs. Please file new issues there (or help contribute!). We are currently migrating and generating new content until December 2022 after which we’ll be decomissioning https://docs.datajoint.org and https://tutorials.datajoint.org in favor of https://datajoint.com/docs/.
proj operator represents projection and is used to select attributes (columns) from a table, to rename them, or to create new calculated attributes.
The simple projection selects a subset of attributes of the original table. However, the primary key attributes are always included.
Using the example schema, let table
department have attributes dept, dept_name, dept_address, and dept_phone.
The primary key attribute is in bold.
department.proj() will have attribute dept.
department.proj('dept') will have attribute dept.
department.proj('dept_name', 'dept_phone') will have attributes dept, dept_name, and dept_phone.
In addition to selecting attributes,
proj can rename them.
Any attribute can be renamed, including primary key attributes.
Renaming is done using a string:
For example, let table
tab have attributes mouse, session, session_date, stimulus, and behavior.
The primary key attributes are in bold.
will have attributes animal, session, and stimulus.
Renaming is often used to control the outcome of a join.
For example, let
tab have attributes slice, and cell.
tab * tab will simply yield
tab * tab.proj('cell->other')
yields all ordered pairs of all cells in each slice.
In addition to selecting or renaming attributes,
proj can compute new attributes from existing ones.
For example, let
tab have attributes
To obtain the new attribute
depth computed as
scan_z - surface_z and then to restrict to
depth > 500:
tab.proj('scan_z-surface_z -> depth') & 'depth > 500'
Calculations are passed to SQL and are not parsed by DataJoint. For available functions, you may refer to the MySQL documentation.