Guest User

Untitled

a guest
Jan 18th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.27 KB | None | 0 0
  1. def ddx(self,s,lat,lon):
  2.  
  3. lonLen = len(lon)
  4. latLen = len(lat)
  5. dsdx = np.empty((latLen,lonLen))
  6. rearth = 6371221.3
  7. # Input data is oriented N-S. Hence invert it. It is oriented W-E.
  8. s = s[::-1,;]
  9. # Differential increment along X direction. Equal grid spacing
  10. # Hence is it just the difference in longitudes in radians.
  11. # Convert into meters by multiplying the radius of earth
  12. di = abs(np.cos(np.radians(0.0))*rearth*(np.radians(lon[1]-lon[0])))
  13.  
  14. # GRID order for loop- S-N(OUTER)
  15. # W-E(INNER)
  16. # Loop east along a row then north
  17. for j in range(0,latLen):
  18. for i in range(1, lonLen-1):
  19. if (abs(lat[j]) >= 90.0):
  20. dsdx[j,0] = 0.0
  21. elif (s[j, i+1] > -999.99 and s[j,i-1] > -999.99):
  22. # ds/dx = s[east] - s[west]/2*di
  23. dsdx[j, i] = (s[j,i+1] - s[j,i-1])/(2.*di)
  24. elif (s[i+1,j] < -999.99 and s[j,i-1] > -999.99 and s[j,i] > -999.99):
  25. dsdx[j,i] = (s[j,i] - s[j,i-1])/di
  26. elif (s[j,i+1] > -999.99 and s[j,i-1] < -999.99 and s[j,i] > -999.99):
  27. dsdx[j,i] = (s[j,i+1] - s[j,i])/di
  28. else:
  29. dsdx[j,i] = -999.99
  30. # Check if the data is global and compute difference at the beginning
  31. # and end of row J
  32. for j in range(0,latLen):
  33. if (abs(lat[j]) >= 90.0):
  34. dsdx[j,0] = 0.0
  35. dsdx[j,-1] =0.0
  36. elif (np.allclose(2*lon[0]-lon[-1],lon[1],1e-3) or np.allclose(2*lon[0]-lon[-1],lon[1] + 360.0,1e-3)):
  37. if (s[j, 1] > -999.99 and s[j, -1] > -999.99):
  38. dsdx[j, 0] = (s[j, 1] - s[j,-1]) / (2.*di)
  39. elif (s[j,1] < -999.99 and s[j,-1] > -999.99 and s[j,0] > -999.99) :
  40. dsdx[j,0] = (s[j,1] - s[j,-1]) / di
  41. elif (s[j, 1] > -999.99 and s[j,-1] > -999.99 and s[j,0] > -999.99):
  42. dsdx[j,0] = (s [j,1] - s[j,0]) /di
  43. else:
  44. dsdx[j, 0] = -999.99
  45. if (s[j,0] > -999.99 and s[j,-2] > -999.99):
  46. dsdx[j,-1] = (s[j, 0] - s[j,-2]) / (2. * di)
  47. elif (s[j,0] < -999.99 and s[j,-2] > -999.99 and s[j,-1] > -999.99):
  48. dsdx[j,-1] = (s[j,-1] - s[j,-2]) / di
  49. elif (s[j,0] > -999.99 and s[j,-2] < -999.99 and s[j,-1] > -999.99) :
  50. dsdx[j,-1] = (s[j,1] - s[j,-1]) / di
  51. else:
  52. dsdx[j, -1] = -999.99
  53. elif (np.allclose(lon[0],lon[-1],1e-3)):
  54. if (s[j, 1] > -999.99 and s[j,-2] > -999.99) :
  55. dsdx[j,0] = (s[j,1] - s[j,-2]) / (2. * di)
  56. elif (s[j,1] < -999.99 and s[j,-2] > -999.99 and s[j,0] > -999.99) :
  57. dsdx[j,0] = (s[j,0] - s[j,-2]) / di
  58. elif (s[1, j] > -999.99 and s[- 2, j] < -999.99 and s[0, j] > -999.99):
  59. dsdx[j,0] = (s[j,1] - s[j,0]) / di
  60. else:
  61. dsdx[j,0] = -999.99
  62. dsdx[j,-1] = dsdx[j,0]
  63. else:
  64. if (s[j, 1] > -999.99 and s[j,0] > -999.99) :
  65. dsdx[j,0] = (s[j,1] - s[j,0]) /di
  66. else:
  67. dsdx[j,0] = -999.99
  68.  
  69. if (s[j,-1] > -999.99 and s[j,-2] > -999.99):
  70. dsdx[j,-1] = (s[j,-1] -s[j,-2]) /di
  71. else:
  72. dsdx[j,-1] = -999.99
  73.  
  74. return dsdx
Add Comment
Please, Sign In to add comment