Esempio n. 1
0
    def get(self):
        user = h.get_user_or_redirect( self )
        if not user: return

        user_id = h.param(self,'user_id')
        service = h.param(self, 'service')
        
        person = Person.gql("WHERE id = :1 AND user = :2", user_id, user)[0]

        template_values = h.template_params( self, user, **{ 'person' : person, 'service' : service })

        if service == 'facebook':
            fb_photos = person.photos.filter('class =', 'FacebookPhoto').filter('album =', None)
            fb_albums = person.albums.filter('class =', 'FacebookAlbum')
            fb_token  = facebook.FacebookToken.for_user(user)
            if fb_token:
                template_values['photos'] = fb_photos
                template_values['albums'] = fb_albums
            else:
                print "no token"
        elif service == 'flickr':
            flickr_photos = person.photos.filter('class =', 'FlickrPhoto').filter('album =', None)
            flickr_albums = person.albums.filter('class =', 'FlickrAlbum')
            flickr_token  = flickr.FlickrToken.for_user(user)
            if flickr_token:
                template_values['photos'] = flickr_photos
                template_values['albums'] = flickr_albums
            else:
                print "no token"
        else:
            print "no service"

        h.render_template( self, 'photos/index.html', template_values )
Esempio n. 2
0
    def get(self):
        user = h.get_user_or_redirect( self )
        if not user: return

        service = h.param(self, 'service')
        t = None
        if service == 'flickr':
            token = flickr.get_auth_token( h.param(self, 'frob') )
            t = flickr.FlickrToken.update_or_create( { 'token':token, 'user':user } )
        elif service == 'facebook':
            token = facebook.get_auth_token( h.param(self,'code') )
            t = facebook.FacebookToken.update_or_create( { 'token':token, 'user':user } )

        self.redirect( '/settings' )
Esempio n. 3
0
    def get(self):
        user = h.get_user_or_redirect( self )
        if not user: return

        service = h.param(self, 'service')
        type    = h.param(self, 'type')

        if service == 'facebook':
            token = facebook.FacebookToken.for_user( user )
            if type == 'photos': # tagged photos
                owner_id  = h.param(self, 'user_id')
                album_id = h.param(self, 'album_id')
                facebook.import_photos( user, token, owner_id, album_id )
                self.redirect("/photos?service=facebook&user_id="+owner_id)
            elif type == 'people':
                facebook.import_people( user, token )
                self.redirect("/")
            elif type == 'albums':
                owner_id = h.param(self, 'user_id')
                facebook.import_albums( user, token, owner_id )
                self.redirect("/photos?service=facebook&user_id="+owner_id)
        elif service == 'flickr':
            token = flickr.FlickrToken.for_user( user )
            if type == 'photos':
                owner_id = h.param(self, 'user_id')
                album_id = h.param(self, 'album_id')
                flickr.import_photos( user, token, owner_id, album_id )
                self.redirect("/photos?service=flickr&user_id="+owner_id)
            elif type == 'people':
                flickr.import_people( user, token )
                self.redirect("/")
            elif type == 'albums':
                None
Esempio n. 4
0
    def get(self):
        user = h.get_user_or_redirect(self)
        if not user: return

        service = h.param(self, 'service')
        type = h.param(self, 'type')

        if service == 'facebook':
            token = facebook.FacebookToken.for_user(user)
            if type == 'photos':  # tagged photos
                owner_id = h.param(self, 'user_id')
                album_id = h.param(self, 'album_id')
                facebook.import_photos(user, token, owner_id, album_id)
                self.redirect("/photos?service=facebook&user_id=" + owner_id)
            elif type == 'people':
                facebook.import_people(user, token)
                self.redirect("/")
            elif type == 'albums':
                owner_id = h.param(self, 'user_id')
                facebook.import_albums(user, token, owner_id)
                self.redirect("/photos?service=facebook&user_id=" + owner_id)
        elif service == 'flickr':
            token = flickr.FlickrToken.for_user(user)
            if type == 'photos':
                owner_id = h.param(self, 'user_id')
                album_id = h.param(self, 'album_id')
                flickr.import_photos(user, token, owner_id, album_id)
                self.redirect("/photos?service=flickr&user_id=" + owner_id)
            elif type == 'people':
                flickr.import_people(user, token)
                self.redirect("/")
            elif type == 'albums':
                None
