示例#1
0
文件: coloc.py 项目: acoat/vacumm
    def plot_ped_mod_on_pro(self, model, profiles, select=None, **kwargs):
        '''Plot potential energy deficit of model data correspponding to profiles position

        :Params: See: :func:`coloc_mod_on_pro`

        '''
        self.verbose(
            'Plotting PED of colocalized %s on %s\nselect: %s\nkwargs: %s',
            model.__class__.__name__, profiles.__class__.__name__, select,
            kwargs)

        # =====
        # Lecture des donnees de stratification
        lons_mod, lats_mod, deps_mod, temp_mod, sal_mod, pres_mod, dens_mod = \
            self.coloc_strat_mod_on_pro(model, profiles, select, **kwargs)

        # =====
        # Calcul ped modele
        ddeps = meshweights(deps_mod, axis=0)
        # Densité moyenne
        dmean = MV2.average(dens_mod, axis=0, weights=ddeps)
        # Anomalie de densité
        danom = dens_mod - dmean
        # Énergie potentielle disponible
        ape = danom * g
        ape *= ddeps
        # Deficit
        ped_mod = MV2.average(ape, axis=0, weights=ddeps)
        ped_mod.units = 'J.m^{-2}'
        ped_mod.long_name = u"Definit d'energie potentielle"
        ped_mod.setAxisList(lons_mod.getAxisList())
        model.verbose('PED:  %s', ped_mod)

        # =====
        # Calcul ped profiles
        ped_pro, lats_pro, lons_pro = profiles.get_ped(select)
        profiles.verbose('PED:  %s', ped_pro)

        # =====
        # Tracés
        vmin = ped_pro.min()
        vmax = ped_pro.max()
        if ped_mod.count():
            vmin = min(ped_mod.min(), vmin)
            vmax = max(ped_mod.max(), vmax)
        else:
            self.warning('No model data')
        if 'latitude' in select:
            lat_min, lat_max = select['latitude'][:2]
        else:
            la = model.get_latitude()
            lat_min, lat_max = min(la), max(la)
        if 'longitude' in select:
            lon_min, lon_max = select['longitude'][:2]
        else:
            lo = model.get_longitude()
            lon_min, lon_max = min(lo), max(lo)

        levels = auto_scale((vmin, vmax))
        vmin = levels[0]
        vmax = levels[-1]
        # Création de la palette
        cmap = cmap_magic(levels)
        # On trace de champ du modèle moyené sur la période choisie
        m = map2(lon=(lon_min, lon_max), lat=(lat_min, lat_max), show=False)
        # On trace le modèle en fond
        msca = None
        try:
            msca = m.map.scatter(lons_mod,
                                 lats_mod,
                                 s=100,
                                 c=ped_mod,
                                 vmin=vmin,
                                 vmax=vmax,
                                 cmap=cmap,
                                 label='model')
        except:
            self.exception('Failed plotting model data')
        # On trace les observations avec des points plus petits
        psca = None
        try:
            psca = m.map.scatter(lons_pro,
                                 lats_pro,
                                 s=25,
                                 c=ped_pro,
                                 vmin=m.vmin,
                                 vmax=m.vmax,
                                 cmap=m.cmap,
                                 label='profiles')
        except:
            self.exception('Failed plotting profiles data')

        # Colorbar
        if msca is not None:
            colorbar(msca)
        elif psca is not None:
            colorbar(psca)
