Example #1
0
def test():
    # define measurement data file
    vftb_file = os.path.join(RockPy.test_data_path, 'vftb', 'MUCVFTB_test.coe')

    # create a sample
    sample = Sample(name='vftb_test_sample')

    # add measurement
    M = sample.add_measurement(mtype='backfield',
                               mfile=vftb_file,
                               machine='vftb',
                               suffix='test 1 none')

    sg = RockPy.SampleGroup(sample_list=sample)
    study = RockPy.Study(samplegroups=sg)
    # get bcr
    M.calculate_bcr(
    )  # prints the linear interpolation of the value (internal calculation)
    print 'bcr', M.bcr  # returns the calculated value
    print M.s300  # returns the S300 value
    M.calc_all()  # calculates all possible results using standard parameters
    print M.results  # returns the calculated value
    # rudimentary plot
    M.plt_backfield()
    sample.calc_all()
    print sample.results
Example #2
0
def import_folder(folder, name='study', study=None):
    if not study:
        study = RockPy.Study(name=name)

    files = [
        i for i in os.listdir(folder) if not i == '.DS_Store'
        if not i.startswith('#')
    ]
    samples = defaultdict(list)

    for i in files:
        d = RockPy.get_info_from_fname(join(folder, i))
        samples[d['name']].append(d)

    for s in samples:
        sgroup_name = samples[s][0]['sample_group']
        if not sgroup_name in study.samplegroup_names:
            sg = RockPy.SampleGroup(name=samples[s][0]['sample_group'])
            study.add_samplegroup(sg)
        sg = study[sgroup_name]
        if not s in study.sdict:
            smpl = RockPy.Sample(**samples[s][0])
            sg.add_samples(smpl)
        for m in samples[s]:
            measurement = smpl.add_measurement(**m)
            if 'ISindex' in m:
                initial = get_IS(m, samples[s])
                measurement.set_initial_state(**initial)
                samples[s].remove(initial)
            if 'IS' in m and m['IS'] == True:
                continue
    return study
Example #3
0
def get_hys_coe_irm_rmp_sample_group(load=False):
    if load:
        study = RockPy.load(file_name='hys_coe_irm_rmp.rpy')
        SG = study[0]
    else:
        S = sample.get_hys_coe_irm_rmp_sample()
        SG = RockPy.SampleGroup(name='hys/coe/irm/rmp', sample_list=S)
        study = RockPy.Study(SG)
        RockPy.save(study, file_name='hys_coe_irm_rmp.rpy')
    return SG
Example #4
0
def get_thellier_samplegroup():
    folder = RockPy.test_data_path

    sample_file = join(folder, 'sample_info.csv')
    tt_data = join(folder, 'NLCRY_Thellier_test.TT')

    SG = RockPy.SampleGroup(name='TT-test-SG')
    SG.import_multiple_samples(sample_file=sample_file)
    for sample in SG.sample_list:
        M = sample.add_measurement(mtype='thellier', mfile=tt_data, machine='cryomag', series='p0')
    return SG
Example #5
0
    def _check_samplegroup_list(self, samplegroup):
        """
        Checks if samplegroup is a list of samples, a list of sample_groups, a single sample or a single samplegroup
        and converts them to be a list of samplegroups
        :param samplegroup:
        :return:
        """

        # check for list
        if isinstance(samplegroup, list):
            # check for sample_group
            if all(isinstance(item, RockPy.Sample)
                   for item in samplegroup):  # all input == samples
                samplegroup = [RockPy.SampleGroup(sample_list=samplegroup)]
            elif all(
                    isinstance(item, RockPy.SampleGroup)
                    for item in samplegroup):  # all input == sample_groups
                samplegroup = samplegroup
            elif all(isinstance(item, RockPy.Study)
                     for item in samplegroup):  # all input == samples
                sgs = []
                for study in samplegroup:
                    sgs.extend(study.samplegroups)
                samplegroup = sgs
            else:
                log.error(
                    'MIXED lists not allowed or no Sample/SampleGroup instance found'
                )
                return None
        if isinstance(samplegroup, RockPy.Sample):
            samplegroup = [RockPy.SampleGroup(sample_list=samplegroup)]
        if isinstance(samplegroup, RockPy.SampleGroup):
            samplegroup = [samplegroup]
        if isinstance(samplegroup, RockPy.Study):
            samplegroup = [samplegroup.all_samplegroup]
        return samplegroup
Example #6
0
    def test_info_dict(self):
        s = RockPy.Tutorials.sample.get_sample_with_multiple_hys()
        sg = RockPy.SampleGroup(sample_list=[s, s])

        s_keys, sg_keys = [], []

        for mtype in s.info_dict['mtype_stype_sval'].keys():
            for stype in s.info_dict['mtype_stype_sval'][mtype].keys():
                for sval in s.info_dict['mtype_stype_sval'][mtype][stype].keys():
                    s_keys.append('_'.join([mtype, stype, str(sval)]))
                    
        for mtype in sg.info_dict['mtype_stype_sval'].keys():
            for stype in sg.info_dict['mtype_stype_sval'][mtype].keys():
                for sval in sg.info_dict['mtype_stype_sval'][mtype][stype].keys():
                    sg_keys.append('_'.join([mtype, stype, str(sval)]))

        self.assertEqual(sorted(s_keys), sorted(sg_keys))
