Example #1
0
"""Test :meth:`~vacumm.data.misc.dataset.OceanDataset.get_temp` with ``at`` keyword and :meth:`~vacumm.data.misc.dataset.OceanDataset.get_temp_u`"""


# Inits
ncfile = "menor.nc"

# Imports
from vcmq import DS, data_sample

# Read data
ds = DS(data_sample(ncfile), 'mars', logger_level='critical')
uu = ds.get_u3d()
uv1 = ds.get_u3d(at='v')
uv2 = ds.get_u3d_v()

# For unittest
result = [
    ('assertNotEqual', [uu.mean(), uv1.mean()]), 
    ('assertEqual', [uv1.mean(), uv2.mean()]), 
    ('assertEqual', [uv1.id, "u3d_v"]), 
    ('assertEqual', [uv2.id, "u3d_v"]), 
]
Example #2
0
"""Test :func:`~vacumm.misc.plot.add_logo`"""

# Imports
from vcmq import N, P, add_logo, os, code_file_name, data_sample
import matplotlib.image as mpimg

# Inits
logofile = data_sample('logo_ifremer.png')
P.plot([2, 6])

# Default
add_logo(logofile, scale=1)

# Upper right / no rescale
add_logo(logofile, loc='upper right')

# Rescale
add_logo(logofile, loc='upper left', scale=2)

# Alpha
add_logo(logofile, loc='lower right', alpha=0.2)

# Save
figfile = code_file_name(ext='png')
if os.path.exists(figfile): os.remove(figfile)
P.savefig(figfile)
Example #3
0
from vcmq import data_sample, map, cdms2

# Read
import cdms2
f = cdms2.open(data_sample('mars3d.xy.nc'))
sst = f('temp', time=slice(0, 1),  lat=(47.8, 48.6), lon=(-5.2, -4.25),  squeeze=1)
f.close()

# Plot
m = map(sst, title='SST in the Iroise Sea', linewidth=.7,
    fill='pcolormesh', cmap='cmocean_thermal', clabel=True,
    vmin=9, top=.9, figsize=(6, 5), clabel_glow=True, clabel_glow_alpha=.4,
    colorbar_shrink=.8, show=False, savefigs=__file__)
Example #4
0
#!/bin/env python
"""Sample executable script using config"""

# FORCE COMMANDLINE ARGUMENTS FOR THE EXAMPLE
from vcmq import data_sample, code_file_name
ARGUMENTS = "--var=temp --zoom-lat-min=48 " + data_sample('mars3d.xy.nc')
import sys
sys.argv = sys.argv[:1] + ARGUMENTS.split()

############################################################################
############################################################################
############################################################################

# Init commandline parser
import os
from argparse import ArgumentParser
parser = ArgumentParser(description="Script to plot a 2D netcdf variable")
parser.add_argument('ncfile', help='input netcdf file')

# Configuration
from vacumm.misc.config import cfgargparse
cfg, args = cfgargparse('misc.config.argparse.ini', parser)
print 'Current configuration:', cfg

# Now use it
# - load zoom
lon = (cfg['zoom']['lon']['min'], cfg['zoom']['lon']['max'])
lat = (cfg['zoom']['lat']['min'], cfg['zoom']['lat']['max'])
# - read var
import cdms2
f = cdms2.open(args.ncfile)
Example #5
0
"""Test :meth:`~vacumm.misc.core_plot.Plot2D.plot_streamplot`"""

from vcmq import map2, data_sample, cdms2, code_file_name
import warnings
warnings.filterwarnings('ignore',
                        'Warning: converting a masked element to nan')

f = cdms2.open(data_sample('mars2d.xyt.nc'))
u = f('u', slice(0, 1), squeeze=1)
v = f('v', slice(0, 1), squeeze=1)
f.close()

map2((u, v),
     fill=False,
     contour=False,
     streamplot=True,
     streamplot_density=3,
     streamplot_linewidth='modulus',
     streamplot_lwmod=3,
     streamplot_color='modulus',
     title='Tidal stream lines',
     colorbar_shrink=0.7,
     savefig=code_file_name(),
     right=1,
     show=False)
from vcmq import cdms2, data_sample, N, cdtime, curve2, round_date, create_time, lindates, regrid1d, add_key, P
from vacumm.misc.grid._interp_ import cellerr1d
from scipy.stats import linregress

