Advertisement
Guest User

Untitled

a guest
Oct 9th, 2017
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.11 KB | None | 0 0
  1. # pylint: disable=W0311
  2.  
  3. import netCDF4 as nc
  4. import numpy as np
  5. import requests
  6. import random
  7.  
  8. def get_index(value, variable):
  9. return np.argmin(abs(variable - value))
  10.  
  11. def get_wcps_index(query):
  12. payload = {'query': query}
  13. r = requests.post(
  14. 'http://localhost:8080/rasdaman/ows/wcps', data=payload)
  15. print r.text
  16. return r.text[1:-1].split(':')[0]
  17.  
  18. def gen_random_lat_lon_int():
  19. return (random.randint(-89,89),random.randint(-179,179))
  20.  
  21. def gen_random_lat_lon_float():
  22. return (random.uniform(-89,89),random.uniform(-179,179))
  23.  
  24.  
  25.  
  26. test_lat_lons = [
  27. (36.9199981689, -8.61900043488),
  28. (30.8374004364, -80.7643966675),
  29. (42.8441009521, -19.9591007233),
  30. (41.7244987488, -20.0016002655),
  31. (36.92, -8.619),
  32. (30.8374, -80.7644),
  33. (42.8441, -19.9591),
  34. (42.8446, -19.9598),
  35. (42.45, -19.9672),
  36. (42.417, -19.961),
  37. (42.0343, -19.9993),
  38. (41.7245, -20.0016),
  39. (41.3224, -20.0069),
  40. (32.912, -117.393),
  41. (40.9291, -20.002),
  42. (37.1231, -19.8676),
  43. (36.8718, -19.8187),
  44. (35.0356, -19.1422),
  45. (32.9284, -79.2897),
  46. (29.847, -123.585),
  47. (31.7826, -17.8372),
  48. (32.43, -119.962),
  49. (32.43, -119.962),
  50. (31.475, -18.2116),
  51. (31.1666, -18.606),
  52. (30.8372, -18.9853),
  53. (30.5009, -19.3523),
  54. (30.1564, -19.71),
  55. (22.47, -158.13),
  56. (20.7928, -157.207),
  57. (28.6364, -20.9943),
  58. (28.1127, -20.9965),
  59. (27.6849, -20.9861),
  60. (33.422, -117.91),
  61. (27.1222, -20.9926),
  62. (20.7928, -157.207),
  63. (25.4952, -20.9987),
  64. (25.0299, -20.9904),
  65. (24.5694, -20.9922),
  66. (24.1392, -20.9995),
  67. (23.234, -21.0042),
  68. (33.325, -119.667),
  69. (33.153, -120.01),
  70. (21.2383, -20.8511),
  71. (20.8254, -20.7646),
  72. (31.992, -122.407),
  73. (16.6999, -19.9994),
  74. (8.8233, -21.7333),
  75. (5.0392, -23.2611),
  76. (34.332, -120.815),
  77. (20.7368, -157.002),
  78. (34.157, -121.157),
  79. (0.5418, -25.106),
  80. (-0.1632, -25.4073),
  81. (-0.5136, -25.5595),
  82. (-0.7727, -25.6632),
  83. (-0.7726, -25.6631),
  84. (33.493, -122.525),
  85. (33.152, -123.225),
  86. (-2.7867, -27.3682),
  87. (20.8583, -156.747),
  88. (5.99, -124.93),
  89. (-7.9446, -28.6641),
  90. (5.993, -124.938),
  91. (-10.8006, -29.8718),
  92. (-11.1604, -30.0405),
  93. (5.17, -124.832),
  94. (31.654, -64.126),
  95. (31.653, -64.116),
  96. (-19.3274, -33.4837),
  97. (42.95, 35.6),
  98. (-20.4182, -34.0616),
  99. (-21.0817, -34.556),
  100. (-21.8544, -35.2803),
  101. (41.8125, -68.3922),
  102. (-25.8142, -39.1074),
  103. (-26.0654, -39.3668),
  104. (-3.99, -124.82),
  105. (-26.3987, -39.7221),
  106. (-26.737, -40.0711),
  107. (-3.991, -124.822),
  108. (-30.614, -43.8666),
  109. (39.29, 25.11),
  110. (42.588, -67.5148),
  111. (59.69, -149.328),
  112. (-32.25, -49.33),
  113. (-32.25, -49.33),
  114. (27.659, -111.228),
  115. (-32.09, -49.67),
  116. (-32.09, -49.67),
  117. (17.6, -67.0),
  118. (17.3, -67.3),
  119. (27.844, -111.042),
  120. (26.982, -110.97),
  121. (34.16, -119.952),
  122. (34.087, -120.029),
  123. (34.344, -119.86),
  124. (34.39, -119.84),
  125. (34.39, -119.84),
  126. (34.3, -119.887),
  127. (34.3, -119.887),
  128. (34.261, -119.901),
  129. (34.261, -119.901),
  130. (34.2035, -119.928)
  131. ]
  132.  
  133.  
  134. test_lat_lons_small = [
  135. (36.9199981689, -8.61900043488),
  136. (30.8374004364, -80.7643966675),
  137. (42.8441009521, -19.9591007233),
  138. (41.7244987488, -20.0016002655),
  139. (36.92, -8.619),
  140. ]
  141.  
  142. lat_query = '''
  143. for a in (test_wcps_accuracy)
  144.  
  145. return
  146.  
  147. imageCrsDomain(a[Lat({Lat}000:{Lat}000), Long({Long}000), ansi("2000-03-01")], Lat)
  148. '''
  149.  
  150. lon_query = '''
  151. for a in (test_wcps_accuracy)
  152.  
  153. return
  154.  
  155. imageCrsDomain(a[Lat({Lat}000), Long({Long}000:{Long}000), ansi("2000-03-01")], Long)
  156. '''
  157.  
  158.  
  159. netcdf_file = 'ESACCI-OC-L3S-CHLOR_A-MERGED-1M_MONTHLY_4km_GEO_PML_OC4v6-200003-fv2.0.nc'
  160.  
  161. dataset = nc.Dataset(netcdf_file)
  162.  
  163. lat_variable = dataset.variables['lat'][:]
  164. lon_variable = dataset.variables['lon'][:]
  165.  
  166. lat_dif_count = 0
  167. lon_dif_count = 0
  168.  
  169. run_count = 1000
  170. gen_lls = []
  171.  
  172. for p in range(run_count):
  173. gen_lls.append(gen_random_lat_lon_int())
  174.  
  175.  
  176.  
  177. for a in range(1):
  178. lat_dif_count = 0
  179. lon_dif_count = 0
  180. i = 0
  181. for x in gen_lls:
  182. print i
  183. i += 1
  184. #x = gen_random_lat_lon()
  185. nc_lat = get_index(x[0], lat_variable)
  186. nc_lon = get_index(x[1], lon_variable)
  187. lat_q = lat_query.format(Lat=str(float(x[0])), Long=str(float(x[1])))
  188. lon_q = lon_query.format(Lat=str(float(x[0])), Long=str(float(x[1])))
  189. print lat_q
  190. print lon_q
  191. wcps_lat = get_wcps_index(lat_q)
  192. wcps_lon = get_wcps_index(lon_q)
  193. lat_diff = nc_lat - int(wcps_lat)
  194. lon_diff = nc_lon - int(wcps_lon)
  195. #print "({})testing {},{}".format(y,x[0],x[1])
  196. #print "testing after convert to float {},{}".format(float(x[0]),float(x[1]))
  197. if lat_diff != 0:
  198. lat_dif_count = lat_dif_count + 1
  199. lon_diff = nc_lon - int(wcps_lon)
  200. if lon_diff != 0:
  201. lon_dif_count = lon_dif_count + 1
  202. if lon_diff != 0 or lat_diff != 0:
  203. print "testing values (lat, lon) : " + str(float(x[0])) + ", " + str(float(x[1]))
  204. print "Lat index = " + str(nc_lat)
  205. print "Lon index = " + str(nc_lon)
  206. print "Lat value from WCPS = " + wcps_lat
  207. print "Lon value from WCPS = " + wcps_lon
  208. print "difference for lat =" + str(lat_diff)
  209. print "difference for lon =" + str(lon_diff)
  210. print '-' * 20
  211. exit(1)
  212. print "testing values (lat, lon) : " + str(float(x[0])) + ", " + str(float(x[1]))
  213. print "Lat index = " + str(nc_lat)
  214. print "Lon index = " + str(nc_lon)
  215. print "Lat value from WCPS = " + wcps_lat
  216. print "Lon value from WCPS = " + wcps_lon
  217. print "difference for lat =" + str(lat_diff)
  218. print "difference for lon =" + str(lon_diff)
  219. print '-' * 20
  220.  
  221. print '-'*30
  222. print ("latitude errors {}/" + str(run_count)).format(lat_dif_count)
  223. print ("longitude errors {}/" + str(run_count)).format(lon_dif_count)
  224.  
  225. dataset.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement