Exemple #1
0
def remap(cs, h0, e0, h, data0, z, depth):
    km, im = h0.shape
    data1 = np.ma.zeros((len(h), im))
    for i in range(im):
        h1 = np.diff(z)
        if h0[:, i].sum() > 0.01:  # ocean
            h1[h < -e0[0, i]] = 0.0  # top
            h1[h > depth[i]] = 0.0  # bottom
            # need to account for SSH and make sure total thicknesses are
            # the same
            dh = h0[:, i].sum() - h1.sum()
            tmp1 = np.nonzero(h1 != 0.0)[0]
            if len(tmp1) > 0:
                if dh > 0.0:
                    # correct thickness in the top non-vanished layer
                    h1[tmp1[0]] = h1[tmp1[0]] + dh  # add
                elif dh < 0.0:
                    h1[tmp1[0]] = h1[tmp1[0]] - dh  # remove
            else:
                data1[:, i] = np.ma.masked

        # for debugging
        #if h0[:,i].sum() != h1.sum():
            #   print 'WARNING: dh, h0[:,i].sum(), h1.sum()',dh, h0[:,i].sum(), h1.sum()

            # remap
            data1[:,
                  i] = mom_remapping.remapping_core_h(h0[:, i], data0[:, i],
                                                      h1, cs)
            # mask
            data1[h1 == 0.0, i] = np.ma.masked
        else:  # land/iceshelf
            data1[:, i] = np.ma.masked

    return data1
Exemple #2
0
def remap(cs,h0,e0,h,data0,z):
   km,im = h0.shape
   data1 = np.ma.zeros((len(h),im))
   for i in range(im):
     h1 = np.diff(z)
     if h0[:,i].sum() > 0.01: # ocean
	h1[h<-e0[0,i]] = 0.0 # top
	h1[h>depth[i]] = 0.0 # bottom
	# need to account for SSH and make sure total thicknesses are
	# the same
	dh = h0[:,i].sum() - h1.sum()
        tmp1 = np.nonzero(h1!=0.0)[0]
        if len(tmp1)>0:
	  if dh > 0.0:
	     # correct thickness in the top non-vanished layer
             h1[tmp1[0]] = h1[tmp1[0]] + dh # add
          elif dh < 0.0:
             h1[tmp1[0]] = h1[tmp1[0]] - dh # remove
        else:
           data1[:,i] = np.ma.masked

        # for debugging
        #if h0[:,i].sum() != h1.sum():
	#   print 'WARNING: dh, h0[:,i].sum(), h1.sum()',dh, h0[:,i].sum(), h1.sum()

        # remap
	data1[:,i] = mom_remapping.remapping_core_h(h0[:,i], data0[:,i], h1, cs)
	# mask
	data1[h1==0.0,i] = np.ma.masked;
     else: # land/iceshelf
	data1[:,i] = np.ma.masked

   return data1
Exemple #3
0
from remapping import mom_remapping
import numpy as np

cs = mom_remapping.Remapping_Cs()
# PCM
cs.remapping_scheme = 0  # PCM

# PPM-H4
cs.remapping_scheme = 2
cs.degree = 2

h0 = 0.75 * np.ones(4)
h1 = 1 * np.ones(3)
h2 = 0.5 * np.ones(6)

u0 = np.array([9., 3., -3., -9.])

print('expected:', [8., 0., -8.])
print(mom_remapping.remapping_core_h(h0, u0, h1, cs))

print('expected:', [10., 6., 2., -2., -6., -10.])
print(mom_remapping.remapping_core_h(h0, u0, h2, cs))