Esempio n. 5
0
    def get(self):
        user = h.get_user_or_redirect(self)
        if not user: return

        service = h.param(self, 'service')
        t = None
        if service == 'flickr':
            token = flickr.get_auth_token(h.param(self, 'frob'))
            t = flickr.FlickrToken.update_or_create({
                'token': token,
                'user': user
            })
        elif service == 'facebook':
            token = facebook.get_auth_token(h.param(self, 'code'))
            t = facebook.FacebookToken.update_or_create({
                'token': token,
                'user': user
            })

        self.redirect('/settings')
Esempio n. 6
0
    def get(self):
        user = h.get_user_or_redirect(self)
        if not user: return

        user_id = h.param(self, 'user_id')
        service = h.param(self, 'service')

        person = Person.gql("WHERE id = :1 AND user = :2", user_id, user)[0]

        template_values = h.template_params(
            self, user, **{
                'person': person,
                'service': service
            })

        if service == 'facebook':
            fb_photos = person.photos.filter('class =',
                                             'FacebookPhoto').filter(
                                                 'album =', None)
            fb_albums = person.albums.filter('class =', 'FacebookAlbum')
            fb_token = facebook.FacebookToken.for_user(user)
            if fb_token:
                template_values['photos'] = fb_photos
                template_values['albums'] = fb_albums
            else:
                print "no token"
        elif service == 'flickr':
            flickr_photos = person.photos.filter('class =',
                                                 'FlickrPhoto').filter(
                                                     'album =', None)
            flickr_albums = person.albums.filter('class =', 'FlickrAlbum')
            flickr_token = flickr.FlickrToken.for_user(user)
            if flickr_token:
                template_values['photos'] = flickr_photos
                template_values['albums'] = flickr_albums
            else:
                print "no token"
        else:
            print "no service"

        h.render_template(self, 'photos/index.html', template_values)
Esempio n. 7
0

def put_center(big_frame, small_frame, y, x):
    offs_y = small_frame.shape[0]//2
    offs_x = small_frame.shape[1]//2

    return put(big_frame, small_frame, y-offs_y, x-offs_x)


@filterwarnings("ignore:The fit may be unsuccessful")
@parametrize("psfsize", [6, 7], ids=lambda x: "psf{}".format(x))
@parametrize("framesize", [10, 11], ids=lambda x: "fr{}".format(x))
@parametrize("y,x", [(4, 4), (4, 6), (6, 5)])
@parametrize("psf_model, fit_fkt",
             [
                 param("gauss", fit_2dgaussian, id="gauss"),
                 param("moff", fit_2dmoffat, id="moff"),
                 param("airy", fit_2dairydisk, id="airy")
             ])
