#2011
#0.1 percent sample data
#train
train11 = functions.read_class(
    tabular_data=file_train11_dbf,
    gt_array_file='/Volumes/ga87rif/Study Project/Samples/A_train11.npy')
#test
test11 = functions.read_class(
    tabular_data=file_test11_dbf,
    gt_array_file='/Volumes/ga87rif/Study Project/Samples/A_test11.npy')

#-----------------------------------------------------------------------------------------------
#read raster values and combine them into train_array

#2009
b1_09_ar = functions.extract_values(shp=file_train09_shp, raster=b1_09)
b2_09_ar = functions.extract_values(shp=file_train09_shp, raster=b2_09)
b3_09_ar = functions.extract_values(shp=file_train09_shp, raster=b3_09)
b4_09_ar = functions.extract_values(shp=file_train09_shp, raster=b4_09)
b5_09_ar = functions.extract_values(shp=file_train09_shp, raster=b5_09)
b7_09_ar = functions.extract_values(shp=file_train09_shp, raster=b7_09)
ndvi_09_ar = functions.extract_values(shp=file_train09_shp, raster=ndvi_09)

train_array_09 = functions.combine_bands(
    b1=b1_09_ar,
    b2=b2_09_ar,
    b3=b3_09_ar,
    b4=b4_09_ar,
    b5=b5_09_ar,
    b7=b7_09_ar,
    ndvi=ndvi_09_ar,
ndbi_11 = 'L2 imagery/2011/ndbi.tif'
mndbi_11 = 'L2 imagery/2011/mndbi.tif'

"""
locate the test shapefiles
"""
file_train09_shp = 'Samples/SLC off/2percent/s09train.shp'
file_train11_shp = 'Samples/SLC off/2percent/s11train.shp'
file_test09_shp = 'Samples/SLC off/2percent/s09test.shp'
file_test11_shp = 'Samples/SLC off/2percent/s11test.shp'

#-----------------------------------------------------------------------------------------------
#read raster values and combine them into train_array (test datasets)

#2009
b1_09_t = functions.extract_values(shp = file_test09_shp, raster = b1_09)
b2_09_t = functions.extract_values(shp = file_test09_shp, raster = b2_09)
b3_09_t = functions.extract_values(shp = file_test09_shp, raster = b3_09)
b4_09_t = functions.extract_values(shp = file_test09_shp, raster = b4_09)
b5_09_t = functions.extract_values(shp = file_test09_shp, raster = b5_09)
b7_09_t = functions.extract_values(shp = file_test09_shp, raster = b7_09)
ndvi_09_t = functions.extract_values(shp = file_test09_shp, raster = ndvi_09)
ndwi_09_t = functions.extract_values(shp = file_test09_shp, raster = ndwi_09)
mndwi1_09_t = functions.extract_values(shp = file_test09_shp, raster = mndwi1_09)
mndwi2_09_t = functions.extract_values(shp = file_test09_shp, raster = mndwi2_09)
ndbi_09_t = functions.extract_values(shp = file_test09_shp, raster = ndbi_09)
mndbi_09_t = functions.extract_values(shp = file_test09_shp, raster = mndbi_09)

test_09 = functions.combine_bands_sf(b1 = b1_09_t, b2 = b2_09_t, b3 = b3_09_t, b4 = b4_09_t, 
	b5 = b5_09_t, b7 = b7_09_t, ndvi = ndvi_09_t, ndwi = ndwi_09_t, mndwi1 = mndwi1_09_t, 
	mndwi2 = mndwi2_09_t, ndbi = ndbi_09_t, mndbi = mndbi_09_t,
コード例 #3
0
#!/usr/bin/python
#
# hack@uchicago Introduction to Python Workshop
# Borja Sotomayor, 2013-2014
"""
Prints out the ten most-frequent values for the
"favorite_count" and "retweet_count" fields in a
tweet dataset
"""

import workshop
import operator
import sys

# For this script to run, you need to implement the extract_values
# and compute_frequencies values in exercise_functions.py
from functions import extract_values, compute_frequencies

tfile = sys.argv[1]
n = int(sys.argv[2])

for field in ["favorite_count", "retweet_count"]:
    print "Top 10 frequencies of %s" % field
    l = extract_values(tfile, n, field)
    freqs = compute_frequencies(l)
    freqs = freqs.items()
    freqs.sort(key=operator.itemgetter(1), reverse=True)
    for value, count in freqs[:10]:
        print value, count
    print
                              gt_array_file='Samples/SLC off/B_test09.npy')

#2011
#0.1 percent sample data
#train
train11 = functions.read_class(tabular_data=file_train11_dbf,
                               gt_array_file='Samples/SLC off/B_train11.npy')
#test
test11 = functions.read_class(tabular_data=file_test11_dbf,
                              gt_array_file='Samples/SLC off/B_test11.npy')

#-----------------------------------------------------------------------------------------------
#read raster values and combine them into train_array (training datasets)

#2009
b1_09_ar = functions.extract_values(shp=file_train09_shp, raster=b1_09)
b2_09_ar = functions.extract_values(shp=file_train09_shp, raster=b2_09)
b3_09_ar = functions.extract_values(shp=file_train09_shp, raster=b3_09)
b4_09_ar = functions.extract_values(shp=file_train09_shp, raster=b4_09)
b5_09_ar = functions.extract_values(shp=file_train09_shp, raster=b5_09)
b7_09_ar = functions.extract_values(shp=file_train09_shp, raster=b7_09)
ndvi_09_ar = functions.extract_values(shp=file_train09_shp, raster=ndvi_09)

train_array_09 = functions.combine_bands(
    b1=b1_09_ar,
    b2=b2_09_ar,
    b3=b3_09_ar,
    b4=b4_09_ar,
    b5=b5_09_ar,
    b7=b7_09_ar,
    ndvi=ndvi_09_ar,
コード例 #5
0
# hack@uchicago Introduction to Python Workshop
# Borja Sotomayor, 2013-2014

"""
Prints out the ten most-frequent values for the
"favorite_count" and "retweet_count" fields in a
tweet dataset
"""

import workshop
import operator
import sys

# For this script to run, you need to implement the extract_values
# and compute_frequencies values in exercise_functions.py
from functions import extract_values, compute_frequencies

tfile = sys.argv[1]
n = int(sys.argv[2])

for field in ["favorite_count", "retweet_count"]:
    print "Top 10 frequencies of %s" % field
    l = extract_values(tfile, n, field)
    freqs = compute_frequencies(l)
    freqs = freqs.items()
    freqs.sort(key = operator.itemgetter(1), reverse = True)
    for value, count in freqs[:10]:
        print value, count    
    print