# Read data
f = cdms2.open(data_sample("radial_speed.nc"))
sp = f("speed")
spe = f("speed_error")
f.close()

# Create hourly time axis
taxi = sp.getTime()
taxi.toRelativeTime("hours since 2000")
ctimesi = taxi.asComponentTime()
ct0 = round_date(ctimesi[0], "hour")
ct1 = round_date(ctimesi[-1], "hour")
taxo = create_time(lindates(ct0, ct1, 1, "hour"), taxi.units)

# Lag error
# - estimation
els = []
lags = N.arange(1, 6)
for lag in lags:
    els.append(N.sqrt(((sp[lag:] - sp[:-lag]) ** 2).mean()))
els = N.array(els)
a, b, _, _, _ = linregress(lags, els)
# - plot
P.figure(figsize=(6, 6))
P.subplot(211)
P.plot(lags, els, "o")
P.plot([0, lags[-1]], [b, a * lags[-1] + b], "g")
Example #7
0
"""Test the :func:`~vacumm.misc.grid.io.Shapes` class"""
from vcmq import N, P, code_file_name, data_sample
from vacumm.misc.io import Shapes

result = []

# File names
shpfile = data_sample("ne_110m_land/ne_110m_land")
figfile = code_file_name(ext=False) + '_%i.png'

# Basic
S = Shapes(shpfile)
result.append(('assertEqual', [len(S), 127]))
S.plot(title='Basic', show=False)
P.savefig(figfile % 0)
P.close()

# Min area
S = Shapes(shpfile, min_area=1000)
result.append(('assertEqual', [len(S), 3]))
S.plot(title='Min area', show=False)
P.savefig(figfile % 1)
P.close()

# Projection
S = Shapes(shpfile, proj='merc')
result.append(('assertGreater', [S[1].area(), 1e12]))
S.plot(title='Projected', show=False)
P.savefig(figfile % 2)
P.close()
Example #8
0
#!/usr/bin/env python
# -*- coding: utf8 -*-
"""Gestion des coordonnées sigma et interpolation 1D"""

from vcmq import NcSigma, SigmaGeneralized, sigma2depths, cdms2, N, section2, create_depth, regrid1d, data_sample

# Lecture de la température
f = cdms2.open(data_sample('mars3d.tsigyx.nc'))
data_in = f('TEMP', time=slice(0, 2))  # T-YX (- = level)

# Détermination des profondeurs d'après les sigma
sigma_converter = NcSigma.factory(
    f)  # détection auto et initialisation du convertisseur
# -> VERIFIER QUE sigma_class EST BIEN SigmaGeneralized
depths_in = sigma_converter.sigma_to_depths(selector=dict(
    time=slice(0, 2))).filled()  # lecture eta, etc + conversion
# (Equivalent à depths_in = sigma_converter(selector=dict(time=slice(0,2))).filled())
f.close()

# Creation de l'axe des profondeurs cibles
depths = N.array([
    0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
    22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85,
    90, 95, 100, 120, 140, 160
])
depths = -depths[::-1]  # croissantes et négatives
depth_out = create_depth(depths)

