notmatthancock / pylidc

An object relational mapping for the LIDC dataset using sqlalchemy.
https://pylidc.github.io
Other
105 stars 41 forks source link

Is filtering supposed to work for querying Annotations? #17

Closed fedorov closed 6 years ago

fedorov commented 6 years ago

I am confused about the behavior of the query below. Should it filter by patient ID, or not?

image

notmatthancock commented 6 years ago

Scans and Annotation objects are stored in different tables, and so to do this type of query, you need a join clause. See here.

notmatthancock commented 6 years ago

Also, to get counts from a query, you can just issue a count on the query, e.g.:

print pl.query(pl.Annotation).join(pl.Scan)\
        .filter(pl.Scan.patient_id == 'LIDC-IDRI-0011').count()
# 23

Alternatively, you can accomplish this same result by:

scan = pl.query(pl.Scan).filter(pl.Scan.patient_id == 'LIDC-IDRI-0011').first()
print len(scan.annotations)
# 23
fedorov commented 6 years ago

Thank you! Sorry for the confusion.

notmatthancock commented 6 years ago

No problem. FYI, pylidc is implemented with sqlalchemy, which is where the filter, count, join, etc ... functions come from. sqlalchemy has nice documentation if you want to dive deeper into more complex query capabilities.