eorca1_create_basin_mask_from_meshmask.py 4.9 KB

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