# Interpolation
data_out = regrid1d(data_in,
                    depth_out,
Example #9
0
"""Test the :func:`~vacumm.misc.grid.io.Shapes` class"""
from vcmq import N, P, code_file_name, data_sample
from vacumm.misc.io import Shapes
result = []

# File names
shpfile = data_sample("ne_110m_land/ne_110m_land")
figfile = code_file_name(ext=False)+'_%i.png'

# Basic
S = Shapes(shpfile)
result.append(('assertEqual', [len(S), 127]))
S.plot(title='Basic', show=False)
P.savefig(figfile%0);P.close()

# Min area
S = Shapes(shpfile, min_area=1000)
result.append(('assertEqual', [len(S), 3]))
S.plot(title='Min area', show=False)
P.savefig(figfile%1);P.close()

# Projection
S = Shapes(shpfile, proj='merc')
result.append(('assertGreater', [S[1].area(), 1e12]))
S.plot(title='Projected', show=False)
P.savefig(figfile%2);P.close()

# Clips
S = Shapes(shpfile, clip=[-10, 42, 10, 51.])
result.append(('assertEqual', [len(S), 3]))
S.plot(title='Clipped', show=False)
Example #10
0
# Imports
from vacumm.report.ifroco.curves import (round_date, P, DS, paris_to_utc, now, os,
    cfgget, N, grid2xy, plot_curves, cdtime, utc_to_paris, Day12hFormatter,
    load_cfg)
from vcmq import data_sample, code_file_name

# Time
#t0 = round_date(now(utc=False), 'day', 'floor')
t0 = round_date(nowtime, 'day', 'floor')
t1 = t0.add(ndayfore, cdtime.Day)
t0 = paris_to_utc(t0)
t1 = paris_to_utc(t1)

# Read
ds = DS(data_sample(ncpat), 'mars', time=(t0, t1), logger_level='critical')
data = ds.get(field)
utc_to_paris(data)

# Read some config values
cfgfile = code_file_name(ext='cfg')
load_cfg(cfgfile)
long_name = cfgget('long_name', field)
long_long_name = cfgget('long_name_model', field)
units = cfgget('units', field)
vmin = cfgget('vmin', field)
vmax = cfgget('vmax', field)
points = cfgget('points', field)

# Interpolate to points
lons = N.array([d[0] for d in points])
Example #11
0
#!/usr/bin/env python
# -*- coding: utf8 -*-
"""Manipulation de bathymetrie sur grille (:mod:`vacumm.bathy.bathy`)"""

from vcmq import cdms2, data_sample, create_grid
from vacumm.bathy.bathy import GriddedBathy, NcGriddedBathy, bathy_list, GriddedBathyMerger, plot_bathy

# Lecture d'une variable dans un fichier
cdms2.axis.latitude_aliases.append('y')
cdms2.axis.longitude_aliases.append('x')
f = cdms2.open(data_sample('ETOPO2v2g_flt.grd'))
var = f('z', lon=(-6.1, -4), lat=(47.8, 48.6))
f.close()

# Creation de l'objet de bathy grillee
bathy = GriddedBathy(var)

# Versions masquees
bathy_masked1 = bathy.masked_bathy()                        # -> nb de points masques ?
bathy.set_shoreline('f')                                    # -> essayer 'i'
bathy_masked2 = bathy.masked_bathy()                        # -> nb de points masques ?

# Plot
bathy.plot(title='Direct')


# Bathy standard
from vacumm.bathy.bathy import NcGriddedBathy, bathy_list
print bathy_list().keys()
sbathy = NcGriddedBathy(lon=(-5.2, -3), lat=(48., 48.9), name='etopo2')
sbathy.plot(title='Bathy par defaut')
# -*- coding: utf8 -*-
# Lecture et masquage de Hs
from vcmq import cdms2, MV2, data_sample, code_base_name

f = cdms2.open(data_sample("swan.four.nc"))
lon = f("longitude")
lat = f("latitude")
missing_value = f["HS"]._FillValue
hs = f("HS", squeeze=1)
f.close()
hs[:] = cdms2.MV.masked_object(hs, missing_value, copy=0)

# Trace sur grille irrégulière
from vacumm.misc.plot import map2

map2(
    hs,
    xaxis=lon,
    yaxis=lat,
    figsize=(6, 4),
    long_name="Significant wave height",
    fill="pcolormesh",
    contour=False,
    savefigs=code_base_name(ext="png"),
    left=0.12,
    right=1,
    show=False,
)
Example #13
0
#!/usr/bin/env python
# -*- coding: utf8 -*-
"""Diagnostics thermodynamiques et dynamiques (:mod:`vacumm.diag.thermdyn` et :mod:`vacumm.diag.dynamics`)"""

from vcmq import DS, data_sample, map2, density, mixed_layer_depth,  barotropic_geostrophic_velocity, kinetic_energy, shapiro2d

# Lecture des données de base
ds = DS(data_sample('menor.nc'))
temp = ds.get_temp(squeeze=1)
sal = ds.get_sal(squeeze=1)
depth = ds.get_depth(squeeze=1)
ssh = ds.get_ssh(squeeze=1)


# Densité
dens_surf = density(temp[-1], sal[-1])                      # -> CALCULER DENSITE 3D
map2(dens_surf)


# Couche mélangée
mld = mixed_layer_depth((temp, sal), depth, mode='deltadens') # -> ESSAYER AUTRES MODES
map2(mld, vmax=600.)


# Vitesse geostrophique
# - vitesses
ug, vg = barotropic_geostrophic_velocity(ssh)
# - energie cinetique
ke = kinetic_energy((ug, vg))                                 # -> TESTER AVEC SSH
ke.long_name = 'Surface geostrophique kinetic energy'
ke = shapiro2d(ke)
# Parameters
ncfile = "menor.nc"
lon = (3.0, 4.5)
lat = (42, 42.8)

# Imports
from vcmq import DS, map2, data_sample
from vacumm.diag.thermdyn import mixed_layer_depth

# Read temperature and depth
ncfile = data_sample(ncfile)
ds = DS(ncfile, "mars", lon=lon, lat=lat)
temp = ds.get_temp(squeeze=1)
depth = ds.get_depth(squeeze=1)

# Compute MLD
mld = mixed_layer_depth(temp, depth, mode="deltatemp")

# Plot
map2(mld, proj="merc", figsize=(6, 6), autoresize=0, colorbar_shrink=0.7, right=1, savefigs=__file__, show=False)


print "Done"
Example #15
0
# -*- coding: utf8 -*-
# %% Imports
from vcmq import cdms2, MV2, data_sample, code_base_name, map2

# %% Read Hs
f = cdms2.open(data_sample('swan.four.nc'))
lon = f('longitude')
lat = f('latitude')
hs = f('HS', squeeze=1)
f.close()

# %% Plot it specifying its irregular grid
map2(hs,
     xaxis=lon,
     yaxis=lat,
     figsize=(6, 4),
     cmap='cmocean_amp',
     long_name='Significant wave height',
     fill='pcolormesh',
     contour=False,
     savefigs=code_base_name(ext='png'),
     left=.12,
     right=1,
     show=False)
Example #16
0
from vcmq import data_sample, map, cdms2

# Read
import cdms2
f = cdms2.open(data_sample('mars3d.xy.nc'))
sst = f('temp',
        time=slice(0, 1),
        lat=(47.8, 48.6),
        lon=(-5.2, -4.25),
        squeeze=1)
f.close()

# Plot
m = map(sst,
        title='SST in the Iroise Sea',
        linewidth=.7,
        fill='pcolormesh',
        cmap='cmocean_thermal',
        clabel=True,
        vmin=9,
        top=.9,
        figsize=(6, 5),
        clabel_glow=True,
        clabel_glow_alpha=.4,
        colorbar_shrink=.8,
        show=False,
        savefigs=__file__,
        close=True)
Example #17
0
#!/usr/bin/env python
# -*- coding: utf8 -*-
"""Exploitation generique de donnes grilles (:mod:`vacumm.data.misc.dataset`)"""

from vcmq import DS, data_sample, map2

# Initialisation
ds = DS(data_sample('menor.nc'), 'mars', lon=(4, 5), lat=(42.5, 43.5), log_level='debug')
print ds.dataset


# Logging
ds.info('Pratique')                                 # -> ESSAYER WARNING
ds.set_loglevel('debug')


# Coordonnees
lon = ds.get_lon()                                  # -> ESSAYER AU POINT U
grid = ds.get_grid()


# Variables
temp = ds.get_temp(level=slice(-1, None), squeeze=True)
sst = ds.get_sst(squeeze=True)                      # -> VERIFIER ATTRIBUTS
ds.info('Plot SST')
map2(sst)
sal = ds.get_sal(lon=(4., 4.5))
print temp.shape, sal.shape

# Generique
ds2 = DS(data_sample('mfs.nc'), 'nemo', lon=(4, 5), lat=(42.5, 43.5))
Example #18
0
#!/usr/bin/env python
# -*- coding: utf8 -*-
"""Filtres 1D et 2D"""

from vcmq import cdms2, curve2, map2, generic1d, generic2d, shapiro2d, bartlett1d, data_sample, curve2, shapiro1d, gaussian1d, gaussian2d

# Lectures
f = cdms2.open(data_sample('mars3d.t.nc'))
sst1d = f('temp')
f.close()
f = cdms2.open(data_sample('menor.nc'))
sst2d = f('TEMP', time=slice(0, 1), level=slice(-1, None), squeeze=1)
f.close()

# 1D

# - filtrages
sst1d_gen13 = generic1d(sst1d, 13)
sst1d_gen3 = generic1d(sst1d, [1., 1., 1.])
sst1d_sha = shapiro1d(sst1d)  # -> SHAPIRO AVEC GENERIC1D
sst1d_bar13 = bartlett1d(sst1d, 13)
# -> TESTEZ GAUSSIEN SUR 13 HEURES

# - plots
curve2(sst1d, 'k', label='Original', show=False, figsize=(12, 5))
curve2(sst1d_gen13, 'r', label='Generic 13 pts', show=False)
curve2(sst1d_gen3, 'g', label='Generic 3 pts', show=False)
curve2(sst1d_sha, 'b', label='shapiro', show=False)
curve2(sst1d_bar13, 'm', label='Bartlett', legend=True)

# -> MASQUEZ UNE PARTIE DES DONNEES ET JOUEZ AVEC LE PARAMETRE MASK=
from vcmq import cdms2, data_sample, N, cdtime, curve2,round_date, create_time, \
    lindates, regrid1d, add_key
from vacumm.misc.grid._interp_ import cellerr1d
from scipy.stats import linregress

# Read data
f = cdms2.open(data_sample('radial_speed.nc'))
sp = f('speed')
spe = f('speed_error')
f.close()

# Create hourly time axis
taxi = sp.getTime()
taxi.toRelativeTime('hours since 2000')
ctimesi = taxi.asComponentTime()
ct0 = round_date(ctimesi[0], 'hour')
ct1 = round_date(ctimesi[-1], 'hour')
taxo = create_time(lindates(ct0, ct1, 1, 'hour'), taxi.units)

# Lag error
# - estimation
els = []
lags = N.arange(1, 6)
for lag in lags:
    els.append(N.sqrt(((sp[lag:]-sp[:-lag])**2).mean()))
els = N.array(els)
a, b, _, _, _ = linregress(lags, els)
# - plot
P.figure(figsize=(6, 6))
P.subplot(211)
P.plot(lags, els, 'o')
Example #20
0
#!/usr/bin/env python
# -*- coding: utf8 -*-
"""Calculs sur les gros fichiers"""

from vcmq import cdms2, Intervals, data_sample, StatAccum, cdtime, curve2, N


# Initialisations

# - ouverture du fichier et infos temporelles
f = cdms2.open(data_sample("mars3d.xt.xe.nc"))
ctimes = f["xe"].getTime().asComponentTime()

# - passage par un accumulateur de stats
sa = StatAccum(tmean=True)


# Boucle sur des intervals journaliers
for itv in Intervals((ctimes[0], ctimes[-1], "cc"), "day"):  # -> ESSAYER 2 JOURS

    # Lecture
    print itv
    tmp = f("xe", time=itv)

    # Accumulation
    sa += tmp
    del tmp

# Finalisation

# - restitution
Example #21
0
#!/usr/bin/env python
# -*- coding: utf8 -*-
"""Filtres 1D et 2D"""

from vcmq import cdms2, curve2, map2, generic1d, generic2d, shapiro2d, bartlett1d, data_sample, curve2, shapiro1d, gaussian1d, gaussian2d

# Lectures
f = cdms2.open(data_sample('mars3d.t.nc'))
sst1d = f('temp')
f.close()
f = cdms2.open(data_sample('menor.nc'))
sst2d = f('TEMP', time=slice(0, 1), level=slice(-1, None), squeeze=1)
f.close()



# 1D

# - filtrages
sst1d_gen13 = generic1d(sst1d, 13)
sst1d_gen3 = generic1d(sst1d, [1., 1., 1.])
sst1d_sha = shapiro1d(sst1d)        # -> SHAPIRO AVEC GENERIC1D
sst1d_bar13 = bartlett1d(sst1d, 13)
# -> TESTEZ GAUSSIEN SUR 13 HEURES

# - plots
curve2(sst1d, 'k', label='Original', show=False, figsize=(12, 5))
curve2(sst1d_gen13, 'r', label='Generic 13 pts', show=False)
curve2(sst1d_gen3, 'g', label='Generic 3 pts', show=False)
curve2(sst1d_sha, 'b', label='shapiro', show=False)
curve2(sst1d_bar13, 'm', label='Bartlett', legend=True)
"""Test :func:`~vacumm.misc.grid.regridding.transect` on a curvilinear grid"""

# Inits
ncfile = "swan.four.nc"
lon0 = -5.1
lon1 = -4.9
lat0 = 48.35
lat1 = 48.55


# Imports
from vcmq import cdms2, data_sample, N, transect, curve2, code_file_name, os, \
    add_map_lines,  P, add_shadow

# Read data
f = cdms2.open(data_sample(ncfile))
hs = f('HS', squeeze=1)
f.close()

# Compute transect
hst, lons, lats = transect(hs, (lon0,lon1), (lat0,lat1), getcoords=True)

# Plot along time
s = curve2(hst, figsize=(8,3), title='Spatial transect on curved grid', 
    show=False, top=0.85)

# Add a small map to show the transect positions
o = add_map_lines(hs, lons, lats, map_bgcolor='w', map_bbox= [.6, .2, .3, .5], map_anchor='W')

# Save
figfile = code_file_name(ext='png')
"""Test :meth:`~vacumm.data.misc.dataset.Dataset.get_var` on multiple files and time selections"""

# Inits
ncfiles = "mars2d.xyt.*.nc"

# Imports
from vcmq import DS, os, map2, data_sample

# Glob pattern
result = []
ds = DS(data_sample("mars2d.xyt.*.nc"), 'mars', logger_level='critical',
    time=("2008-08-15 06", "2008-08-15 09"))
assert ds.get_ssh().shape == (4, 50, 50)
assert ds.get_ssh(time=("2008-08-15 06", "2008-08-15 07", 'co'),squeeze=True).shape==(50, 50)

# With dates
ds = DS(data_sample("mars2d.xyt.%Y%m%d%H.nc"), 'mars', logger_level='critical',
    time=("2008-08-15 06", "2008-08-15 09"))
assert ds.get_ssh(
    time=("2008-08-15 06", "2008-08-15 07", 'cc')).shape==(2, 50, 50)


from vcmq import (cdms2, data_sample, N, cdtime, curve2, round_date,
                  create_time, lindates, regrid1d, add_key, P)
from vacumm.misc.grid._interp_ import cellerr1d
from scipy.stats import linregress

# Read data
f = cdms2.open(data_sample('radial_speed.nc'))
sp = f('speed')
spe = f('speed_error')
f.close()

# Create hourly time axis
taxi = sp.getTime()
taxi.toRelativeTime('hours since 2000')
ctimesi = taxi.asComponentTime()
ct0 = round_date(ctimesi[0], 'hour')
ct1 = round_date(ctimesi[-1], 'hour')
taxo = create_time(lindates(ct0, ct1, 1, 'hour'), taxi.units)

# Lag error
# - estimation
els = []
lags = N.arange(1, 6)
for lag in lags:
    els.append(N.sqrt(((sp[lag:] - sp[:-lag])**2).mean()))
els = N.array(els)
a, b, _, _, _ = linregress(lags, els)
# - plot
P.figure(figsize=(6, 6))
P.subplot(211)
P.plot(lags, els, 'o')
Example #25
0
#!/usr/bin/env python
# -*- coding: utf8 -*-
"""Le regrillage"""


from vcmq import N, cdms2, curve2, map2, regrid1d, regrid2d, data_sample, \
    create_grid, regrid_method, CDATRegridder, resol, add_grid, P


# Lecture
f = cdms2.open(data_sample('mfs.nc'))
select = dict(lat=(42.5, 43.5), lon=(3, 4))
ssti = f('votemper', level=slice(0, 1), squeeze=1, **select)
f.close()
gridi = ssti.getGrid()
dxi, dyi = resol(gridi)


# Nouvelle grille
factor = 0.634                                                # -> CHANGEZ LE FACTEUR
dxo = dxi*factor
dyo = dyi*factor
grido = create_grid((3.13, 3.8, dxo), (42.62, 43.4, dyo))


# Quelle méthode ?
method = regrid_method(gridi, grido)
print method


# Regrillage
Example #26
0
"""Test :meth:`~vacumm.misc.core_plot.Plot2D.plot_streamplot`"""

from vcmq import map2, data_sample, cdms2, code_file_name
import warnings
warnings.filterwarnings('ignore', 'Warning: converting a masked element to nan')

f = cdms2.open(data_sample('mars2d.xyt.nc'))
u = f('u', slice(0, 1), squeeze=1)
v = f('v', slice(0, 1), squeeze=1)
f.close()

map2((u, v), fill=False, contour=False, streamplot=True, streamplot_density=3, 
    streamplot_linewidth='modulus', streamplot_lwmod=3, streamplot_color='modulus', 
    title='Tidal stream lines', colorbar_shrink=0.7, savefig=code_file_name(), 
    right=1, show=False)
# Imports
#from matplotlib import use ; use('Agg')
from vcmq import cdms2, bounds1d, bounds2d, data_sample, MV2, cp_props, N, minmax, code_file_name, P, os, psinfo, gc
#from cdms2.mvCdmsRegrid import CdmsRegrid
from time import time
from traceback import format_exc
from mpi4py import MPI

comm = MPI.COMM_WORLD
rank = comm.Get_rank()
size = comm.Get_size()


#if rank==0: print 'read'
f = cdms2.open(data_sample(ncfile))
vari2d = f(ncvar)[0,yslice,xslice]
f.close()
gridi = vari2d.getGrid()
vari2d[:] += 3*vari2d.mean()
vari2d[:, -1] = MV2.masked
nyi,nxi = vari2d.shape

#if rank==0: print 'expand in time and depth'
vari = MV2.resize(vari2d, (nt, nz)+vari2d.shape)
cp_props(vari2d, vari)


#if rank==0: print 'grido'
loni = gridi.getLongitude()
lati = gridi.getLatitude()
Example #28
0
#!/usr/bin/env python
# -*- coding: utf8 -*-
"""Gestion des coordonnées sigma et interpolation 1D"""

from vcmq import NcSigma, SigmaGeneralized, sigma2depths, cdms2, N, section2, create_depth, regrid1d, data_sample


# Lecture de la température
f =cdms2.open(data_sample('mars3d.tsigyx.nc'))
data_in = f('TEMP', time=slice(0,2)) # T-YX (- = level)


# Détermination des profondeurs d'après les sigma
sigma_converter = NcSigma.factory(f)                # détection auto et initialisation du convertisseur
# -> VERIFIER QUE sigma_class EST BIEN SigmaGeneralized
depths_in = sigma_converter.sigma_to_depths(selector=dict(time=slice(0,2))).filled()          # lecture eta, etc + conversion
# (Equivalent à depths_in = sigma_converter(selector=dict(time=slice(0,2))).filled())
f.close()


# Creation de l'axe des profondeurs cibles
depths = N.array([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,
    22,24,26,28,30,32,34,36,38,40,45,50,55,60,65,70,75,80,85,90,95,100,120,140,160])
depths = -depths[::-1] # croissantes et négatives
depth_out = create_depth(depths)


# Interpolation
data_out = regrid1d(data_in, depth_out, axi=depths_in, axis=1, method='linear', extrap=1)

Example #29
0
    curve2,
    map2,
    regrid1d,
    regrid2d,
    data_sample,
    create_grid,
    regrid_method,
    CDATRegridder,
    resol,
    add_grid,
    P,
)


# Lecture
f = cdms2.open(data_sample("mfs.nc"))
select = dict(lat=(42.5, 43.5), lon=(3, 4))
ssti = f("votemper", level=slice(0, 1), squeeze=1, **select)
f.close()
gridi = ssti.getGrid()
dxi, dyi = resol(gridi)


# Nouvelle grille
factor = 0.634  # -> CHANGEZ LE FACTEUR
dxo = dxi * factor
dyo = dyi * factor
grido = create_grid((3.13, 3.8, dxo), (42.62, 43.4, dyo))


# Quelle méthode ?
"""Test :meth:`~vacumm.data.misc.OceanDataset.plot_hsection` with MFS"""

# Inits
ncfile = "mfs.nc"
depth = -1000.0

# Imports
from vcmq import DS, data_sample, os, code_file_name

# Setup dataset
ds = DS(data_sample(ncfile), "nemo", logger_level="critical")

# Plot hsection
figfile = code_file_name(ext="png")
if os.path.exists(figfile):
    os.remove(figfile)
ds.plot_hsection("temp", depth, savefig=figfile, fill="contourf", show=False, close=True)
Example #31
0
"""Test :meth:`~vacumm.data.misc.dataset.Dataset.get_var` on multiple files and time selections"""

# Inits
ncfiles = "mars2d.xyt.*.nc"