def test_fit2d(psf_model, fit_fkt, y, x, framesize, psfsize):
    frame = np.zeros((framesize, framesize))
    psf = create_synth_psf(psf_model, shape=(psfsize, psfsize))

    inj_frame = put_center(frame, psf, y, x)

    y_out, x_out = fit_fkt(inj_frame)

    # correct "half-pixel centering", to make output of fit_2d* comparable
    # with `put`.
    if (
        (framesize % 2 == 0 and psfsize % 2 == 0) or
Esempio n. 8
0
from helpers import aarc, np, param, parametrize
from vip_hci.var.filters import (fft, ifft, cube_filter_iuwt,
                                 cube_filter_highpass, cube_filter_lowpass,
                                 frame_filter_highpass, frame_filter_lowpass)

CUBE = np.ones((5, 10, 10), dtype=float)
FRAME = np.arange(100, dtype=float).reshape((10, 10))


@parametrize("filter_mode", [
    "laplacian", "laplacian-conv", "median-subt", "gauss-subt",
    "fourier-butter", "hann"
])
@parametrize("data, fkt", [
    param(CUBE, cube_filter_highpass, id="cube"),
    param(FRAME, frame_filter_highpass, id="frame")
],
             ids=lambda x: (x.__name__ if callable(x) else None))
def test_highpass(data, fkt, filter_mode):
    res = fkt(data, mode=filter_mode)
    assert res.shape == data.shape


@parametrize("filter_mode", ["median", "gauss"])
@parametrize("data, fkt", [
    param(CUBE, cube_filter_lowpass, id="cube"),
    param(FRAME, frame_filter_lowpass, id="frame")
],
             ids=lambda x: (x.__name__ if callable(x) else None))
def test_lowpass(data, fkt, filter_mode):
Esempio n. 9
0
    """
    if request.param == "3D":
        cube = np.zeros((3, 5, 5))
        psf = np.ones((1, 1))
    elif request.param == "4D":
        cube = np.zeros((2, 3, 5, 5))  # lambda, frames, width, height
        psf = np.ones((2, 1, 1))

    angles = np.array([0, 90, 180])

    return cube, psf, angles


@parametrize("branches, dists", [
    param(1, 2, id="1br-2"),
    param(2, 2, id="2br-2"),
    param(2, [1, 2], id="2br-[1,2]")
])
def test_cube_inject_companions(dataset, branches, dists):
    """
    Verify position of injected companions, for 3D and 4D cases.
    """
    def _expected(branches, dists):
        """
        Expected positions.
        """
        if branches == 1 and dists == 2:
            return [(2, 4)]
        elif branches == 2 and dists == 2:
            return [(2, 4), (2, 0)]
Esempio n. 10
0
    """
    if request.param == "3D":
        cube = np.zeros((3, 5, 5))
        psf = np.ones((1, 1))
    elif request.param == "4D":
        cube = np.zeros((2, 3, 5, 5))  # lambda, frames, width, height
        psf = np.ones((2, 1, 1))

    angles = np.array([0, 90, 180])

    return cube, psf, angles


@parametrize("branches, dists",
             [
                param(1, 2, id="1br-2"),
                param(2, 2, id="2br-2"),
                param(2, [1, 2], id="2br-[1,2]")
             ])
def test_cube_inject_companions(dataset, branches, dists):
    """
    Verify position of injected companions, for 3D and 4D cases.
    """
    def _expected(branches, dists):
        """
        Expected positions.
        """
        if branches == 1 and dists == 2:
            return [(2, 4)]
        elif branches == 2 and dists == 2:
            return [(2, 4), (2, 0)]
Esempio n. 11
0
FRAME = np.arange(100, dtype=float).reshape((10, 10))


@parametrize("filter_mode",
             [
                 "laplacian",
                 "laplacian-conv",
                 "median-subt",
                 "gauss-subt",
                 "fourier-butter",
                 "hann"
             ]
             )
@parametrize("data, fkt",
             [
                 param(CUBE, cube_filter_highpass, id="cube"),
                 param(FRAME, frame_filter_highpass, id="frame")
             ],
             ids=lambda x: (x.__name__ if callable(x) else None)
             )
def test_highpass(data, fkt, filter_mode):
    res = fkt(data, mode=filter_mode)
    assert res.shape == data.shape


@parametrize("filter_mode", ["median", "gauss"])
@parametrize("data, fkt",
             [
                 param(CUBE, cube_filter_lowpass, id="cube"),
                 param(FRAME, frame_filter_lowpass, id="frame")
             ],
Esempio n. 12
0
    return big_frame


def put_center(big_frame, small_frame, y, x):
    offs_y = small_frame.shape[0] // 2
    offs_x = small_frame.shape[1] // 2

    return put(big_frame, small_frame, y - offs_y, x - offs_x)


@filterwarnings("ignore:The fit may be unsuccessful")
@parametrize("psfsize", [6, 7], ids=lambda x: "psf{}".format(x))
@parametrize("framesize", [10, 11], ids=lambda x: "fr{}".format(x))
@parametrize("y,x", [(4, 4), (4, 6), (6, 5)])
@parametrize("psf_model, fit_fkt", [
    param("gauss", fit_2dgaussian, id="gauss"),
    param("moff", fit_2dmoffat, id="moff"),
    param("airy", fit_2dairydisk, id="airy")
])
def test_fit2d(psf_model, fit_fkt, y, x, framesize, psfsize):
    frame = np.zeros((framesize, framesize))
    psf = create_synth_psf(psf_model, shape=(psfsize, psfsize))

    inj_frame = put_center(frame, psf, y, x)

    y_out, x_out = fit_fkt(inj_frame)

    # correct "half-pixel centering", to make output of fit_2d* comparable
    # with `put`.
    if ((framesize % 2 == 0 and psfsize % 2 == 0)
            or (framesize % 2 == 1 and psfsize % 2 == 0)):