Ejemplo n.º 1
0
    def format_sushibar(ftype_data, sobj_name=None):
        if not sobj_name in ftype_data.raw_data:
            return

        data = ftype_data.raw_data[sobj_name]
        # data = np.nan_to_num(ftype_data.raw_data[sobj_name])
        header = ftype_data.header

        af3 = np.array([i for i in data if np.isnan(i[header.index('par2')])])
        data = np.array([i for i in data if not np.isnan(i[header.index('par2')])])

        # GENERATE RockPy Data object for data
        data = RockPy3.Data(data=data, column_names=list(map(str.lower, header)))
        data.rename_column('m', 'mag')
        data.rename_column('meas. time', 'time')
        data.define_alias('m', ('x', 'y', 'z'))
        if af3.any():
            af3 = RockPy3.Data(data=af3, column_names=list(map(str.lower, header)))
            af3.rename_column('m', 'mag')
            af3.rename_column('meas. time', 'time')
            af3.define_alias('m', ('x', 'y', 'z'))
        else:
            af3 = None

        out = {'data': data,
               'af3': af3}
        return out
Ejemplo n.º 2
0
    def __init__(self,
                 sobj,
                 mtype='mass',
                 fpath=None,
                 ftype='generic',
                 mass=1.0,
                 mass_unit='kg',
                 std=None,
                 time=None,
                 series=None,
                 **options):
        super(Mass, self).__init__(sobj=sobj,
                                   fpath=fpath,
                                   ftype=ftype,
                                   series=series,
                                   **options)

        mass_conversion = convert2(mass_unit, 'kg', 'mass')

        if not mass_conversion:
            self.log.warning(
                'mass unit << %s >> most likely not mass-compatible' % unit)
            self.log.error('CAN NOT create Measurement')
            self.has_data = False
            return

        self._data = {
            'data':
            RockPy3.Data(column_names=['variable', 'mass', 'time', 'std_dev'])
        }
        self._data['data'][mtype] = mass * mass_conversion
        self._data['data']['time'] = time
        self._data['data']['std_dev'] = std
Ejemplo n.º 3
0
 def format_jr6(ftype_data, sobj_name=None):
     data = RockPy3.Data(data=ftype_data.data, column_names=ftype_data.header)
     data.define_alias('m', ('x', 'y', 'z'))
     data = data.append_columns(column_names='mag', data=data.magnitude(key='m'))
     data = data.sort(key='variable')
     out = {'data': data}
     return out
Ejemplo n.º 4
0
 def results(self):
     results = RockPy3.Data(column_names='mID')
     for i, mid in enumerate(self._raw_results):
         if not 'mID' in self._raw_results[mid].column_names:
             aux = self._raw_results[mid].append_columns(column_names='mID',
                                                         data=mid)
         else:
             aux = self._raw_results[mid]
         results = results.append_rows(aux)
     return results
Ejemplo n.º 5
0
 def results(self):
     results = RockPy3.Data(column_names='mID')
     for s in sorted(self._raw_results):
         for mid in self._raw_results[s]:
             if not 'mID' in results.column_names:
                 aux = self._raw_results[s][mid].append_columns(
                     column_names='mID', data=mid)
             else:
                 aux = self._raw_results[s][mid]
             results = results.append_rows(aux)
     return results
Ejemplo n.º 6
0
    def __init__(self,
                 sobj,
                 mtype,
                 fpath=None,
                 ftype='combined',
                 height=None,
                 diameter=None,
                 sample_shape='cylinder',
                 x_len=None,
                 y_len=None,
                 z_len=None,
                 std=None,
                 time=None,
                 series=None,
                 **options):

        super(Volume, self).__init__(sobj=sobj,
                                     fpath=fpath,
                                     ftype='combined',
                                     **options)
        self.sample_shape = sample_shape

        volume = np.nan

        if sample_shape == 'cylinder' and height and diameter:
            height_data = height.data['data']['height'].v[0]
            diameter_data = diameter.data['data']['diameter'].v[0]
            volume = self.cylinder(height_data, diameter_data)

        if x_len and y_len and z_len:
            if sample_shape != 'cube':  # check if all three dimensions but wrong/unset sample_shape
                self.log.warning(
                    'sample_shape != cube \t but x_len, y_len, z_len provided -> assuming cube'
                )
                sample_shape = 'cube'
            if sample_shape == 'cube':
                x = x_len.data['data']['length'].v[0]
                y = y_len.data['data']['length'].v[0]
                z = z_len.data['data']['length'].v[0]
            volume = self.cube(x, y, z)

        if diameter and not height:
            if sample_shape == 'sphere':
                diameter_data = diameter.data['data']['diameter'].v[0]
                volume = self.sphere(diameter_data)

        # store in RockPy Data object
        self._data = {
            'data': RockPy3.Data(column_names=['volume', 'time', 'std_dev'])
        }
        self._data['data'][mtype] = volume
        self._data['data']['time'] = time
        self._data['data']['std_dev'] = std
