Exemple #1
0
def refinetight(f, df, tri, phases, cutoff=0.1):
    a1 = tri.x
    a2 = tri.y
    print('tightening...', end='\t\t')
    bounds, _, tri = getpts(tri,phases)
    bounds = longenough(tri, bounds, cutoff)
    if len(bounds)==0:
        print('No refinement: already within cutoff')
        return a1, a2, phases, 0
    else:
        print('Moving {:d} points'.format(len(bounds)))
    
    oldpoints = hp.uniq(np.hstack(bounds))
    a1new, a2new = getmidpoints(tri, bounds)
    
    phasesnew = getpd(f, df, a1new, a2new)
    
    for op in oldpoints[::-1]:
        phases = np.delete(phases, op)
        a1 = np.delete(a1, op)
        a2 = np.delete(a2, op)
    a1 = np.hstack((a1, a1new))
    a2 = np.hstack((a2, a2new))        
    phases = np.hstack((phases, phasesnew))
    
    tri = mpt.Triangulation(a1,a2)

    return tri, phases, len(bounds)
Exemple #2
0
    def get(self, month):
        if month.capitalize() in seasons().keys():
            recipes = uniq([k for k in queryForMonth(seasons()[month][0])] +
                           [k for k in queryForMonth(seasons()[month][1])] +
                           [k for k in queryForMonth(seasons()[month][2])])
            recipes = [Recipe.get(k) for k in recipes]
        else:
            recipes = [r for r in Recipe.gql('WHERE %s = TRUE' % month.lower())]

        templatevalues = RequestContext(self.request, {
            'month' : month.capitalize(),
            'recipes' : recipes,
            'json' : simplejson.dumps([r.to_dict() for r in recipes]),
            })

        path = os.path.join(os.path.dirname(__file__), 'month.html')
        self.response.out.write(template.render(path, templatevalues))
Exemple #3
0
    def get(self, ingredient_key):
        i = Ingredient.get(ingredient_key)
        if i == None:
            # TODO: error page?
            return

        # Gather all the recipes for all the QIs for this ingredient
        recipes = uniq([qi.recipe for qi in i.quantifiedingredient_set],
                       lambda x: x.title)

        buckets,keys = bucketize(recipes, lambda x: x.title)
        templatevalues = RequestContext(self.request, {
                'ingredient' : i,
                'recipes' : recipes,
                'buckets' : buckets,
                'keys' : keys
                })
        path = os.path.join(os.path.dirname(__file__), 'recipes_by_ingredient.html')
        self.response.out.write(template.render(path, templatevalues))
Exemple #4
0
    def get(self, tag_name):
        t = Tag.get_by_name(tag_name)
        if t == None:
            # TODO: error page?
            return

        # Gather all the recipes for all the QIs for this ingredient
        recipes = uniq([Recipe.get(key) for key in t.tagged],
                       lambda x: x.title)

        buckets,keys = bucketize(recipes, lambda x: x.title)
        templatevalues = RequestContext(self.request, {
                'tag' : t,
                'recipes' : recipes,
                'buckets' : buckets,
                'keys' : keys
                })
        path = os.path.join(os.path.dirname(__file__), 'recipes_by_tag.html')
        self.response.out.write(template.render(path, templatevalues))