def test_add_measurement(self): measurement = self.sample.add_measurement( mtype='thellier', mfile=self.cryomag_thellier_file, machine='cryomag') check = { 'nrm': [ 2.00000000e+01, 2.08720000e-08, -8.95180000e-09, 5.04950000e-09, 2.88920000e-10, 735277.720278, 2.32652650e-08 ], } for i in check: for j, v in enumerate(check[i]): self.assertAlmostEqual(measurement.data[i].v[0][j], v, 5) path = join( RockPy.test_data_path, 'LF4C-HX_1a_TT_CRY#320[mg]_5.17[mm]_5.84[mm]#pressure_1.2_GPa#.000' ) print RockPy.get_fname_from_info(sample_group='LF4C-HX', sample_name='1a', mtype='TT', machine='CRY', mass=320, mass_unit='mg', height=5.17, height_unit='mm', diameter=5.87, series='pressure', svals=1.2, sunits='GPa') m = self.sample.add_measurement(path=path)
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
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
def test_add_m2_mdict(self): sample = RockPy.Sample(name='test') compare = deepcopy(sample.mdict) m1 = RockPy.Measurement(sample_obj=sample, mfile=None, machine='generic', mtype='mass', mdata=[1]) m1.add_sval(stype='m1a', sval=1) m1.add_sval(stype='m1b', sval=2) sample.add_m2_mdict(mobj=m1) self.assertTrue(m1 in sample.mdict['stype']['m1a']) self.assertTrue(m1 in sample.mdict['stype']['m1b']) m2 = RockPy.Measurement(sample_obj=sample, mfile=None, machine='generic', mtype='height', mdata=[1]) m2.add_sval(stype='m2a', sval=3) m2.add_sval(stype='m2b', sval=4) self.assertTrue(m2 in sample.mdict['stype']['m2a']) self.assertTrue(m2 in sample.mdict['stype']['m2b']) m2.add_sval(stype='m2c-added_later', sval=100) self.assertTrue(m2 in sample.mdict['stype']['m2c-added_later']) sample.remove_m_from_mdict(mobj=m1) self.assertFalse('m1a' in sample.mdict['stype']) self.assertFalse('m1b' in sample.mdict['stype']) sample.remove_m_from_mdict(mobj=m2) self.assertDictEqual(compare, sample.mdict)
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
def setUp(self): vsm_file = '../tutorials.rst/test_data/MUCVSM_test.hys' # vsm_file = join(RockPy.test_data_path, 'vsm', 'LTPY_527,1a_HYS_VSM#XX[mg]___#TEMP_300_K#STD000.000') self.sample = RockPy.Sample('test') self.VSM_test = RockPy.Sample('test') self.VSM_hys = self.VSM_test.add_measurement(mtype='hysteresis', mfile=vsm_file, machine='vsm') self.simulation = self.sample.add_simulation(mtype='hysteresis', mrs_ms=0.5, ms=5., b_sat=0.8, hf_sus=0)
def test_add_m2_info_dict(self): sample = RockPy.Sample(name='test') m = RockPy.Measurement(sample_obj=sample, mfile=None, machine='generic', mtype='mass', mdata=[1]) sample.add_measurement(mobj=m) pprint(sample.info_dict) sample2 = RockPy.Sample(name='test') sample2.add_m2_info_dict(m) sample2.add_m2_info_dict(m) pprint(sample2.info_dict)
def setUp(self): self.sample = RockPy.Sample( name='test_sample', mass=34.5, mass_unit='mg', diameter=5.4, height=4.3, length_unit='mm', series='pressure_0.0_GPa; temperature_300.0_C') self.cryomag_thellier_file = join(RockPy.test_data_path, 'cryomag', 'NLCRY_Thellier_test.TT') self.cryomag_thellier_is_file = join(RockPy.test_data_path, 'cryomag', 'NLCRY_Thellier_is_test.TT') # vftb self.vftb_coe_file = join(RockPy.test_data_path, 'VFTB', 'MUCVFTB_test.coe') self.vftb_hys_file = join(RockPy.test_data_path, 'VFTB', 'MUCVFTB_test.hys') self.vftb_irm_file = join(RockPy.test_data_path, 'VFTB', 'MUCVFTB_test.irm') self.vftb_rmp_file = join(RockPy.test_data_path, 'VFTB', 'MUCVFTB_test.rmp') # vsm self.vsm_hys_file = '' self.vsm_hys_virgin_file = '' self.vsm_hys_msi_file = '' self.vsm_coe_file = '' self.vsm_coe_irm_file = '' self.vsm_coe_irm_induced_file = '' self.vsm_rmp_file = ''
def test_add_samplegroup(self): study = RockPy.Study(samplegroups=self.sample_group) self.assertEqual(1, len(study.samplegroups)) # add second sample_group study.add_samplegroup(self.sample_group) # adding two sample_groups should make three sample_groups because all_samplegroup is added automatically self.assertEqual(3, len(study.samplegroups))
def __init__(self, sample_obj, mtype, mfile=None, machine='generic', value=1.0, unit='m', direction=None, std=None, time=None, **options): super(Length, self).__init__(sample_obj=sample_obj, mtype=mtype, mfile=mfile, machine=machine, **options) self.mtype = mtype self.machine = machine self.direction = direction length_conversion = convert2(unit, 'm', 'length') self._raw_data = { 'data': RockPy.RockPyData(column_names=[mtype, 'time', 'std_dev']) } self._raw_data['data'][mtype] = value * length_conversion self._raw_data['data']['time'] = time self._raw_data['data']['std_dev'] = std
def test(): Sample = RockPy.Sample(name='parameter_test', mass=10., mass_unit='kg', height=4.5, diameter=6., length_unit='mm') Sample = RockPy.Sample(name='parameter_test', mass=10., mass_unit='kg', sample_shape='sphere', x_len=4.5, y_len=6., z_len=6., length_unit='mm') print Sample.volume, Sample.mass
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
def Arai(): S = RockPy.Tutorials.sample_group.get_thellier_samplegroup() ST = RockPy.Study(S, name='TT-test-ST') P = RockPy.Visualize.paleointensity.Arai(ST) P.add_all_samples() P.show()
def test(): vftb_file = 'test_data/MUCVFTB_test.hys' vsm_file = 'test_data/MUCVSM_test.hys' sample = RockPy.Sample(name='vftb_test_sample') sample2 = RockPy.Sample(name='vsm_test_sample') M = sample.add_measurement(mtype='hysteresis', mfile=vftb_file, machine='vftb') M = sample2.add_measurement(mtype='hysteresis', mfile=vsm_file, machine='vsm') study = RockPy.Study(samplegroups=[sample]) RockPy.save(study, file_name='test.rpy') study2 = RockPy.load(file_name='test.rpy') print study2
def get_sample_with_multiple_hys(): sample = RockPy.Sample(name='test_sample', mass=34.5, mass_unit='mg', diameter=5.4, height=4.3, length_unit='mm', series='pressure_0.0_GPa; temperature_300.0_C') vftb_hys_file = join(RockPy.test_data_path, 'vftb', 'MUCVFTB_test.hys') m1 = sample.add_measurement(mtype='hys', machine='vftb', mfile=vftb_hys_file, series='pressure_0.0_GPa; temperature_100.0_C') m2 = deepcopy(m1) m3 = deepcopy(m2) for dtype in m2.data: for column in m2.data[dtype].column_names: m2.data[dtype][column] = 0.1 + m2.data[dtype][column].v for dtype in m3.data: for column in m3.data[dtype].column_names: m3.data[dtype][column] = 0.1 + m3.data[dtype][column].v return sample
def test(): vftb_file = 'test_data/MUCVFTB_test.rmp' sample = RockPy.Sample(name='vftb_test_sample') M = sample.add_measurement(mtype='thermocurve', mfile=vftb_file, machine='vftb') M.plt_thermocurve()
def test(): sample = RP.Sample(name='test_sample') sample.add_measurement( mtype='thellier', mfile='../tutorials.rst/test_data/NLCRY_Thellier_test.TT', machine='cryomag') Plot = Arai(plot_samples=sample) Plot.show()
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
def get_af_demag_sample(): folder = RockPy.test_data_path S = RockPy.Sample(name='WURM') af = join(folder, 'MUCSUSH_af_test.af') S.add_measurement(mtype='afdemag', mfile=af, machine='sushibar', magtype='irm') return S
def test(): import RockPy from os.path import join test_file = join(RockPy.test_data_path, 'MUCSUSH_af_test.af') S = RockPy.Sample(name='WURM') print S.add_measurement(mtype='afdemag', mfile=test_file, machine='sushibar')
def Day1977(): SG = RockPy.Tutorials.sample_group.get_hys_coe_irm_rmp_sample_group( load=False) ST = RockPy.Study(name='day_plot', samplegroups=SG) S = SG.sample_list[0] m = S.get_measurements('hysteresis')[0] m.show_plots()
def test(): dfile = os.path.join(RockPy.test_data_path, 'vftb', 'MUCVFTB_test.rmp') sample = RockPy.Sample(name='vftb_test') M = sample.add_measurement(mtype='thermocurve', mfile=dfile, machine='vftb') M.plt_thermocurve()
def test(): vftb_file = 'test_data/MUCVFTB_test.irm' sample = RockPy.Sample(name='vftb_test_sample') M = sample.add_measurement(mtype='irm_acquisition', mfile=vftb_file, machine='vftb') print list(M.data['remanence']['field'].v) print list(M.data['remanence']['mag'].v)
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
def setUp(self): self.sample = RockPy.Sample(name='test_sample') # files vsm_file = os.path.join( RockPy.test_data_path, 'vsm', 'FeNi20_FeNi20-Ga72-G01_VISC_VSM#6,0[mg]_[]_[]###.001') # add measurements self.vsm_measurement = self.sample.add_measurement(mtype='viscosity', mfile=vsm_file, machine='vsm')
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
def __init__(self, sample_obj, mtype, mfile=None, machine='combined', height=None, diameter=None, sample_shape='cylinder', x_len=None, y_len=None, z_len=None, std=None, time=None, **options): super(Volume, self).__init__(sample_obj=sample_obj, mtype=mtype, mfile=mfile, machine='combined', **options) self.sample_shape = sample_shape 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.logger.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._raw_data = { 'data': RockPy.RockPyData(column_names=['volume', 'time', 'std_dev']) } self._raw_data['data'][mtype] = volume self._raw_data['data']['time'] = time self._raw_data['data']['std_dev'] = std
def get_test_sample(recalc=False): if os.path.isfile(join(RockPy.test_data_path, 'TTtest.rpy')) or recalc: cryomag_file1 = join(RockPy.test_data_path, 'LF4C-HX_1a_TT_CRY#320[mg]_5.17[mm]_5.84[mm]#pressure_0.0_GPa#.000') cryomag_file2 = join(RockPy.test_data_path, 'LF4C-HX_1a_TT_CRY#320[mg]_5.17[mm]_5.84[mm]#pressure_0.6_GPa#.000') cryomag_file3 = join(RockPy.test_data_path, 'LF4C-HX_1a_TT_CRY#320[mg]_5.17[mm]_5.84[mm]#pressure_1.2_GPa#.000') # creating a sample sample = RockPy.Sample(name='1a') # adding the measurement to the sample M = sample.add_measurement(mtype='thellier', mfile=cryomag_file1, machine='cryomag', series='Pressure_0.0_GPa') M = sample.add_measurement(mtype='thellier', mfile=cryomag_file2, machine='cryomag', series='Pressure_1.0_GPa') M = sample.add_measurement(mtype='thellier', mfile=cryomag_file3, machine='cryomag', series='Pressure_0.0_GPa') RockPy.save(sample, 'TTtest.rpy', RockPy.test_data_path) else: sample = RockPy.load('TTtest.rpy', RockPy.test_data_path) return sample
def get_hys_all_sample(): folder = RockPy.test_data_path S = RockPy.Sample(name='test_sample', mass=14.2, mass_unit='mg', diameter=5.4, length_unit='nm', height=23.8) mfile1 = join(folder, 'MUCVSM_test.hys') mfile2 = join(folder, 'MUCVFTB_test.hys') S.add_measurement(mtype='hys', mfile=mfile1, machine='vsm') S.add_measurement(mtype='hys', mfile=mfile2, machine='vftb') return S
def test(): # thellier output file from cryomag cryomag_file = 'test_data/NLCRY_Thellier_test.TT' # creating a sample sample = RockPy.Sample(name='1a', mass='1.0', mass_unit='mg') # adding the measurement to the sample M = sample.add_measurement(mtype='thellier', mfile=cryomag_file, machine='cryomag') S = Arai(sample) print S S.show()
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
def create_dummy_measurement(mtype, mfile=None, machine=None, idx=0, mdata=None, sample=None): s = RockPy.Sample(name='dummy_sample') m = s.add_measurement( mtype=mtype, mfile=mfile, machine=machine, # general idx=idx, mdata=mdata, ) if sample: m.sample_obj = sample return m
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))
def test(): # SG = get_thellier_samplegroup() # SG = get_hys_coe_irm_rmp_sample_group() S = RockPy.load('hys_coe_irm_rmp.rpy', '/Users/mike/Desktop/')