Example #1
0
"""Test :func:`~vacumm.misc.plot.plot2d` with specified cell bounds"""

# Imports
from vcmq import MV2, N, code_file_name, plot2d, os

# Init
var = MV2.reshape(MV2.arange(4*3), (3, 4))
var.units = 'Count'
var.long_name = 'Navets'
x = var.getAxis(1)
x.units = 'km'
x.long_name = 'Distance'
y = var.getAxis(0)
y.units = 'm'
y.long_name = 'Height'
y.designateLevel()

# Bounds
y[:] = [1.5, 3.5, 4.5]
y2db = N.array([0., 3, 4, 5])

# Plot
figfile = code_file_name(ext='png')
if os.path.exists(figfile): os.remove(figfile)
plot2d(var, savefig=figfile, show=False, close=True, y2db=y2db, fill='pcolor',
    xmin=-.5, xmax=3.5, ymin=0, ymax=5, cmap='jet')

# Unittest
result = {"files":figfile}
Example #2
0
"""Test :class:`~vacumm.misc.stats.StatAccum` for a pair of variables"""

# Imports
from vcmq import MV2, N
from vacumm.misc.stats import StatAccum
import warnings
warnings.filterwarnings('error', "boolean index did not match",
                        N.VisibleDeprecationWarning)

# Setup masked data
nt, ny, nx = 20, 15, 10
var1 = MV2.arange(1. * nt * ny * nx).reshape(nt, ny, nx)
var1.getAxis(0).designateTime()
var1.getAxis(0).units = 'months since 2000'
var2 = var1.clone()
var2[:] += N.ma.sin(var1) * 100
var1[3:13, 5:9, 3:7] = MV2.masked
var2[5:15, 7:12, 1:5] = MV2.masked
mask = var1.mask | var2.mask  # common mask
vmax = var2.max()
bins = N.linspace(-0.1 * vmax, 0.9 * vmax, 14)
nbins = len(bins)
maskyx = mask.all(axis=0)
maskt = mask.reshape((nt, -1)).all(axis=1)

# Direct
varm1 = var1.asma().copy()
varm2 = var2.asma().copy()
varm1[mask] = N.ma.masked
varm2[mask] = N.ma.masked
var2dm1 = varm1.reshape(nt, -1)
Example #3
0
"""Test :func:`~vacumm.misc.plot.curve2` with a time axis"""

# Imports
from vcmq import MV2, code_file_name, os, code_file_name, curve2

# Init
var = MV2.arange(5.)
var.units = 'W'
var.long_name = 'Power'
axis = var.getAxis(0)
axis.units = 'months since 2013-01-01'
axis.long_name = 'Time'
axis.axis = 'T'

# Plot
figfile = code_file_name(ext='png')
if os.path.exists(figfile): os.remove(figfile)
curve2(var, savefig=figfile, show=True, close=True)
"""Test :class:`~vacumm.misc.stats.StatAccum` for a single variable"""

# Imports
from vcmq import MV2, N
from vacumm.misc.stats import StatAccum

# Setup masked data
nt, ny, nx = 20, 15, 10
var = MV2.arange(1.*nt*ny*nx).reshape(nt, ny, nx)
var[3:13, 5:9, 3:7] = MV2.masked
var.getAxis(0).designateTime()
var.getAxis(0).units = 'months since 2000'
vmax = var.max()
bins = N.linspace(-0.1*vmax, 0.9*vmax, 14)
nbins = len(bins)
maskyx = var.mask.all(axis=1)
maskt = var.mask.reshape((nt, -1)).all(axis=1)

