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'
def test_rotate(pid): for client, fn in zip([Client(), Filesystem(['../exampleData'])], ['target_web', 'target_file']): target = client.resolve(pid) print target.info fn = os.path.join('/Users/jfutrelle/Pictures', fn + '.png') target.image().save(fn, 'png') print 'saved %s' % fn
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')
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')
#!/usr/bin/python from sys import argv, stdout import cgi import cgitb import resolve import rss import mosaic from spider.dashboard import spider from ifcb.db.bins2db import bins2db from ifcb.io.path import Filesystem from config import FS_ROOTS if __name__ == '__main__': cgitb.enable() print 'Content-type: text/plain\n' bins2db(Filesystem(FS_ROOTS)) spider() print 'done'
from config import FS_ROOTS from ifcb.io.path import Filesystem import mosaic import sys import ifcb if __name__=='__main__': if len(sys.argv) < 2: print >> sys.stderr, 'usage: %s [pid] [outputfile]' % sys.argv[0] else: fs = Filesystem(FS_ROOTS) b = fs.resolve(ifcb.pid(sys.argv[1])) outfile = None if len(sys.argv) > 2: outfile = sys.argv[2] print >> sys.stderr, 'Generating mosaic for %s' % str(b) mosaic.save_mosaic(b,outfile)
from sys import argv import mosaic import ifcb from ifcb.io.file import BinFile from ifcb.io.path import Filesystem 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)
import io from array import array from ifcb.io.file import BinFile from ifcb.io.dir import DayDir, YearsDir from ifcb.io.path import Filesystem from ifcb.io.convert import bin2xml, target2image, fs2json_feed, fs2html_feed, fs2atom, fs2rss, day2html, bin2html, target2html, target2xml, target2json, target2rdf, bin2json, day2rdf, day2xml, day2json, bin2hdr, bin2adc, bin2roi import ifcb import pickle from config import FEED from mosaic import doit import urllib2 as urllib from PIL import Image from cStringIO import StringIO J = Filesystem(['/Volumes/J_IFCB/ifcb_data_MVCO_jun06']) E = Filesystem(['../exampleData']) def test1(): for sfx in ['157_181359', '188_200152', '214_150922', '237_000054']: bin = BinFile('../exampleData/headerFiles/IFCB1_2006_' + sfx) print bin.headers() def test2(): dd = DayDir('/Volumes/J_IFCB/ifcb_data_MVCO_jun06/IFCB1_2010_193') day2html(dd) day2json(dd) day2xml(dd) day2rdf(dd)
from ifcb.io.convert import fs2atom, fs2json_feed, fs2html_feed, fs2rss, bin2csv from ifcb.io.path import Filesystem from config import FS_ROOTS, FEED import time import re if __name__ == '__main__': #dates = r'2007-11-01T00:29:00Z' #date = time.strptime(re.sub('Z$','UTC',dates),'%Y-%m-%dT%H:%M:%S%Z') bin = Filesystem(FS_ROOTS).resolve( 'http://ifcb-data.whoi.edu/IFCB1_2011_270_193351') bin2csv(bin)
#!/usr/bin/python import cgitb from ifcb.io.path import Filesystem from config import FS_ROOTS import sys if __name__ == '__main__': cgitb.enable() fs = Filesystem(FS_ROOTS) print 'Content-type: text/plain\n' for day in fs.all_days(): print 'I know about some data' sys.exit(2) else: print 'I cannot find any data'
format = cgi.FieldStorage().getvalue('format','atom') # default format is atom size = int(cgi.FieldStorage().getvalue('n','25')) # default number of bins to return is 25 date = None dates = cgi.FieldStorage().getvalue('date',None) # default date is now if dates is not None and dates != 'now': if re.match(r'^\d{4}-\d{2}-\d{2}$',dates): # is it an unadorned yyyy-mm-dd? date = time.strptime(dates+'UTC','%Y-%m-%d%Z') # assume midnight UTC elif re.match(r'^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$',dates): # ISO 8601 in YYYY-mm-ddTHH:MM:SSZ? date = time.strptime(re.sub('Z$','UTC',dates),'%Y-%m-%dT%H:%M:%S%Z') # parse dayss = cgi.FieldStorage().getvalue('day',None) if dayss is not None: if re.match(r'^\d{4}-\d{2}-\d{2}$',dayss): # is it an unadorned yyyy-mm-dd? date = time.strptime(dayss+'UTC','%Y-%m-%d%Z') # assume midnight UTC elif re.match(r'^\d{4}-\d{3}$',dayss): # is it a julian day (yyyy-jjj)? date = time.strptime(dayss+'UTC','%Y-%j%Z') fs = Filesystem(FS_ROOTS) if dayss is not None: bin_ids = list(day_bins(date)) else: bin_ids = list(latest_bins(size,date)) bins = [fs.resolve(pid) for pid in bin_ids] mime = dict(atom='application/atom+xml', json='application/json', html='text/html', rss='application/rss+xml')[format] headers = ['Content-type: %s' % mime, 'Cache-control: max-age=60', ''] for h in headers: print h link = '.'.join([FEED,format]) if format == 'atom': bins2atom(bins,link) elif format == 'json':
if __name__ == '__main__': out = sys.stdout pid = cgi.FieldStorage().getvalue('pid') format = 'rdf' # default format is RDF, to support "linked open data" if re.search(r'\.[a-z]+$', pid): # does the pid have an extension? (pid, ext) = os.path.splitext(pid) format = re.sub(r'^\.', '', ext) # the extension minus the "." is the "format" format = cgi.FieldStorage().getvalue('format', format) # specified format overrides detail = cgi.FieldStorage().getvalue( 'detail', DETAIL_SHORT) # default detail is "short" scale = float(cgi.FieldStorage().getvalue('scale', '1.0')) # default scale is "1.0" try: object = Filesystem(FS_ROOTS).resolve(pid) # resolve the object mime_type = MIME_MAP[format] # compute its MIME type headers = [ 'Content-type: %s' % mime_type, 'Cache-control: max-age=%d' % DATA_TTL, '' ] for h in headers: print h if isinstance(object, BinFile) or isinstance( object, StitchedBin): # is the object a bin? { 'rdf': bin2rdf, 'xml': bin2xml, 'html': bin2html, 'json': bin2json, 'adc': bin2adc,
from sys import argv import mosaic import ifcb from ifcb.io.file import BinFile from ifcb.io.path import Filesystem 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')
from ifcb.db.bins2db import bins2db from ifcb.io.path import Filesystem from config import FS_ROOTS fs = Filesystem(FS_ROOTS) #for d in fs.all_days(): # print d #bins2db(fs,[]) bins2db(fs)
from config import FS_ROOTS from ifcb.io.path import Filesystem import mosaic import sys import ifcb if __name__ == '__main__': if len(sys.argv) < 2: print >> sys.stderr, 'usage: %s [pid] [outputfile]' % sys.argv[0] else: fs = Filesystem(FS_ROOTS) b = fs.resolve(ifcb.pid(sys.argv[1])) outfile = None if len(sys.argv) > 2: outfile = sys.argv[2] print >> sys.stderr, 'Generating mosaic for %s' % str(b) mosaic.save_mosaic(b, outfile)