Ejemplo n.º 7
0
    def mean_results(self):
        """
        Gives a RockPyData object with all results from mean measurements

        Note:
            does not average the results

        Returns
        -------
            RockPyData
        """
        results = RockPy3.Data(column_names='mID')
        for i, mid in enumerate(self._raw_results):
            aux = self._raw_mean_results[mid].append_columns(
                column_names='mID', data=mid)
            results = results.append_rows(aux)
        return results
Ejemplo n.º 8
0
    def format_sushibar(ftype_data, sobj_name=None):
        if not sobj_name in ftype_data.raw_data:
            return
        data = np.nan_to_num(ftype_data.raw_data[sobj_name])
        header = ftype_data.header

        # data = np.array([i for i in data if not np.isnan(i[header.index('par2')])])
        # print(data)
        # GENERATE RockPy Data object for data
        data = RockPy3.Data(data=data,
                            column_names=list(map(str.lower, header)))
        data.rename_column('m', 'mag')
        data.rename_column('meas. time', 'time')
        data.define_alias('m', ('x', 'y', 'z'))
        data.define_alias('variable', 'par1')

        out = {
            'data': data,
        }
        return out
Ejemplo n.º 9
0
    def format_jr6(ftype_data, sobj_name=None):
        """
        Import of a JR6 ftype_data object
        
        Parameters
        ----------
        ftype_data
        sobj_name

        Returns
        -------

        """
        data = RockPy3.Data(data=ftype_data.data,
                            column_names=ftype_data.header)
        data.define_alias('m', ('x', 'y', 'z'))
        data = data.append_columns(column_names='mag',
                                   data=data.magnitude(key='m'))
        data = data.sort()
        data.define_alias('step', 'variable')
        out = {'data': data}
        return out
Ejemplo n.º 10
0
    def format_cryomag(ftype_data, sobj_name=None):
        if not sobj_name in ftype_data.raw_data:
            RockPy3.logger.warning(
                'CANT find sample name << {} >> in file'.format(sobj_name))
            sobj_name = list(ftype_data.raw_data.keys())[0]
            # raise ValueError('no sample named << {} >> in file'.format(sobj_name))
        raw_data = ftype_data.raw_data[sobj_name]['stepdata']

        header = ['step', 'D', 'I', 'M', 'X', 'Y', 'Z', 'a95', 'sM', 'time']
        data = []
        for d in raw_data:
            aux = [d['step']]
            aux_data = [d['results'][h] for h in header[1:]]
            aux.extend(aux_data)
            data.append(aux)
        data = np.array(data).astype(float)
        data = RockPy3.Data(data=data,
                            column_names=list(map(str.lower, header)))
        data.rename_column('m', 'mag')
        data.define_alias('m', ('x', 'y', 'z'))
        data.define_alias('variable', 'step')
        out = {'data': data}
        return out
Ejemplo n.º 11
0
    def __init__(self,
                 sobj,
                 fpath=None,
                 ftype='generic',
                 value=None,
                 unit='m',
                 direction=None,
                 std=None,
                 time=None,
                 series=None,
                 **options):
        super(Length, self).__init__(sobj=sobj,
                                     fpath=fpath,
                                     ftype=ftype,
                                     series=series,
                                     **options)
        if not value:
            return

        self.ftype = ftype
        self.direction = direction

        length_conversion = convert2(unit, 'm', 'length')

        if not length_conversion:
            self.log.warning('unit << %s >> most likely not %s-compatible' %
                             (unit, self.__class__.get_subclass_name()))
            self.log.error('CAN NOT create Measurement')
            self.has_data = False
            return

        self._data = {
            'data': RockPy3.Data(column_names=[self.mtype, 'time', 'std_dev'])
        }
        self._data['data'][self.mtype] = value * length_conversion
        self._data['data']['time'] = time
        self._data['data']['std_dev'] = std
Ejemplo n.º 12
0
        def wrapped_feature(*args, **kwargs):
            # format the argspec
            parameter = get_full_argspec(func=feature, args=args, kwargs=kwargs)
            visual = parameter['self']

            # update the plt_props of the feature
            kwargs['plt_props'] = {}

            name = kwargs.pop('name', '')

            if self.single:
                self.update_plt_props(kwargs, visual=visual, name=name)
                self.plt_single_feature(feature=feature, visual=visual, **kwargs)
                return wrapped_feature

            ############################################################################################################
            # determine data parameters hierachically from fig -> visual -> feature
            # meaning if only fig data, plot fig_input
            # if fig_input and data -> fig_input is overwritten by data etc.
            plt_info = self.get_plt_infos(feature=feature, visual=visual, name=name)
            RockPy3.logger.debug('Input from:')

            for k, v in sorted(plt_info.items()):
                RockPy3.logger.debug('            {}:{}'.format(k, v))

            ############################################################################################################
            # RESULT FEATURES

            if self.result_feature:
                """
                result feature uses either visual of feature plot_mean, plot_base and ignore_samples flags
                if ignore_samples True: the mean of all samples_is calculated
                                  False: the mean for each individual sample is plotted
                """
                # cycle through possible inputs
                data = {}

                for plt_type in ('groupbase', 'samplebase', 'other', 'samplemean', 'groupmean'):
                    if plt_type not in plt_info:
                        continue
                    # skip everything that should not be plotted
                    if not plt_info['plot_' + plt_type]:
                        continue

                    # get the list of measurements
                    mlist = plt_info[plt_type]
                    # initialize plot properties
                    kwargs['plt_props'] = {}

                    # skip anything that has nothing to plot
                    if not mlist:
                        continue

                    # get rid of measurements without proper result and series
                    mlist = [m for m in mlist if m.has_result(visual.result) if m.get_series(stype=visual.series)]

                    # seaparate list into separate lists for each sample
                    # if ignore samples, all measurements will be used
                    if not plt_info['ignore_samples']:
                        samples = set(m.sobj.name for m in copy(mlist))
                        mlists = [tuple(m for m in mlist if m.sobj.name == sname) for sname in samples]

                    else:
                        mlists = [mlist]

                    # mlists is now a list of measurements for each sample
                    # iterate over the samples measurements
                    for mlist in mlists:
                        data.setdefault(plt_type, [])

                        # initialize the RPdata for each sample
                        sdata = RockPy3.Data(column_names=[visual.series, visual.result], row_names=[])

                        # calculate the results and get the series for all measurements
                        for m in mlist:
                            # get the sval of the specified series
                            sval = m.get_series(visual.series)[0].v
                            # calculate the result using the calculation parameters
                            res = getattr(m, 'result_' + visual.result)(**plt_info['calculation_parameter'])
                            d = RockPy3.Data(data=[sval, res[0]],
                                             column_names=[visual.series, visual.result],
                                             row_names='{}({})'.format(m.sobj.name, m.id))
                            sdata = sdata.append_rows(data=d)

                            # plot each individual result, append them to data
                            if 'base' in plt_type or plt_type == 'other':
                                kwargs['plt_props'] = deepcopy(m.plt_props)
                                # overwrite the plot properties of the measurement object if specified in the decorator
                                # e.g. for setting marker = '' in the hysteresis_data feature
                                self.update_plt_props(kwargs, visual=visual, name=name)

                                # update the plt_props for reducing the alpha
                                if (plt_type == 'samplebase' and plt_info['plot_samplemean'] and plt_info[
                                    'samplemean']) or \
                                        (plt_type == 'groupbase' and plt_info[
                                                'plot_groupmean' and plt_info['groupmean']]):
                                    kwargs['plt_props']['alpha'] = plt_info['base_alpha']
                                feature(visual, data=d, **kwargs)
                        else:
                            data[plt_type].append(sdata)

                        if plt_type == 'other' and plt_info['plot_samplemean']:
                            for i, sdata in enumerate(data['other']):
                                kwargs['plt_props'] = deepcopy(mlists[i][0].plt_props)
                                self.update_plt_props(kwargs, visual=visual, name=name)
                                sdata = sdata.eliminate_duplicate_variable_rows(substfunc='mean').sort()
                                # print(name)
                                # print(sdata)
                                feature(visual, data=sdata, **kwargs)

                    if 'mean' in plt_type:
                        mean_data = []
                        # if result_from_means: the results will be calculated from the data  of any mean measurement
                        # that has been calculated beforand otherwise the mean of the results will be calculated
                        if not plt_info['result_from_means']:
                            base = plt_type.replace('mean', 'base')
                            for sdata in data[base]:
                                sdata = sdata.eliminate_duplicate_variable_rows(substfunc='mean').sort()
                                mean_data.append(sdata)
                        else:
                            for sdata in data[plt_type]:
                                sdata = sdata.eliminate_duplicate_variable_rows(substfunc='mean').sort()
                                mean_data.append(sdata)
                        # print(mean_data)
                        for sdata in mean_data:
                            # print(sdata)
                            kwargs['plt_props'] = {}
                            kwargs['plt_props'] = deepcopy(mlist[0].plt_props)

                            # overwrite the plot properties of the measurement object if specified in the decorator
                            # e.g. for setting marker = '' in the hysteresis_data feature
                            self.update_plt_props(kwargs, visual=visual, name=name)
                            kwargs['plt_props'].update({'alpha': 1, 'zorder': 100})
                            feature(visual, data=sdata, **kwargs)

            ############################################################################################################
            # NORMAL FEATURES
            else:
                # cycle through possible inputs
                for plt_type in ('groupmean', 'samplemean', 'groupbase', 'samplebase', 'other'):
                    # skip everything that should not be plotted
                    if not plt_info['plot_' + plt_type] or not plt_type in plt_info:
                        continue
                    # get the list of measurements
                    mlist = plt_info[plt_type]

                    # initialize plot properties
                    kwargs['plt_props'] = {}

                    if not mlist:
                        continue

                    # for visuals with several possible mtypes
                    for mtype in self.mtypes:
                        if type(mtype) == str:
                            mtype = (mtype,)
                        if len(mtype) > 1:
                            mobj = MlistToTupleList(mlist, mtype)
                        elif len(mtype) == 1:
                            mobj = [m for m in mlist if m.mtype == mtype[0]]
                        else:
                            visual.log.error(
                                    'FEATURE {} data doesnt match mtype requirements {}'.format(feature.__name__,
                                                                                                mtype))
                        for mt_tuple in mobj:
                            try:
                                kwargs['plt_props'].update(mt_tuple[0].plt_props)
                            except TypeError:
                                kwargs['plt_props'].update(mt_tuple.plt_props)

                            # overwrite the plot properties of the measurement object if specified in the decorator
                            # e.g. for setting marker = '' in the hysteresis_data feature
                            kwargs = self.update_plt_props(kwargs, visual=visual, name=name)

                            for k in list(kwargs.keys()):
                                if k in kwargs['plt_props']:
                                    kwargs.pop(k)
                            # change the alpha to base_alpha if group or sample base should be plotted and the means
                            if (plt_type == 'samplebase' and plt_info['plot_samplemean'] and plt_info['samplemean']) or \
                                    (plt_type == 'groupbase' and plt_info['plot_groupmean'] and plt_info['groupmean']):
                                kwargs['plt_props']['alpha'] = plt_info['base_alpha']
                            if plt_type == 'groupmean':
                                kwargs['plt_props']['zorder'] = 100
                            if plt_type == 'samplemean':
                                kwargs['plt_props']['zorder'] = 50
                            feature(visual, mobj=mt_tuple, **kwargs)