Пример #1
0
    def gener_borders( self, thick, dens = None, domain = None, \
                        file_b = 'borders.ll' ):#, file_s = 'shapes' ):
        '''Generates files:
        -'file_b.ll' (lon-lat convension) list of points filtered by
        optional 'dens' density (hpgrid method) and located whithin 'thick'
        distance from ocean coasts (in kilometers) inside domain.
        -'contours[.ll,.xyz]' current contours inside domain.
        -garbage due to inner calls.
        '''
        contour = [ [ GC.norm_lon( c[0] ) , GC.norm_lat( c[1] ) ] \
                    for c in self.contour ]

        #selecting contour in domain
        if domain:
            contour = [ c for c in contour[:] if is_inside( c, domain ) ]

        temp = geofiles.lonlat_to_xyz( contour )

        #outputting contours
        geofiles.w_xyz( 'contours.xyz', temp )
        geofiles.w_lonlat( 'contours.ll', contour )

        #merging contours and verts inside domain
        points = geofiles.xyz_to_lonlat( self.verts )
        if domain:
            points = [ p for p in points[:] if is_inside( p, domain ) ]
        else:
            pass

        points = geofiles.lonlat_to_xyz( points + contour )

        #filtering by 'dens'
        if dens:
            tg = hpgrid.Grid()
            tg.points = points
            tg.points_filter( dens )
            points = tg.points

        points = geofiles.xyz_to_lonlat( points )
        geofiles.w_lonlat( 'temp.ll', points )
    
##        #outputting shapes
##        geofiles.w_xyz( file_s + '.xyz', points )
##        points = geofiles.xyz_to_lonlat( points )
##        geofiles.w_lonlat( file_s + '.ll', points )

        #creating borders with GMT
        ts = str( thick )
##        subprocess.call( 'gmt gmtselect ' + file_s + '.ll -fg -C' + ts + \
##                         'k/contours.ll > ' + file_b + '.ll', shell=True )
        subprocess.call( 'gmt gmtselect ' + 'temp.ll -fg -C' + ts + \
                         'k/contours.ll > ' + file_b, shell=True )

        os.remove('temp.ll')

        return
Пример #2
0
def main():
    print( 'Generating borders:' )

    print('-loading shapes')
    bord = BG.Border( '/home/gleb/Documents/GMT_DATA/gshhg-shp-2.3.4/GSHHS_shp/l/GSHHS_l_L1' )

    print('-preparing contours')
    #better use all shapes, but that takes time
    bord.make_shapes_contour( domain = (45, 315, 50, 90) )

    print('-adding verts')
    bord.add_hp_verts( 5.0, 4.0 )
    bord.add_hp_verts( 2.0, 2.0, (0, 360, 60, 90) ) #0.5 0.9
    print('  high resolution domain')
    bord.add_hp_verts( 0.7, 0.7, (150, 270, 60, 85) )
    bord.add_hp_verts( 0.1, 0.1, (180, 250, 65, 82) )
    bord.add_hp_verts( 0.04, 0.01, (190, 230, 65, 79) )

    bord.add_hp_verts( 0.05, 0.01, (195, 225, 67, 75) )

    bverts = bord.verts[:]
##    #canal
##    print('-adding `canal` high resolution domain')
##    bord.add_contour( 'canal.ll' )
##    bord.add_hp_verts( 0.07, 0.07, (175, 190, 55, 60) )

    print('-filtering contours')
    bord.filter_contour( 0.05, (0, 360, 50, 90) )

    print('-actually generating borders` file')
##    bord.gener_borders( 50, domain=(90, 270, 50, 90) )
    bord.gener_borders( 50, domain=(150, 260, 50, 90) )
    bord.filter_v_by_b( 'borders.ll', 'contours.ll', 150, 'marks.ll' ) 

    print('-adding coverage')