# Direct
varm = var.asma()
var2d = var.asma().reshape(nt, -1)
dstats = dict(
    tavail = 1.*(~var.mask).sum(axis=0)/var.shape[0],
    tmean = var.mean(axis=0),
    tstd = var.std(axis=0),
    tmin = var.min(axis=0),
    tmax = var.max(axis=0),
    savail = 1.*(~var2d.mask).sum(axis=1)/var2d.shape[1],
    smean = var2d.mean(axis=1),
    sstd = var2d.std(axis=1),
    smin = var2d.min(axis=1),
Example #5
0
"""Test :func:`~vacumm.misc.plot.curve2` with an arbitrary axis"""

# Imports
from vcmq import MV2, code_file_name, os, code_file_name, curve2

# Init
var = MV2.arange(5.)
var.units = '$Kg$'
var.long_name = 'Flour'
axis = var.getAxis(0)
axis.units = 'm'
axis.long_name = 'Distance'


# Plot
figfile = code_file_name(ext='png')
if os.path.exists(figfile): os.remove(figfile)
curve2(var, savefig=figfile, show=False, close=True)

Example #6
0
"""Test function :func:`~vacumm.misc.plot.taylor` in different configurations"""
from vcmq import taylor, rc, code_file_name, MV2, N

# Make some data
nt = 50
nens = 50
# - references
ref1 = MV2.sin(MV2.arange(nt, dtype='f')) * 10.
ref2 = ref1 * 1.2
# - ensemble 1
dat1 = MV2.resize(ref1, (nens, nt)) + N.resize(N.random.rand(nt * nens),
                                               (nens, nt)) * 20.
dat1.long_name = 'Set 1'
dat1.units = 'meters'
# - modele 2
dat2 = MV2.resize(ref2, (nens, nt)) + N.resize(N.random.rand(nt * nens),
                                               (nens, nt)) * 40.
dat2.long_name = 'Set 2'

# Plot
rc('font', size=8)
kwplot = dict(figsize=(5, 5),
              savefigs_pdf=False,
              show=False,
              close=True,
              savefigs_verbose=False)
basename = code_file_name(ext=False) + '_%i'
# - single variable
taylor(dat1[0],
       ref1,
       savefigs=basename % 0,
Example #7
0
"""Test :func:`~vacumm.misc.plot.plot2d` with a time axis"""

# Imports
from vcmq import MV2, code_file_name, plot2d, os

# Init
var = MV2.reshape(MV2.arange(10*8), (8,10))
var.units = 'Count'
var.long_name = 'Carottes'
x = var.getAxis(1)
x.units = 'months since 2000'
x.long_name = 'Time'
y = var.getAxis(0)
y.units = 'Hz'
y.long_name = 'Frequency'

# Plot
figfile = code_file_name(ext='png')
if os.path.exists(figfile): os.remove(figfile)
plot2d(var, savefig=figfile, show=False, close=True, fill='pcolor', order='t-')

# Unittest
result = {"files":figfile}
Example #8
0
"""Test :func:`~vacumm.misc.plot.plot2d` with arbitrary axes"""

# %% Imports
from vcmq import MV2, code_file_name, plot2d, os

# %% Init
var = MV2.reshape(MV2.arange(10 * 8), (8, 10))
var.units = 'Count'
var.long_name = 'Navets'
x = var.getAxis(1)
x.units = 'km'
x.long_name = 'Distance'
y = var.getAxis(0)
y.units = 'Hz'
y.long_name = 'Frequency'

# %% Plot
figfile = code_file_name(ext='png')
if os.path.exists(figfile): os.remove(figfile)
plot2d(var, savefig=figfile, show=False, close=True)
Example #9
0
#!/usr/bin/env python
# -*- coding: utf8 -*-
"""Utilitaires et conventions de formatage

"""

from vcmq import MV2, cdms2, N
from vacumm.data.cf import VAR_SPECS, format_var, match_var, format_axis, AXIS_SPECS, GENERIC_VAR_NAMES


# Création d'une variable 1D
sst = MV2.arange(5.)                        # -> VERIFIER LES INFOS DE CET VARIABLE
sst.getAxis(0).designateLongitude()         # -> VERIFIER LES INFOS DE CET AXE


# Formatage
format_var(sst, 'sst')                      # -> VERIFIER LES NOUVELLES INFOS DE VAR+AXE
# -> FORMATER L'AXE EN LATITUDE AU POINT U


# Verification
print match_var(sst,'sst')
Example #10
0
"""Test :func:`~vacumm.misc.grid.misc.GriddedSelector`"""

# %% Imports
from vcmq import N, MV2, create_grid, rotate_grid, GriddedSelector

# %% Rectangular grid
rgrid = create_grid((-14., -4, .25), (43., 52, .25), 'rect')
var = MV2.reshape(MV2.arange(2 * rgrid.shape[0] * rgrid.shape[1]),
                  (2, ) + rgrid.shape)
gs = GriddedSelector(rgrid, lon=(-9, -6, 'co'), lat=(44.1, 48.2))
rvar = gs(var)
assert rvar.shape == (2, 16, 12)
assert rvar.getLongitude()[-1] == -6.25
assert rvar.getLatitude()[-1] == 48

# %% Curvilinear
cgrid = rotate_grid(rgrid, 30.)
gs = GriddedSelector(cgrid, lon=(-9, -6, 'co'), lat=(44.1, 48.2))
cvar = gs(var)
assert cvar.shape == (2, 20, 18)
assert cvar.getLongitude().asma()[~gs.mask].min() == -9
assert cvar.getLatitude().asma()[~gs.mask].max() <= 48.2

# %% Unstructured
N.random.seed(0)
ugrid = create_grid(N.random.uniform(-14, -4, 100),
                    N.random.uniform(43, 52, 100), 'unstruct')
var = MV2.resize(ugrid.getLatitude().asma(), (2, ) + ugrid.shape)
gs = GriddedSelector(ugrid, lon=(-9, -6, 'co'), lat=(44.1, 48.2))
uvar = gs(var)
assert uvar.getGrid().shape == (34, )
Example #11
0
#!/usr/bin/env python
# -*- coding: utf8 -*-
"""Utilitaires et conventions de formatage

"""

from vcmq import MV2, cdms2, N
from vacumm.data.cf import VAR_SPECS, format_var, match_var, format_axis, AXIS_SPECS, GENERIC_VAR_NAMES

# Création d'une variable 1D
sst = MV2.arange(5.)  # -> VERIFIER LES INFOS DE CET VARIABLE
sst.getAxis(0).designateLongitude()  # -> VERIFIER LES INFOS DE CET AXE

# Formatage
format_var(sst, 'sst')  # -> VERIFIER LES NOUVELLES INFOS DE VAR+AXE
# -> FORMATER L'AXE EN LATITUDE AU POINT U

# Verification
print match_var(sst, 'sst')
Example #12
0
"""Test function :func:`~vacumm.misc.plot.taylor` in different configurations"""
from vcmq import taylor, rc, code_file_name, MV2, N

# Make some data
nt = 50
nens = 50
# - references
ref1 = MV2.sin(MV2.arange(nt, dtype='f'))*10.
ref2 = ref1*1.2
# - ensemble 1
dat1 = MV2.resize(ref1, (nens, nt))+N.resize(N.random.rand(nt*nens), (nens, nt))*20.
dat1.long_name = 'Set 1'
dat1.units = 'meters'
# - modele 2
dat2 = MV2.resize(ref2, (nens, nt))+N.resize(N.random.rand(nt*nens), (nens, nt))*40.
dat2.long_name = 'Set 2'

# Plot
rc('font', size=8)
kwplot = dict(figsize=(5,5), savefigs_pdf=False, show=False, close=True, savefigs_verbose=False)
basename = code_file_name(ext=False)+'_%i'
# - single variable
taylor(dat1[0], ref1, savefigs=basename%0, colors='cyan', title='Basic', **kwplot)
# - single variable without normalization
taylor(dat1[0], ref1, savefigs=basename%1, normalize=False, reflabel='Reference', 
    title='No normalization', **kwplot)
# - several variables with same ref
taylor([d for d in dat1], ref1, colors='cyan', savefigs=basename%2, 
    title='Several variables', **kwplot)
# - several variables with same ref with specified colors
taylor([d for d in dat1[:3]], ref1, colors = ['r', 'g', 'b'],