orca1_create_basin_mask_from_meshmask.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. #!/usr/bin/env python
  2. # L. Brodeau, april 2010
  3. import sys
  4. import numpy as nmp
  5. from netCDF4 import Dataset
  6. from string import replace
  7. if len(sys.argv) != 2:
  8. print 'Usage: '+sys.argv[0]+' <mesh_mask_ORCA1_file.nc>'
  9. sys.exit(0)
  10. cf_mm = sys.argv[1]
  11. cf_out = replace(cf_mm, 'mesh_mask', 'basin_mask')
  12. print '\n'
  13. # Opening the Netcdf file:
  14. f_mm = Dataset(cf_mm)
  15. print 'File ', cf_mm, 'is open...\n'
  16. # Extracting the longitude 2D array:
  17. xlon = f_mm.variables['nav_lon'][:,:]
  18. # Extracting the longitude 2D array:
  19. xlat = f_mm.variables['nav_lat'][:,:]
  20. # Extracting tmask at surface level:
  21. tmask = f_mm.variables['tmask'][0,0,:,:]
  22. f_mm.close()
  23. # Info on the shape of t:
  24. [ nj, ni ] = tmask.shape
  25. print 'Dimension = ', ni, nj, '\n'
  26. mask_atl = nmp.zeros((nj,ni))
  27. mask_pac = nmp.zeros((nj,ni))
  28. mask_ind = nmp.zeros((nj,ni))
  29. mask_soc = nmp.zeros((nj,ni)) ; # Souther Ocean
  30. mask_wed = nmp.zeros((nj,ni)) ; # Weddell Sea
  31. mask_ip1 = nmp.zeros((nj,ni))
  32. mask_inp = nmp.zeros((nj,ni))
  33. # ATL for ORCA1
  34. # ~~~~~~~~~~~~~
  35. mask_atl[:,:] = tmask[:,:]
  36. # Removing Southern Ocean:
  37. #mask_atl[:95,:] = 0
  38. # Removing Pacific and Indian
  39. mask_atl[0:246,0:190] = 0 # 246 => to keep Pacific side of the arctic basin...
  40. mask_atl[0:168,0:223] = 0 ; mask_atl[0:255,310:] = 0
  41. mask_atl[165:177,190:204] = 0; mask_atl[165:180,190:198] = 0; mask_atl[165:170,200:206] = 0
  42. mask_atl[188:209,282:] = 0; mask_atl[209:215,288:] = 0
  43. # REMOVING INDONESIA + AUSTRALIA
  44. # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  45. mask_ip1[:,:] = tmask[:,:]
  46. mask_ip1[114:122,53:75] = 0
  47. mask_ip1[119:126,68:74] = 0
  48. mask_ip1[124:143,44:59] = 0
  49. mask_ip1[128:159,33:42] = 0
  50. mask_ip1[120:142,52:61] = 0
  51. mask_ip1[124:136,41:70] = 0
  52. mask_ip1[127:128,37:42] = 0
  53. mask_ip1[120:126,60:70] = 0
  54. mask_ip1[141:158,30:33] = 0
  55. mask_ip1[152:162,26:30] = 0
  56. # PAC for ORCA1
  57. # ~~~~~~~~~~~~~
  58. mask_pac[:,:] = tmask[:,:]
  59. # Removing Southern Ocean until souther Australia:
  60. mask_pac[:95,:] = 0
  61. # Removing Indonesian side
  62. mask_pac[:,:45] = 0
  63. mask_pac[88:145,45:61] = 0
  64. mask_pac[112:125,59:70] = 0
  65. mask_pac[123:136,60:67] = 0
  66. mask_pac[88:99,60:71] = 0 # bottom Australia
  67. # V2
  68. #mask_pac[:,:26] = 0
  69. # Removing Atlantic
  70. idxatl = nmp.where(mask_atl == 1.0)
  71. mask_pac[idxatl] = 0
  72. # Removing atlantic bottom and the rest (Indian)
  73. mask_pac[83:,224:] = 0
  74. # IND for ORCA1
  75. # ~~~~~~~~~~~~~
  76. mask_ind[:,:] = tmask[:,:]
  77. # Removing Southern Ocean until southern Australia:
  78. mask_ind[:95,:] = 0
  79. # Removing Atl and Pac
  80. mask_ind[:,:] = mask_ind[:,:] - mask_atl[:,:] - mask_pac[:,:]
  81. mask_ind[93:100,46:68] = 0 # australia bottom
  82. # Removing Mediterranean+Caspian sea:
  83. mask_ind[192:228,279:329] = 0
  84. mask_ind[198:242,328:344] = 0
  85. # Indo-Pacific
  86. # ~~~~~~~~~~~~
  87. mask_inp[:,:] = tmask[:,:]
  88. mask_inp[:95,:] = 0
  89. # Removing Atlantic
  90. idxatl = nmp.where(mask_atl == 1.0)
  91. mask_inp[idxatl] = 0
  92. mask_inp[93:100,46:68] = 0 # australia bottom
  93. # Removing Mediterranean sea:
  94. mask_inp[192:228,279:329] = 0
  95. mask_inp[198:242,328:344] = 0
  96. # Removing indonesia
  97. #mask_inp[:,:] = mask_inp[:,:] * mask_ip1[:,:]
  98. # Souther Ocean
  99. mask_soc[:,:] = tmask[:,:]
  100. idxatl = nmp.where(mask_atl+mask_pac+mask_ind > 0.5)
  101. mask_soc[idxatl] = 0
  102. mask_soc[122:,:] = 0
  103. # Weddell Sea:
  104. mask_wed[:,:] = tmask[:,:]
  105. mask_wed[:,:233] = 0
  106. mask_wed[55:,:] = 0
  107. mask_wed[:,300:] = 0
  108. # Creating output file:
  109. f_out = Dataset(cf_out, 'w',format='NETCDF3_CLASSIC')
  110. # Dimensions:
  111. f_out.createDimension('x', ni)
  112. f_out.createDimension('y', nj)
  113. # Variables
  114. id_lon = f_out.createVariable('nav_lon','f4',('y','x',))
  115. id_lat = f_out.createVariable('nav_lat','f4',('y','x',))
  116. id_atl = f_out.createVariable('tmaskatl' ,'f4',('y','x',)) ; id_atl.long_name = 'Atlantic Basin'
  117. id_pac = f_out.createVariable('tmaskpac' ,'f4',('y','x',)) ; id_pac.long_name = 'Pacific Basin'
  118. id_ind = f_out.createVariable('tmaskind' ,'f4',('y','x',)) ; id_ind.long_name = 'Indian Basin'
  119. id_soc = f_out.createVariable('tmasksoc' ,'f4',('y','x',)) ; id_soc.long_name = 'Southern Basin'
  120. id_inp = f_out.createVariable('tmaskinp' ,'f4',('y','x',)) ; id_inp.long_name = 'Indo-Pacific Basin'
  121. id_wed = f_out.createVariable('tmaskwed' ,'f4',('y','x',)) ; id_wed.long_name = 'Weddell Sea'
  122. # Filling variables:
  123. id_lat[:,:] = xlat[:,:]
  124. id_lon[:,:] = xlon[:,:]
  125. id_atl[:,:] = mask_atl[:,:]
  126. id_pac[:,:] = mask_pac[:,:]
  127. id_ind[:,:] = mask_ind[:,:]
  128. id_soc[:,:] = mask_soc[:,:]
  129. id_inp[:,:] = mask_inp[:,:]
  130. id_wed[:,:] = mask_wed[:,:]
  131. f_out.About = 'ORCA1 main oceanic basin land-sea mask created from '+cf_mm
  132. f_out.Author = ' Generated with "orca1_create_basin_mask_from_meshmask.py" of BaraKuda (https://github.com/brodeau/barakuda)'
  133. f_out.close()
  134. print cf_out+' sucessfully created!'