-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_mthread.py
executable file
·79 lines (64 loc) · 2.51 KB
/
test_mthread.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# -*- coding: utf-8 -*-
"""
Spyder Editor
This is a temporary script file.
"""
import threading
from threading import Thread
import numpy as np
from osgeo import gdal
import cv2
import time
from sys import getsizeof
# params
INTERPOLATION = cv2.INTER_LINEAR
gdal.UseExceptions()
# path_im_ms = './data/spot6/GEBZE/S6_GEBZE_MS.tiff'
# path_im_pan = './data/spot6/GEBZE/S6_GEBZE_PAN.tiff'
path_im_ms = './data/spot6/URFA2/S6_URFA_MS.JP2'
path_im_pan = './data/spot6/URFA2/S6_URFA_PAN.JP2'
start = time.time()
ds_ms = gdal.Open(path_im_ms, gdal.GA_ReadOnly)
ds_pan = gdal.Open(path_im_pan, gdal.GA_ReadOnly)
np_pan_orj = ds_pan.GetRasterBand(1).ReadAsArray()
np_ms1_orj = ds_ms.GetRasterBand(1).ReadAsArray()
np_ms2_orj = ds_ms.GetRasterBand(2).ReadAsArray()
np_ms3_orj = ds_ms.GetRasterBand(3).ReadAsArray()
np_pan = cv2.resize(np_pan_orj, dsize=(ds_pan.RasterXSize/4,
ds_pan.RasterYSize/4), interpolation=INTERPOLATION).astype('complex64')
np_ms1 = cv2.resize(np_ms1_orj, dsize=(ds_ms.RasterXSize/4,
ds_ms.RasterYSize/4), interpolation=INTERPOLATION).astype('complex64')
np_ms2 = cv2.resize(np_ms2_orj, dsize=(ds_ms.RasterXSize/4,
ds_ms.RasterYSize/4), interpolation=INTERPOLATION).astype('complex64')
np_ms3 = cv2.resize(np_ms3_orj, dsize=(ds_ms.RasterXSize/4,
ds_ms.RasterYSize/4), interpolation=INTERPOLATION).astype('complex64')
del np_pan_orj, np_ms1_orj, np_ms2_orj, np_ms3_orj
end1 = time.time() - start
print "## ", str(end1), " seconds for load data"
def npfft2(np_in):
return np.fft.fft2(np_in)
#print("FINISH %s " % threading.current_thread())
def npfft2_v2(np_in, np_out, index):
np_out[index] = np.fft.fft2(np_in)
#print("FINISH %s " % threading.current_thread())
#Creating only four threads for now
fft1 = np.empty((np.shape(np_pan_orj)), dtype='complex64')
start = time.time()
fft1 = npfft2(np_pan_orj)
print "## ", str(time.time() - start), " seconds for fftw"
start = time.time()
for i in (np_pan_orj, np_pan_orj):
th = Thread(target=npfft2, args=(i, ))
th.start()
th.join()
print "## ", str(time.time() - start), " seconds for fftw"
for thread in threading.enumerate():
print("Thread name is %s." % thread.getName())
############
threads = [None] * 4
for i in range(len(threads)):
threads[i] = Thread(target=foo, args=(np_pan_orj[0:i], results, i))
threads[i].start()
# do some other stuff
for i in range(len(threads)):
threads[i].join()