Beispiel #1
0
    def test_add_errors(self):
        d = RockPyData(column_names=['A', 'B'])
        #d['A'].v = 1  # Attribute Error NoneType has no attribute, maybe initialize to np.nan?
        #d['B'] = 2
        #d['A'].e = 4
        #d['B'].e = 5
        d = d.append_rows([1, 2])
        #print d
        d.e = [[4, 5]]

        self.assertEqual(5., d['B'].e)
Beispiel #2
0
    def from_simulation(cls,
                        sobj,
                        idx=None,
                        ms=250.,
                        bmax=0.5,
                        E=0.005,
                        G=0.3,
                        steps=20,
                        log_steps=False,
                        noise=None,
                        color=None,
                        marker=None,
                        linestyle=None):
        """
        Simulates a backfield measurement based on a single log-normal gaussian distribution.

        E:  Median destructive field - represents the mean value of the log-Gaussian distribution, and therefore, the
            logarithmic field value of the maximum gradient.

        G:  G describes the standard deviation or half-width of the distribution.

        """
        cls.clslog.info('CREATING simulation measurement with {}'.format(
            locals()))

        calculation = np.arange(0, 2, 1e-6)
        fields = np.round(np.linspace(1e-9, bmax, steps), 4)
        dist = lognorm([G], loc=E)
        calc_mag = dist.cdf(calculation)
        indices = [np.argmin(abs(v - calculation)) for v in fields]
        mag = [calc_mag[i] for i in indices]
        # mag /= 1/2 * max(mag)
        # mag -= 1
        # mag *= ms

        # mag = G * (np.sqrt(np.pi) / 2) * (sp.special.erf((log_fields - E) / G) - sp.special.erf((-E) / G)) #leonhardt2004

        # if noise:
        # n = np.random.normal(0, ms * (noise / 100), steps)
        # mag = mag + n

        mdata = cls.empty_mdata()
        mdata['remanence'] = RockPyData(column_names=['field', 'mag'],
                                        data=np.c_[fields - bmax, mag])

        return cls(sobj,
                   fpath=None,
                   mdata=mdata,
                   ftype='simulation',
                   color=color,
                   marker=marker,
                   linestyle=linestyle,
                   idx=idx)
Beispiel #3
0
    def setUp(self):
        # run before each test
        self.testdata = ((1, 2, 3, 4), (1, 6, 7, 8), (1, 2, 11, 12), (1, 6, 55,
                                                                      66))

        self.col_names = ('F', 'Mx', 'My', 'Mz')
        self.row_names = ('1.Zeile', '2.Zeile_A', '3.Zeile', '4.Zeile_A')
        self.units = ('T', 'mT', 'fT', 'pT')

        self.RPD = RockPyData(column_names=self.col_names,
                              row_names=self.row_names,
                              units=self.units,
                              data=self.testdata)
Beispiel #4
0
    def format_vftb(ftype_data, sobj_name=None):
        '''
        formats the output from vftb to measurement.data
        :return:
        '''
        data = ftype_data.data
        header = ftype_data.header

        mdata = {}
        mdata['data'] = RockPyData(column_names=header, data=data[0])
        mdata['data']['mag'] = mdata['data']['mag'].v * ftype_data.mass

        mdata['data'].define_alias('variable', 'field')

        return mdata
Beispiel #5
0
    def format_vsm(ftype_data, sobj_name=None):
        """
        formats the vsm output to be compatible with irm acquisition measurements
        :return:
        """

        data = ftype_data.data
        header = ftype_data.header

        # check if vsm file actually contains a dcd measurement
        if not ftype_data.info_header['include irm?']:
            return

        mdata = {}
        mdata['data'] = RockPyData(column_names=header, data=data[0])
        mdata['data'].rename_column('remanence', 'mag')

        return mdata
Beispiel #6
0
    def format_vftb(ftype_data, sobj_name=None):
        data = ftype_data.data
        units = ftype_data.units
        header = ftype_data.header
        mdata = OrderedDict(warming=None, cooling=None)

        if len(data) > 2:
            RockPy3.logger.warning(
                'LENGTH of machine.out_thermocurve =! 2. Assuming data[0] = heating data[1] = cooling'
            )
        if 3 > len(data) > 1:
            for idx, dtype in enumerate(('warming', 'cooling')):
                mdata[dtype] = RockPyData(column_names=header,
                                          data=data[idx],
                                          units=units)
        else:
            RockPy3.logger.error('LENGTH of machine.out_thermocurve < 2.')
        return mdata
Beispiel #7
0
    def format_vsm(ftype_data, sobj_name=None):
        '''
        Reading routine for thermal demagnetization curves measured with a VSM.
        '''
        header = ftype_data.header
        segments = ftype_data.segment_data
        data = ftype_data.data

        mdata = OrderedDict()

        aux = np.array([j for i in data for j in i])  # combine all data arrays
        a = np.array([(i, v)
                      for i, v in enumerate(np.diff(aux, axis=0)[:, 0])])

        sign = np.sign(np.diff(aux, axis=0)[:, 1])

        threshold = 3
        zero_crossings = [
            i + 1 for i in range(len(a[:, 1]) - 1)
            if a[i, 1] > 0 > a[i + 1, 1] and a[i, 1] > 0 > a[i + 2, 1]
            or a[i, 1] < 0 < a[i + 1, 1] and a[i, 1] < 0 < a[i + 2, 1]
        ]

        zero_crossings = [0] + zero_crossings  # start with zero index
        zero_crossings += [len(aux)]  # append last index

        ut = 0  # running number warming
        dt = 0  # running number cooling

        for i, v in enumerate(zero_crossings):
            if v < zero_crossings[-1]:  # prevents index Error
                if sum(a[v:zero_crossings[i + 1], 1]) < 0:  # cooling
                    name = 'cooling%02i' % (ut)
                    ut += 1
                else:
                    name = 'warming%02i' % (dt)
                    dt += 1
                data = aux[v:zero_crossings[i + 1] + 1]
                rpd = RockPyData(column_names=header, data=data)
                rpd.rename_column('temperature', 'temp')
                rpd.rename_column('moment', 'mag')
                mdata.update({name: rpd})

        return mdata
Beispiel #8
0
    def format_vsm(ftype_data, sobj_name=None):
        '''
        formats the output from vsm to measurement.data
        :return:
        '''
        idx = 0
        data = ftype_data.data
        header = ftype_data.header

        # check if vsm file actually contains a dcd measurement
        if not ftype_data.info_header['include dcd?']:
            return
        else:
            if ftype_data.info_header['include irm?']:
                idx += 1

        mdata = {}
        mdata['data'] = RockPyData(column_names=header, data=data[idx])
        mdata['data'].rename_column('remanence', 'mag')

        return mdata
Beispiel #9
0
    def format_mpms(ftype_data, sobj_name=None):
        if ftype_data.name == sobj_name:
            temp_index = ftype_data.units.index('K')

            # see if it a cooling or a warming curve
            mean_temp_difference_between_steps = np.mean(
                np.diff(ftype_data.data[:, temp_index]))
            if mean_temp_difference_between_steps > 0:
                dtype = 'warming'
            else:
                dtype = 'cooling'

            mdata = RockPyData(column_names=ftype_data.header,
                               data=ftype_data.data,
                               units=ftype_data.units)
            mdata.rename_column('Temperature', 'temp')
            mdata.rename_column('Long Moment', 'mag')
            data = {dtype: mdata}
            return data
        else:
            RockPy3.logger.error(
                'SAMPLE name of file does not match specified sample_name. << {} != {} >>'
                .format(ftype_data.name, sobj_name))