示例#2
0
文件: coloc.py 项目: jfleroux/vacumm
    def plot_ped_mod_on_pro(self, model, profiles, select=None, **kwargs):
        '''Plot potential energy deficit of model data correspponding to profiles position

        :Params: See: :func:`coloc_mod_on_pro`

        '''
        self.verbose('Plotting PED of colocalized %s on %s\nselect: %s\nkwargs: %s',
            model.__class__.__name__, profiles.__class__.__name__, select, kwargs)

        # =====
        # Lecture des donnees de stratification
        lons_mod, lats_mod, deps_mod, temp_mod, sal_mod, pres_mod, dens_mod = \
            self.coloc_strat_mod_on_pro(model, profiles, select, **kwargs)

        # =====
        # Calcul ped modele
        ddeps = meshweights(deps_mod, axis=0)
        # Densité moyenne
        dmean = MV2.average(dens_mod, axis=0, weights=ddeps)
        # Anomalie de densité
        danom = dens_mod-dmean
        # Énergie potentielle disponible
        ape = danom * g
        ape *= ddeps
        # Deficit
        ped_mod = MV2.average(ape, axis=0, weights=ddeps)
        ped_mod.units = 'J.m^{-2}'
        ped_mod.long_name = u"Definit d'energie potentielle"
        ped_mod.setAxisList(lons_mod.getAxisList())
        model.verbose('PED:  %s', ped_mod)

        # =====
        # Calcul ped profiles
        ped_pro, lats_pro, lons_pro = profiles.get_ped(select)
        profiles.verbose('PED:  %s', ped_pro)

        # =====
        # Tracés
        vmin = ped_pro.min()
        vmax = ped_pro.max()
        if ped_mod.count():
            vmin = min(ped_mod.min(), vmin)
            vmax = max(ped_mod.max(), vmax)
        else:
            self.warning('No model data')
        if 'latitude' in select:
            lat_min, lat_max = select['latitude'][:2]
        else:
            la = model.get_latitude()
            lat_min, lat_max = min(la), max(la)
        if 'longitude' in select:
            lon_min, lon_max = select['longitude'][:2]
        else:
            lo = model.get_longitude()
            lon_min, lon_max = min(lo), max(lo)

        levels = auto_scale((vmin, vmax))
        vmin = levels[0]
        vmax = levels[-1]
        # Création de la palette
        cmap = cmap_magic(levels)
        # On trace de champ du modèle moyené sur la période choisie
        m = map2(lon=(lon_min, lon_max), lat=(lat_min, lat_max), show=False)
        # On trace le modèle en fond
        msca = None
        try: msca = m.map.scatter(lons_mod, lats_mod, s=100, c=ped_mod, vmin=vmin, vmax=vmax, cmap=cmap, label='model')
        except: self.exception('Failed plotting model data')
        # On trace les observations avec des points plus petits
        psca = None
        try: psca = m.map.scatter(lons_pro, lats_pro, s=25, c=ped_pro, vmin=m.vmin, vmax=m.vmax, cmap=m.cmap, label='profiles')
        except: self.exception('Failed plotting profiles data')

        # Colorbar
        if msca is not None:
            colorbar(msca)
        elif psca is not None:
            colorbar(psca)