Example #7
0
def import_folderOLD(folder, name='study', study=None):
    """
    imports a whole folder creating a study, sample_groups and samples
    """
    if not study:
        study = RockPy.Study(name=name)
    # get all files in directory
    files = [
        i for i in os.listdir(folder) if not i == '.DS_Store'
        if not i.startswith('#')
    ]

    for f in files:
        d = RockPy.get_info_from_fname(f, folder)
        if 'IS' in d and d['IS']:
            pass
        if not d['sample_group'] in study.samplegroup_names:
            sg = RockPy.SampleGroup(name=d['sample_group'])
            study.add_samplegroup(sg)
        else:
            sg = study.gdict[d['sample_group']]
        if not d['name'] in sg.sample_names:
            s = RockPy.Sample(**d)
            sg.add_samples(s)
        else:
            s = sg.get_samples(snames=d['name'])[0]
        m = s.add_measurement(**d)

        if 'ISindex' in d:
            idx = [(i, f) for i, f in enumerate(files)
                   if d['ISindex'] in f.split('.')[-1]
                   if 'IS_True' in f]  #initial_state index
            if len(idx) > 1:
                print 'more than one initial state found not adding any'
            else:
                initial = RockPy.get_info_from_fname(files[idx[0]], folder)
                del files[idx[0]]
                m.set_initial_state(**initial)

    # print study
    # print study.samplegroups
    # print sg
    # print sg.samples
    # print s
    return study
Example #8
0
 def setUp(self):
     self.sample = RP.Sample(name='test_sample')
     self.sample.add_measurement(mtype='thellier', mfile='../tutorials.rst/test_data/NLCRY_Thellier_test.TT',
                                 machine='cryomag')
     self.sample_group = RP.SampleGroup(sample_list=self.sample)
     self.Plot = Visualize.base.Generic()
Example #9
0
 def test_average_sample(self):
     s = RockPy.Tutorials.sample.get_sample_with_multiple_hys()
     sg = RockPy.SampleGroup(sample_list=[s, s])
     mean = sg.mean_sample(interpolate=False)
     print mean.mean_measurements
Example #10
0
from RockPy.VisualizeV3 import Figure

__author__ = 'mike'
import RockPy
from os.path import join
from RockPy import VisualizeV3

if __name__  == '__main__':

    folder = join(RockPy.test_data_path, 'vsm', 'visualizev3_test')
    study = RockPy.Study(name='visualize V3 test')

    ''' SG 1 '''
    sg1 = RockPy.SampleGroup(name='SG1')
    s1a = RockPy.Sample(name='1a')
    s1b = RockPy.Sample(name='1b')
    sg1.add_samples([s1a, s1b])

    # adding measurements
    s1a.add_measurement(mtype='mass', value=62.7, unit='mg')
    h1a1 = s1a.add_measurement(mtype='hys', mfile=join(folder, 'FeNi_FeNi20-Jd001\'-G01_HYS_VSM#62,7[mg]_[]_[]##STD014.001'), machine='vsm')
    s1a.add_measurement(mtype='mass', value=51.5, unit='mg')
    h1a2 = s1a.add_measurement(mtype='hys', mfile=join(folder, 'FeNi_FeNi20-Jd001\'-G02_HYS_VSM#51,5[mg]_[]_[]##STD014.001'), machine='vsm')
    s1b.add_measurement(mtype='mass', value=60.0, unit='mg')
    h1b1 = s1b.add_measurement(mtype='hys', mfile=join(folder, 'FeNi_FeNi20-Jd120-G02_HYS_VSM#60,0[mg]_[]_[]##STD015.001'), machine='vsm')
    s1b.add_measurement(mtype='mass', value=50.8, unit='mg')
    h1b2 = s1b.add_measurement(mtype='hys', mfile=join(folder, 'FeNi_FeNi20-Jd120-G03_HYS_VSM#50,8[mg]_[]_[]##STD015.001'), machine='vsm')

    # adding series parameters
    h1a1.add_sval(stype='mtime', sval=1)
    h1a2.add_sval(stype='mtime', sval=1)
Example #11
0
 def all_group(self):
     out = RockPy.SampleGroup(name='all')
     for i in self._samplegroups:
         out.add_samples(i.slist)
     self._all_samplegroup = out
     return out
Example #12
0
 def setUp(self):
     self.sample_group = RockPy.SampleGroup()
     self.sample = RockPy.Sample(name='test_sample')
     self.sample_group.add_samples(self.sample)
     self.study = RockPy.Study(self.sample_group)