示例#1
0
    def __init__(self, msl=None, names=None, **kwargs):
        if msl is None:
            msl = get_config_value(__name__, 'meansealevel_file')
#            msl = _get_option_('meansealevel_file')
            if msl is None:
                raise MeanSeaLevel("Can't find a default file of mean sea levels")
        if isinstance(msl, str): # file
            if not os.path.isabs(msl):
                msl = os.path.abspath(os.path.join(dirname,  '../../../../data', msl))
            if not os.path.exists(msl):
                raise MeanSeaLevel("File of mean sea levels not found: %s"%msl)
            data = []
            names = []
            xx = [] ; yy = [] ; zz = []
            f = open(msl)
            for line in f:
                name = unicode(line[:29].strip(), 'utf8')
                y, x, z = [float(v) for v in line[29:].split()]
                names.append(name)
                xx.append(x)
                yy.append(y)
                zz.append(z)
            f.close()
            msl = (xx, yy, zz)
        elif isinstance(msl, MeanSeaLevel): # instance
            names = list(msl.names())

        kwargs.setdefault('units', 'm')
        kwargs.setdefault('long_name', 'Mean sea level')
        XYZBathy.__init__(self, msl, **kwargs)
        self._names = names
示例#2
0
    def __init__(self, msl=None, names=None, **kwargs):
        if msl is None:
            msl = get_config_value(__name__, 'meansealevel_file')
#            msl = _get_option_('meansealevel_file')
            if msl is None:
                raise MeanSeaLevel("Can't find a default file of mean sea levels")
        if isinstance(msl, str): # file
            if not os.path.isabs(msl):
                msl = os.path.abspath(os.path.join(dirname,  '../../../../data', msl))
            if not os.path.exists(msl):
                raise MeanSeaLevel("File of mean sea levels not found: %s"%msl)
            data = []
            names = []
            xx = [] ; yy = [] ; zz = []
            f = open(msl)
            for line in f:
                name = str(line[:29].strip(), 'utf8')
                y, x, z = [float(v) for v in line[29:].split()]
                names.append(name)
                xx.append(x)
                yy.append(y)
                zz.append(z)
            f.close()
            msl = (xx, yy, zz)
        elif isinstance(msl, MeanSeaLevel): # instance
            names = list(msl.names())

        kwargs.setdefault('units', 'm')
        kwargs.setdefault('long_name', 'Mean sea level')
        XYZBathy.__init__(self, msl, **kwargs)
        self._names = names
示例#3
0
# Creation de fausses bathymetries xyz
# - fonction generatrice
def gene_bathy(xc, yc, xr, yr, n=500, amp=30.):
    noise = N.random.random(n)
    a = N.random.random(n) * N.pi * 2
    r = N.random.random(n)
    x = xc + xr * r * N.cos(a)
    y = yc + yr * r * N.sin(a)
    return N.asarray([
        x, y,
        N.exp(-(x - xc)**2 / xr**2 - (y - yc)**2 / yr**2) * amp + noise
    ])


# - creations
xyz1 = XYZBathy(gene_bathy(-5, 48.3, .3, .15))  # top right
xyz2 = XYZBathy(gene_bathy(-5.45, 48.1, .45, .25, n=1000, amp=20),
                transp=False)  # bot left

# Recuperation de donnees
x = xyz1.x
y = xyz1.y
z = xyz1.z

# Exclusions/selections
xyz1.select([[-5.4, 48.1], [-4.8, 48.1], [-5.1, 48.5]])
xyz1.exclude([-5.2, 48., -5, 48.25])

# Infos
print xyz1.xmin  # -> essayer get_xmin avec mask
print xyz1.resol()  # -> essayer avec deg=...
示例#4
0
xr = .4
yr = .15
noise = N.random.random(n)
a = N.random.random(n) * N.pi * 2
r = N.random.random(n)
x = xc + r * xr * N.cos(a)
y = yc + r * yr * N.sin(a)
bathy = N.asarray([
    x, y,
    N.exp(-(x - xc)**2 / xr**2 - (y - yc)**2 / yr**2) * 30. + noise
]).transpose()
fbathy = __file__[:-2] + 'xyz'
N.savetxt(fbathy, bathy)

# %% Load XYZ with undersampling
xyz = XYZBathy(fbathy, long_name='My XYZ', rsamp=0.01)
#  on aurait pu charger directement :
#  >>> xyz = XYZBathy(bathy)

