ndvi21.py 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  1. import numpy as np
  2. import time,sys
  3. import requests
  4. import json
  5. import matplotlib
  6. import matplotlib as mpl
  7. mpl.use('Agg')
  8. import matplotlib.pyplot as plt
  9. import datetime
  10. import os
  11. import urllib
  12. import urllib.request
  13. import urllib.parse
  14. import base64
  15. #import cv2
  16. from PIL import Image
  17. import time
  18. def c21():
  19. head = {
  20. 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36',
  21. }
  22. url = ("http://52.195.10.119/MQTT/c21a.php")
  23. res = requests.post(url, headers=head)
  24. a =json.loads(res.text)
  25. time1a = int(a['time1a'])
  26. time2a = int(a['time2a'])
  27. time3a = int(a['time3a'])
  28. time4a = int(a['time4a'])
  29. time5a = int(a['time5a'])
  30. time6a = int(a['time6a'])
  31. time7a = int(a['time7a'])
  32. time8a = int(a['time8a'])
  33. time9a = int(a['time9a'])
  34. print(time1a)
  35. if (time1a == 0):
  36. print('wow')
  37. elif (time1a == 1):
  38. print('1')
  39. img21_1()
  40. print('2')
  41. throw21()
  42. print('3')
  43. if (time2a == 0):
  44. print('wow')
  45. elif (time2a == 1):
  46. print('1')
  47. img21_2()
  48. print('2')
  49. throw21()
  50. print('3')
  51. if (time3a == 0):
  52. print('wow')
  53. elif (time3a == 1):
  54. print('1')
  55. img21_3()
  56. print('2')
  57. throw21()
  58. print('3')
  59. if (time4a == 0):
  60. print('wow')
  61. elif (time4a == 1):
  62. print('1')
  63. img21_4()
  64. print('2')
  65. throw21()
  66. print('3')
  67. if (time5a == 0):
  68. print('wow')
  69. elif (time5a == 1):
  70. print('1')
  71. img21_5()
  72. print('2')
  73. throw21()
  74. print('3')
  75. if (time6a == 0):
  76. print('wow')
  77. elif (time6a == 1):
  78. print('1')
  79. img21_6()
  80. print('2')
  81. throw21()
  82. print('3')
  83. if (time7a == 0):
  84. print('wow')
  85. elif (time7a == 1):
  86. print('1')
  87. img21_7()
  88. print('2')
  89. throw21()
  90. print('3')
  91. if (time8a == 0):
  92. print('wow')
  93. elif (time8a == 1):
  94. print('1')
  95. img21_8()
  96. print('2')
  97. throw21()
  98. print('3')
  99. if (time9a == 0):
  100. print('wow')
  101. elif (time9a == 1):
  102. print('1')
  103. img21_9()
  104. print('2')
  105. throw21()
  106. print('3')
  107. def img21_1():
  108. ndvis = datetime.datetime.now().strftime('/var/www/html/cust/21/ndvi1/%Y-%m-%d_%H.%M.tif') #ndvi is time.tif
  109. ndvia = datetime.datetime.now().strftime('/var/www/html/cust/21/ndvia1/%Y-%m-%d_%H.%M.png') #ndvi is time.png
  110. ndviajpg = datetime.datetime.now().strftime('/var/www/html/cust/21/ndvia/c.png') #ndvi is c.png
  111. irt = datetime.datetime.now().strftime('/var/www/html/cust/21/ir1/%Y-%m-%d_%H.%M.tif') # irtif is time.tif
  112. nt = datetime.datetime.now().strftime('/var/www/html/cust/21/n1/%Y-%m-%d_%H.%M.tif') # ntif is time.tif
  113. irj = datetime.datetime.now().strftime('/var/www/html/cust/21/irj1/%Y-%m-%d_%H.%M.jpg') # irjpg is time.jpg
  114. nj = datetime.datetime.now().strftime('/var/www/html/cust/21/nj1/%Y-%m-%d_%H.%M.jpg') # njpg is time.jpg
  115. date = datetime.datetime.now().strftime('\n%Y-%m-%d_%H.%Mn')
  116. rgb_img0 = Image.open('/var/www/html/cust/21/c/a1.tif')
  117. ir_img0 = Image.open('/var/www/html/cust/21/c/b1.tif')
  118. rgb_img0.save(nt)
  119. ir_img0.save(irt)
  120. rgb_img0.save(nj,quality=95)
  121. ir_img0.save(irj,quality=95)
  122. r,_,_ = rgb_img0.split()
  123. r = np.asarray(r, dtype=float)
  124. ir,_,_ = ir_img0.split()
  125. ir = np.asarray(ir, dtype=float)
  126. ndvi = np.zeros(r.size) # The NDVI image will be the same size as the input image
  127. np.seterr(divide='ignore', invalid='ignore')
  128. ndvi = np.true_divide(np.subtract(ir, r), np.add(ir, r))
  129. # Display the results
  130. plt.plot(ndvi)
  131. plt.imshow(ndvi, cmap=plt.cm.get_cmap('Spectral'))
  132. plt.colorbar()
  133. #plt.show()
  134. plt.savefig(ndvis)
  135. plt.savefig(ndvia)
  136. plt.savefig(ndviajpg)
  137. plt.close('all')
  138. f = open('/var/www/html/cust/c21_1.txt','a')
  139. f.write(date)
  140. f.close()
  141. #plt.close(na)
  142. def img21_2():
  143. ndvis = datetime.datetime.now().strftime('/var/www/html/cust/21/ndvi2/%Y-%m-%d_%H.%M.tif') #ndvi is time.tif
  144. ndvia = datetime.datetime.now().strftime('/var/www/html/cust/21/ndvia2/%Y-%m-%d_%H.%M.png') #ndvi is time.png
  145. ndviajpg = datetime.datetime.now().strftime('/var/www/html/cust/21/ndvia/c.png') #ndvi is c.png
  146. irt = datetime.datetime.now().strftime('/var/www/html/cust/21/ir2/%Y-%m-%d_%H.%M.tif') # irtif is time.tif
  147. nt = datetime.datetime.now().strftime('/var/www/html/cust/21/n2/%Y-%m-%d_%H.%M.tif') # ntif is time.tif
  148. irj = datetime.datetime.now().strftime('/var/www/html/cust/21/irj2/%Y-%m-%d_%H.%M.jpg') # irjpg is time.jpg
  149. nj = datetime.datetime.now().strftime('/var/www/html/cust/21/nj2/%Y-%m-%d_%H.%M.jpg') # njpg is time.jpg
  150. date = datetime.datetime.now().strftime('\n%Y-%m-%d_%H.%Mn')
  151. rgb_img0 = Image.open('/var/www/html/cust/21/c/a2.tif')
  152. ir_img0 = Image.open('/var/www/html/cust/21/c/b2.tif')
  153. rgb_img0.save(nt)
  154. ir_img0.save(irt)
  155. rgb_img0.save(nj,quality=95)
  156. ir_img0.save(irj,quality=95)
  157. r,_,_ = rgb_img0.split()
  158. r = np.asarray(r, dtype=float)
  159. ir,_,_ = ir_img0.split()
  160. ir = np.asarray(ir, dtype=float)
  161. ndvi = np.zeros(r.size) # The NDVI image will be the same size as the input image
  162. np.seterr(divide='ignore', invalid='ignore')
  163. ndvi = np.true_divide(np.subtract(ir, r), np.add(ir, r))
  164. # Display the results
  165. plt.plot(ndvi)
  166. plt.imshow(ndvi, cmap=plt.cm.get_cmap('Spectral'))
  167. plt.colorbar()
  168. #plt.show()
  169. plt.savefig(ndvis)
  170. plt.savefig(ndvia)
  171. plt.savefig(ndviajpg)
  172. plt.close('all')
  173. f = open('/var/www/html/cust/c21_2.txt','a')
  174. f.write(date)
  175. f.close()
  176. def img21_3():
  177. ndvis = datetime.datetime.now().strftime('/var/www/html/cust/21/ndvi3/%Y-%m-%d_%H.%M.tif') #ndvi is time.tif
  178. ndvia = datetime.datetime.now().strftime('/var/www/html/cust/21/ndvia3/%Y-%m-%d_%H.%M.png') #ndvi is time.png
  179. ndviajpg = datetime.datetime.now().strftime('/var/www/html/cust/21/ndvia/c.png') #ndvi is c.png
  180. irt = datetime.datetime.now().strftime('/var/www/html/cust/21/ir3/%Y-%m-%d_%H.%M.tif') # irtif is time.tif
  181. nt = datetime.datetime.now().strftime('/var/www/html/cust/21/n3/%Y-%m-%d_%H.%M.tif') # ntif is time.tif
  182. irj = datetime.datetime.now().strftime('/var/www/html/cust/21/irj3/%Y-%m-%d_%H.%M.jpg') # irjpg is time.jpg
  183. nj = datetime.datetime.now().strftime('/var/www/html/cust/21/nj3/%Y-%m-%d_%H.%M.jpg') # njpg is time.jpg
  184. date = datetime.datetime.now().strftime('\n%Y-%m-%d_%H.%Mn')
  185. rgb_img0 = Image.open('/var/www/html/cust/21/c/a3.tif')
  186. ir_img0 = Image.open('/var/www/html/cust/21/c/b3.tif')
  187. rgb_img0.save(nt)
  188. ir_img0.save(irt)
  189. rgb_img0.save(nj,quality=95)
  190. ir_img0.save(irj,quality=95)
  191. r,_,_ = rgb_img0.split()
  192. r = np.asarray(r, dtype=float)
  193. ir,_,_ = ir_img0.split()
  194. ir = np.asarray(ir, dtype=float)
  195. ndvi = np.zeros(r.size) # The NDVI image will be the same size as the input image
  196. np.seterr(divide='ignore', invalid='ignore')
  197. ndvi = np.true_divide(np.subtract(ir, r), np.add(ir, r))
  198. # Display the results
  199. plt.plot(ndvi)
  200. plt.imshow(ndvi, cmap=plt.cm.get_cmap('Spectral'))
  201. plt.colorbar()
  202. #plt.show()
  203. plt.savefig(ndvis)
  204. plt.savefig(ndvia)
  205. plt.savefig(ndviajpg)
  206. plt.close('all')
  207. f = open('/var/www/html/cust/c21_3.txt','a')
  208. f.write(date)
  209. f.close()
  210. def img21_4():
  211. ndvis = datetime.datetime.now().strftime('/var/www/html/cust/21/ndvi4/%Y-%m-%d_%H.%M.tif') #ndvi is time.tif
  212. ndvia = datetime.datetime.now().strftime('/var/www/html/cust/21/ndvia4/%Y-%m-%d_%H.%M.png') #ndvi is time.png
  213. ndviajpg = datetime.datetime.now().strftime('/var/www/html/cust/21/ndvia/c.png') #ndvi is c.png
  214. irt = datetime.datetime.now().strftime('/var/www/html/cust/21/ir4/%Y-%m-%d_%H.%M.tif') # irtif is time.tif
  215. nt = datetime.datetime.now().strftime('/var/www/html/cust/21/n4/%Y-%m-%d_%H.%M.tif') # ntif is time.tif
  216. irj = datetime.datetime.now().strftime('/var/www/html/cust/21/irj4/%Y-%m-%d_%H.%M.jpg') # irjpg is time.jpg
  217. nj = datetime.datetime.now().strftime('/var/www/html/cust/21/nj4/%Y-%m-%d_%H.%M.jpg') # njpg is time.jpg
  218. date = datetime.datetime.now().strftime('\n%Y-%m-%d_%H.%Mn')
  219. rgb_img0 = Image.open('/var/www/html/cust/21/c/a4.tif')
  220. ir_img0 = Image.open('/var/www/html/cust/21/c/b4.tif')
  221. rgb_img0.save(nt)
  222. ir_img0.save(irt)
  223. rgb_img0.save(nj,quality=95)
  224. ir_img0.save(irj,quality=95)
  225. r,_,_ = rgb_img0.split()
  226. r = np.asarray(r, dtype=float)
  227. ir,_,_ = ir_img0.split()
  228. ir = np.asarray(ir, dtype=float)
  229. ndvi = np.zeros(r.size) # The NDVI image will be the same size as the input image
  230. np.seterr(divide='ignore', invalid='ignore')
  231. ndvi = np.true_divide(np.subtract(ir, r), np.add(ir, r))
  232. # Display the results
  233. plt.plot(ndvi)
  234. plt.imshow(ndvi, cmap=plt.cm.get_cmap('Spectral'))
  235. plt.colorbar()
  236. #plt.show()
  237. plt.savefig(ndvis)
  238. plt.savefig(ndvia)
  239. plt.savefig(ndviajpg)
  240. plt.close('all')
  241. f = open('/var/www/html/cust/c21_4.txt','a')
  242. f.write(date)
  243. f.close()
  244. def img21_5():
  245. ndvis = datetime.datetime.now().strftime('/var/www/html/cust/21/ndvi5/%Y-%m-%d_%H.%M.tif') #ndvi is time.tif
  246. ndvia = datetime.datetime.now().strftime('/var/www/html/cust/21/ndvia5/%Y-%m-%d_%H.%M.png') #ndvi is time.png
  247. ndviajpg = datetime.datetime.now().strftime('/var/www/html/cust/21/ndvia/c.png') #ndvi is c.png
  248. irt = datetime.datetime.now().strftime('/var/www/html/cust/21/ir5/%Y-%m-%d_%H.%M.tif') # irtif is time.tif
  249. nt = datetime.datetime.now().strftime('/var/www/html/cust/21/n5/%Y-%m-%d_%H.%M.tif') # ntif is time.tif
  250. irj = datetime.datetime.now().strftime('/var/www/html/cust/21/irj5/%Y-%m-%d_%H.%M.jpg') # irjpg is time.jpg
  251. nj = datetime.datetime.now().strftime('/var/www/html/cust/21/nj5/%Y-%m-%d_%H.%M.jpg') # njpg is time.jpg
  252. date = datetime.datetime.now().strftime('\n%Y-%m-%d_%H.%Mn')
  253. rgb_img0 = Image.open('/var/www/html/cust/21/c/a5.tif')
  254. ir_img0 = Image.open('/var/www/html/cust/21/c/b5.tif')
  255. rgb_img0.save(nt)
  256. ir_img0.save(irt)
  257. rgb_img0.save(nj,quality=95)
  258. ir_img0.save(irj,quality=95)
  259. r,_,_ = rgb_img0.split()
  260. r = np.asarray(r, dtype=float)
  261. ir,_,_ = ir_img0.split()
  262. ir = np.asarray(ir, dtype=float)
  263. ndvi = np.zeros(r.size) # The NDVI image will be the same size as the input image
  264. np.seterr(divide='ignore', invalid='ignore')
  265. ndvi = np.true_divide(np.subtract(ir, r), np.add(ir, r))
  266. # Display the results
  267. plt.plot(ndvi)
  268. plt.imshow(ndvi, cmap=plt.cm.get_cmap('Spectral'))
  269. plt.colorbar()
  270. #plt.show()
  271. plt.savefig(ndvis)
  272. plt.savefig(ndvia)
  273. plt.savefig(ndviajpg)
  274. plt.close('all')
  275. f = open('/var/www/html/cust/c21_5.txt','a')
  276. f.write(date)
  277. f.close()
  278. def img21_6():
  279. ndvis = datetime.datetime.now().strftime('/var/www/html/cust/21/ndvi6/%Y-%m-%d_%H.%M.tif') #ndvi is time.tif
  280. ndvia = datetime.datetime.now().strftime('/var/www/html/cust/21/ndvia6/%Y-%m-%d_%H.%M.png') #ndvi is time.png
  281. ndviajpg = datetime.datetime.now().strftime('/var/www/html/cust/21/ndvia/c.png') #ndvi is c.png
  282. irt = datetime.datetime.now().strftime('/var/www/html/cust/21/ir6/%Y-%m-%d_%H.%M.tif') # irtif is time.tif
  283. nt = datetime.datetime.now().strftime('/var/www/html/cust/21/n6/%Y-%m-%d_%H.%M.tif') # ntif is time.tif
  284. irj = datetime.datetime.now().strftime('/var/www/html/cust/21/irj6/%Y-%m-%d_%H.%M.jpg') # irjpg is time.jpg
  285. nj = datetime.datetime.now().strftime('/var/www/html/cust/21/nj6/%Y-%m-%d_%H.%M.jpg') # njpg is time.jpg
  286. date = datetime.datetime.now().strftime('\n%Y-%m-%d_%H.%Mn')
  287. rgb_img0 = Image.open('/var/www/html/cust/21/c/a6.tif')
  288. ir_img0 = Image.open('/var/www/html/cust/21/c/b6.tif')
  289. rgb_img0.save(nt)
  290. ir_img0.save(irt)
  291. rgb_img0.save(nj,quality=95)
  292. ir_img0.save(irj,quality=95)
  293. r,_,_ = rgb_img0.split()
  294. r = np.asarray(r, dtype=float)
  295. ir,_,_ = ir_img0.split()
  296. ir = np.asarray(ir, dtype=float)
  297. ndvi = np.zeros(r.size) # The NDVI image will be the same size as the input image
  298. np.seterr(divide='ignore', invalid='ignore')
  299. ndvi = np.true_divide(np.subtract(ir, r), np.add(ir, r))
  300. # Display the results
  301. plt.plot(ndvi)
  302. plt.imshow(ndvi, cmap=plt.cm.get_cmap('Spectral'))
  303. plt.colorbar()
  304. #plt.show()
  305. plt.savefig(ndvis)
  306. plt.savefig(ndvia)
  307. plt.savefig(ndviajpg)
  308. plt.close('all')
  309. f = open('/var/www/html/cust/c21_6.txt','a')
  310. f.write(date)
  311. f.close()
  312. def img21_7():
  313. ndvis = datetime.datetime.now().strftime('/var/www/html/cust/21/ndvi7/%Y-%m-%d_%H.%M.tif') #ndvi is time.tif
  314. ndvia = datetime.datetime.now().strftime('/var/www/html/cust/21/ndvia7/%Y-%m-%d_%H.%M.png') #ndvi is time.png
  315. ndviajpg = datetime.datetime.now().strftime('/var/www/html/cust/21/ndvia/c.png') #ndvi is c.png
  316. irt = datetime.datetime.now().strftime('/var/www/html/cust/21/ir7/%Y-%m-%d_%H.%M.tif') # irtif is time.tif
  317. nt = datetime.datetime.now().strftime('/var/www/html/cust/21/n7/%Y-%m-%d_%H.%M.tif') # ntif is time.tif
  318. irj = datetime.datetime.now().strftime('/var/www/html/cust/21/irj7/%Y-%m-%d_%H.%M.jpg') # irjpg is time.jpg
  319. nj = datetime.datetime.now().strftime('/var/www/html/cust/21/nj7/%Y-%m-%d_%H.%M.jpg') # njpg is time.jpg
  320. date = datetime.datetime.now().strftime('\n%Y-%m-%d_%H.%Mn')
  321. rgb_img0 = Image.open('/var/www/html/cust/21/c/a7.tif')
  322. ir_img0 = Image.open('/var/www/html/cust/21/c/b7.tif')
  323. rgb_img0.save(nt)
  324. ir_img0.save(irt)
  325. rgb_img0.save(nj,quality=95)
  326. ir_img0.save(irj,quality=95)
  327. r,_,_ = rgb_img0.split()
  328. r = np.asarray(r, dtype=float)
  329. ir,_,_ = ir_img0.split()
  330. ir = np.asarray(ir, dtype=float)
  331. ndvi = np.zeros(r.size) # The NDVI image will be the same size as the input image
  332. np.seterr(divide='ignore', invalid='ignore')
  333. ndvi = np.true_divide(np.subtract(ir, r), np.add(ir, r))
  334. # Display the results
  335. plt.plot(ndvi)
  336. plt.imshow(ndvi, cmap=plt.cm.get_cmap('Spectral'))
  337. plt.colorbar()
  338. #plt.show()
  339. plt.savefig(ndvis)
  340. plt.savefig(ndvia)
  341. plt.savefig(ndviajpg)
  342. plt.close('all')
  343. f = open('/var/www/html/cust/c21_7.txt','a')
  344. f.write(date)
  345. f.close()
  346. def img21_8():
  347. ndvis = datetime.datetime.now().strftime('/var/www/html/cust/21/ndvi8/%Y-%m-%d_%H.%M.tif') #ndvi is time.tif
  348. ndvia = datetime.datetime.now().strftime('/var/www/html/cust/21/ndvia8/%Y-%m-%d_%H.%M.png') #ndvi is time.png
  349. ndviajpg = datetime.datetime.now().strftime('/var/www/html/cust/21/ndvia/c.png') #ndvi is c.png
  350. irt = datetime.datetime.now().strftime('/var/www/html/cust/21/ir8/%Y-%m-%d_%H.%M.tif') # irtif is time.tif
  351. nt = datetime.datetime.now().strftime('/var/www/html/cust/21/n8/%Y-%m-%d_%H.%M.tif') # ntif is time.tif
  352. irj = datetime.datetime.now().strftime('/var/www/html/cust/21/irj8/%Y-%m-%d_%H.%M.jpg') # irjpg is time.jpg
  353. nj = datetime.datetime.now().strftime('/var/www/html/cust/21/nj8/%Y-%m-%d_%H.%M.jpg') # njpg is time.jpg
  354. date = datetime.datetime.now().strftime('\n%Y-%m-%d_%H.%Mn')
  355. rgb_img0 = Image.open('/var/www/html/cust/21/c/a8.tif')
  356. ir_img0 = Image.open('/var/www/html/cust/21/c/b8.tif')
  357. rgb_img0.save(nt)
  358. ir_img0.save(irt)
  359. rgb_img0.save(nj,quality=95)
  360. ir_img0.save(irj,quality=95)
  361. r,_,_ = rgb_img0.split()
  362. r = np.asarray(r, dtype=float)
  363. ir,_,_ = ir_img0.split()
  364. ir = np.asarray(ir, dtype=float)
  365. ndvi = np.zeros(r.size) # The NDVI image will be the same size as the input image
  366. np.seterr(divide='ignore', invalid='ignore')
  367. ndvi = np.true_divide(np.subtract(ir, r), np.add(ir, r))
  368. # Display the results
  369. plt.plot(ndvi)
  370. plt.imshow(ndvi, cmap=plt.cm.get_cmap('Spectral'))
  371. plt.colorbar()
  372. #plt.show()
  373. plt.savefig(ndvis)
  374. plt.savefig(ndvia)
  375. plt.savefig(ndviajpg)
  376. plt.close('all')
  377. f = open('/var/www/html/cust/c21_8.txt','a')
  378. f.write(date)
  379. f.close()
  380. def img21_9():
  381. ndvis = datetime.datetime.now().strftime('/var/www/html/cust/21/ndvi/%Y-%m-%d_%H.%M.tif') #ndvi is time.tif
  382. ndvia = datetime.datetime.now().strftime('/var/www/html/cust/21/ndvia/%Y-%m-%d_%H.%M.png') #ndvi is time.png
  383. ndviajpg = datetime.datetime.now().strftime('/var/www/html/cust/21/ndvia/c.png') #ndvi is c.png
  384. irt = datetime.datetime.now().strftime('/var/www/html/cust/21/ir/%Y-%m-%d_%H.%M.tif') # irtif is time.tif
  385. nt = datetime.datetime.now().strftime('/var/www/html/cust/21/n/%Y-%m-%d_%H.%M.tif') # ntif is time.tif
  386. irj = datetime.datetime.now().strftime('/var/www/html/cust/21/irj/%Y-%m-%d_%H.%M.jpg') # irjpg is time.jpg
  387. nj = datetime.datetime.now().strftime('/var/www/html/cust/21/nj/%Y-%m-%d_%H.%M.jpg') # njpg is time.jpg
  388. date = datetime.datetime.now().strftime('\n%Y-%m-%d_%H.%Mn')
  389. rgb_img0 = Image.open('/var/www/html/cust/21/c/a.tif')
  390. ir_img0 = Image.open('/var/www/html/cust/21/c/b.tif')
  391. rgb_img0.save(nt)
  392. ir_img0.save(irt)
  393. rgb_img0.save(nj,quality=95)
  394. ir_img0.save(irj,quality=95)
  395. r,_,_ = rgb_img0.split()
  396. r = np.asarray(r, dtype=float)
  397. ir,_,_ = ir_img0.split()
  398. ir = np.asarray(ir, dtype=float)
  399. ndvi = np.zeros(r.size) # The NDVI image will be the same size as the input image
  400. np.seterr(divide='ignore', invalid='ignore')
  401. ndvi = np.true_divide(np.subtract(ir, r), np.add(ir, r))
  402. # Display the results
  403. plt.plot(ndvi)
  404. plt.imshow(ndvi, cmap=plt.cm.get_cmap('Spectral'))
  405. plt.colorbar()
  406. #plt.show()
  407. plt.savefig(ndvis)
  408. plt.savefig(ndvia)
  409. plt.savefig(ndviajpg)
  410. plt.close('all')
  411. f = open('/var/www/html/cust/c21.txt','a')
  412. f.write(date)
  413. f.close()
  414. def throw21():
  415. dress = '/var/www/html/cust/21/c/'
  416. for root, dirs, files in os.walk(dress):
  417. print('files: {}'.format(len(files)))
  418. if len(files)>=1:
  419. files.sort()
  420. for f in files:
  421. with open(os.path.join(root, f), "rb") as imageFile:
  422. str = base64.b64encode(imageFile.read())
  423. url = 'http://60.250.156.234/cust/t21.php'
  424. values = {'data1':str, 'name':f}
  425. data1 = urllib.parse.urlencode(values)
  426. data1 = data1.encode('utf-8')
  427. req = urllib.request.Request(url, data1)
  428. req.add_header('User-Agent','Magic Browser')
  429. resp = urllib.request.urlopen(req)
  430. respdata1 = resp.read()
  431. print(os.path.join(root, f))
  432. #print(respdata1)
  433. os.remove(os.path.join(root, f))
  434. print("ok")
  435. url = 'http://52.195.10.119/MQTT/BBtoNDVI.php'
  436. data = {'nrs': 'KDARES21'}
  437. data = urllib.parse.urlencode(data)
  438. data = data.encode('utf-8')
  439. req = urllib.request.Request(url, data)
  440. req.add_header('User-Agent', 'Magic Browser')
  441. resp = urllib.request.urlopen(req)
  442. respData = resp.read()
  443. print("ok")
  444. while True:
  445. c21()