示例#3
0
文件: coloc.py 项目: acoat/vacumm
    def plot_mld_mod_on_pro(self,
                            model,
                            profiles,
                            select=None,
                            deep=False,
                            **kwargs):
        '''Plot mixed layer depth of model data correspponding to profiles position

        :Params:

          - **deep**: deep water computation mode if true

          Other params, see: :func:`coloc_mod_on_pro`

        '''
        self.verbose(
            'Plotting MLD of colocalized %s on %s\nselect: %s\ndeep: %s\nkwargs: %s',
            model.__class__.__name__, profiles.__class__.__name__, select,
            deep, kwargs)

        # =====
        # Lecture des donnees de stratification
        lons_mod, lats_mod, deps_mod, temp_mod, sal_mod, pres_mod, dens_mod = \
            self.coloc_strat_mod_on_pro(model, profiles, select, **kwargs)

        # =====
        # Calcul mld modele

        # MLD en eaux peu profondes
        if not deep:
            ddeps = meshweights(deps_mod, axis=0)
            # Densité min/max
            dmin = dens_mod.min(axis=0)
            dmax = dens_mod.max(axis=0)
            # Densité moyenne
            dmean = numpy.ma.average(dens_mod, axis=0, weights=ddeps)
            # Profondeur max (max+demi épaisseur)
            H = deps_mod[-1] + ddeps[-1] * .5
            # MLD
            mld_mod = H * (dmax - dmean) / (dmax - dmin)
        # MLD en eaux profondes
        else:
            # Profondeur de référence
            dep = -10
            # Axe pour interpolation
            from vacumm.misc.axes import create_dep
            depaxis = create_dep([dep])
            # Interpolations
            dens_mod_ref = dens_mod_ref.reorder('-z')
            dens_mod_ref = regrid1dold(
                dens_mod, axo=depaxis, xmap=0,
                xmapper=deps_mod)  # Required order: ...z
            dens_mod_ref = dens_mod_ref.reorder('z-')
            # Valeur du différentiel de densité (cf. de Boyer Montégut et all, 2003)
            delta_dens = 0.03
            # Densité cible
            dens_mod_target = dens_mod_ref + 0.03
            # Masques de la couche mélangée et des eaux profondes
            dens_mod_target3d = MV2.resize(dens_mod_target, dens_mod.shape)
            dens_mod_good = (dens_mod.asma() <=
                             dens_mod_target3d.asma()).filled(False)
            dens_mod_bad = (dens_mod.asma() >
                            dens_mod_target3d.asma()).filled(False)
            # Profondeurs juste au dessus et en dessous de la MLD
            deps_mod_above = MV2.masked_where(dens_mod_bad,
                                              deps_mod).min(axis=0)
            deps_mod_below = MV2.masked_where(dens_mod_good,
                                              deps_mod).max(axis=0)
            # Masques associés
            from vacumm.misc import closeto
            mask_above = closeto(deps_mod,
                                 MV2.resize(deps_mod_above, deps_mod.shape))
            mask_below = closeto(deps_mod,
                                 MV2.resize(deps_mod_below, deps_mod.shape))
            # Densités juste au dessus et en dessous de la MLD
            dens_mod_above = MV2.masked_where(dens_mod, mask_above).max(axis=0)
            dens_mod_below = MV2.masked_where(dens_mod, mask_below).min(axis=0)
            # Interpolation
            dens_mod_delta = dens_mod_above - dens_mod_below
            deps_mod_mld = (dens_mod_target - dens_mod_above) * deps_mod_above
            deps_mod_mld += (dens_mod_below - dens_mod_target) * deps_mod_below
            deps_mod_mld = MV2.where(dens_mod_delta.mask, MV2.masked,
                                     deps_mod_mld / dens_mod_delta)
            mld_mod = deps_mod_mld
        # Finalize
        mld_mod = MV2.array(mld_mod)
        mld_mod.units = 'm'
        mld_mod.long_name = u'Profondeur de la couche de melange'
        mld_mod.setAxisList(lons_mod.getAxisList())
        model.verbose('MLD:  %s', mld_mod)

        # =====
        # Calcul mld profiles
        mld_pro, lats_pro, lons_pro = profiles.get_mld(select)
        profiles.verbose('MLD:  %s', mld_pro)

        # =====
        # Tracés
        vmin = mld_pro.min()
        vmax = mld_pro.max()
        if mld_mod.count():
            vmin = min(mld_mod.min(), vmin)
            vmax = max(mld_mod.max(), vmax)
        else:
            self.warning('No model data')
        if 'latitude' in select:
            lat_min, lat_max = select['latitude'][:2]
        else:
            la = model.get_latitude()
            lat_min, lat_max = min(la), max(la)
        if 'longitude' in select:
            lon_min, lon_max = select['longitude'][:2]
        else:
            lo = model.get_longitude()
            lon_min, lon_max = min(lo), max(lo)

        levels = auto_scale((vmin, vmax))
        vmin = levels[0]
        vmax = levels[-1]
        # Création de la palette
        cmap = cmap_magic(levels)
        # On trace de champ du modèle moyené sur la période choisie
        m = map2(lon=(lon_min, lon_max), lat=(lat_min, lat_max), show=False)
        # On trace le modèle en fond

        # =====
        msca = None
        try:
            msca = m.map.scatter(lons_mod,
                                 lats_mod,
                                 s=100,
                                 c=mld_mod,
                                 vmin=vmin,
                                 vmax=vmax,
                                 cmap=cmap,
                                 label='model')
        except:
            self.exception('Failed plotting model data')
        # =====
        # Triangulation du modèle
        #        import matplotlib.tri as tri
        #        triang = tri.Triangulation(lons_mod, lats_mod)
        #        # On trace le modèle en fond
        #        mod = m.axes.tripcolor(triang, mld_mod, vmin=vmin, vmax=vmax, cmap=cmap)
        # =====

        # On trace les observations avec des points plus petits
        psca = None
        try:
            psca = m.map.scatter(lons_pro,
                                 lats_pro,
                                 s=25,
                                 c=mld_pro,
                                 vmin=m.vmin,
                                 vmax=m.vmax,
                                 cmap=m.cmap,
                                 label='profiles')
        except:
            self.exception('Failed plotting profiles data')

        # Colorbar
        if msca is not None:
            colorbar(msca)
        elif psca is not None:
            colorbar(psca)
