creating a BrainVisa database hierarchy

Questions about BrainVisa usage and installation

Moderators: denghien, riviere

Post Reply
Manik
Posts: 99
Joined: Fri Mar 05, 2004 1:00 pm
Location: INSERM U836, Grenoble

creating a BrainVisa database hierarchy

Post by Manik »

Hi all,

I am trying to create a specific database hierarchy. I know how my data should be organized, and I try to write a BrainVisa hierarchy to meet my needs.

Is there a tutorial somewhere about writing a hierarchy ?
I am using shfjHierarchy.py as a template, and I declared the new types I needed in a "types.py" file.

I wonder what is the difference between SetFileNameAttribute and SetFileNameStrongAttribute when creating a directory.
What kind of information should be put using SetWeakAttr ? Any information to be used by BV processes ?

Is it possible to declare a "variable name" without a directory ? I mean, is it possible to put in a "d|*", SetFileNameAttribute('subject'), SetType( 'Subject' ),
a file named <subject>_<typeOfExam> without creating a directory for "typeOfExam" ?

Thank you for your help !
Manik Bhattacharjee
INSERM U836
User avatar
Yann Cointepas
Posts: 316
Joined: Tue Jan 20, 2004 2:56 pm
Location: Neurospin, Saint Aubin, France
Contact:

Post by Yann Cointepas »

Hi Manik,

No, there is no tutorial but if you agree I can explain you how to do it and you write tutorial...

The types.py is in the oldest part of BrainVISA. As a consequence, there is no dependency system between types files. I could do this system so that you can put your types in your own file.

You can put anything in attributes. They are not interpreted by BrainVISA. They are used for data query and filtering. There is two kinds of attributes: weak and strong. I introduced this difference in order to speed-up database parsing. The difference arrise when you do a query on a Read/WriteDiskItem (mainly via linkParameters). Two data with different strong attributes will not be linked together. For example, protocol is a strong attribute in shfjHierarchy.py. Therefore, if query the database (via findValue or linkParameters()) for T1 MRI with a DiskItem having protocol='waow' you will only get result in that protocol. On the other hand if you query with a DiskItem having database='/mydirectory/mybase', you will get all the T1 MR of all databases because database is a weakAttribute.

As a rule of thumb, if you are not sure of what you are doing, use the weakest attribute.

To use <subject>_<typeOfExam> in a hierarchy rule, you do not need to build a directory but typeOfExam must be an attribute declared in the hierarchy file and whose value is accessible when parsing the rule. This is required because rules are used to generate names for non existing files (for WriteDiskItem). I cannot see exactly what you want to do here but if you give me more information, I could help you in finding a solution.
Manik
Posts: 99
Joined: Fri Mar 05, 2004 1:00 pm
Location: INSERM U836, Grenoble

Post by Manik »

Thank you very much for the answer.

In fact, I already wrote a (small) document to describe how to do that kind of thing (in fact, only what I found out), and as soon as I consider it ok, I will send it to you (and translate it in english if I have time for this).

I understand much better the use of attributes now.

About what I am doing :

For each patient I have a structure like this :

Code: Select all

surgery/
   before/
        <subject>_<exam>_<referential> (e.g. Smith_T1mri_T1mriBefore.ima)
   during/
   after/
   transforms/
        <referential1>_TO_<referential2>_<method>
        e.g. T1mriBefore_TO_T1mriAfter_CACP.trm
Right now, I just find the referential name by reading and splitting the filenames in my process, but I wondered if there was not a better way to do this using BrainVisa attributes.
Manik Bhattacharjee
INSERM U836
User avatar
Yann Cointepas
Posts: 316
Joined: Tue Jan 20, 2004 2:56 pm
Location: Neurospin, Saint Aubin, France
Contact:

Post by Yann Cointepas »

I see. It is not easy to handle referentials in a hierarchy.
It is always a bad idea to split filenames in processe because it is only going to work with the hierarchy it is designed for. If I write my own hierarchy with another filename pattern it will not work.

You can use the possibility to use dictionary of attributes to query database. Let's take an example. You have a process with the following signature :

Code: Select all

signature = Signature(
  'before', ReadDiskItem( 'T1 MRI', shfjGlobals.aimsVolumeFormats ),
  'after', ReadDiskItem( 'T1 MRI', shfjGlobals.aimsVolumeFormats ),
 'transformation', WriteDiskItem( 'Transformation', 'Transformation matrix' ),
}
If you want to find a value for'transformation' when 'before' and 'other' are selected, you should write something looking like this :

Code: Select all

def findTransformation( values, process ):
  if values.before is not None and values.after is not None:
    # Copy the attributes of one of the two images to get protocol, subject, etc.
    attributes = self.before.attributes()
    attributes[ 'referential1' ] = before.get( 'referential' )
    attributes[ 'referential2' ] = after.get( 'referential' )
    return process.signature[ 'transformation' ].findValue( attributes )

def initialization( self ):
  self.linkParameters( 'transformation', [ 'before', 'after' ], findTransformation )
This kind of code may fail for various reasons. Often it is because of the hierarchy file. Unfortunately, it is hard to debug what happend in findValue. You can add 'debug = True' in the findValue() call and check the console output but you will nedd to have the findValue() source code opened to analyse this output.

Let me know if you need more information.
Manik
Posts: 99
Joined: Fri Mar 05, 2004 1:00 pm
Location: INSERM U836, Grenoble

Post by Manik »

Ok, I understand better the way I should use linkParameters.

But in fact, I am doing something a little more complicated : I put a "Transform directory" in the signature of my process, then I list all files in it, to compute paths from one referential to another.

There may be a better way to do this, but that is the only way I tried that works...

If in the directory there is A_TO_B, B_TO_D, C_TO_D, I list those files, and I compute a path between referentials : if the data I want to use is in referentials A and C, I will create in Anatomist A, B, C and D referentials, and link them together with the appropriate transformations.
Manik Bhattacharjee
INSERM U836
Post Reply