# Imports
from vcmq import DS, os, map2, data_sample

# Glob pattern
result = []
ds = DS(data_sample("mars2d.xyt.*.nc"),
        'mars',
        logger_level='critical',
        time=("2008-08-15 06", "2008-08-15 09"))
assert ds.get_ssh().shape == (4, 50, 50)
assert ds.get_ssh(time=("2008-08-15 06", "2008-08-15 07", 'co'),
                  squeeze=True).shape == (50, 50)

# With dates
ds = DS(data_sample("mars2d.xyt.%Y%m%d%H.nc"),
        'mars',
        logger_level='critical',
        time=("2008-08-15 06", "2008-08-15 09"))
assert ds.get_ssh(time=("2008-08-15 06", "2008-08-15 07",
                        'cc')).shape == (2, 50, 50)
Example #32
0
for selname in 'lon', 'lat', 'time':
    val = getattr(options, selname)
    if val is not None:
        try:
            lon = eval(options.lon)
        except:
            parser.error('--%s: wrong argument' % selname)
    select[selname] = val

# Imports
from vcmq import DS, map2, MV2, data_sample

# The file
ncfile = options.ncfile
if not os.path.exists(ncfile):
    ncfile = data_sample(ncfile)
if not os.path.exists(ncfile):
    parser.error('File not found: ' + ncfile)

