Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.90 KB | None | 0 0
  1. ##Surfaces is a dictionary which has keys for each neutral surface
  2. ## at each neutral surface it has a multi dimensional array with this structure:
  3. ## [[lon],[lat],[nsdepth],[[nsdepth],[temp],[salinity],[PV],[uz],[vz]]]
  4. ## I plan on reworking it into a dictionary to make my code more clear soon
  5. ##Neighbors is a dictionary which has keys for each neutral surface
  6. ## every key has a value which is another dictionary which has one key
  7. ## which is the point at which we are calculating the derivative. The value
  8. ## connected to that key is an array of the indexs of the four nearest points to that point
  9.  
  10. def componentDistance(surfaces,k,i1,i2):
  11. #x = surfaces[k][0][i1] - surfaces[k][0][i2]
  12. #if abs(x) > abs(360 - (x+360)%360):
  13. #x = np.sign(x)*(360-(x+360)%360)
  14. if (surfaces[k][0][i1]+180 ) > (surfaces[k][0][i2]+180):
  15. x = surfaces[k][0][i1]+180 - (surfaces[k][0][i2]+180)
  16. if x>180:
  17. x = -(360-x)
  18. else:
  19. x = surfaces[k][0][i1]+180 - (surfaces[k][0][i2]+180)
  20. if x < -180:
  21. x= -(-360-x)
  22. x=x*np.cos(np.deg2rad(surfaces[k][1][i2]))*111000.0
  23. #print(surfaces[k][0][i1],surfaces[k][0][i2],x)
  24.  
  25. y = (surfaces[k][1][i1]-surfaces[k][1][i2])*111000.0
  26. return x,y
  27.  
  28.  
  29. def addPrimeToSurfaces(surfaces,neighbors,debug=False):
  30. for k in surfaces.keys():
  31. surfaces[k][2].append(np.zeros(len(surfaces[k][1])))
  32. surfaces[k][2].append(np.zeros(len(surfaces[k][1])))
  33. alldxs = []
  34. for k in neighbors.keys():
  35. print("adding primes to: ",k)
  36. for r in neighbors[k].keys():
  37. #alright so here k is our NS
  38. #r is the index of the point for which we are calculating these prime values
  39. #adjacent is the list of adjacent points
  40. adjacent = neighbors[k][r]
  41. dxsum = 0
  42. dysum = 0
  43. dxs = []
  44. dys = []
  45. dhs = []
  46. dists = 0
  47. for i in adjacent:
  48. dx,dy = componentDistance(surfaces,k,i,r)
  49. dxs.append(dx)
  50. dys.append(dy)
  51. dxindexs = [np.argmin(dxs),np.argmax(dxs)]
  52. dyindexs = [np.argmin(dys),np.argmax(dys)]
  53. dxfinal,b = componentDistance(surfaces,k,adjacent[dxindexs[1]],adjacent[dxindexs[0]])
  54. b,dyfinal = componentDistance(surfaces,k,adjacent[dyindexs[1]],adjacent[dyindexs[0]])
  55. #print(r,adjacent)
  56. dhx = surfaces[k][2][0][adjacent[dxindexs[1]]] - surfaces[k][2][0][adjacent[dxindexs[0]]]
  57. #dhx = surfaces[k][2][0][adjacent[dxindexs[1]]]
  58. dhy = surfaces[k][2][0][adjacent[dyindexs[1]]]-surfaces[k][2][0][adjacent[dyindexs[0]]]
  59. #dhy = surfaces[k][2][0][adjacent[dyindexs[1]]] - surfaces[k][2][0][adjacent[dyindexs[0]]]
  60. dhdtheta = dhx/dxfinal
  61. dhdr = dhy/dyfinal
  62. surfaces[k][2][4][r] = dhdtheta
  63. surfaces[k][2][5][r] = dhdr
  64. return surfaces
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement