def search(d, recursive=True, store_meta=True):
<EOL>scans = col.defaultdict(lambda: col.defaultdict(lambda: col.defaultdict(list)))<EOL>for dirpath,dirnames,filenames in os.walk(os.path.expanduser(d)):<EOL><INDENT>for f in filenames:<EOL><INDENT>fullfile = os.path.join(dirpath, f)<EOL>try:<EOL><INDENT>d = pydicom.read_file(fullfile, stop_before_pixels=True)<EOL><DEDENT>except pydicom.filereader.InvalidDicomError:<EOL><INDENT>continue<EOL><DEDENT>meta = {k: getattr(d, k, None) for k in d.dir()} if store_meta else None<EOL>scans[d.StudyInstanceUID][d.SeriesNumber][d.InstanceNumber].append(DicomFile(meta=meta, file=fullfile))<EOL><DEDENT>if not recursive:<EOL><INDENT>del dirnames[:]<EOL><DEDENT><DEDENT>return scans<EOL>
Search for DICOM files within a given directory and receive back a 
dictionary of {StudyInstanceUID: {SeriesNumber: [files]}}

Example usage::
    >>> import yaxil.dicom
    >>> yaxil.dicom.search("~/dicoms").keys()
    ['1.2.340.500067.8.9.10.11012.13000001401516017181900000200']

:param d: Directory name
:type d: str
:param recursive: Search recursively
:type recursive: bool
:param store_meta: Read and store metadata for each file for fast lookups
:type store_meta: bool
:returns: Dictionary of {StudyInstanceUID: {SeriesNumber: [files]}}
:rtype: dict