##    grid = hpgrid.Grid()
##    grid.points_gen( 5. )
##    grid.points_filter( 4. )
##
##    pol = hpgrid.Grid( hpgrid.Domain( theta = (0, 0.44) ) )
##    pol.points_gen( 1. )
##    pol.points_filter( 1. )
##
##    hig = hpgrid.Grid( hpgrid.Domain( units=0, phi = (170,240), \
##                                    theta = (14, 30) ) )
##    hig.points_gen( 0.15 )
##    hig.points_filter( 0.15 )
##
##    #alaska north shores
##    can = hpgrid.Grid( hpgrid.Domain( units=0, phi = (200,220), \
##                                      theta = (15, 25) ) )
##    # (0 (180 185) (30 40) )
##    can.points_gen( 0.1 )
##    can.points_filter( 0.1 )
##
##    verts = geofiles.xyz_to_lonlat( grid.points + pol.points + hig.points + \
##                                    can.points )
    verts = geofiles.xyz_to_lonlat( bverts )
    geofiles.w_lonlat( 'verts.ll', verts )

    print('\n-finalizing files')
    bord.extract_borders_from_v( 'verts.ll', 'borders.ll', 1 )
    verts = geofiles.r_lonlat( 'extrd.ll' )
    bords = geofiles.r_lonlat( 'borders.ll' )
    geofiles.w_xyz( 'shapes.xyz', geofiles.lonlat_to_xyz( verts + bords ) )

    #os.remove( 'verts.ll' )

    print('done!\n')
    return 
Пример #3
0
def main():
    print( 'Generating borders:' )

    print('-loading shapes')
    bord = BG.Border( '/home/gleb/Documents/GMT_DATA/gshhg-shp-2.3.4/GSHHS_shp/l/GSHHS_l_L1' )

    print('-preparing contours')
    #better use all shapes, but that takes time
    bord.make_shapes_contour( domain = (45, 315, 50, 90) )

    print('-adding verts')
    bord.add_hp_verts( 15.0, 14.0 )
    bord.add_hp_verts( 2., 1., (0, 360, 60, 90) ) #0.5 0.9
    print('  high resolution domain')
    bord.add_hp_verts( 0.1, 0.1, (180, 240, 65, 75) )
    bord.add_hp_verts( 0.02, 0.01, (200, 220, 69, 72) )

    print('-filtering contours')
    bord.filter_contour( 0.01, (0, 360, 50, 90) )

    print('-actually generating borders` file')
    bord.gener_borders( 75, 0.01, domain=(190, 240, 60, 80), file_b='b0.ll')
    bord.gener_borders( 150, 0.1, domain=(190, 240, 60, 80), file_b='b1.ll' )
    bord.gener_borders( 300, 0.7, domain=(190, 240, 60, 80), file_b='b2.ll' )
    #bord.filter_v_by_b( 'borders.ll', 'contours.ll', 50, 'marks.ll' ) 

    print('-adding coverage')
    grid = hpgrid.Grid()
    grid.points_gen( 5. )
    grid.points_filter( 4. )

    pol = hpgrid.Grid( hpgrid.Domain( theta = (0, 0.44) ) )
    pol.points_gen( 2. )
    pol.points_filter( 2. )

    hig = hpgrid.Grid( hpgrid.Domain( units=0, phi = (170,210), \
                                    theta = (20, 30) ) )
    hig.points_gen( 1. )
    hig.points_filter( 1. )

    can = hpgrid.Grid( hpgrid.Domain( units=0, phi = (180,185), \
                                    theta = (30, 40) ) )
    can.points_gen( 1. )
    can.points_filter( 1. )

    verts = geofiles.xyz_to_lonlat( grid.points + pol.points + hig.points + \
                                    can.points )
    geofiles.w_lonlat( 'verts.ll', verts )

    print('\n-file gen')
    bord.extract_borders_from_v( 'b1.ll', 'b0.ll', 5, 'bb1.ll' )
    bord.extract_borders_from_v( 'b2.ll', 'b0.ll', 78, 'bb2.ll' )
    bord.extract_borders_from_v( 'verts.ll', 'b0.ll', 225, 'vv.ll' )
    
    verts = geofiles.r_lonlat( 'vv.ll' )
    b0 = geofiles.r_lonlat( 'b0.ll' )
    b1 = geofiles.r_lonlat( 'bb1.ll' )
    b2 = geofiles.r_lonlat( 'bb2.ll' )
    v = BG.dupl_del( verts + b0 + b1 + b2 )
    geofiles.w_xyz( 'shapes.xyz', geofiles.lonlat_to_xyz( v ) )

    os.remove( 'vv.ll' )
    os.remove( 'b0.ll' )
    os.remove( 'b1.ll' )
    os.remove( 'b2.ll' )
    os.remove( 'bb1.ll' )
    os.remove( 'bb2.ll' )
    os.remove( 'verts.ll' )

    print('done!\n')
    return