# Read temperature and depth
ds = DS(ncfile, options.model, **select)
mld = ds.get_mld(mode='deltatemp', squeeze=1)

# Time average (if needed)
if mld.ndim == 3:
    mld = MV2.average(mld, axis=0)

# Plot
map2(mld,
     proj='merc',
     figsize=(6, 6),
Example #33
0
from vcmq import cdms2, P, curve2, savefigs, data_sample
from vacumm.tide.filters import demerliac, godin
from vacumm.tide.filters import extrema, zeros
from vacumm.tide.marigraph import Marigraph
from vacumm.tide.station_info import StationInfo

# Stations
station = StationInfo('Brest')
print station.attributes()
print station.name, station.longitude
print 'Niveau moyen a Brest:', station.nm


# Read sea level at Brest
f = cdms2.open(data_sample("tide.sealevel.BREST.mars.nc"))
sea_level = f('sea_level')
f.close()


# Surcotes/decotes
cotes, tide = demerliac(sea_level, get_tide=True)            # -> ESSAYER GODIN
kwp = dict(date_fmt='%b', date_locator='month')
curve2(sea_level, 'b', show=False, figsize=(15, 4), **kwp)
curve2(tide, 'r', **kwp)
curve2(cotes, figsize=(15, 4), **kwp)


# Extremas
slzoom1 = sea_level(('2006-10-01', '2006-10-02'))[::4] # Toutes les heures
bm, pm = extrema(slzoom1, spline=True, ref='mean')           # -> SANS SPLINES
Example #34
0
# -*- coding: utf8 -*-
# Read sea level at Brest
from vcmq import cdms2, P, curve2, savefigs, data_sample
f = cdms2.open(data_sample("tide.sealevel.BREST.mars.nc"))
sea_level = f('sea_level')
f.close()

# Filtering
from vacumm.tide.filters import demerliac
cotes, tide = demerliac(sea_level, get_tide=True)

# Plots
kwplot = dict(date_fmt='%d/%m', show=False, date_rotation=0)
# - tidal signal
curve2(sea_level,
       'k',
       subplot=211,
       label='Original',
       title='Sea level at Brest',
       **kwplot)
curve2(tide, 'b', label='Tidal signal', **kwplot)
P.legend().legendPatch.set_alpha(.7)
# - surcotes/decotes
curve2(cotes, 'r', subplot=212, hspace=.3, label='Demerliac', **kwplot)
P.legend().legendPatch.set_alpha(.7)
savefigs(__file__, savefigs_pdf=True)
P.close()
Example #35
0
# Imports
from vacumm.report.ifroco.curves import (round_date, P, DS, paris_to_utc, now,
                                         os, cfgget, N, grid2xy, plot_curves,
                                         cdtime, utc_to_paris, Day12hFormatter,
                                         load_cfg)
from vcmq import data_sample, code_file_name

# Time
#t0 = round_date(now(utc=False), 'day', 'floor')
t0 = round_date(nowtime, 'day', 'floor')
t1 = t0.add(ndayfore, cdtime.Day)
t0 = paris_to_utc(t0)
t1 = paris_to_utc(t1)

# Read
ds = DS(data_sample(ncpat), 'mars', time=(t0, t1), logger_level='critical')
data = ds.get(field)
utc_to_paris(data)

# Read some config values
cfgfile = code_file_name(ext='cfg')
load_cfg(cfgfile)
long_name = cfgget('long_name', field)
long_long_name = cfgget('long_name_model', field)
units = cfgget('units', field)
vmin = cfgget('vmin', field)
vmax = cfgget('vmax', field)
points = cfgget('points', field)

# Interpolate to points
lons = N.array([d[0] for d in points])