source: production/onslow_2006/plot_data_extent.py @ 3031

Last change on this file since 3031 was 3024, checked in by sexton, 19 years ago

some more words

File size: 4.3 KB
Line 
1from pylab import *
2from geospatial_data import *
3from pmesh.create_mesh import convert_points_from_latlon_to_utm
4from coordinate_transforms.redfearn import degminsec2decimal_degrees
5from os import sep
6from utilities.polygon import inside_polygon
7import project
8from utilities.polygon import plot_polygons, poly_xy, polygon_area
9
10datadir = project.datadir
11ion()
12
13print 'Area of overall polygon: ', polygon_area(project.polyAll)
14
15plot_data = False
16plot_with_poly = True
17
18def read_community_file(filename1, filename2, polygon):
19    from coordinate_transforms.redfearn import redfearn
20    from utilities.polygon import inside_polygon
21    fid1 = open(filename1)
22    lines = fid1.readlines()
23    fid1.close()
24    xlocs = []
25    ylocs = []
26    community = []
27    population = []
28    line1 = lines[0]
29    line11 = line1.split(',')
30    fid2 = open(filename2,'w')
31    s = 'Easting, Northing, Community, Population\n'
32    fid2.write(s)
33    for i in range(len(line11)):
34        if line11[i].strip('\n').strip(' ') == 'LATITUDE': lat_index = i
35        if line11[i].strip('\n').strip(' ') == 'LONGITUDE': lon_index = i
36        if line11[i].strip('\n').strip(' ') == 'COMMUNITY': name_index = i
37        if line11[i].strip('\n').strip(' ') == 'POPULATION': pop_index = i
38    for line in lines[1:]:
39        fields = line.split(',')
40        lat = float(fields[lat_index])
41        lon = float(fields[lon_index])
42        z, easting, northing = redfearn(lat,lon)
43        v = inside_polygon([easting,northing],polygon)
44        if z == 50 and v == True:
45            xlocs.append(easting)
46            ylocs.append(northing)
47            community = fields[name_index]
48            population = fields[pop_index]
49            s = '%f, %f, %s, %s\n' %(easting, northing, community, population)
50            fid2.write(s)
51            print community, easting, northing
52   
53    return xlocs, ylocs, community, population
54
55def read_file(filename1):
56    fid1 = open(filename1)
57    lines = fid1.readlines()
58    fid1.close()
59    x = []
60    y = []
61    line1 = lines[0]
62    for line in lines[1:]:
63        fields = line.split(',')
64        x.append(float(fields[0]))
65        y.append(float(fields[1]))
66   
67    return x, y
68
69if plot_data == True:
70    file1 = datadir+'onslow_onshore_30m_dted.pts'
71    file2 = datadir+'onslow_offshore_points.xya'
72
73    G1 = Geospatial_data(file_name = file1)
74    G2 = Geospatial_data(file_name = file2)
75
76    pts1 = G1.get_data_points(absolute = True)
77    pts2 = G2.get_data_points(absolute = True)
78
79    if plot_with_poly == True:
80        figname = 'onslow_data_poly'
81        x1, y1 = poly_xy(project.polyAll)
82        x2, y2 = poly_xy(project.poly_onslow)
83        x3, y3 = poly_xy(project.poly_coast)
84        x4, y4 = poly_xy(project.poly_region)
85        figure(1)
86        plot(pts1[:,0],pts1[:,1],'g.',
87             pts2[:,0],pts2[:,1],'b.',
88             x1,y1,'r-',x2,y2,'r-',x3,y3,'r-',x4,y4,'r-')
89        xlabel('Eastings')
90        ylabel('Northings')
91        savefig(figname)
92    else:
93        figure(2)
94        plot(pts1[:,0],pts1[:,1],'g.',
95             pts2[:,0],pts2[:,1],'b.')
96        xlabel('Eastings')
97        ylabel('Northings')
98        savefig('onslow_data_extent')
99else:
100   
101    figure(3)
102    figname = 'onslow_polys_test'
103    vec = plot_polygons([project.polyAll,
104                        project.poly_onslow, project.poly_coast],#, project.poly_region],
105                        figname,
106                        verbose = True)
107    figure(4)
108    x1, y1 = poly_xy(project.polyAll)
109    figname = 'onslow_communities'
110    x, y, community, population= \
111           read_community_file(project.community_filename, \
112                               project.community_scenario, project.polyAll)
113    #coastx, coasty = read_file(project.coast_filename)
114    #plot(x1,y1,'r-',x,y,'r+', coastx,coasty,'g.')
115    plot(x1,y1,'r-',x,y,'r+')
116    xlabel('Eastings')
117    ylabel('Northings')
118    savefig(figname)
119    figure(4)
120    figname = 'onslow_gauges'
121    x, y = read_file(project.gauge_filename)
122    plot(x1,y1,'r-',x,y,'r+')
123    savefig(figname)
124
125    figure(5)
126    figname = 'onslow_new_boundary_test'
127    x50, y50 = poly_xy(project.bounding_poly50)
128    #x25, y25 = poly_xy(project.bounding_poly25)
129    #plot(x50,y50,'r-',x25,y25,'r-',x1,y1,'g-')
130    plot(x50,y50,'r-',x1,y1,'g-')
131    savefig(figname)
132close('all')
Note: See TracBrowser for help on using the repository browser.