Exemple #1
0
    def make_contour_bounds_shapefile(self):
        import databundles.geo as dg
        from numpy import ma
        import yaml


        shape_file_dir = self.filesystem.path('extracts','contours')
        shape_file = os.path.join(shape_file_dir, 'contours.shp') # One of two. 
        
        if os.path.exists(shape_file):
            return shape_file_dir

        partition = self.partitions.all[0]# There is only one
        hdf = partition.hdf5file
        hdf.open()
        
        a1,_ = hdf.get_geo('property')
        a2,aa = hdf.get_geo('violent')
     
        a = dg.std_norm(ma.masked_equal(a1[...] + a2[...],0))   # ... Converts to a Numpy array. 

        # Creates the shapefile in the extracts/contour directory
        envelopes = dg.bound_clusters_in_raster( a, aa, shape_file_dir, 0.1,0.7, use_bb=True, use_distance=50)
  
        # Cache the envelopes for later. 
        env_file = self.filesystem.path('build','envelopes.yaml')
        with open(env_file,'w') as f:
            f.write(yaml.dump(envelopes, indent=4, default_flow_style=False))
  
        return  shape_file_dir
Exemple #2
0
    def build_aa_map(self):
        '''
        '''
        import databundles.library as dl
        import databundles.geo as dg
        import random 
        from numpy import  ma
        
        rs = 3
    
        # make a helper to store files in the extracts directory
        ed = lambda f: self.filesystem.path('extracts','subs',f+'.tiff')
    
        l = dl.get_library()
        aa = dg.get_analysis_area(l, geoid=self.config.build.aa_geoid)
        
        r =  l.find(dl.QueryCommand().identity(id='a2z2HM').partition(table='incidents',space=aa.geoid)).pop()
        source_partition = l.get(r.partition).partition

        k = dg.GaussianKernel(33,11)
        
        sub_aas = [self.get_sub_aas()[1]]
        
        top_a = aa.new_array()
        for i, sub_aa in enumerate(sub_aas):
            where = sub_aa.is_in_ll_query()
            sub_a = sub_aa.new_array()
            trans = sub_aa.get_translator()

            q = "select * from incidents WHERE {}".format(where)
        
            for row in source_partition.query(q):
                p = trans(row['lon'],row['lat'])
                k.apply_add(sub_a, p)
                print row
            
            sub_aa.write_geotiff(ed(str(i)), dg.std_norm(ma.masked_equal(sub_a,0)))
            sub_aa.write_geotiff(ed(str(i)), sub_a)

      
        return True