Changeset 2324 for trunk


Ignore:
Timestamp:
10/05/11 11:00:08 (13 years ago)
Author:
Malte Marquarding
Message:

Fixed bug in plotetr based statistics where median always showed nan. Need to get stats function explictly from the numpy.ma module. Also put in a filter for the stats to not show stats for annotations. Everything with a label starting with '_' gets ignored.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/python/customgui_base.py

    r2172 r2324  
    176176            if self.lastspan: self._remove_span(self.lastspan)
    177177
    178         self.lastspan = self._draw_span(self._thisregion['axes'],self._thisregion['xs'],xnow,fill="")
     178        self.lastspan = self._draw_span(self._thisregion['axes'],
     179                                        self._thisregion['xs'], xnow, fill="")
    179180        del xnow
    180181
     
    217218
    218219    def _subplot_stats(self,selection):
    219         #from numpy import ma, ndarray
    220         import numpy
    221220        statstr = ['max', 'min', 'median', 'mean', 'sum', 'std'] #'rms']
    222221        panelstr = selection['axes'].title.get_text()
     
    225224        asaplog.post()
    226225        for line in selection['axes'].lines:
     226            # Don't include annotations
     227            if line.get_label().startswith("_"):
     228                continue
    227229            label = panelstr + ", "+line.get_label()
    228230            x = line.get_xdata()
    229             selmsk = self._create_flag_from_array(x,selection['worldx'],selection['invert'])
     231            newmsk = None
     232            selmsk = self._create_flag_from_array(x,
     233                                                  selection['worldx'],
     234                                                  selection['invert'])
     235            ydat = None
    230236            y = line.get_ydata()
    231             if isinstance(y,numpy.ma.masked_array):
     237            if numpy.ma.isMaskedArray(y):
    232238                ydat = y.data
    233239                basemsk = y.mask
     
    237243            if not isinstance(basemsk, bool):
    238244                # should be ndarray
    239                 newmsk = mask_or(selmsk,basemsk)
     245                newmsk = mask_or(selmsk, basemsk)
    240246            elif basemsk:
    241247                # the whole original spectrum is flagged
     
    244250                # no channel was flagged originally
    245251                newmsk = selmsk
    246             mdata = numpy.ma.masked_array(ydat,mask=newmsk)
    247             del x, y, ydat, basemsk, selmsk, newmsk
     252            mdata = numpy.ma.masked_array(ydat, mask=newmsk)
    248253            statval = {}
    249254            for stat in statstr:
    250                 statval[stat] = getattr(numpy,stat)(mdata)
    251             self._print_stats(statval,statstr=statstr,label=label,\
     255                # need to get the stat functions from the ma module!!!
     256                statval[stat] = getattr(numpy.ma,stat)(mdata)
     257            self._print_stats(statval, statstr=statstr, label=label,\
    252258                              mask=selection['worldx'],\
    253259                              unmask=selection['invert'])
    254260            asaplog.push(ssep)
    255261            asaplog.post()
    256             del mdata, statval
    257         del ssep, panelstr
    258262
    259263    def _create_flag_from_array(self,x,masklist,invert):
     
    297301        sout += ("%f "*len(statstr) % tuple(statvals))
    298302        asaplog.push(sout)
    299         del sout, maskstr, masktype, statvals, key, stats, statstr, mask, label
     303        #del sout, maskstr, masktype, statvals, key, stats, statstr, mask, label
    300304
    301305
     
    10771081        statval = {}
    10781082        statstr = ['max', 'min', 'mean', 'median', 'sum', 'stddev', 'rms']
    1079         if isinstance(rows,list) and len(rows) > 0:
     1083        if isinstance(rows, list) and len(rows) > 0:
    10801084            for irow in rows:
    10811085                for stat in statstr:
     
    10951099                for stat in statstr:
    10961100                    statval[stat] = mathobj._statsrow(scan,mask,stat,irow)[0]
    1097                 self._print_stats(scan,irow,statval,statstr=statstr,mask=masklist)
     1101                self._print_stats(scan,irow,statval,statstr=statstr,
     1102                                  mask=masklist)
    10981103                del irow, mask
    10991104            del srow, masklist
Note: See TracChangeset for help on using the changeset viewer.