示例#4
0
文件: coloc.py 项目: jfleroux/vacumm
    def plot_mld_mod_on_pro(self, model, profiles, select=None, deep=False, **kwargs):
        '''Plot mixed layer depth of model data correspponding to profiles position

        :Params:

          - **deep**: deep water computation mode if true

          Other params, see: :func:`coloc_mod_on_pro`

        '''
        self.verbose('Plotting MLD of colocalized %s on %s\nselect: %s\ndeep: %s\nkwargs: %s',
            model.__class__.__name__, profiles.__class__.__name__, select, deep, kwargs)

        # =====
        # Lecture des donnees de stratification
        lons_mod, lats_mod, deps_mod, temp_mod, sal_mod, pres_mod, dens_mod = \
            self.coloc_strat_mod_on_pro(model, profiles, select, **kwargs)

        # =====
        # Calcul mld modele

        # MLD en eaux peu profondes
        if not deep:
            ddeps = meshweights(deps_mod, axis=0)
            # Densité min/max
            dmin = dens_mod.min(axis=0)
            dmax = dens_mod.max(axis=0)
            # Densité moyenne
            dmean = numpy.ma.average(dens_mod, axis=0, weights=ddeps)
            # Profondeur max (max+demi épaisseur)
            H = deps_mod[-1]+ddeps[-1]*.5
            # MLD
            mld_mod = H*(dmax-dmean)/(dmax-dmin)
        # MLD en eaux profondes
        else:
            # Profondeur de référence
            dep = -10
            # Axe pour interpolation
            from vacumm.misc.axes import create_dep
            depaxis = create_dep([dep])
            # Interpolations
            dens_mod_ref = dens_mod_ref.reorder('-z')
            dens_mod_ref = regrid1dold(dens_mod, axo=depaxis, xmap=0, xmapper=deps_mod) # Required order: ...z
            dens_mod_ref = dens_mod_ref.reorder('z-')
            # Valeur du différentiel de densité (cf. de Boyer Montégut et all, 2003)
            delta_dens = 0.03
            # Densité cible
            dens_mod_target = dens_mod_ref+0.03
            # Masques de la couche mélangée et des eaux profondes
            dens_mod_target3d = MV2.resize(dens_mod_target, dens_mod.shape)
            dens_mod_good = (dens_mod.asma() <= dens_mod_target3d.asma()).filled(False)
            dens_mod_bad = (dens_mod.asma() > dens_mod_target3d.asma()).filled(False)
            # Profondeurs juste au dessus et en dessous de la MLD
            deps_mod_above = MV2.masked_where(dens_mod_bad, deps_mod).min(axis=0)
            deps_mod_below = MV2.masked_where(dens_mod_good, deps_mod).max(axis=0)
            # Masques associés
            from vacumm.misc import closeto
            mask_above = closeto(deps_mod, MV2.resize(deps_mod_above, deps_mod.shape))
            mask_below = closeto(deps_mod, MV2.resize(deps_mod_below, deps_mod.shape))
            # Densités juste au dessus et en dessous de la MLD
            dens_mod_above = MV2.masked_where(dens_mod, mask_above).max(axis=0)
            dens_mod_below = MV2.masked_where(dens_mod, mask_below).min(axis=0)
            # Interpolation
            dens_mod_delta = dens_mod_above-dens_mod_below
            deps_mod_mld = (dens_mod_target-dens_mod_above)*deps_mod_above
            deps_mod_mld += (dens_mod_below-dens_mod_target)*deps_mod_below
            deps_mod_mld = MV2.where(dens_mod_delta.mask, MV2.masked, deps_mod_mld/dens_mod_delta)
            mld_mod = deps_mod_mld
        # Finalize
        mld_mod = MV2.array(mld_mod)
        mld_mod.units = 'm'
        mld_mod.long_name = u'Profondeur de la couche de melange'
        mld_mod.setAxisList(lons_mod.getAxisList())
        model.verbose('MLD:  %s', mld_mod)

        # =====
        # Calcul mld profiles
        mld_pro, lats_pro, lons_pro = profiles.get_mld(select)
        profiles.verbose('MLD:  %s', mld_pro)

        # =====
        # Tracés
        vmin = mld_pro.min()
        vmax = mld_pro.max()
        if mld_mod.count():
            vmin = min(mld_mod.min(), vmin)
            vmax = max(mld_mod.max(), vmax)
        else:
            self.warning('No model data')
        if 'latitude' in select:
            lat_min, lat_max = select['latitude'][:2]
        else:
            la = model.get_latitude()
            lat_min, lat_max = min(la), max(la)
        if 'longitude' in select:
            lon_min, lon_max = select['longitude'][:2]
        else:
            lo = model.get_longitude()
            lon_min, lon_max = min(lo), max(lo)

        levels = auto_scale((vmin, vmax))
        vmin = levels[0]
        vmax = levels[-1]
        # Création de la palette
        cmap = cmap_magic(levels)
        # On trace de champ du modèle moyené sur la période choisie
        m = map2(lon=(lon_min, lon_max), lat=(lat_min, lat_max), show=False)
        # On trace le modèle en fond

        # =====
        msca = None
        try: msca = m.map.scatter(lons_mod, lats_mod, s=100, c=mld_mod, vmin=vmin, vmax=vmax, cmap=cmap, label='model')
        except: self.exception('Failed plotting model data')
        # =====
        # Triangulation du modèle
#        import matplotlib.tri as tri
#        triang = tri.Triangulation(lons_mod, lats_mod)
#        # On trace le modèle en fond
#        mod = m.axes.tripcolor(triang, mld_mod, vmin=vmin, vmax=vmax, cmap=cmap)
        # =====

        # On trace les observations avec des points plus petits
        psca = None
        try: psca = m.map.scatter(lons_pro, lats_pro, s=25, c=mld_pro, vmin=m.vmin, vmax=m.vmax, cmap=m.cmap, label='profiles')
        except: self.exception('Failed plotting profiles data')

        # Colorbar
        if msca is not None:
            colorbar(msca)
        elif psca is not None:
            colorbar(psca)