コード例 #1
0
def doit(pid,size='medium',format='jpg',headers=True,out=sys.stdout,fs_roots=FS_ROOTS,page=0):
    format = dict(png='png', jpg='jpeg', gif='gif', json='json')[format] # validate
    # sizes map to widths, widths map to height via fixed 16:9 aspect ratio
    tw = {'icon':48, 'thumb':128, 'small':320, 'medium':800, 'large':1024, '720p':1280, '1080p':1920, 'max':2400}[size]
    wh = box(tw,ASPECT_RATIO)
    size_thresh = 1200
    try:
        bin = Filesystem(fs_roots).resolve(pid) # fetch the bin
        # all mosaics are created at 2400 x 1260 and then scaled down
        fullarea = box(2400,ASPECT_RATIO)
        if format == 'json': # if the caller just wants the layout
            if headers:
                for h in ['Content-type: application/json',
                          'Cache-control: max-age=31622400',
                          '']:
                    print h
            json.dump(layout(bin, fullarea, size_thresh, page=page),out) # give it to em
        else:
            if headers:
                cache_key = ifcb.lid(pid) + '/mz/p'+str(page)+'/'+str(tw)+'.'+format
                cache_io(cache_key, lambda o: http(bin, fullarea, size_thresh, wh, o, format, page=page), out)
            else:
                stream(thumbnail(mosaic(bin,fullarea,size_thresh,page=page),wh),out,format)
    except KeyError:
        print 'Status: 404\n'
コード例 #2
0
ファイル: mosaic.py プロジェクト: hsosik/ifcb-analysis
def doit(pid, size="medium", format="jpg", headers=True, out=sys.stdout, fs_roots=FS_ROOTS, page=0):
    format = dict(png="png", jpg="jpeg", gif="gif", json="json")[format]  # validate
    # sizes map to widths, widths map to height via fixed 16:9 aspect ratio
    tw = {
        "icon": 48,
        "thumb": 128,
        "small": 320,
        "medium": 800,
        "large": 1024,
        "720p": 1280,
        "1080p": 1920,
        "max": 2400,
    }[size]
    wh = box(tw, ASPECT_RATIO)
    size_thresh = 1200
    try:
        bin = Filesystem(fs_roots).resolve(pid)  # fetch the bin
        # all mosaics are created at 2400 x 1260 and then scaled down
        fullarea = box(2400, ASPECT_RATIO)
        if format == "json":  # if the caller just wants the layout
            if headers:
                for h in ["Content-type: application/json", "Cache-control: max-age=31622400", ""]:
                    print h
            json.dump(layout(bin, fullarea, size_thresh, page=page), out)  # give it to em
        else:
            if headers:
                cache_key = ifcb.lid(pid) + "/mz/p" + str(page) + "/" + str(tw) + "." + format
                cache_io(cache_key, lambda o: http(bin, fullarea, size_thresh, wh, o, format, page=page), out)
            else:
                stream(thumbnail(mosaic(bin, fullarea, size_thresh, page=page), wh), out, format)
    except KeyError:
        print "Status: 404\n"
コード例 #3
0
ファイル: path.py プロジェクト: hsosik/ifcb-analysis
 def __day(self, pid):
     lid = ifcb.lid(pid)  # local id
     for years in self.years_dirs:  # search the years dirs
         day_path = os.path.join(years.dir, lid)  # compute the day path
         if os.path.exists(day_path):  # if it exists
             return DayDir(day_path)  # construct a DayDir to represent it
     raise KeyError("day " + pid + " not found")
コード例 #4
0
ファイル: path.py プロジェクト: reuf/ifcb-analysis
 def __day(self, pid):
     lid = ifcb.lid(pid)  # local id
     for years in self.years_dirs:  # search the years dirs
         day_path = os.path.join(years.dir, lid)  # compute the day path
         if os.path.exists(day_path):  # if it exists
             return DayDir(day_path)  # construct a DayDir to represent it
     raise KeyError('day ' + pid + ' not found')
コード例 #5
0
ファイル: pids.py プロジェクト: reuf/ifcb-analysis
def parse_id(pid,namespace=None):
    lid = ifcb.lid(pid,namespace)
    # attempt to guess format
    if re.match(r'^IFCB',lid):
        return OldPid(lid)
    elif re.match(r'D.*IFCB\d+_?\d*$',lid):
        return NewPid(lid)
    elif re.match(r'^D\d+$',lid): # day dir in new format
        return NewPid(lid)
    else:
        raise KeyError('unrecognized ID format %s' % lid)
コード例 #6
0
def test_bin(pid):
    #client = Client()
    client = Filesystem(['../exampleData'])
    catch = False
    dir = os.path.join('stitch', ifcb.lid(pid))
    try:
        os.mkdir(dir)
    except:
        pass
    unstitched = client.resolve(pid)
    stitched = StitchedBin(unstitched)
    print stitched
    pairs = list(find_pairs(unstitched))
    for target, ignore in pairs:
        t = stitched.target(target)
        print 'Got %s' % t
        basename = ifcb.lid(t.pid)
        t.image().save(os.path.join(dir, basename + '.png'), 'png')
        t.mask().save(os.path.join(dir, basename + '_mask.png'), 'png')
        t.stitch_raw().save(os.path.join(dir, basename + '_raw.png'), 'png')
