def sort_mlist_in_stype_dict(self, mlist): #todo needed? """ sorts a list of measurements according to their stype and svals""" mlist = to_list(mlist) out = {} for m in mlist: for t in m.series: if not t.stype in out: out[t.stype] = {} if not t.value in out: out[t.stype][t.value] = [] out[t.stype][t.value].append(m) return out
def get_series(self, stypes=None, svals=None): """ searches for given stypes and svals in self.series and returns them Parameters ---------- stypes: list, str stype or stypes to be looked up svals: float sval or svals to be looked up Returns """ out = self.series if stypes: stypes = to_list(stypes) out = [i for i in out if i.stype in stypes] if svals: svals = to_list(svals) out = [i for i in out if i.value in svals] return out
def add_visual(self, visual, name=None, plt_input=None, calculation_parameter=None, **visual_opt): """ adds a visual to the plot. This creates a new subplot. Parameters ---------- visual: list, str name of visual to add. """ input_exchange = [] # convert visual to list visuals = to_list(visual) for visual in visuals: # check if visual exists otherwise don't create it if visual in Visual.inheritors(): if not name: name = visual n = self._n_visuals # create instance of visual by dynamically calling from inheritors dictionary visual_obj = Visual.inheritors()[visual]( plt_input=plt_input, plt_index=n, fig=self, name=name, calculation_parameter=calculation_parameter, **visual_opt) self._visuals.append([name, visual, visual_obj]) self._n_visuals += 1 else: self.logger.warning('VISUAL << %s >> not implemented yet' % visual) self.logger.warning('\tIMPLEMENTED VISUALS: %s' % Visual.inheritors().keys()) return self.fig = self._create_fig() return visual_obj
def add_visual(self, visual, name=None, plt_input=None, calculation_parameter=None, **visual_opt): """ adds a visual to the plot. This creates a new subplot. Parameters ---------- visual: list, str name of visual to add. """ input_exchange = [] # convert visual to list visuals = to_list(visual) for visual in visuals: # check if visual exists otherwise don't create it if visual in Visual.inheritors(): if not name: name = visual n = self._n_visuals # create instance of visual by dynamically calling from inheritors dictionary visual_obj = Visual.inheritors()[visual](plt_input=plt_input, plt_index=n, fig=self, name=name, calculation_parameter=calculation_parameter, **visual_opt) self._visuals.append([name, visual, visual_obj]) self._n_visuals += 1 else: self.logger.warning('VISUAL << %s >> not implemented yet' % visual) self.logger.warning('\tIMPLEMENTED VISUALS: %s' % Visual.inheritors().keys()) return self.fig = self._create_fig() return visual_obj
__author__ = 'volk'
def get_measurements(self, mtypes=None, series=None, stypes=None, svals=None, sval_range=None, mean=False, invert = False, **options): """ Returns a list of measurements of type = mtypes Parameters ---------- mtypes: list, str mtypes to be returned series: list(tuple) list of tuples, to search for several sepcific series. e.g. [('mtime',4),('gc',2)] will only return mesurements that fulfill both criteria. Supercedes stype, sval and sval_range. Returnes only measurements that meet series exactly! stypes: list, str series type sval_range: list, str series range e.g. sval_range = [0,2] will give all from 0 to 2 including 0,2 also '<2', '<=2', '>2', and '>=2' are allowed. svals: float series value to be searched for. caution: will be overwritten when sval_range is given invert: if invert true it returns only measurements that do not meet criteria sval_range: can be used to look up measurements within a certain range. if only one value is given, it is assumed to be an upper limit and the range is set to [0, sval_range] mean: bool not implemented, yet^ Returns ------- list list of RockPy.Measurements that meet search criteria or if invert is True, do not meet criteria. Note ---- there is no connection between stype and sval. This may cause problems. I you have measurements with M1: [pressure, 0.0, GPa], [temperature, 100.0, C] M2: [pressure, 1.0, GPa], [temperature, 100.0, C] and you search for stypes=['pressure','temperature'], svals=[0,100]. It will return both M1 and M2 because both M1 and M2 have [temperature, 100.0, C]. """ mtypes = to_list(mtypes) stypes = to_list(stypes) svals = to_list(svals) if mean: mdict = self.mean_mdict mdict_type = 'mean_mdict' else: mdict = self.mdict mdict_type = 'mdict' if sval_range: if isinstance(sval_range, list): svals = [i for i in mdict['sval'] if sval_range[0] <= i <= sval_range[1]] if isinstance(sval_range, str): sval_range = sval_range.strip() #remove whitespaces in case '> 4' is provided if '<' in sval_range: if '=' in sval_range: svals = [i for i in mdict['sval'] if i <= float(sval_range.replace('<=',''))] else: svals = [i for i in mdict['sval'] if i < float(sval_range.replace('<',''))] if '>' in sval_range: if '=' in sval_range: svals = [i for i in mdict['sval'] if i >= float(sval_range.replace('>=',''))] else: svals = [i for i in mdict['sval'] if i > float(sval_range.replace('>',''))] self.logger.info('SEARCHING %s for sval_range << %s >>' %(mdict_type, ', '.join(map(str, svals)))) out = [] if not series: for mtype in mtypes: for stype in stypes: for sval in svals: measurements = self.get_mtype_stype_sval(mtype=mtype, stype=stype, sval=sval, mdict_type=mdict_type) for m in measurements: if not m in out: out.append(m) else: # searching for specific series, all mtypes specified that fit the series description will be returned series = to_list(series) for mtype in mtypes: #cycle through mtypes aux = [] for s in series: aux.extend(self.get_mtype_stype_sval(mtype=mtype, stype=s[0], sval=float(s[1]))) out.extend(list(set([i for i in aux if aux.count(i) == len(series)]))) # invert list to contain only measurements that do not meet criteria if invert: out = [i for i in mdict['measurements'] if not i in out] return out