# %% Add a selection zone
#  -> triangulaire, par coordonnees [[x1,y1],...]
xyz.select([[-5.4, 48.1], [-4.8, 48.1], [-5.1, 48.5]])

# %% Add an exclusion zone
#  -> rectangulaire, par coins [xmin,ymin,xmax,ymax]
xyz.exclude([-5.2, 48., -5, 48.25])

# %% Info
print xyz

# %% Get data
示例#5
0
# - fonction generatrice
def gene_bathy(xc, yc, xr, yr, n=500, amp=30.):
    noise = N.random.random(n)
    a = N.random.random(n) * N.pi * 2
    r = N.random.random(n)
    x = xc + xr * r * N.cos(a)
    y = yc + yr * r * N.sin(a)
    return N.asarray([
        x, y,
        N.exp(-(x - xc)**2 / xr**2 - (y - yc)**2 / yr**2) * amp + noise
    ])


# - creations
xyz1 = XYZBathy(gene_bathy(-5, 48.3, .3, .15))  # top right
xyz2 = XYZBathy(gene_bathy(-5.45, 48.3, .2, .1, amp=10))  # top left
xyz3 = XYZBathy(gene_bathy(-5.45, 48.1, .45, .25, n=1000, amp=20),
                transp=False)  # bot left
xyz4 = XYZBathy(gene_bathy(-5., 48.1, .14, .08, n=300))  # bot right
fxyz5 = __file__[:-2] + 'xyz5.xyz'
N.savetxt(fxyz5, gene_bathy(-5.15, 48.2, .2, .1, amp=15).transpose())  # center

# Fusion directe
xyz = xyz1 + xyz2 + xyz3 + xyz4 + fxyz5

# Plot
import pylab as P

P.figure(figsize=(5., 8.5))
P.subplot(311)
示例#6
0
from vcmq import N, os, merc, create_grid, resol, map2, P
from vacumm.bathy.bathy import XYZBathy, XYZBathyMerger

# Creation de fausses bathymetries xyz
# - fonction generatrice
def gene_bathy(xc, yc, xr, yr, n=500, amp=30.0):
    noise = N.random.random(n)
    a = N.random.random(n) * N.pi * 2
    r = N.random.random(n)
    x = xc + xr * r * N.cos(a)
    y = yc + yr * r * N.sin(a)
    return N.asarray([x, y, N.exp(-(x - xc) ** 2 / xr ** 2 - (y - yc) ** 2 / yr ** 2) * amp + noise])


# - creations
xyz1 = XYZBathy(gene_bathy(-5, 48.3, 0.3, 0.15))  # top right
xyz2 = XYZBathy(gene_bathy(-5.45, 48.1, 0.45, 0.25, n=1000, amp=20), transp=False)  # bot left

# Recuperation de donnees
x = xyz1.x
y = xyz1.y
z = xyz1.z

# Exclusions/selections
xyz1.select([[-5.4, 48.1], [-4.8, 48.1], [-5.1, 48.5]])
xyz1.exclude([-5.2, 48.0, -5, 48.25])


# Infos
print xyz1.xmin  # -> essayer get_xmin avec mask
print xyz1.resol()  # -> essayer avec deg=...
示例#7
0
from vacumm.misc.grid import create_grid, resol
from vacumm.misc.plot import map2

# Creation d'une fausse bathymetrie xyz
n = 1000 ; xc = -5.1 ; yc = 48.2 ; xr = .4 ; yr = .15
noise = N.random.random(n)
a = N.random.random(n)*N.pi*2
r = N.random.random(n)
x = xc + r*xr*N.cos(a)
y = yc + r*yr*N.sin(a)
bathy = N.asarray([x, y, N.exp(-(x-xc)**2/xr**2-(y-yc)**2/yr**2)*30.+noise]).transpose()
fbathy = __file__[:-2]+'xyz'
N.savetxt(fbathy, bathy)

# Chargement dans XYZ avec sous echantillonage
xyz = XYZBathy(fbathy,  long_name='My XYZ', rsamp=0.01)
#  on aurait pu charger directement :
#  >>> xyz = XYZBathy(bathy)

# Ajout d'une zone de selection
#  -> triangulaire, par coordonnees [[x1,y1],...]
xyz.select([[-5.4, 48.1], [-4.8, 48.1], [-5.1, 48.5]])

# Ajout d'une zone d'exclusion
#  -> rectangulaire, par coins [xmin,ymin,xmax,ymax]
xyz.exclude([-5.2, 48., -5, 48.25])

# Infos
print xyz

# Recuperation des valeurs