コード例 #7
0
ファイル: stitch.py プロジェクト: hsosik/ifcb-analysis
def test_bin(pid):
    #client = Client()
    client = Filesystem(['../exampleData'])
    catch = False
    dir = os.path.join('stitch',ifcb.lid(pid))
    try:
        os.mkdir(dir)
    except:
        pass
    unstitched = client.resolve(pid)
    stitched = StitchedBin(unstitched)
    print stitched
    pairs = list(find_pairs(unstitched))
    for target,ignore in pairs:
        t = stitched.target(target)
        print 'Got %s' % t
        basename = ifcb.lid(t.pid)
        t.image().save(os.path.join(dir,basename+'.png'),'png')
        t.mask().save(os.path.join(dir,basename+'_mask.png'),'png')
        t.stitch_raw().save(os.path.join(dir,basename+'_raw.png'),'png')
コード例 #8
0
ファイル: stitching.py プロジェクト: reuf/ifcb-analysis
 def __pairs(self):
     if self.pairs is None:
         cache_key = '_'.join([ifcb.lid(self.pid), 'spairs'])
         self.pairs = cache_obj(cache_key,
                                lambda: list(find_pairs(self.bin)))
     return self.pairs
コード例 #9
0
ファイル: stitching.py プロジェクト: reuf/ifcb-analysis
 def lid(self):
     return ifcb.lid(self.pid)
コード例 #10
0
ファイル: blob_unzip.py プロジェクト: reuf/ifcb-analysis
def pid2blobpng(pid):
    lid = ifcb.lid(pid)
    blobzip = ZipFile(zip_path(lid))
    png = blobzip.read(lid + '.png')
    blobzip.close()
    return png
コード例 #11
0
ファイル: pids.py プロジェクト: reuf/ifcb-analysis
 def __init__(self,pid,namespace=None):
     self.lid = ifcb.lid(pid,namespace)
     self.date_format = '%Y%m%d'
     self.datetime_format = '%Y%m%dT%H%M%S'
コード例 #12
0
ファイル: file.py プロジェクト: hsosik/ifcb-analysis
 def lid(self):
     return ifcb.lid(self.pid)
コード例 #13
0
ファイル: stitching.py プロジェクト: hsosik/ifcb-analysis
 def __pairs(self):
     if self.pairs is None:
         cache_key = '_'.join([ifcb.lid(self.pid),'spairs'])
         self.pairs = cache_obj(cache_key,lambda: list(find_pairs(self.bin)))
     return self.pairs
コード例 #14
0
if __name__ == '__main__':
    pid = argv[1]
    print 'Resolving...'
    bin = Filesystem(FS_ROOTS).resolve(pid)  # fetch the bin
    nrois = bin.length()
    width = 2400
    height = nrois * 4
    while True:
        print 'Fitting ...'
        lo = mosaic.layout(bin, (width, height),
                           sort_key=lambda t: t.processingEndTime)
        nfit = len(lo['tiles'])
        print 'Fit %d of %d ROIs in a %d x %d mosaic...' % (nfit, nrois, width,
                                                            height)
        if nfit < nrois:
            height = int(height * 1.5)
        else:
            print 'Computing image...'
            image = mosaic.mosaic(bin, (width, height), existing_layout=lo)
            thumb_width = 1024
            thumb_height = int(round(0.426667 * height))
            print 'downscaling to %d x %d ...' % (thumb_width, thumb_height)
            thumb = mosaic.thumbnail(image, (thumb_width, thumb_height))
            (ext, fmt) = ('.jpg', 'JPEG')
            fn = ifcb.lid(pid) + ext
            print 'saving to disk in %s...' % fn
            with open(fn, 'wb') as out:
                thumb.save(fn, fmt)
            break
コード例 #15
0
ファイル: blob_unzip.py プロジェクト: hsosik/ifcb-analysis
def pid2blobpng(pid):
    lid = ifcb.lid(pid)
    blobzip = ZipFile(zip_path(lid))
    png = blobzip.read(lid + ".png")
    blobzip.close()
    return png
コード例 #16
0
ファイル: full_mosaic.py プロジェクト: hsosik/ifcb-analysis
from ifcb.io import HEIGHT, WIDTH, TARGET_NUMBER, PID, PROCESSING_END_TIME
from config import FS_ROOTS, DATA_TTL

if __name__=='__main__':
    pid = argv[1]
    print 'Resolving...'
    bin = Filesystem(FS_ROOTS).resolve(pid) # fetch the bin
    nrois = bin.length()
    width = 2400
    height = nrois * 4
    while True:
        print 'Fitting ...'
        lo = mosaic.layout(bin, (width, height), sort_key=lambda t: t.processingEndTime)
        nfit = len(lo['tiles'])
        print 'Fit %d of %d ROIs in a %d x %d mosaic...' % (nfit, nrois, width, height)
        if nfit < nrois:
            height = int(height * 1.5)
        else:
            print 'Computing image...'
            image = mosaic.mosaic(bin, (width, height), existing_layout=lo)
            thumb_width = 1024;
            thumb_height = int(round(0.426667 * height))
            print 'downscaling to %d x %d ...' % (thumb_width, thumb_height)
            thumb = mosaic.thumbnail(image, (thumb_width, thumb_height))
            (ext, fmt) = ('.jpg', 'JPEG')
            fn = ifcb.lid(pid) + ext
            print 'saving to disk in %s...' % fn
            with open(fn, 'wb') as out:
                thumb.save(fn, fmt)
            break