DrSAR / SARlabpy

git clone git@pfeifer.phas.ubc.ca:SARlabpy (do not push to github, please)
http://code.SARlab.ca
Other
1 stars 0 forks source link

Parsing the stored masterlist - sarpy.io.masterlist_parse.get_scans_from_masterlist #338

Closed firasm closed 9 years ago

firasm commented 9 years ago

I've created a helper function to help me parse masterlists and I want a second set of eyes on it to see if it's the right thing to do.

You can test it out as follows:

import sarpy
scn = sarpy.Scan("HPGP4Ts03.vw1/7")

res = sarpy.io.masterlist_parse.get_scans_from_masterlist(scn,['roi','LL.-'])

Here is the res printed

{'LL.-': ['HPGP4Ts08.vx1/5',
  'HPGP4Ts05.vx1/5',
  'HPGP4Ts04.vw1/4',
  'HPGP4Ts06.vx1/5',
  'HPGP4Ts03.vw1/5',
  'HPGP4Ts02.vw1/5'],
 'roi': ['HPGP4Ts08.vx1/5',
  'HPGP4Ts05.vx1/5',
  'HPGP4Ts04.vw1/4',
  'HPGP4Ts06.vx1/5',
  'HPGP4Ts03.vw1/5',
  'HPGP4Ts02.vw1/5']}

What do you think?

I need this because it's necessary to have a list/dictionary of scans for each scan_label provided. I intend to replace the code snippet in my wrappers that read the old masterlist:

    root = os.path.join(os.path.expanduser('~/sdata'),
                        masterlist_name,
                        masterlist_name)

    fname_to_open = root+'.json'
    with open(os.path.join(fname_to_open),'r') as master_file:
        json_str = master_file.read()
        master_list = json.JSONDecoder(
                           object_pairs_hook=collections.OrderedDict
                           ).decode(json_str)

    # Here is the dictionary where the patient is looped over

    for k,v in master_list.iteritems():
firasm commented 9 years ago

here's the commit: a9586625987716c983adb14d0ee9f14c8b1b8a86

firasm commented 9 years ago

get all patients from an experiment:

def get_patients_from_experiment(Experiment_name, verbose = False,namesOnly=False):

    subject_list = get_unique_list_elements(sarpy.Experiment(Experiment_name).get_SUBJECT_id())

    Patients = []  

    for subject in subject_list:
        curr_patient = sarpy.Patient(subject)
        Patients.append(curr_patient)        

        if verbose:
            print('Patient {0} has {1} sessions.'.format(subject,len(curr_patient.studies)))

    if namesOnly:
        return [a.patient_id for a in Patients]

    else:
        return list(set(Patients))
DrSAR commented 9 years ago

Some potential use cases

DrSAR commented 9 years ago

The new functionality within commit cb3d56f24 allows for quick access to all patients and all scanlabels in a given Experiment assembled from a masterlist. I would think a lot of the desired features aimed at above is covered by this. Obsolete?

firasm commented 9 years ago

agreed, this is all done except for "get all scan with given ‘adata’ (this is hard and potentially unrelated)"

and that one is a new feature request in #343.