def main(): """ NAME chi_magic.py DESCRIPTION plots magnetic susceptibility as a function of frequency and temperature and AC field SYNTAX chi_magic.py [command line options] OPTIONS -h prints help message and quits -f FILE, specify measurements format file, default "measurements.txt" -T IND, specify temperature step to plot -- NOT IMPLEMENTED -e EXP, specify experiment name to plot -fmt [svg,jpg,png,pdf] set figure format [default is svg] -sav save figure and quit """ if "-h" in sys.argv: print(main.__doc__) return infile = pmag.get_named_arg("-f", "measurements.txt") dir_path = pmag.get_named_arg("-WD", ".") infile = pmag.resolve_file_name(infile, dir_path) fmt = pmag.get_named_arg("-fmt", "svg") save_plots = False interactive = True if "-sav" in sys.argv: interactive = False save_plots = True experiments = pmag.get_named_arg("-e", "") ipmag.chi_magic(infile, dir_path, experiments, fmt, save_plots, interactive)
def test_aniso_depthplot_with_no_files(self): program_ran, error_message = ipmag.ani_depthplot2() expected_file = pmag.resolve_file_name('rmag_anisotropy.txt') self.assertFalse(program_ran) self.assertEqual( error_message, "Could not find rmag_anisotropy type file: {}.\nPlease provide a valid file path and try again" .format(expected_file))
def main(): """ NAME dmag_magic.py DESCRIPTION plots intensity decay curves for demagnetization experiments SYNTAX dmag_magic -h [command line options] INPUT takes magic formatted measurements.txt files OPTIONS -h prints help message and quits -f FILE: specify input file, default is: measurements.txt -obj OBJ: specify object [loc, sit, sam, spc] for plot, default is by location -LT [AF,T,M]: specify lab treatment type, default AF -XLP [PI]: exclude specific lab protocols, (for example, method codes like LP-PI) -N do not normalize by NRM magnetization -sav save plots silently and quit -fmt [svg,jpg,png,pdf] set figure format [default is svg] NOTE loc: location (study); sit: site; sam: sample; spc: specimen """ if '-h' in sys.argv: print(main.__doc__) sys.exit() # initialize variables from command line + defaults dir_path = pmag.get_named_arg("-WD", default_val=".") input_dir_path = pmag.get_named_arg('-ID', '') if not input_dir_path: input_dir_path = dir_path in_file = pmag.get_named_arg("-f", default_val="measurements.txt") in_file = pmag.resolve_file_name(in_file, input_dir_path) if "-ID" not in sys.argv: input_dir_path = os.path.split(in_file)[0] plot_by = pmag.get_named_arg("-obj", default_val="loc") LT = pmag.get_named_arg("-LT", "AF") no_norm = pmag.get_flag_arg_from_sys("-N") norm = False if no_norm else True interactive = True save_plots = pmag.get_flag_arg_from_sys("-sav") if save_plots: interactive = False fmt = pmag.get_named_arg("-fmt", "svg") XLP = pmag.get_named_arg("-XLP", "") spec_file = pmag.get_named_arg("-fsp", default_val="specimens.txt") samp_file = pmag.get_named_arg("-fsa", default_val="samples.txt") site_file = pmag.get_named_arg("-fsi", default_val="sites.txt") loc_file = pmag.get_named_arg("-flo", default_val="locations.txt") ipmag.dmag_magic(in_file, dir_path, input_dir_path, spec_file, samp_file, site_file, loc_file, plot_by, LT, norm, XLP, save_plots, fmt, interactive, n_plots="all")
def main(): """ NAME dmag_magic.py DESCRIPTION plots intensity decay curves for demagnetization experiments SYNTAX dmag_magic -h [command line options] INPUT takes magic formatted measurements.txt files OPTIONS -h prints help message and quits -f FILE: specify input file, default is: measurements.txt -obj OBJ: specify object [loc, sit, sam, spc] for plot, default is by location -LT [AF,T,M]: specify lab treatment type, default AF -XLP [PI]: exclude specific lab protocols, (for example, method codes like LP-PI) -N do not normalize by NRM magnetization -sav save plots silently and quit -fmt [svg,jpg,png,pdf] set figure format [default is svg] NOTE loc: location (study); sit: site; sam: sample; spc: specimen """ if '-h' in sys.argv: print(main.__doc__) sys.exit() # initialize variables from command line + defaults dir_path = pmag.get_named_arg("-WD", default_val=".") input_dir_path = pmag.get_named_arg('-ID', '') if not input_dir_path: input_dir_path = dir_path in_file = pmag.get_named_arg("-f", default_val="measurements.txt") in_file = pmag.resolve_file_name(in_file, input_dir_path) if "-ID" not in sys.argv: input_dir_path = os.path.split(in_file)[0] plot_by = pmag.get_named_arg("-obj", default_val="loc") LT = pmag.get_named_arg("-LT", "AF") no_norm = pmag.get_flag_arg_from_sys("-N") norm = False if no_norm else True interactive = True save_plots = pmag.get_flag_arg_from_sys("-sav") if save_plots: interactive = False fmt = pmag.get_named_arg("-fmt", "svg") XLP = pmag.get_named_arg("-XLP", "") spec_file = pmag.get_named_arg("-fsp", default_val="specimens.txt") samp_file = pmag.get_named_arg("-fsa", default_val="samples.txt") site_file = pmag.get_named_arg("-fsi", default_val="sites.txt") loc_file = pmag.get_named_arg("-flo", default_val="locations.txt") ipmag.dmag_magic(in_file, dir_path, input_dir_path, spec_file, samp_file, site_file, loc_file, plot_by, LT, norm, XLP, save_plots, fmt, interactive)
def main(): """ NAME chi_magic.py DESCRIPTION plots magnetic susceptibility as a function of frequency and temperature and AC field SYNTAX chi_magic.py [command line options] OPTIONS -h prints help message and quits -f FILE, specify measurements format file, default "measurements.txt" -T IND, specify temperature step to plot -e EXP, specify experiment name to plot -fmt [svg,jpg,png,pdf] set figure format [default is svg] -sav save figure and quit """ if "-h" in sys.argv: print(main.__doc__) return infile = pmag.get_named_arg("-f", "measurements.txt") dir_path = pmag.get_named_arg("-WD", ".") infile = pmag.resolve_file_name(infile, dir_path) fmt = pmag.get_named_arg("-fmt", "svg") show_plots = True if "-sav" in sys.argv: show_plots = False experiments = pmag.get_named_arg("-e", "") # read in data from data model 3 example file chi_data_all = pd.read_csv(infile, sep='\t', header=1) if not experiments: try: experiments = chi_data_all.experiment.unique() except Exception as ex: print(ex) experiments = ["all"] else: experiments = [experiments] plotnum = 0 figs = {} fnames = {} for exp in experiments: if exp == "all": chi_data = chi_data_all chi_data = chi_data_all[chi_data_all.experiment == exp] if len(chi_data) <= 1: print('Not enough data to plot {}'.format(exp)) continue plotnum += 1 pmagplotlib.plot_init(plotnum, 5, 5) # set up plot figs[str(plotnum)] = plotnum fnames[str(plotnum)] = exp + '_temperature.{}'.format(fmt) # get arrays of available temps, frequencies and fields Ts = np.sort(chi_data.meas_temp.unique()) Fs = np.sort(chi_data.meas_freq.unique()) Bs = np.sort(chi_data.meas_field_ac.unique()) # plot chi versus temperature at constant field b = Bs.max() for num, f in enumerate(Fs): this_f = chi_data[chi_data.meas_freq == f] this_f = this_f[this_f.meas_field_ac == b] plt.plot(this_f.meas_temp, 1e6*this_f.susc_chi_volume, label='%i' % (f)+' Hz') plt.legend() plt.xlabel('Temperature (K)') plt.ylabel('$\chi$ ($\mu$SI)') plt.title('B = '+'%7.2e' % (b) + ' T') plotnum += 1 figs[str(plotnum)] = plotnum fnames[str(plotnum)] = exp + '_frequency.{}'.format(fmt) pmagplotlib.plot_init(plotnum, 5, 5) # set up plot ## plot chi versus frequency at constant B b = Bs.max() t = Ts.min() this_t = chi_data[chi_data.meas_temp == t] this_t = this_t[this_t.meas_field_ac == b] plt.semilogx(this_t.meas_freq, 1e6 * this_t.susc_chi_volume, label='%i' % (t)+' K') plt.legend() plt.xlabel('Frequency (Hz)') plt.ylabel('$\chi$ ($\mu$SI)') plt.title('B = '+'%7.2e' % (b) + ' T') if show_plots: pmagplotlib.draw_figs(figs) ans = input( "enter s[a]ve to save files, [return] to quit ") if ans == 'a': pmagplotlib.save_plots(figs, fnames) sys.exit() else: sys.exit() else: pmagplotlib.save_plots(figs, fnames)
def test_aniso_depthplot_with_no_files(self): program_ran, error_message = ipmag.aniso_depthplot() expected_file = pmag.resolve_file_name('rmag_anisotropy.txt') self.assertFalse(program_ran) self.assertEqual(error_message, "Could not find rmag_anisotropy type file: {}.\nPlease provide a valid file path and try again".format(expected_file))
def main(): """ NAME lowrie_magic.py DESCRIPTION plots intensity decay curves for Lowrie experiments SYNTAX lowrie_magic.py -h [command line options] INPUT takes measurements formatted input files OPTIONS -h prints help message and quits -f FILE: specify input file, default is magic_measurements.txt -N do not normalize by maximum magnetization -fmt [svg, pdf, eps, png] specify fmt, default is svg -sav saves plots and quits -DM [2, 3] MagIC data model number """ if '-h' in sys.argv: print(main.__doc__) sys.exit() if len(sys.argv) <= 1: print(main.__doc__) print('you must supply a file name') sys.exit() FIG = {} # plot dictionary FIG['lowrie'] = 1 # demag is figure 1 pmagplotlib.plot_init(FIG['lowrie'], 6, 6) norm = 1 # default is to normalize by maximum axis in_file = pmag.get_named_arg("-f", "measurements.txt") dir_path = pmag.get_named_arg("-WD", ".") in_file = pmag.resolve_file_name(in_file, dir_path) data_model = pmag.get_named_arg("-DM", 3) data_model = int(float(data_model)) fmt = pmag.get_named_arg("-fmt", "svg") if '-N' in sys.argv: norm = 0 # don't normalize if '-sav' in sys.argv: plot = 1 # silently save and quit else: plot = 0 # generate plots print(in_file) # read in data PmagRecs, file_type = pmag.magic_read(in_file) if data_model == 2 and file_type != "magic_measurements": print('bad input file', file_type) sys.exit() if data_model == 3 and file_type != "measurements": print('bad input file', file_type) sys.exit() if data_model == 2: meth_code_col = 'magic_method_codes' spec_col = 'er_specimen_name' dec_col = "measurement_dec" inc_col = 'measurement_inc' moment_col = 'measurement_magn_moment' temp_col = 'treatment_temp' else: meth_code_col = 'method_codes' spec_col = 'specimen' dec_col = 'dir_dec' inc_col = 'dir_inc' moment_col = 'magn_moment' temp_col = "treat_temp" PmagRecs = pmag.get_dictitem(PmagRecs, meth_code_col, 'LP-IRM-3D', 'has') # get all 3D IRM records if len(PmagRecs) == 0: print('no records found with the method code LP-IRM-3D') sys.exit() specs = pmag.get_dictkey(PmagRecs, spec_col, '') sids = [] for spec in specs: if spec not in sids: sids.append(spec) # get list of unique specimen names for spc in sids: # step through the specimen names print(spc) specdata = pmag.get_dictitem(PmagRecs, spec_col, spc, 'T') # get all this one's data DIMs, Temps = [], [] for dat in specdata: # step through the data DIMs.append([ float(dat[dec_col]), float(dat[inc_col]), float(dat[moment_col]) ]) Temps.append(float(dat[temp_col]) - 273.) carts = pmag.dir2cart(DIMs).transpose() if norm == 1: # want to normalize nrm = (DIMs[0][2]) # normalize by NRM ylab = "M/M_o" else: nrm = 1. # don't normalize ylab = "Magnetic moment (Am^2)" xlab = "Temperature (C)" pmagplotlib.plot_xy(FIG['lowrie'], Temps, abs(carts[0]) / nrm, sym='r-') pmagplotlib.plot_xy(FIG['lowrie'], Temps, abs(carts[0]) / nrm, sym='ro') # X direction pmagplotlib.plot_xy(FIG['lowrie'], Temps, abs(carts[1]) / nrm, sym='c-') pmagplotlib.plot_xy(FIG['lowrie'], Temps, abs(carts[1]) / nrm, sym='cs') # Y direction pmagplotlib.plot_xy(FIG['lowrie'], Temps, abs(carts[2]) / nrm, sym='k-') pmagplotlib.plot_xy(FIG['lowrie'], Temps, abs(carts[2]) / nrm, sym='k^', title=spc, xlab=xlab, ylab=ylab) # Z direction files = {'lowrie': 'lowrie:_' + spc + '_.' + fmt} if plot == 0: pmagplotlib.draw_figs(FIG) ans = input('S[a]ve figure? [q]uit, <return> to continue ') if ans == 'a': pmagplotlib.save_plots(FIG, files) elif ans == 'q': sys.exit() else: pmagplotlib.save_plots(FIG, files) pmagplotlib.clearFIG(FIG['lowrie'])
def main(): """ NAME mk_redo.py DESCRIPTION Makes thellier_redo and zeq_redo files from existing pmag_specimens format file SYNTAX mk_redo.py [-h] [command line options] INPUT takes specimens.txt formatted input file OPTIONS -h: prints help message and quits -f FILE: specify input file, default is 'specimens.txt' -F REDO: specify output file suffix, default is redo so that output filenames are 'thellier_redo' for thellier data and 'zeq_redo' for direction only data OUTPUT makes a thellier_redo or a zeq_redo format file """ if '-h' in sys.argv: print(main.__doc__) sys.exit() zfile, tfile = 'zeq_redo', 'thellier_redo' zredo, tredo = "", "" dir_path = pmag.get_named_arg('-WD', '.') inspec = pmag.get_named_arg('-f', 'specimens.txt') if '-F' in sys.argv: ind = sys.argv.index('-F') redo = sys.argv[ind + 1] tfile = redo zfile = redo inspec = pmag.resolve_file_name(inspec, dir_path) zfile = pmag.resolve_file_name(zfile, dir_path) tfile = pmag.resolve_file_name(tfile, dir_path) # # read in data # specs = [] prior_spec_data, file_type = pmag.magic_read(inspec) if file_type != 'specimens': print(file_type, " this is not a valid pmag_specimens file") sys.exit() outstrings = [] for spec in prior_spec_data: tmp = spec["method_codes"].split(":") meths = [] for meth in tmp: methods = meth.strip().split('-') for m in methods: if m not in meths: meths.append(m) if 'DIR' in meths: # DE-BFL, DE-BFP or DE-FM specs.append(spec['specimen']) if 'dir_comp' in list(spec.keys()) and spec['dir_comp'] != "" and spec['dir_comp'] != " ": comp_name = spec['dir_comp'] else: comp_name = string.ascii_uppercase[specs.count( spec['specimen']) - 1] calculation_type = "DE-BFL" # assume default calculation type is best-fit line if "BFP" in meths: calculation_type = 'DE-BFP' elif "FM" in meths: calculation_type = 'DE-FM' if zredo == "": zredo = open(zfile, "w") outstring = '%s %s %s %s %s \n' % ( spec["specimen"], calculation_type, spec["meas_step_min"], spec["meas_step_max"], comp_name) if outstring not in outstrings: zredo.write(outstring) outstrings.append(outstring) # only writes unique interpretions elif "PI" in meths and "TRM" in meths: # thellier record if tredo == "": tredo = open(tfile, "w") outstring = '%s %i %i \n' % (spec["specimen"], float( spec["meas_step_min"]), float(spec["meas_step_max"])) if outstring not in outstrings: tredo.write(outstring) outstrings.append(outstring) # only writes unique interpretions print('Redo files saved to: ', zfile, tfile)
def plot(in_file="measurements.txt", dir_path=".", input_dir_path="", spec_file="specimens.txt", samp_file="samples.txt", site_file="sites.txt", loc_file="locations.txt", plot_by="loc", LT="AF", norm=True, XLP="", save_plots=True, fmt="svg"): """ plots intensity decay curves for demagnetization experiments Parameters ---------- in_file : str, default "measurements.txt" dir_path : str output directory, default "." input_dir_path : str input file directory (if different from dir_path), default "" spec_file : str input specimen file name, default "specimens.txt" samp_file: str input sample file name, default "samples.txt" site_file : str input site file name, default "sites.txt" loc_file : str input location file name, default "locations.txt" plot_by : str [spc, sam, sit, loc] (specimen, sample, site, location), default "loc" LT : str lab treatment [T, AF, M], default AF norm : bool normalize by NRM magnetization, default True XLP : str exclude specific lab protocols, (for example, method codes like LP-PI) default "" save_plots : bool plot and save non-interactively, default True fmt : str ["png", "svg", "pdf", "jpg"], default "svg" Returns --------- type - Tuple : (True or False indicating if conversion was sucessful, file name(s) written) """ dir_path = os.path.realpath(dir_path) if not input_dir_path: input_dir_path = dir_path input_dir_path = os.path.realpath(input_dir_path) # format plot_key name_dict = {'loc': 'location', 'sit': 'site', 'sam': 'sample', 'spc': 'specimen'} if plot_by not in name_dict.values(): try: plot_key = name_dict[plot_by] except KeyError: print('Unrecognized plot_by {}, falling back to plot by location'.format(plot_by)) plot_key = "loc" else: plot_key = plot_by # figure out what kind of experiment LT = "LT-" + LT + "-Z" print('LT', LT) if LT == "LT-T-Z": units, dmag_key = 'K', 'treat_temp' elif LT == "LT-AF-Z": units, dmag_key = 'T', 'treat_ac_field' elif LT == 'LT-M-Z': units, dmag_key = 'J', 'treat_mw_energy' else: units = 'U' # init FIG = {} # plot dictionary FIG['demag'] = 1 # demag is figure 1 # create contribution and add required headers fnames = {"specimens": spec_file, "samples": samp_file, 'sites': site_file, 'locations': loc_file} if not os.path.exists(pmag.resolve_file_name(in_file, input_dir_path)): print('-E- Could not find {}'.format(in_file)) return False, [] contribution = cb.Contribution(input_dir_path, single_file=in_file, custom_filenames=fnames) file_type = list(contribution.tables.keys())[0] print(len(contribution.tables['measurements'].df), ' records read from ', in_file) # add plot_key into measurements table if plot_key not in contribution.tables['measurements'].df.columns: #contribution.propagate_name_down(plot_key, 'measurements') contribution.propagate_location_to_measurements() data_container = contribution.tables[file_type] # pare down to only records with useful data # grab records that have the requested code data_slice = data_container.get_records_for_code(LT) # and don't have the offending code data = data_container.get_records_for_code(XLP, incl=False, use_slice=True, sli=data_slice, strict_match=False) # make sure quality is in the dataframe if 'quality' not in data.columns: data['quality'] = 'g' # get intensity key and make sure intensity data is not blank intlist = ['magn_moment', 'magn_volume', 'magn_mass'] IntMeths = [col_name for col_name in data.columns if col_name in intlist] # get rid of any entirely blank intensity columns for col_name in IntMeths: if not data[col_name].any(): data.drop(col_name, axis=1, inplace=True) IntMeths = [col_name for col_name in data.columns if col_name in intlist] if len(IntMeths) == 0: print('-E- No intensity headers found') return False, [] int_key = IntMeths[0] # plot first intensity method found - normalized to initial value anyway - doesn't matter which used data = data[data[int_key].notnull()] # make list of individual plots # by default, will be by location_name plotlist = data[plot_key].unique() plotlist.sort() pmagplotlib.plot_init(FIG['demag'], 5, 5) last_plot = False # iterate through and plot the data for plt in plotlist: if plt == plotlist[-1]: last_plot = True plot_data = data[data[plot_key] == plt].copy() if not save_plots: print(plt, 'plotting by: ', plot_key) if len(plot_data) > 2: title = plt spcs = [] spcs = plot_data['specimen'].unique() for spc in spcs: INTblock = [] spec_data = plot_data[plot_data['specimen'] == spc] for ind, rec in spec_data.iterrows(): INTblock.append([float(rec[dmag_key]), 0, 0, float(rec[int_key]), 1, rec['quality']]) if len(INTblock) > 2: pmagplotlib.plot_mag(FIG['demag'], INTblock, title, 0, units, norm) if save_plots: files = {} for key in list(FIG.keys()): if pmagplotlib.isServer: files[key] = title + '_' + LT + '.' + fmt incl_dir = False else: # if not server, include directory in output path files[key] = os.path.join(dir_path, title + '_' + LT + '.' + fmt) incl_dir = True pmagplotlib.save_plots(FIG, files, incl_directory=incl_dir) else: pmagplotlib.draw_figs(FIG) prompt = " S[a]ve to save plot, [q]uit, Return to continue: " ans = input(prompt) if ans == 'q': return True, [] if ans == "a": files = {} for key in list(FIG.keys()): if pmagplotlib.isServer: files[key] = title + '_' + LT + '.' + fmt incl_dir = False else: # if not server, include directory in output path files[key] = os.path.join(dir_path, title + '_' + LT + '.' + fmt) incl_dir = True pmagplotlib.save_plots(FIG, files, incl_directory=incl_dir) pmagplotlib.clearFIG(FIG['demag']) if last_plot: return True, []
def convert(**kwargs): # initialize some stuff methcode="LP-NO" phi,theta,peakfield,labfield=0,0,0,0 pTRM,MD=0,0 dec=[315,225,180,135,45,90,270,270,270,90,180,180,0,0,0] inc=[0,0,0,0,0,-45,-45,0,45,45,45,-45,-90,-45,45] tdec=[0,90,0,180,270,0,0,90,0] tinc=[0,0,90,0,0,-90,0,0,90] missing=1 demag="N" citations='This study' fmt='old' Samps=[] trm=0 irm=0 #get args user = kwargs.get('user', '') dir_path = kwargs.get('dir_path', '.') output_dir_path = dir_path meas_file = kwargs.get('meas_file', 'measurements.txt') # measurement outfile meas_file = pmag.resolve_file_name(meas_file, output_dir_path) spec_file = kwargs.get('spec_file', 'specimens.txt') # specimen outfile spec_file = pmag.resolve_file_name(spec_file, output_dir_path) samp_file = kwargs.get('samp_file', 'samples.txt') # sample outfile samp_file = pmag.resolve_file_name(samp_file, output_dir_path) site_file = kwargs.get('site_file', 'sites.txt') # site outfile site_file = pmag.resolve_file_name(site_file, output_dir_path) loc_file = kwargs.get('loc_file', 'locations.txt') # location outfile loc_file = pmag.resolve_file_name(loc_file, output_dir_path) mag_file = kwargs.get('mag_file', '') mag_file = pmag.resolve_file_name(mag_file, dir_path) labfield = kwargs.get('labfield', '') if labfield: labfield = float(labfield) *1e-6 else: labfield = 0 phi = kwargs.get('phi', 0) if phi: phi = float(phi) else: phi = 0 theta = kwargs.get('theta', 0) if theta: theta=float(theta) else: theta = 0 peakfield = kwargs.get('peakfield', 0) if peakfield: peakfield=float(peakfield) *1e-3 else: peakfield = 0 specnum = kwargs.get('specnum', 0) samp_con = kwargs.get('samp_con', '1') location = kwargs.get('location', 'unknown') samp_infile = kwargs.get('samp_infile', '') syn = kwargs.get('syn', 0) institution = kwargs.get('institution', '') syntype = kwargs.get('syntype', '') inst = kwargs.get('inst', '') noave = kwargs.get('noave', 0) codelist = kwargs.get('codelist', '') coil = kwargs.get('coil', '') cooling_rates = kwargs.get('cooling_rates', '') lat = kwargs.get('lat', '') lon = kwargs.get('lon', '') timezone = kwargs.get('timezone', 'UTC') # make sure all initial values are correctly set up (whether they come from the command line or a GUI) if samp_infile: Samps, file_type = pmag.magic_read(samp_infile) if coil: coil = str(coil) methcode="LP-IRM" irmunits = "V" if coil not in ["1","2","3"]: print(__doc__) print('not a valid coil specification') return False, '{} is not a valid coil specification'.format(coil) if mag_file: lines = pmag.open_file(mag_file) if not lines: print("you must provide a valid mag_file") return False, "you must provide a valid mag_file" if not mag_file: print(__doc__) print("mag_file field is required option") return False, "mag_file field is required option" if specnum!=0: specnum=-specnum if "4" == samp_con[0]: if "-" not in samp_con: print("naming convention option [4] must be in form 4-Z where Z is an integer") print('---------------') return False, "naming convention option [4] must be in form 4-Z where Z is an integer" else: Z=samp_con.split("-")[1] samp_con="4" if "7" == samp_con[0]: if "-" not in samp_con: print("option [7] must be in form 7-Z where Z is an integer") return False, "option [7] must be in form 7-Z where Z is an integer" else: Z=samp_con.split("-")[1] samp_con="7" else: Z = 0 if codelist: codes=codelist.split(':') if "AF" in codes: demag='AF' if'-dc' not in sys.argv: methcode="LT-AF-Z" if'-dc' in sys.argv: methcode="LT-AF-I" if "T" in codes: demag="T" if '-dc' not in sys.argv: methcode="LT-T-Z" if '-dc' in sys.argv: methcode="LT-T-I" if "I" in codes: methcode="LP-IRM" irmunits="mT" if "I3d" in codes: methcode="LT-T-Z:LP-IRM-3D" if "S" in codes: demag="S" methcode="LP-PI-TRM:LP-PI-ALT-AFARM" trm_labfield=labfield ans=input("DC lab field for ARM step: [50uT] ") if ans=="": arm_labfield=50e-6 else: arm_labfield=float(ans)*1e-6 ans=input("temperature for total trm step: [600 C] ") if ans=="": trm_peakT=600+273 # convert to kelvin else: trm_peakT=float(ans)+273 # convert to kelvin if "G" in codes: methcode="LT-AF-G" if "D" in codes: methcode="LT-AF-D" if "TRM" in codes: demag="T" trm=1 if "CR" in codes: demag="T" cooling_rate_experiment=1 cooling_rates_list=cooling_rates.split(',') # command_line does not exist in this code #if command_line: # ind=sys.argv.index("CR") # cooling_rates=sys.argv[ind+1] # cooling_rates_list=cooling_rates.split(',') #else: # cooling_rates_list=str(cooling_rates).split(',') if demag=="T" and "ANI" in codes: methcode="LP-AN-TRM" if demag=="T" and "CR" in codes: methcode="LP-CR-TRM" if demag=="AF" and "ANI" in codes: methcode="LP-AN-ARM" if labfield==0: labfield=50e-6 if peakfield==0: peakfield=.180 MeasRecs,SpecRecs,SampRecs,SiteRecs,LocRecs=[],[],[],[],[] version_num=pmag.get_version() ################################## for line in lines: instcode="" if len(line)>2: MeasRec,SpecRec,SampRec,SiteRec,LocRec={},{},{},{},{} MeasRec['software_packages']=version_num MeasRec["description"]="" MeasRec["treat_temp"]='%8.3e' % (273) # room temp in kelvin MeasRec["meas_temp"]='%8.3e' % (273) # room temp in kelvin MeasRec["treat_ac_field"]='0' MeasRec["treat_dc_field"]='0' MeasRec["treat_dc_field_phi"]='0' MeasRec["treat_dc_field_theta"]='0' meas_type="LT-NO" rec=line.split() try: float(rec[0]); print("No specimen name for line #%d in the measurement file"%lines.index(line)); continue except ValueError: pass if rec[1]==".00":rec[1]="0.00" treat=rec[1].split('.') if methcode=="LP-IRM": if irmunits=='mT': labfield=float(treat[0])*1e-3 else: labfield=pmag.getfield(irmunits,coil,treat[0]) if rec[1][0]!="-": phi,theta=0.,90. else: phi,theta=0.,-90. meas_type="LT-IRM" MeasRec["treat_dc_field"]='%8.3e'%(labfield) MeasRec["treat_dc_field_phi"]='%7.1f'%(phi) MeasRec["treat_dc_field_theta"]='%7.1f'%(theta) if len(rec)>6: code1=rec[6].split(';') # break e.g., 10/15/02;7:45 indo date and time if len(code1)==2: # old format with AM/PM missing=0 code2=code1[0].split('/') # break date into mon/day/year code3=rec[7].split(';') # break e.g., AM;C34;200 into time;instr/axes/measuring pos;number of measurements yy=int(code2[2]) if yy <90: yyyy=str(2000+yy) else: yyyy=str(1900+yy) mm=int(code2[0]) if mm<10: mm="0"+str(mm) else: mm=str(mm) dd=int(code2[1]) if dd<10: dd="0"+str(dd) else: dd=str(dd) time=code1[1].split(':') hh=int(time[0]) if code3[0]=="PM":hh=hh+12 if hh<10: hh="0"+str(hh) else: hh=str(hh) min=int(time[1]) if min<10: min= "0"+str(min) else: min=str(min) dt=yyyy+":"+mm+":"+dd+":"+hh+":"+min+":00" local = pytz.timezone(timezone) naive = datetime.datetime.strptime(dt, "%Y:%m:%d:%H:%M:%S") local_dt = local.localize(naive, is_dst=None) utc_dt = local_dt.astimezone(pytz.utc) MeasRec["timestamp"]=utc_dt.strftime("%Y-%m-%dT%H:%M:%S")+"Z" if inst=="": if code3[1][0]=='C':instcode='SIO-bubba' if code3[1][0]=='G':instcode='SIO-flo' else: instcode='' MeasRec["meas_n_orient"]=code3[1][2] elif len(code1)>2: # newest format (cryo7 or later) if "LP-AN-ARM" not in methcode:labfield=0 fmt='new' date=code1[0].split('/') # break date into mon/day/year yy=int(date[2]) if yy <90: yyyy=str(2000+yy) else: yyyy=str(1900+yy) mm=int(date[0]) if mm<10: mm="0"+str(mm) else: mm=str(mm) dd=int(date[1]) if dd<10: dd="0"+str(dd) else: dd=str(dd) time=code1[1].split(':') hh=int(time[0]) if hh<10: hh="0"+str(hh) else: hh=str(hh) min=int(time[1]) if min<10: min= "0"+str(min) else: min=str(min) dt=yyyy+":"+mm+":"+dd+":"+hh+":"+min+":00" local = pytz.timezone(timezone) naive = datetime.datetime.strptime(dt, "%Y:%m:%d:%H:%M:%S") local_dt = local.localize(naive, is_dst=None) utc_dt = local_dt.astimezone(pytz.utc) MeasRec["timestamp"]=utc_dt.strftime("%Y-%m-%dT%H:%M:%S")+"Z" if inst=="": if code1[6][0]=='C': instcode='SIO-bubba' if code1[6][0]=='G': instcode='SIO-flo' else: instcode='' if len(code1)>1: MeasRec["meas_n_orient"]=code1[6][2] else: MeasRec["meas_n_orient"]=code1[7] # takes care of awkward format with bubba and flo being different if user=="":user=code1[5] if code1[2][-1]=='C': demag="T" if code1[4]=='microT' and float(code1[3])!=0. and "LP-AN-ARM" not in methcode: labfield=float(code1[3])*1e-6 if code1[2]=='mT' and methcode!="LP-IRM": demag="AF" if code1[4]=='microT' and float(code1[3])!=0.: labfield=float(code1[3])*1e-6 if code1[4]=='microT' and labfield!=0. and meas_type!="LT-IRM": phi,theta=0.,-90. if demag=="T": meas_type="LT-T-I" if demag=="AF": meas_type="LT-AF-I" MeasRec["treat_dc_field"]='%8.3e'%(labfield) MeasRec["treat_dc_field_phi"]='%7.1f'%(phi) MeasRec["treat_dc_field_theta"]='%7.1f'%(theta) if code1[4]=='' or labfield==0. and meas_type!="LT-IRM": if demag=='T':meas_type="LT-T-Z" if demag=="AF":meas_type="LT-AF-Z" MeasRec["treat_dc_field"]='0' if syn==0: specimen=rec[0] MeasRec["specimen"]=specimen if specnum!=0: sample=rec[0][:specnum] else: sample=rec[0] if samp_infile and Samps: # if samp_infile was provided AND yielded sample data samp=pmag.get_dictitem(Samps,'sample',sample,'T') if len(samp)>0: location=samp[0]["location"] site=samp[0]["site"] else: location='' site='' else: site=pmag.parse_site(sample,samp_con,Z) if location!='' and location not in [x['location'] if 'location' in list(x.keys()) else '' for x in LocRecs]: LocRec['location'] = location LocRec['lat_n'] = lat LocRec['lat_s'] = lat LocRec['lon_e'] = lon LocRec['lon_w'] = lon LocRecs.append(LocRec) if site!='' and site not in [x['site'] if 'site' in list(x.keys()) else '' for x in SiteRecs]: SiteRec['location'] = location SiteRec['site'] = site SiteRec['lat'] = lat SiteRec['lon'] = lon SiteRecs.append(SiteRec) if sample!='' and sample not in [x['sample'] if 'sample' in list(x.keys()) else '' for x in SampRecs]: SampRec['site'] = site SampRec['sample'] = sample SampRecs.append(SampRec) if specimen!='' and specimen not in [x['specimen'] if 'specimen' in list(x.keys()) else '' for x in SpecRecs]: SpecRec["specimen"]=specimen SpecRec['sample'] = sample SpecRecs.append(SpecRec) else: specimen=rec[0] MeasRec["specimen"]=specimen if specnum!=0: sample=rec[0][:specnum] else: sample=rec[0] site=pmag.parse_site(sample,samp_con,Z) if location!='' and location not in [x['location'] if 'location' in list(x.keys()) else '' for x in LocRecs]: LocRec['location'] = location LocRec['lat_n'] = lat LocRec['lat_s'] = lat LocRec['lon_e'] = lon LocRec['lon_w'] = lon LocRecs.append(LocRec) if site!='' and site not in [x['site'] if 'site' in list(x.keys()) else '' for x in SiteRecs]: SiteRec['location'] = location SiteRec['site'] = site SiteRec['lat'] = lat SiteRec['lon'] = lon SiteRecs.append(SiteRec) if sample!='' and sample not in [x['sample'] if 'sample' in list(x.keys()) else '' for x in SampRecs]: SampRec['site'] = site SampRec['sample'] = sample SampRecs.append(SampRec) if specimen!='' and specimen not in [x['specimen'] if 'specimen' in list(x.keys()) else '' for x in SpecRecs]: SpecRec["specimen"]=specimen SpecRec['sample'] = sample SpecRecs.append(SpecRec) SampRec["institution"]=institution SampRec["material_type"]=syntype #MeasRec["sample"]=sample if float(rec[1])==0: pass elif demag=="AF": if methcode != "LP-AN-ARM": MeasRec["treat_ac_field"]='%8.3e' %(float(rec[1])*1e-3) # peak field in tesla if meas_type=="LT-AF-Z": MeasRec["treat_dc_field"]='0' else: # AARM experiment if treat[1][0]=='0': meas_type="LT-AF-Z:LP-AN-ARM:" MeasRec["treat_ac_field"]='%8.3e' %(peakfield) # peak field in tesla MeasRec["treat_dc_field"]='%8.3e'%(0) if labfield!=0 and methcode!="LP-AN-ARM": print("Warning - inconsistency in mag file with lab field - overriding file with 0") else: meas_type="LT-AF-I:LP-AN-ARM" ipos=int(treat[0])-1 MeasRec["treat_dc_field_phi"]='%7.1f' %(dec[ipos]) MeasRec["treat_dc_field_theta"]='%7.1f'% (inc[ipos]) MeasRec["treat_dc_field"]='%8.3e'%(labfield) MeasRec["treat_ac_field"]='%8.3e' %(peakfield) # peak field in tesla elif demag=="T" and methcode == "LP-AN-TRM": MeasRec["treat_temp"]='%8.3e' % (float(treat[0])+273.) # temp in kelvin if treat[1][0]=='0': meas_type="LT-T-Z:LP-AN-TRM" MeasRec["treat_dc_field"]='%8.3e'%(0) MeasRec["treat_dc_field_phi"]='0' MeasRec["treat_dc_field_theta"]='0' else: MeasRec["treat_dc_field"]='%8.3e'%(labfield) if treat[1][0]=='7': # alteration check as final measurement meas_type="LT-PTRM-I:LP-AN-TRM" else: meas_type="LT-T-I:LP-AN-TRM" # find the direction of the lab field in two ways: # (1) using the treatment coding (XX.1=+x, XX.2=+y, XX.3=+z, XX.4=-x, XX.5=-y, XX.6=-z) ipos_code=int(treat[1][0])-1 # (2) using the magnetization DEC=float(rec[4]) INC=float(rec[5]) if INC < 45 and INC > -45: if DEC>315 or DEC<45: ipos_guess=0 if DEC>45 and DEC<135: ipos_guess=1 if DEC>135 and DEC<225: ipos_guess=3 if DEC>225 and DEC<315: ipos_guess=4 else: if INC >45: ipos_guess=2 if INC <-45: ipos_guess=5 # prefer the guess over the code ipos=ipos_guess MeasRec["treat_dc_field_phi"]='%7.1f' %(tdec[ipos]) MeasRec["treat_dc_field_theta"]='%7.1f'% (tinc[ipos]) # check it if ipos_guess!=ipos_code and treat[1][0]!='7': print("-E- ERROR: check specimen %s step %s, ATRM measurements, coding does not match the direction of the lab field!"%(rec[0],".".join(list(treat)))) elif demag=="S": # Shaw experiment if treat[1][1]=='0': if int(treat[0])!=0: MeasRec["treat_ac_field"]='%8.3e' % (float(treat[0])*1e-3) # AF field in tesla MeasRec["treat_dc_field"]='0' meas_type="LT-AF-Z" # first AF else: meas_type="LT-NO" MeasRec["treat_ac_field"]='0' MeasRec["treat_dc_field"]='0' elif treat[1][1]=='1': if int(treat[0])==0: MeasRec["treat_ac_field"]='%8.3e' %(peakfield) # peak field in tesla MeasRec["treat_dc_field"]='%8.3e'%(arm_labfield) MeasRec["treat_dc_field_phi"]='%7.1f'%(phi) MeasRec["treat_dc_field_theta"]='%7.1f'%(theta) meas_type="LT-AF-I" else: MeasRec["treat_ac_field"]='%8.3e' % ( float(treat[0])*1e-3) # AF field in tesla MeasRec["treat_dc_field"]='0' meas_type="LT-AF-Z" elif treat[1][1]=='2': if int(treat[0])==0: MeasRec["treat_ac_field"]='0' MeasRec["treat_dc_field"]='%8.3e'%(trm_labfield) MeasRec["treat_dc_field_phi"]='%7.1f'%(phi) MeasRec["treat_dc_field_theta"]='%7.1f'%(theta) MeasRec["treat_temp"]='%8.3e' % (trm_peakT) meas_type="LT-T-I" else: MeasRec["treat_ac_field"]='%8.3e' % ( float(treat[0])*1e-3) # AF field in tesla MeasRec["treat_dc_field"]='0' meas_type="LT-AF-Z" elif treat[1][1]=='3': if int(treat[0])==0: MeasRec["treat_ac_field"]='%8.3e' %(peakfield) # peak field in tesla MeasRec["treat_dc_field"]='%8.3e'%(arm_labfield) MeasRec["treat_dc_field_phi"]='%7.1f'%(phi) MeasRec["treat_dc_field_theta"]='%7.1f'%(theta) meas_type="LT-AF-I" else: MeasRec["treat_ac_field"]='%8.3e' % ( float(treat[0])*1e-3) # AF field in tesla MeasRec["treat_dc_field"]='0' meas_type="LT-AF-Z" # Cooling rate experient # added by rshaar elif demag=="T" and methcode == "LP-CR-TRM": MeasRec["treat_temp"]='%8.3e' % (float(treat[0])+273.) # temp in kelvin if treat[1][0]=='0': meas_type="LT-T-Z:LP-CR-TRM" MeasRec["treat_dc_field"]='%8.3e'%(0) MeasRec["treat_dc_field_phi"]='0' MeasRec["treat_dc_field_theta"]='0' else: MeasRec["treat_dc_field"]='%8.3e'%(labfield) if treat[1][0]=='7': # alteration check as final measurement meas_type="LT-PTRM-I:LP-CR-TRM" else: meas_type="LT-T-I:LP-CR-TRM" MeasRec["treat_dc_field_phi"]='%7.1f' % (phi) # labfield phi MeasRec["treat_dc_field_theta"]='%7.1f' % (theta) # labfield theta indx=int(treat[1][0])-1 # alteration check matjed as 0.7 in the measurement file if indx==6: cooling_time= cooling_rates_list[-1] else: cooling_time=cooling_rates_list[indx] MeasRec["description"]="cooling_rate"+":"+cooling_time+":"+"K/min" noave=1 elif demag!='N': if len(treat)==1:treat.append('0') MeasRec["treat_temp"]='%8.3e' % (float(treat[0])+273.) # temp in kelvin if trm==0: # demag=T and not trmaq if treat[1][0]=='0': meas_type="LT-T-Z" else: MeasRec["treat_dc_field"]='%8.3e' % (labfield) # labfield in tesla (convert from microT) MeasRec["treat_dc_field_phi"]='%7.1f' % (phi) # labfield phi MeasRec["treat_dc_field_theta"]='%7.1f' % (theta) # labfield theta if treat[1][0]=='1':meas_type="LT-T-I" # in-field thermal step if treat[1][0]=='2': meas_type="LT-PTRM-I" # pTRM check pTRM=1 if treat[1][0]=='3': MeasRec["treat_dc_field"]='0' # this is a zero field step meas_type="LT-PTRM-MD" # pTRM tail check else: labfield=float(treat[1])*1e-6 MeasRec["treat_dc_field"]='%8.3e' % (labfield) # labfield in tesla (convert from microT) MeasRec["treat_dc_field_phi"]='%7.1f' % (phi) # labfield phi MeasRec["treat_dc_field_theta"]='%7.1f' % (theta) # labfield theta meas_type="LT-T-I:LP-TRM" # trm acquisition experiment MeasRec["dir_csd"]=rec[2] MeasRec["magn_moment"]='%10.3e'% (float(rec[3])*1e-3) # moment in Am^2 (from emu) MeasRec["dir_dec"]=rec[4] MeasRec["dir_inc"]=rec[5] MeasRec["instrument_codes"]=instcode MeasRec["analysts"]=user MeasRec["citations"]=citations if "LP-IRM-3D" in methcode : meas_type=methcode #MeasRec["method_codes"]=methcode.strip(':') MeasRec["method_codes"]=meas_type MeasRec["quality"]='g' if 'std' in rec[0]: MeasRec["standard"]='s' else: MeasRec["standard"]='u' MeasRec["treat_step_num"]='1' #print MeasRec['treat_temp'] MeasRecs.append(MeasRec) con = nb.Contribution(output_dir_path,read_tables=[]) # create MagIC tables con.add_magic_table_from_data(dtype='specimens', data=SpecRecs) con.add_magic_table_from_data(dtype='samples', data=SampRecs) con.add_magic_table_from_data(dtype='sites', data=SiteRecs) con.add_magic_table_from_data(dtype='locations', data=LocRecs) MeasOuts=pmag.measurements_methods3(MeasRecs,noave) con.add_magic_table_from_data(dtype='measurements', data=MeasOuts) # write MagIC tables to file con.tables['specimens'].write_magic_file(custom_name=spec_file) con.tables['samples'].write_magic_file(custom_name=samp_file) con.tables['sites'].write_magic_file(custom_name=site_file) con.tables['locations'].write_magic_file(custom_name=loc_file) meas_file = con.tables['measurements'].write_magic_file(custom_name=meas_file) return True, meas_file
def main(): """ NAME revtest_magic.py DESCRIPTION calculates bootstrap statistics to test for antipodality INPUT FORMAT takes dec/inc data from sites table SYNTAX revtest_magic.py [command line options] OPTION -h prints help message and quits -f FILE, sets pmag_sites filename on command line -crd [s,g,t], set coordinate system, default is geographic -exc use criteria file to set acceptance criteria (only available for data model 3) -fmt [svg,png,jpg], sets format for image output -sav saves plot and quits -DM [2, 3] MagIC data model num, default is 3 """ if '-h' in sys.argv: # check if help is needed print(main.__doc__) sys.exit() # graceful quit dir_path = pmag.get_named_arg("-WD", ".") coord = pmag.get_named_arg("-crd", "0") # default to geographic coordinates if coord == 's': coord = '-1' elif coord == 'g': coord = '0' elif coord == 't': coord = '100' fmt = pmag.get_named_arg("-fmt", "svg") if '-sav' in sys.argv: plot = 1 data_model = int(float(pmag.get_named_arg("-DM"))) if data_model == 2: infile = pmag.get_named_arg("-f", "pmag_sites.txt") critfile = "pmag_criteria.txt" tilt_corr_col = 'site_tilt_correction' dec_col = "site_dec" inc_col = "site_inc" crit_code_col = "pmag_criteria_code" else: infile = pmag.get_named_arg("-f", "sites.txt") critfile = "criteria.txt" tilt_corr_col = "dir_tilt_correction" dec_col = "dir_dec" inc_col = "dir_inc" crit_code_col = "criterion" D = [] # infile = pmag.resolve_file_name(infile, dir_path) dir_path = os.path.split(infile)[0] critfile = pmag.resolve_file_name(critfile, dir_path) # if data_model == 2: Accept = ['site_k', 'site_alpha95', 'site_n', 'site_n_lines'] else: Accept = [ 'dir_k', 'dir_alpha95', 'dir_n_samples', 'dir_n_specimens_line' ] data, file_type = pmag.magic_read(infile) if 'sites' not in file_type: print("Error opening file", file_type) sys.exit() # ordata,file_type=pmag.magic_read(orfile) SiteCrits = [] if '-exc' in sys.argv and data_model != 2: crits, file_type = pmag.magic_read(critfile) for crit in crits: if crit[crit_code_col] == "DE-SITE": SiteCrit = crit SiteCrits.append(SiteCrit) elif '-exc' in sys.argv and data_model == 2: print( '-W- You have selected the -exc option, which is not available with MagIC data model 2.' ) for rec in data: if rec[tilt_corr_col] == coord: Dec = float(rec[dec_col]) Inc = float(rec[inc_col]) if '-exc' in sys.argv and data_model != 2: fail = False for SiteCrit in SiteCrits: for key in Accept: if key not in SiteCrit['table_column']: continue if key not in rec: continue if SiteCrit['criterion_value'] != "": op = OPS[SiteCrit['criterion_operation']] if not op(float(rec[key]), float(SiteCrit['criterion_value'])): fail = True if not fail: D.append([Dec, Inc, 1.]) else: D.append([Dec, Inc, 1.]) # set up plots CDF = {'X': 1, 'Y': 2, 'Z': 3} pmagplotlib.plot_init(CDF['X'], 5, 5) pmagplotlib.plot_init(CDF['Y'], 5, 5) pmagplotlib.plot_init(CDF['Z'], 5, 5) # # flip reverse mode # D1, D2 = pmag.flip(D) counter, NumSims = 0, 500 # # get bootstrapped means for each data set # if len(D1) < 5 or len(D2) < 5: print('not enough data in two different modes for reversals test') sys.exit() print('doing first mode, be patient') BDI1 = pmag.di_boot(D1) print('doing second mode, be patient') BDI2 = pmag.di_boot(D2) pmagplotlib.plot_com(CDF, BDI1, BDI2, [""]) files = {} for key in list(CDF.keys()): files[key] = 'REV' + '_' + key + '.' + fmt if plot == 0: pmagplotlib.draw_figs(CDF) ans = input("s[a]ve plots, [q]uit: ") if ans == 'a': pmagplotlib.save_plots(CDF, files) else: pmagplotlib.save_plots(CDF, files) sys.exit()
def main(): """ NAME mini_magic.py DESCRIPTION converts the Yale minispin format to magic_measurements format files SYNTAX mini_magic.py [command line options] OPTIONS -h: prints the help message and quits. -usr USER: identify user, default is "" -f FILE: specify input file, required -F FILE: specify output file, default is magic_measurements.txt -LP [colon delimited list of protocols, include all that apply] AF: af demag T: thermal including thellier but not trm acquisition -A: don't average replicate measurements -vol: volume assumed for measurement in cm^3 (default 12 cc) -DM NUM: MagIC data model (2 or 3, default 3) INPUT Must put separate experiments (all AF, thermal, etc.) in seperate files Format of Yale MINI files: LL-SI-SP_STEP, Declination, Inclination, Intensity (mA/m), X,Y,Z """ args = sys.argv if "-h" in args: print(main.__doc__) sys.exit() # initialize some stuff methcode = "LP-NO" demag = "N" # # get command line arguments # data_model_num = int(float(pmag.get_named_arg("-DM", 3))) user = pmag.get_named_arg("-usr", "") dir_path = pmag.get_named_arg("-WD", ".") inst = pmag.get_named_arg("-inst", "") magfile = pmag.get_named_arg("-f", reqd=True) magfile = pmag.resolve_file_name(magfile, dir_path) if "-A" in args: noave = 1 else: noave = 0 if data_model_num == 2: meas_file = pmag.get_named_arg("-F", "magic_measurements.txt") else: meas_file = pmag.get_named_arg("-F", "measurements.txt") meas_file = pmag.resolve_file_name(meas_file, dir_path) volume = pmag.get_named_arg("-vol", 12) # assume a volume of 12 cc if not provided methcode = pmag.get_named_arg("-LP", "LP-NO") #ind = args.index("-LP") #codelist = args[ind+1] #codes = codelist.split(':') #if "AF" in codes: # demag = 'AF' # methcode = "LT-AF-Z" #if "T" in codes: # demag = "T" convert.mini(magfile, dir_path, meas_file, data_model_num, volume, noave, inst, user, methcode)
def main(): """ NAME lnp_magic.py DESCRIPTION makes equal area projections site by site from specimen formatted file with Fisher confidence ellipse using McFadden and McElhinny (1988) technique for combining lines and planes SYNTAX lnp_magic [command line options] INPUT takes magic formatted specimens file OUPUT prints site_name n_lines n_planes K alpha95 dec inc R OPTIONS -h prints help message and quits -f FILE: specify input file, default is 'specimens.txt', ('pmag_specimens.txt' for legacy data model 2) -fsa FILE: specify samples file, required to plot by site for data model 3 (otherwise will plot by sample) default is 'samples.txt' -crd [s,g,t]: specify coordinate system, [s]pecimen, [g]eographic, [t]ilt adjusted default is specimen -fmt [svg,png,jpg] format for plots, default is svg -sav save plots and quit -P: do not plot -F FILE, specify output file of dec, inc, alpha95 data for plotting with plotdi_a and plotdi_e -exc use criteria in criteria table # NOT IMPLEMENTED -DM NUMBER MagIC data model (2 or 3, default 3) """ if '-h' in sys.argv: print(main.__doc__) sys.exit() dir_path = pmag.get_named_arg("-WD", ".") data_model = int(float(pmag.get_named_arg("-DM", 3))) fmt = pmag.get_named_arg("-fmt", 'svg') if data_model == 2: in_file = pmag.get_named_arg('-f', 'pmag_specimens.txt') crit_file = "pmag_criteria.txt" else: in_file = pmag.get_named_arg('-f', 'specimens.txt') samp_file = pmag.get_named_arg('-fsa', 'samples.txt') crit_file = "criteria.txt" in_file = pmag.resolve_file_name(in_file, dir_path) dir_path = os.path.split(in_file)[0] if data_model == 3: samp_file = pmag.resolve_file_name(samp_file, dir_path) if '-crd' in sys.argv: ind = sys.argv.index("-crd") crd = sys.argv[ind + 1] if crd == 's': coord = "-1" if crd == 'g': coord = "0" if crd == 't': coord = "100" else: coord = "-1" out_file = pmag.get_named_arg('-F', '') if out_file: out = open(dir_path + '/' + out_file, 'w') if '-P' in sys.argv: make_plots = 0 # do not plot else: make_plots = 1 # do plot if '-sav' in sys.argv: plot = 1 # save plots and quit else: plot = 0 # show plots intereactively (if make_plots) # if data_model == 2: Specs, file_type = pmag.magic_read(in_file) if 'specimens' not in file_type: print('Error opening ', in_file, file_type) sys.exit() else: fnames = {'specimens': in_file, 'samples': samp_file} con = cb.Contribution(dir_path, read_tables=['samples', 'specimens'], custom_filenames=fnames) con.propagate_name_down('site', 'specimens') if 'site' in con.tables['specimens'].df.columns: site_col = 'site' else: site_col = 'sample' tilt_corr_col = "dir_tilt_correction" mad_col = "dir_mad_free" alpha95_col = "dir_alpha95" site_alpha95_col = "dir_alpha95" dec_col = "dir_dec" inc_col = "dir_inc" num_meas_col = "dir_n_measurements" k_col = "dir_k" cols = [ site_col, tilt_corr_col, mad_col, alpha95_col, dec_col, inc_col ] con.tables['specimens'].front_and_backfill(cols) con.tables['specimens'].df = con.tables['specimens'].df.where( con.tables['specimens'].df.notnull(), "") Specs = con.tables['specimens'].convert_to_pmag_data_list() ## using criteria file was never fully implemented #if '-exc' in sys.argv: # Crits, file_type = pmag.magic_read(pmag.resolve_file_name(crit_file, dir_path)) # for crit in Crits: # if mad_col in crit: # M = float(crit['specimen_mad']) # if num_meas_col in crit: # N = float(crit['specimen_n']) # if site_alpha95_col in crit and 'site' in crit: # acutoff = float(crit['site_alpha95']) # if k_col in crit: # kcutoff = float(crit['site_k']) #else: # Crits = "" sitelist = [] # initialize some variables FIG = {} # plot dictionary FIG['eqarea'] = 1 # eqarea is figure 1 M, N, acutoff, kcutoff = 180., 1, 180., 0. if data_model == 2: site_col = 'er_site_name' tilt_corr_col = "specimen_tilt_correction" mad_col = "specimen_mad" alpha95_col = 'specimen_alpha95' dec_col = "specimen_dec" inc_col = "specimen_inc" num_meas_col = "specimen_n" site_alpha95_col = "site_alpha95" else: # data model 3 pass for rec in Specs: if rec[site_col] not in sitelist: sitelist.append(rec[site_col]) sitelist.sort() if make_plots == 1: EQ = {} EQ['eqarea'] = 1 for site in sitelist: pmagplotlib.plot_init(EQ['eqarea'], 4, 4) print(site) data = [] for spec in Specs: if tilt_corr_col not in list(spec.keys()): spec[tilt_corr_col] = '-1' # assume unoriented if spec[site_col] == site: if mad_col not in list(spec.keys()) or spec[mad_col] == "": if alpha95_col in list( spec.keys()) and spec[alpha95_col] != "": spec[mad_col] = spec[alpha95_col] else: spec[mad_col] = '180' if not spec[num_meas_col]: continue if (float(spec[tilt_corr_col]) == float(coord)) and (float(spec[mad_col]) <= M) and ( float(spec[num_meas_col]) >= N): rec = {} for key in list(spec.keys()): rec[key] = spec[key] rec["dec"] = float(spec[dec_col]) rec["inc"] = float(spec[inc_col]) rec["tilt_correction"] = spec[tilt_corr_col] data.append(rec) if len(data) > 2: fpars = pmag.dolnp(data, 'specimen_direction_type') print("Site lines planes kappa a95 dec inc") print(site, fpars["n_lines"], fpars["n_planes"], fpars["K"], fpars["alpha95"], fpars["dec"], fpars["inc"], fpars["R"]) if out_file != "": if float(fpars["alpha95"]) <= acutoff and float( fpars["K"]) >= kcutoff: out.write('%s %s %s\n' % (fpars["dec"], fpars['inc'], fpars['alpha95'])) print('% tilt correction: ', coord) if make_plots == 1: files = {} files['eqarea'] = site + '_' + crd + '_' + 'eqarea' + '.' + fmt pmagplotlib.plot_lnp(EQ['eqarea'], site, data, fpars, 'specimen_direction_type') if plot == 0: pmagplotlib.draw_figs(EQ) ans = input( "s[a]ve plot, [q]uit, <return> to continue:\n ") if ans == "a": pmagplotlib.save_plots(EQ, files) if ans == "q": sys.exit() else: pmagplotlib.save_plots(EQ, files) else: print( 'skipping site - not enough data with specified coordinate system' )
def main(): """ NAME eqarea_magic.py DESCRIPTION makes equal area projections from declination/inclination data SYNTAX eqarea_magic.py [command line options] INPUT takes magic formatted sites, samples, specimens, or measurements OPTIONS -h prints help message and quits -f FILE: specify input magic format file from magic, default='sites.txt' supported types=[measurements, specimens, samples, sites] -fsp FILE: specify specimen file name, (required if you want to plot measurements by sample) default='specimens.txt' -fsa FILE: specify sample file name, (required if you want to plot specimens by site) default='samples.txt' -fsi FILE: specify site file name, default='sites.txt' -flo FILE: specify location file name, default='locations.txt' -obj OBJ: specify level of plot [all, sit, sam, spc], default is all -crd [s,g,t]: specify coordinate system, [s]pecimen, [g]eographic, [t]ilt adjusted default is geographic, unspecified assumed geographic -fmt [svg,png,jpg] format for output plots -ell [F,K,B,Be,Bv] plot Fisher, Kent, Bingham, Bootstrap ellipses or Boostrap eigenvectors -c plot as colour contour -cm CM use color map CM [default is coolwarm] -sav save plot and quit quietly -no-tilt data are unoriented, allows plotting of measurement dec/inc NOTE all: entire file; sit: site; sam: sample; spc: specimen """ # extract arguments from sys.argv if '-h' in sys.argv: print(main.__doc__) sys.exit() dir_path = pmag.get_named_arg("-WD", default_val=".") input_dir_path = pmag.get_named_arg('-ID', '') if not input_dir_path: input_dir_path = dir_path in_file = pmag.get_named_arg("-f", default_val="sites.txt") in_file = pmag.resolve_file_name(in_file, input_dir_path) if "-ID" not in sys.argv: input_dir_path = os.path.split(in_file)[0] plot_by = pmag.get_named_arg("-obj", default_val="all").lower() spec_file = pmag.get_named_arg("-fsp", default_val="specimens.txt") samp_file = pmag.get_named_arg("-fsa", default_val="samples.txt") site_file = pmag.get_named_arg("-fsi", default_val="sites.txt") loc_file = pmag.get_named_arg("-flo", default_val="locations.txt") ignore_tilt = False if '-no-tilt' in sys.argv: ignore_tilt = True color_map = "coolwarm" if '-c' in sys.argv: contour = True if '-cm' in sys.argv: ind = sys.argv.index('-cm') color_map = sys.argv[ind+1] else: color_map = 'coolwarm' else: contour = False interactive = True save_plots = False if '-sav' in sys.argv: save_plots = True interactive = False plot_ell = False if '-ell' in sys.argv: plot_ell = pmag.get_named_arg("-ell", "F") crd = pmag.get_named_arg("-crd", default_val="g") fmt = pmag.get_named_arg("-fmt", "svg") ipmag.eqarea_magic(in_file, dir_path, input_dir_path, spec_file, samp_file, site_file, loc_file, plot_by, crd, ignore_tilt, save_plots, fmt, contour, color_map, plot_ell, "all", interactive)
def main(): """ NAME strip_magic.py DESCRIPTION plots various parameters versus depth or age SYNTAX strip_magic.py [command line optins] OPTIONS -h prints help message and quits -DM NUM: specify data model num, options 2 (legacy) or 3 (default) -f FILE: specify input magic format file from magic,default='pmag_results.txt' supported types=[pmag_specimens, pmag_samples, pmag_sites, pmag_results, magic_web] -obj [sit,sam,all]: specify object to site,sample,all for pmag_result table, default is all -fmt [svg,png,jpg], format for images - default is svg -x [age,pos]: specify whether age or stratigraphic position -y [dec,inc,int,chi,lat,lon,vdm,vadm] (lat and lon are VGP lat and lon) -Iex: plot the expected inc at lat - only available for results with lat info in file -ts TS amin amax: plot the GPTS for the time interval between amin and amax (numbers in Ma) TS: [ck95, gts04] -mcd method_code, specify method code, default is first one encountered -sav save plot and quit NOTES when x and/or y are not specified, a list of possibilities will be presented to the user for choosing """ if '-h' in sys.argv: print(main.__doc__) sys.exit() xaxis, xplotind, yplotind = "", 0, 0 # (0 for strat pos) yaxis, Xinc = "", "" plot = 0 obj = 'all' data_model_num = int(pmag.get_named_arg("-DM", 3)) # 2.5 keys if data_model_num == 2: supported = ['pmag_specimens', 'pmag_samples', 'pmag_sites', 'pmag_results', 'magic_web'] # available file types Depth_keys = ['specimen_core_depth', 'specimen_height', 'specimen_elevation', 'specimen_composite_depth', 'sample_core_depth', 'sample_height', 'sample_elevation', 'sample_composite_depth', 'site_core_depth', 'site_height', 'site_elevation', 'site_composite_depth', 'average_height'] Age_keys = ['specimen_inferred_age', 'sample_inferred_age', 'site_inferred_age', 'average_age'] Unit_keys = {'specimen_inferred_age': 'specimen_inferred_age_unit', 'sample_inferred_age': 'sample_inferred_age_unit', 'site_inferred_age': 'site_inferred_age_unit', 'average_age': 'average_age_unit'} Dec_keys = ['measurement_dec', 'specimen_dec', 'sample_dec', 'site_dec', 'average_dec'] Inc_keys = ['measurement_inc', 'specimen_inc', 'sample_inc', 'site_inc', 'average_inc'] Int_keys = ['measurement_magnitude', 'measurement_magn_moment', 'measurement_magn_volume', 'measurement_magn_mass', 'specimen_int', 'specimen_int_rel', 'sample_int', 'sample_int_rel', 'site_int', 'site_int_rel', 'average_int', 'average_int_rel'] Chi_keys = ['measurement_chi_volume', 'measurement_chi_mass'] Lat_keys = ['sample_lat', 'site_lat', 'average_lat'] VLat_keys = ['vgp_lat'] VLon_keys = ['vgp_lon'] Vdm_keys = ['vdm'] Vadm_keys = ['vadm'] method_col_name = "magic_method_codes" else: # 3.0 keys supported = ["specimens", "samples", "sites", "locations"] # available file types Depth_keys = [ "height", "core_depth", "elevation", "composite_depth" ] Age_keys = [ "age" ] Unit_keys = { "age": "age" } Chi_keys = [ "susc_chi_volume", "susc_chi_mass" ] Int_keys = [ "magn_moment", "magn_volume", "magn_mass", "int_abs", "int_rel" ] Inc_keys = [ "dir_inc" ] Dec_keys = [ "dir_dec" ] Lat_Keys = [ "lat" ] VLat_keys = [ "vgp_lat", "pole_lat" ] VLon_keys = [ "vgp_lon", "pole_lon" ] Vdm_keys = [ "vdm", "pdm" ] Vadm_keys = [ "vadm", "padm" ] method_col_name = "method_codes" # X_keys = [Age_keys, Depth_keys] Y_keys = [Dec_keys, Inc_keys, Int_keys, Chi_keys, VLat_keys, VLon_keys, Vdm_keys, Vadm_keys] method, fmt = "", 'svg' FIG = {'strat': 1} plotexp, pTS = 0, 0 dir_path = pmag.get_named_arg("-WD", ".") # default files if data_model_num == 3: res_file = pmag.get_named_arg("-f", "sites.txt") else: res_file = pmag.get_named_arg("-f", "pmag_results.txt") res_file = pmag.resolve_file_name(res_file, dir_path) if '-fmt' in sys.argv: ind = sys.argv.index('-fmt') fmt = sys.argv[ind+1] if '-obj' in sys.argv: ind = sys.argv.index('-obj') obj = sys.argv[ind+1] if '-x' in sys.argv: ind = sys.argv.index('-x') xaxis = sys.argv[ind+1] if '-y' in sys.argv: ind = sys.argv.index('-y') yaxis = sys.argv[ind+1] if yaxis == 'dec': ykeys = Dec_keys if yaxis == 'inc': ykeys = Inc_keys if yaxis == 'int': ykeys = Int_keys if yaxis == 'chi': ykeys = Chi_keys if yaxis == 'lat': ykeys = VLat_keys if yaxis == 'lon': ykeys = VLon_keys if yaxis == 'vdm': ykeys = Vdm_keys if yaxis == 'vadm': ykeys = Vadm_keys if '-mcd' in sys.argv: ind = sys.argv.index('-mcd') method = sys.argv[ind+1] if '-ts' in sys.argv: ind = sys.argv.index('-ts') ts = sys.argv[ind+1] amin = float(sys.argv[ind+2]) amax = float(sys.argv[ind+3]) pTS = 1 if '-Iex' in sys.argv: plotexp = 1 if '-sav' in sys.argv: plot = 1 # # # get data read in Results, file_type = pmag.magic_read(res_file) if file_type not in supported: print("Unsupported file type ({}), try again".format(file_type)) sys.exit() PltObjs = ['all'] if data_model_num == 2: if file_type == 'pmag_results': # find out what to plot for rec in Results: resname = rec['pmag_result_name'].split() if 'Sample' in resname and 'sam' not in PltObjs: PltObjs.append('sam') if 'Site' in resname and 'sit' not in PltObjs: PltObjs.append('sit') methcodes = [] # need to know all the measurement types from method_codes if "magic_method_codes" in list(Results[0].keys()): for rec in Results: meths = rec["magic_method_codes"].split(":") for meth in meths: if meth.strip() not in methcodes and 'LP' in meth: # look for the lab treatments methcodes.append(meth.strip()) # # initialize some variables X_unit = "" # Unit for age or depth plotting (meters if depth) Xplots, Yplots = [], [] Xunits = [] yplotind, xplotind = 0, 0 # # step through possible plottable keys # if xaxis == "" or yaxis == "": for key in list(Results[0].keys()): for keys in X_keys: for xkeys in keys: if key in xkeys: for ResRec in Results: if ResRec[key] != "": # only plot something if there is something to plot! Xplots.append(key) break for keys in Y_keys: for pkeys in keys: if key in pkeys: for ResRec in Results: if ResRec[key] != "": Yplots.append(key) break X, Y = [], [] for plt in Xplots: if plt in Age_keys and 'age' not in X: X.append('age') if plt in Depth_keys and 'pos' not in X: X.append('pos') for plt in Yplots: if plt in Dec_keys and 'dec' not in Y: Y.append('dec') if plt in Inc_keys and 'inc' not in Y: Y.append('inc') if plt in Int_keys and 'int' not in Y: Y.append('int') if plt in Chi_keys and 'chi' not in Y: Y.append('chi') if plt in VLat_keys and 'lat' not in Y: Y.append('lat') if plt in VLon_keys and 'lon' not in Y: Y.append('lon') if plt in Vadm_keys and 'vadm' not in Y: Y.append('vadm') if plt in Vdm_keys and 'vdm' not in Y: Y.append('vdm') if file_type == 'pmag_results': print('available objects for plotting: ', PltObjs) print('available X plots: ', X) print('available Y plots: ', Y) print('available method codes: ', methcodes) f = open(dir_path+'/.striprc', 'w') for x in X: f.write('x:'+x+'\n') for y in Y: f.write('y:'+y+'\n') for m in methcodes: f.write('m:'+m+'\n') for obj in PltObjs: f.write('obj:'+obj+'\n') sys.exit() if plotexp == 1: for lkey in Lat_keys: for key in list(Results[0].keys()): if key == lkey: lat = float(Results[0][lkey]) Xinc = [pmag.pinc(lat), -pmag.pinc(lat)] break if Xinc == "": print('can not plot expected inc for site - lat unknown') if method != "" and method not in methcodes: print('your method not available, but these are: ') print(methcodes) print('use ', methcodes[0], '? ^D to quit') if xaxis == 'age': for akey in Age_keys: for key in list(Results[0].keys()): if key == akey: Xplots.append(key) Xunits.append(Unit_keys[key]) if xaxis == 'pos': for dkey in Depth_keys: for key in list(Results[0].keys()): if key == dkey: Xplots.append(key) if len(Xplots) == 0: print('desired X axis information not found') sys.exit() if xaxis == 'age': age_unit = Results[0][Xunits[0]] if len(Xplots) > 1: print('multiple X axis keys found, using: ', Xplots[xplotind]) for ykey in ykeys: for key in list(Results[0].keys()): if key == ykey: Yplots.append(key) if len(Yplots) == 0: print('desired Y axis information not found') sys.exit() if len(Yplots) > 1: print('multiple Y axis keys found, using: ', Yplots[yplotind]) # check if age or depth info if len(Xplots) == 0: print("Must have either age or height info to plot ") sys.exit() # # check for variable to plot # # # determine X axis (age or depth) # if xaxis == "age": plotind = "1" if method == "": try: method = methcodes[0] except IndexError: method = "" if xaxis == 'pos': xlab = "Stratigraphic Height (meters)" else: xlab = "Age ("+age_unit+")" Xkey = Xplots[xplotind] Ykey = Yplots[yplotind] ylab = Ykey # # collect the data for plotting XY = [] isign = 1. # if float(Results[0][Xkey])/float(Results[-1][Xkey])>0 and float(Results[0][Xkey])<0: # isign=-1. # x axis all same sign and negative, take positive (e.g.,for depth in core) # xlab="Stratigraphic Position (meters)" # else: # isign=1. for rec in Results: if "magic_method_codes" in list(rec.keys()): meths = rec["magic_method_codes"].split(":") if method in meths: # make sure it is desired lab treatment step if obj == 'all' and rec[Xkey].strip() != "": XY.append([isign*float(rec[Xkey]), float(rec[Ykey])]) elif rec[Xkey].strip() != "": name = rec['pmag_result_name'].split() if obj == 'sit' and "Site" in name: XY.append([isign*float(rec[Xkey]), float(rec[Ykey])]) if obj == 'sam' and "Sample" in name: XY.append([isign*float(rec[Xkey]), float(rec[Ykey])]) elif method == "": if obj == 'all' and rec[Xkey].strip() != "": XY.append([isign*float(rec[Xkey]), float(rec[Ykey])]) elif rec[Xkey].strip() != "": name = rec['pmag_result_name'].split() if obj == 'sit' and "Site" in name: XY.append([isign*float(rec[Xkey]), float(rec[Ykey])]) if obj == 'sam' and "Sample" in name: XY.append([isign*float(rec[Xkey]), float(rec[Ykey])]) else: print("Something wrong with your plotting choices") break XY.sort() title = "" if "er_locations_names" in list(Results[0].keys()): title = Results[0]["er_location_names"] if "er_locations_name" in list(Results[0].keys()): title = Results[0]["er_location_name"] labels = [xlab, ylab, title] pmagplotlib.plot_init(FIG['strat'], 10, 5) pmagplotlib.plot_strat(FIG['strat'], XY, labels) # plot them if plotexp == 1: pmagplotlib.plot_hs(FIG['strat'], Xinc, 'b', '--') if yaxis == 'inc' or yaxis == 'lat': pmagplotlib.plot_hs(FIG['strat'], [0], 'b', '-') pmagplotlib.plot_hs(FIG['strat'], [-90, 90], 'g', '-') if pTS == 1: FIG['ts'] = 2 pmagplotlib.plot_init(FIG['ts'], 10, 5) pmagplotlib.plot_ts(FIG['ts'], [amin, amax], ts) files = {} for key in list(FIG.keys()): files[key] = key+'.'+fmt if pmagplotlib.isServer: black = '#000000' purple = '#800080' files = {} files['strat'] = xaxis+'_'+yaxis+'_.'+fmt files['ts'] = 'ts.'+fmt titles = {} titles['strat'] = 'Depth/Time Series Plot' titles['ts'] = 'Time Series Plot' FIG = pmagplotlib.add_borders(FIG, titles, black, purple) pmagplotlib.save_plots(FIG, files) elif plot == 1: pmagplotlib.save_plots(FIG, files) else: pmagplotlib.draw_figs(FIG) ans = input(" S[a]ve to save plot, [q]uit without saving: ") if ans == "a": pmagplotlib.save_plots(FIG, files)
def main(): """ NAME lowrie_magic.py DESCRIPTION plots intensity decay curves for Lowrie experiments SYNTAX lowrie_magic.py -h [command line options] INPUT takes measurements formatted input files OPTIONS -h prints help message and quits -f FILE: specify input file, default is magic_measurements.txt -N do not normalize by maximum magnetization -fmt [svg, pdf, eps, png] specify fmt, default is svg -sav saves plots and quits -DM [2, 3] MagIC data model number """ if '-h' in sys.argv: print(main.__doc__) sys.exit() if len(sys.argv) <= 1: print(main.__doc__) print('you must supply a file name') sys.exit() FIG = {} # plot dictionary FIG['lowrie'] = 1 # demag is figure 1 pmagplotlib.plot_init(FIG['lowrie'], 6, 6) norm = 1 # default is to normalize by maximum axis in_file = pmag.get_named_arg("-f", "measurements.txt") dir_path = pmag.get_named_arg("-WD", ".") in_file = pmag.resolve_file_name(in_file, dir_path) data_model = pmag.get_named_arg("-DM", 3) data_model = int(float(data_model)) fmt = pmag.get_named_arg("-fmt", "svg") if '-N' in sys.argv: norm = 0 # don't normalize if '-sav' in sys.argv: plot = 1 # silently save and quit else: plot = 0 # generate plots print(in_file) # read in data PmagRecs, file_type = pmag.magic_read(in_file) if data_model == 2 and file_type != "magic_measurements": print('bad input file', file_type) sys.exit() if data_model == 3 and file_type != "measurements": print('bad input file', file_type) sys.exit() if data_model == 2: meth_code_col = 'magic_method_codes' spec_col = 'er_specimen_name' dec_col = "measurement_dec" inc_col = 'measurement_inc' moment_col = 'measurement_magn_moment' temp_col = 'treatment_temp' else: meth_code_col = 'method_codes' spec_col = 'specimen' dec_col = 'dir_dec' inc_col = 'dir_inc' moment_col = 'magn_moment' temp_col = "treat_temp" PmagRecs = pmag.get_dictitem( PmagRecs, meth_code_col, 'LP-IRM-3D', 'has') # get all 3D IRM records if len(PmagRecs) == 0: print('no records found with the method code LP-IRM-3D') sys.exit() specs = pmag.get_dictkey(PmagRecs, spec_col, '') sids = [] for spec in specs: if spec not in sids: sids.append(spec) # get list of unique specimen names for spc in sids: # step through the specimen names print(spc) specdata = pmag.get_dictitem( PmagRecs, spec_col, spc, 'T') # get all this one's data DIMs, Temps = [], [] for dat in specdata: # step through the data DIMs.append([float(dat[dec_col]), float( dat[inc_col]), float(dat[moment_col])]) Temps.append(float(dat[temp_col])-273.) carts = pmag.dir2cart(DIMs).transpose() if norm == 1: # want to normalize nrm = (DIMs[0][2]) # normalize by NRM ylab = "M/M_o" else: nrm = 1. # don't normalize ylab = "Magnetic moment (Am^2)" xlab = "Temperature (C)" pmagplotlib.plot_xy(FIG['lowrie'], Temps, abs(carts[0]) / nrm, sym='r-') pmagplotlib.plot_xy(FIG['lowrie'], Temps, abs(carts[0]) / nrm, sym='ro') # X direction pmagplotlib.plot_xy(FIG['lowrie'], Temps, abs(carts[1]) / nrm, sym='c-') pmagplotlib.plot_xy(FIG['lowrie'], Temps, abs(carts[1]) / nrm, sym='cs') # Y direction pmagplotlib.plot_xy(FIG['lowrie'], Temps, abs(carts[2]) / nrm, sym='k-') pmagplotlib.plot_xy(FIG['lowrie'], Temps, abs(carts[2]) / nrm, sym='k^', title=spc, xlab=xlab, ylab=ylab) # Z direction files = {'lowrie': 'lowrie:_'+spc+'_.'+fmt} if plot == 0: pmagplotlib.draw_figs(FIG) ans = input('S[a]ve figure? [q]uit, <return> to continue ') if ans == 'a': pmagplotlib.save_plots(FIG, files) elif ans == 'q': sys.exit() else: pmagplotlib.save_plots(FIG, files) pmagplotlib.clearFIG(FIG['lowrie'])
def convert(**kwargs): version_num = pmag.get_version() dir_path = kwargs.get('dir_path', '.') mag_file = kwargs.get('mag_file') input_dir_path = kwargs.get('input_dir_path', dir_path) if input_dir_path == dir_path: mag_file = pmag.resolve_file_name(mag_file, dir_path) input_dir_path = os.path.split(mag_file)[0] output_dir_path = dir_path user = kwargs.get('user', '') meas_file = kwargs.get('meas_file', 'measurements.txt') # outfile spec_file = kwargs.get('spec_file', 'specimens.txt') # specimen outfile samp_file = kwargs.get('samp_file', 'samples.txt') # sample outfile site_file = kwargs.get('site_file', 'sites.txt') # site outfile loc_file = kwargs.get('loc_file', 'locations.txt') # location outfile specnum = kwargs.get('specnum', 1) samp_con = kwargs.get('samp_con', '1') location = kwargs.get('location', 'unknown') lat = kwargs.get('lat', '') lon = kwargs.get('lon', '') noave = kwargs.get('noave', 0) # default (0) means DO average meth_code = kwargs.get('meth_code', "LP-NO") volume = float(kwargs.get('volume', 2.5)) * 1e-6 timezone = kwargs.get('timestamp', 'UTC') # format variables mag_file = os.path.join(input_dir_path, mag_file) if specnum != 0: specnum = -int(specnum) if samp_con.startswith("4"): if "-" not in samp_con: print("option [4] must be in form 4-Z where Z is an integer") return False, "naming convention option [4] must be in form 4-Z where Z is an integer" else: Z = samp_con.split("-")[1] samp_con = "4" elif samp_con.startswith("7"): if "-" not in samp_con: print("option [7] must be in form 7-Z where Z is an integer") return False, "naming convention option [7] must be in form 7-Z where Z is an integer" else: Z = samp_con.split("-")[1] samp_con = "7" else: Z = 1 #create data holders MeasRecs, SpecRecs, SampRecs, SiteRecs, LocRecs = [], [], [], [], [] data = pmag.open_file(mag_file) # remove garbage/blank lines data = [i for i in data if len(i) >= 5] if not len(data): print('No data') return n = 0 end = False # loop through records while not end: first_line = data[n].split() sampleName = first_line[0] demagLevel = first_line[2] date = first_line[3] + ":0:0:0" n += 2 third_line = data[n].split() if not third_line[0].startswith('SPEC.ANGLES'): print('third line of a block should start with SPEC.ANGLES') print(third_line) return specimenAngleDec = third_line[1] specimenAngleInc = third_line[2] n += 4 while not data[n].startswith('MEAN'): n += 1 mean_line = data[n] Mx = mean_line[1] My = mean_line[2] Mz = mean_line[3] n += 1 precision_line = data[n].split() if not precision_line[0].startswith('Modulus'): print('precision line should start with "Modulus"') return splitExp = precision_line[2].split('A') intensityVolStr = precision_line[1] + splitExp[0] intensityVol = float(intensityVolStr) # check and see if Prec is too big and messes with the parcing. precisionStr = '' if len(precision_line) == 6: #normal line precisionStr = precision_line[5][0:-1] else: precisionStr = precision_line[4][0:-1] precisionPer = float(precisionStr) precision = intensityVol * precisionPer / 100 while not data[n].startswith('SPEC.'): n += 1 specimen_line = data[n].split() specimenDec = specimen_line[2] specimenInc = specimen_line[3] n += 1 geographic_line = data[n] if not geographic_line.startswith('GEOGR'): geographic_dec = '' geographic_inc = '' else: geographic_line = geographic_line.split() geographicDec = geographic_line[1] geographicInc = geographic_line[2] # Add data to various MagIC data tables. specimen = sampleName if specnum != 0: sample = specimen[:specnum] else: sample = specimen site = pmag.parse_site(sample, samp_con, Z) MeasRec, SpecRec, SampRec, SiteRec, LocRec = {}, {}, {}, {}, {} if specimen != "" and specimen not in [ x['specimen'] if 'specimen' in list(x.keys()) else "" for x in SpecRecs ]: SpecRec['specimen'] = specimen SpecRec['sample'] = sample SpecRec["citations"] = "This study" SpecRec["analysts"] = user SpecRec['volume'] = volume SpecRecs.append(SpecRec) if sample != "" and sample not in [ x['sample'] if 'sample' in list(x.keys()) else "" for x in SampRecs ]: SampRec['sample'] = sample SampRec['site'] = site SampRec["citations"] = "This study" SampRec["analysts"] = user SampRec['azimuth'] = specimenAngleDec sample_dip = str(float(specimenAngleInc) - 90.0) #convert to magic orientation SampRec['dip'] = sample_dip SampRec['method_codes'] = meth_code SampRecs.append(SampRec) if site != "" and site not in [ x['site'] if 'site' in list(x.keys()) else "" for x in SiteRecs ]: SiteRec['site'] = site SiteRec['location'] = location SiteRec["citations"] = "This study" SiteRec["analysts"] = user SiteRec['lat'] = lat SiteRec['lon'] = lon SiteRecs.append(SiteRec) if location != "" and location not in [ x['location'] if 'location' in list(x.keys()) else "" for x in LocRecs ]: LocRec['location'] = location LocRec["citations"] = "This study" LocRec["analysts"] = user LocRec['lat_n'] = lat LocRec['lon_e'] = lon LocRec['lat_s'] = lat LocRec['lon_w'] = lon LocRecs.append(LocRec) local = pytz.timezone(timezone) naive = datetime.datetime.strptime(date, "%m-%d-%Y:%H:%M:%S") local_dt = local.localize(naive, is_dst=None) utc_dt = local_dt.astimezone(pytz.utc) timestamp = utc_dt.strftime("%Y-%m-%dT%H:%M:%S") + "Z" MeasRec["specimen"] = specimen MeasRec["timestamp"] = timestamp MeasRec['description'] = '' MeasRec["citations"] = "This study" MeasRec['software_packages'] = version_num MeasRec["treat_temp"] = '%8.3e' % (273) # room temp in kelvin MeasRec["meas_temp"] = '%8.3e' % (273) # room temp in kelvin MeasRec["quality"] = 'g' MeasRec["standard"] = 'u' MeasRec["treat_step_num"] = '1' MeasRec["treat_ac_field"] = '0' if demagLevel == 'NRM': meas_type = "LT-NO" elif demagLevel[0] == 'A': if demagLevel[:2] == 'AD': treat = float(demagLevel[2:]) else: treat = float(demagLevel[1:]) meas_type = "LT-AF-Z" MeasRec["treat_ac_field"] = '%8.3e' % ( treat * 1e-3) # convert from mT to tesla elif demagLevel[0] == 'T': meas_type = "LT-T-Z" treat = float(demagLevel[1:]) MeasRec["treat_temp"] = '%8.3e' % (treat + 273.) # temp in kelvin else: print("measurement type unknown", demagLevel) return False, "measurement type unknown" MeasRec["magn_moment"] = str(intensityVol * volume) # Am^2 MeasRec["magn_volume"] = intensityVolStr # A/m MeasRec["dir_dec"] = specimenDec MeasRec["dir_inc"] = specimenInc MeasRec['method_codes'] = meas_type MeasRecs.append(MeasRec) # ignore all the rest of the special characters. Some data files not consistantly formatted. n += 1 while ((len(data[n]) <= 5 and data[n] != '') or data[n].startswith('----')): n += 1 if n >= len(data): break if n >= len(data): # we're done! end = True #end of data while loop con = nb.Contribution(output_dir_path, read_tables=[]) con.add_magic_table_from_data(dtype='specimens', data=SpecRecs) con.add_magic_table_from_data(dtype='samples', data=SampRecs) con.add_magic_table_from_data(dtype='sites', data=SiteRecs) con.add_magic_table_from_data(dtype='locations', data=LocRecs) MeasOuts = pmag.measurements_methods3(MeasRecs, noave) con.add_magic_table_from_data(dtype='measurements', data=MeasOuts) con.tables['specimens'].write_magic_file(custom_name=spec_file) con.tables['samples'].write_magic_file(custom_name=samp_file) con.tables['sites'].write_magic_file(custom_name=site_file) con.tables['locations'].write_magic_file(custom_name=loc_file) con.tables['measurements'].write_magic_file(custom_name=meas_file) return True, meas_file
def main(): """ NAME chi_magic.py DESCRIPTION plots magnetic susceptibility as a function of frequency and temperature and AC field SYNTAX chi_magic.py [command line options] OPTIONS -h prints help message and quits -f FILE, specify measurements format file, default "measurements.txt" -T IND, specify temperature step to plot -e EXP, specify experiment name to plot -fmt [svg,jpg,png,pdf] set figure format [default is svg] -sav save figure and quit """ if "-h" in sys.argv: print(main.__doc__) return infile = pmag.get_named_arg("-f", "measurements.txt") dir_path = pmag.get_named_arg("-WD", ".") infile = pmag.resolve_file_name(infile, dir_path) fmt = pmag.get_named_arg("-fmt", "svg") show_plots = True if "-sav" in sys.argv: show_plots = False experiments = pmag.get_named_arg("-e", "") # read in data from data model 3 example file chi_data_all = pd.read_csv(infile, sep='\t', header=1) if not experiments: try: experiments = chi_data_all.experiment.unique() except Exception as ex: print(ex) experiments = ["all"] else: experiments = [experiments] plotnum = 0 figs = {} fnames = {} for exp in experiments: if exp == "all": chi_data = chi_data_all chi_data = chi_data_all[chi_data_all.experiment == exp] if len(chi_data) <= 1: print('Not enough data to plot {}'.format(exp)) continue plotnum += 1 pmagplotlib.plot_init(plotnum, 5, 5) # set up plot figs[str(plotnum)] = plotnum fnames[str(plotnum)] = exp + '_temperature.{}'.format(fmt) # get arrays of available temps, frequencies and fields Ts = np.sort(chi_data.meas_temp.unique()) Fs = np.sort(chi_data.meas_freq.unique()) Bs = np.sort(chi_data.meas_field_ac.unique()) # plot chi versus temperature at constant field b = Bs.max() for num, f in enumerate(Fs): this_f = chi_data[chi_data.meas_freq == f] this_f = this_f[this_f.meas_field_ac == b] plt.plot(this_f.meas_temp, 1e6 * this_f.susc_chi_volume, label='%i' % (f) + ' Hz') plt.legend() plt.xlabel('Temperature (K)') plt.ylabel('$\chi$ ($\mu$SI)') plt.title('B = ' + '%7.2e' % (b) + ' T') plotnum += 1 figs[str(plotnum)] = plotnum fnames[str(plotnum)] = exp + '_frequency.{}'.format(fmt) pmagplotlib.plot_init(plotnum, 5, 5) # set up plot ## plot chi versus frequency at constant B b = Bs.max() t = Ts.min() this_t = chi_data[chi_data.meas_temp == t] this_t = this_t[this_t.meas_field_ac == b] plt.semilogx(this_t.meas_freq, 1e6 * this_t.susc_chi_volume, label='%i' % (t) + ' K') plt.legend() plt.xlabel('Frequency (Hz)') plt.ylabel('$\chi$ ($\mu$SI)') plt.title('B = ' + '%7.2e' % (b) + ' T') if show_plots: pmagplotlib.draw_figs(figs) ans = input("enter s[a]ve to save files, [return] to quit ") if ans == 'a': pmagplotlib.save_plots(figs, fnames) sys.exit() else: sys.exit() else: pmagplotlib.save_plots(figs, fnames)
def main(): """ NAME mk_redo.py DESCRIPTION Makes thellier_redo and zeq_redo files from existing pmag_specimens format file SYNTAX mk_redo.py [-h] [command line options] INPUT takes specimens.txt formatted input file OPTIONS -h: prints help message and quits -f FILE: specify input file, default is 'specimens.txt' -F REDO: specify output file suffix, default is redo so that output filenames are 'thellier_redo' for thellier data and 'zeq_redo' for direction only data OUTPUT makes a thellier_redo or a zeq_redo format file """ if '-h' in sys.argv: print(main.__doc__) sys.exit() zfile, tfile = 'zeq_redo', 'thellier_redo' zredo, tredo = "", "" dir_path = pmag.get_named_arg('-WD', '.') inspec = pmag.get_named_arg('-f', 'specimens.txt') if '-F' in sys.argv: ind = sys.argv.index('-F') redo = sys.argv[ind + 1] tfile = redo zfile = redo inspec = pmag.resolve_file_name(inspec, dir_path) zfile = pmag.resolve_file_name(zfile, dir_path) tfile = pmag.resolve_file_name(tfile, dir_path) # # read in data # specs = [] prior_spec_data, file_type = pmag.magic_read(inspec) if file_type != 'specimens': print(file_type, " this is not a valid pmag_specimens file") sys.exit() outstrings = [] for spec in prior_spec_data: tmp = spec["method_codes"].split(":") meths = [] for meth in tmp: methods = meth.strip().split('-') for m in methods: if m not in meths: meths.append(m) if 'DIR' in meths: # DE-BFL, DE-BFP or DE-FM specs.append(spec['specimen']) if 'dir_comp' in list(spec.keys( )) and spec['dir_comp'] != "" and spec['dir_comp'] != " ": comp_name = spec['dir_comp'] else: comp_name = string.ascii_uppercase[ specs.count(spec['specimen']) - 1] calculation_type = "DE-BFL" # assume default calculation type is best-fit line if "BFP" in meths: calculation_type = 'DE-BFP' elif "FM" in meths: calculation_type = 'DE-FM' if zredo == "": zredo = open(zfile, "w") outstring = '%s %s %s %s %s \n' % ( spec["specimen"], calculation_type, spec["meas_step_min"], spec["meas_step_max"], comp_name) if outstring not in outstrings: zredo.write(outstring) outstrings.append(outstring) # only writes unique interpretions elif "PI" in meths and "TRM" in meths: # thellier record if tredo == "": tredo = open(tfile, "w") outstring = '%s %i %i \n' % (spec["specimen"], float(spec["meas_step_min"]), float(spec["meas_step_max"])) if outstring not in outstrings: tredo.write(outstring) outstrings.append(outstring) # only writes unique interpretions print('Redo files saved to: ', zfile, tfile)
def convert(**kwargs): # initialize defaults version_num=pmag.get_version() citations="This study" dir_path,demag='.','NRM' depth_method='a' dir_path = kwargs.get('dir_path', '.') input_dir_path = kwargs.get('input_dir_path', dir_path) output_dir_path = dir_path # rename dir_path after input_dir_path is set noave = kwargs.get('noave', 0) # default (0) is DO average csv_file = kwargs.get('csv_file', '') meas_file = kwargs.get('meas_file', 'measurements.txt') spec_file = kwargs.get('spec_file', 'specimens.txt') samp_file = kwargs.get('samp_file', 'samples.txt') site_file = kwargs.get('site_file', 'sites.txt') loc_file = kwargs.get('loc_file', 'locations.txt') lat = kwargs.get('lat', '') lon = kwargs.get('lon', '') # format variables if csv_file=="": filelist=os.listdir(input_dir_path) # read in list of files to import else: filelist=[csv_file] # parsing the data MeasRecs,SpecRecs,SampRecs,SiteRecs,LocRecs=[],[],[],[],[] file_found = False for f in filelist: # parse each file year_warning = True if f[-3:].lower()=='csv': print('processing:', f) file_found = True # get correct full filename and read data fname = pmag.resolve_file_name(f, input_dir_path) full_file = open(fname) file_input=full_file.readlines() full_file.close() keys=file_input[0].replace('\n','').split(',') # splits on underscores keys=[k.strip('"') for k in keys] if "Interval Top (cm) on SHLF" in keys:interval_key="Interval Top (cm) on SHLF" elif " Interval Bot (cm) on SECT" in keys:interval_key=" Interval Bot (cm) on SECT" elif "Offset (cm)" in keys: interval_key="Offset (cm)" else: print("couldn't find interval or offset amount") if "Top Depth (m)" in keys:depth_key="Top Depth (m)" elif "CSF-A Top (m)" in keys:depth_key="CSF-A Top (m)" elif "Depth CSF-A (m)" in keys:depth_key="Depth CSF-A (m)" else: print("couldn't find depth") if "CSF-B Top (m)" in keys: comp_depth_key="CSF-B Top (m)" # use this model if available elif "Depth CSF-B (m)" in keys: comp_depth_key="Depth CSF-B (m)" else: comp_depth_key=""; print("couldn't find composite depth") if "Demag level (mT)" in keys:demag_key="Demag level (mT)" elif "Demag Level (mT)" in keys: demag_key="Demag Level (mT)" elif "Treatment Value" in keys: demag_key="Treatment Value" else: print("couldn't find demag type") if "Inclination (Tray- and Bkgrd-Corrected) (deg)" in keys:inc_key="Inclination (Tray- and Bkgrd-Corrected) (deg)" elif "Inclination background + tray corrected (deg)" in keys:inc_key="Inclination background + tray corrected (deg)" elif "Inclination background + tray corrected (\xc2\xb0)" in keys:inc_key="Inclination background + tray corrected (\xc2\xb0)" elif "Inclination background & tray corrected (deg)" in keys:inc_key="Inclination background & tray corrected (deg)" elif "Inclination background & tray corrected (deg)" in keys:inc_key="Inclination background & tray corrected (deg)" elif "Inclination background & drift corrected (deg)" in keys:inc_key="Inclination background & drift corrected (deg)" else: print("couldn't find inclination") if "Declination (Tray- and Bkgrd-Corrected) (deg)" in keys:dec_key="Declination (Tray- and Bkgrd-Corrected) (deg)" elif "Declination background + tray corrected (deg)" in keys:dec_key="Declination background + tray corrected (deg)" elif "Declination background + tray corrected (\xc2\xb0)" in keys:dec_key="Declination background + tray corrected (\xc2\xb0)" elif "Declination background & tray corrected (deg)" in keys:dec_key="Declination background & tray corrected (deg)" elif "Declination background & tray corrected (deg)" in keys:dec_key="Declination background & tray corrected (deg)" elif "Declination background & drift corrected (deg)" in keys:dec_key="Declination background & drift corrected (deg)" else: print("couldn't find declination") if "Intensity (Tray- and Bkgrd-Corrected) (A/m)" in keys:int_key="Intensity (Tray- and Bkgrd-Corrected) (A/m)" elif "Intensity background + tray corrected (A/m)" in keys:int_key="Intensity background + tray corrected (A/m)" elif "Intensity background & tray corrected (A/m)" in keys:int_key="Intensity background & tray corrected (A/m)" elif "Intensity background & tray corrected (A/m)" in keys:int_key="Intensity background & tray corrected (A/m)" elif "Intensity background & drift corrected (A/m)" in keys:int_key="Intensity background & drift corrected (A/m)" else: print("couldn't find magnetic moment") if "Core Type" in keys: core_type="Core Type" elif "Type" in keys: core_type="Type" else: print("couldn't find core type") if 'Run Number' in keys: run_number_key='Run Number' elif 'Test No.' in keys: run_number_key='Test No.' else: print("couldn't find run number") if 'Test Changed On' in keys: date_key='Test Changed On' elif "Timestamp (UTC)" in keys: date_key="Timestamp (UTC)" else: print("couldn't find timestamp") if "Section" in keys: sect_key="Section" elif "Sect" in keys: sect_key="Sect" else: print("couldn't find section number") if 'Section Half' in keys: half_key='Section Half' elif "A/W" in keys: half_key="A/W" else: print("couldn't find half number") if "Text ID" in keys: text_id="Text ID" elif "Text Id" in keys: text_id="Text Id" else: print("couldn't find ID number") for line in file_input[1:]: InRec={} test=0 recs=line.split(',') for k in range(len(keys)): if len(recs)==len(keys): InRec[keys[k]]=line.split(',')[k].strip(""" " ' """) if 'Exp' in list(InRec.keys()) and InRec['Exp']!="": test=1 # get rid of pesky blank lines (why is this a thing?) if not test: continue run_number="" inst="IODP-SRM" volume='15.59' # set default volume to this if 'Sample Area (cm?)' in list(InRec.keys()) and InRec['Sample Area (cm?)']!= "": volume=InRec['Sample Area (cm?)'] MeasRec,SpecRec,SampRec,SiteRec,LocRec={},{},{},{},{} expedition=InRec['Exp'] location=InRec['Site']+InRec['Hole'] # Maintain backward compatibility for the ever-changing LIMS format (Argh!) while len(InRec['Core'])<3: InRec['Core']='0'+InRec['Core'] if "Last Tray Measurment" in list(InRec.keys()) and "SHLF" not in InRec[text_id] or 'dscr' in csv_file : # assume discrete sample specimen=expedition+'-'+location+'-'+InRec['Core']+InRec[core_type]+"-"+InRec[sect_key]+'-'+InRec[half_key]+'-'+str(InRec[interval_key]) else: # mark as continuous measurements specimen=expedition+'-'+location+'-'+InRec['Core']+InRec[core_type]+"_"+InRec[sect_key]+InRec[half_key]+'-'+str(InRec[interval_key]) sample = expedition+'-'+location+'-'+InRec['Core']+InRec[core_type] site = expedition+'-'+location if not InRec[dec_key] or not InRec[inc_key]: print("No dec or inc found for specimen %s, skipping"%specimen); continue if specimen!="" and specimen not in [x['specimen'] if 'specimen' in list(x.keys()) else "" for x in SpecRecs]: SpecRec['specimen'] = specimen SpecRec['sample'] = sample SpecRec['citations']=citations SpecRec['volume'] = volume SpecRec['specimen_alternatives']=InRec[text_id] SpecRecs.append(SpecRec) if sample!="" and sample not in [x['sample'] if 'sample' in list(x.keys()) else "" for x in SampRecs]: SampRec['sample'] = sample SampRec['site'] = site SampRec['citations']=citations SampRec['azimuth']='0' SampRec['dip']='0' SampRec['core_depth']=InRec[depth_key] if comp_depth_key!='': SampRec['composite_depth']=InRec[comp_depth_key] if "SHLF" not in InRec[text_id]: SampRec['method_codes']='FS-C-DRILL-IODP:SP-SS-C:SO-V' else: SampRec['method_codes']='FS-C-DRILL-IODP:SO-V' SampRecs.append(SampRec) if site!="" and site not in [x['site'] if 'site' in list(x.keys()) else "" for x in SiteRecs]: SiteRec['site'] = site SiteRec['location'] = location SiteRec['citations']=citations SiteRec['lat'] = lat SiteRec['lon'] = lon SiteRecs.append(SiteRec) if location!="" and location not in [x['location'] if 'location' in list(x.keys()) else "" for x in LocRecs]: LocRec['location']=location LocRec['citations']=citations LocRec['expedition_name']=expedition LocRec['lat_n'] = lat LocRec['lon_e'] = lon LocRec['lat_s'] = lat LocRec['lon_w'] = lon LocRecs.append(LocRec) MeasRec['specimen'] = specimen MeasRec['magic_software_packages']=version_num MeasRec["treat_temp"]='%8.3e' % (273) # room temp in kelvin MeasRec["meas_temp"]='%8.3e' % (273) # room temp in kelvin MeasRec["treat_ac_field"]=0 MeasRec["treat_dc_field"]='0' MeasRec["treat_dc_field_phi"]='0' MeasRec["treat_dc_field_theta"]='0' MeasRec["quality"]='g' # assume all data are "good" MeasRec["standard"]='u' # assume all data are "good" if run_number_key in list(InRec.keys()) and InRec[run_number_key]!= "": run_number=InRec[run_number_key] datestamp=InRec[date_key].split() # date time is second line of file if '/' in datestamp[0]: mmddyy=datestamp[0].split('/') # break into month day year if len(mmddyy[0])==1: mmddyy[0]='0'+mmddyy[0] # make 2 characters if len(mmddyy[1])==1: mmddyy[1]='0'+mmddyy[1] # make 2 characters if len(mmddyy[2])==1: mmddyy[2] = '0'+mmddyy[2] # make 2 characters if len(datestamp[1])==1: datestamp[1]='0'+datestamp[1] # make 2 characters hour, minute = datestamp[1].split(':') if len(hour) == 1: hour = '0' + hour date=mmddyy[0]+':'+mmddyy[1]+":"+mmddyy[2] +':' + hour + ":" + minute + ":00" #date=mmddyy[2] + ':'+mmddyy[0]+":"+mmddyy[1] +':' + hour + ":" + minute + ":00" if '-' in datestamp[0]: mmddyy=datestamp[0].split('-') # break into month day year date=mmddyy[0]+':'+mmddyy[1]+":"+mmddyy[2] +':' +datestamp[1]+":0" if len(date.split(":")) > 6: date=date[:-2] # try with month:day:year try: utc_dt = datetime.datetime.strptime(date, "%m:%d:%Y:%H:%M:%S") except ValueError: # try with year:month:day try: utc_dt = datetime.datetime.strptime(date, "%Y:%m:%d:%H:%M:%S") except ValueError: # if all else fails, assume the year is in the third position # and try padding with '20' new_date = pad_year(date, ind=2, warn=year_warning, fname=os.path.split(f)[1]) utc_dt = datetime.datetime.strptime(new_date, "%m:%d:%Y:%H:%M:%S") # only give warning once per csv file year_warning = False MeasRec['timestamp']=utc_dt.strftime("%Y-%m-%dT%H:%M:%S")+"Z" MeasRec["method_codes"]='LT-NO' if 'Treatment Type' in list(InRec.keys()) and InRec['Treatment Type']!="": if "AF" in InRec['Treatment Type'].upper(): MeasRec['method_codes'] = 'LT-AF-Z' inst=inst+':IODP-SRM-AF' # measured on shipboard in-line 2G AF treatment_value=float(InRec[demag_key].strip('"'))*1e-3 # convert mT => T MeasRec["treat_ac_field"]=treatment_value # AF demag in treat mT => T elif "T" in InRec['Treatment Type'].upper(): MeasRec['method_codes'] = 'LT-T-Z' inst=inst+':IODP-TDS' # measured on shipboard Schonstedt thermal demagnetizer treatment_value=float(InRec['Treatment Value'])+273 # convert C => K MeasRec["treat_temp"]=treatment_value elif 'Alternating Frequency' in InRec['Treatment Type']: MeasRec['method_codes'] = 'LT-AF-Z' inst=inst+':IODP-DTECH' # measured on shipboard Dtech D2000 treatment_value=float(InRec[demag_key])*1e-3 # convert mT => T MeasRec["treat_ac_field"]=treatment_value # AF demag in treat mT => T elif 'Thermal' in InRec['Treatment Type']: MeasRec['method_codes'] = 'LT-T-Z' inst=inst+':IODP-TDS' # measured on shipboard Schonstedt thermal demagnetizer treatment_value=float(InRec[demag_key])+273 # convert C => K MeasRec["treat_temp"]='%8.3e'%(treatment_value) # elif InRec[demag_key]!="0": MeasRec['method_codes'] = 'LT-AF-Z' inst=inst+':IODP-SRM-AF' # measured on shipboard in-line 2G AF try: treatment_value=float(InRec[demag_key])*1e-3 # convert mT => T except ValueError: print("Couldn't determine treatment value was given treatment value of %s and demag key %s; setting to blank you will have to manually correct this (or fix it)"%(InRec[demag_key], demag_key)); treatment_value='' MeasRec["treat_ac_field"]=treatment_value # AF demag in treat mT => T MeasRec["standard"]='u' # assume all data are "good" vol=float(volume)*1e-6 # convert from cc to m^3 if run_number!="": MeasRec['external_database_ids']={'LIMS':run_number} else: MeasRec['external_database_ids']="" MeasRec['dir_inc']=InRec[inc_key] MeasRec['dir_dec']=InRec[dec_key] intens = InRec[int_key] try: MeasRec['magn_moment']='%8.3e'%(float(intens)*vol) # convert intensity from A/m to Am^2 using vol except ValueError: print("couldn't find magnetic moment for specimen %s and int_key %s; leaving this field blank you'll have to fix this manually"%(specimen, int_key)); MeasRec['magn_moment']='' MeasRec['instrument_codes']=inst MeasRec['treat_step_num']='1' MeasRec['dir_csd']='0' MeasRec['meas_n_orient']='' MeasRecs.append(MeasRec) if not file_found: print("No .csv files were found") return (False, "No .csv files were found") con = nb.Contribution(output_dir_path,read_tables=[]) con.add_magic_table_from_data(dtype='specimens', data=SpecRecs) con.add_magic_table_from_data(dtype='samples', data=SampRecs) con.add_magic_table_from_data(dtype='sites', data=SiteRecs) con.add_magic_table_from_data(dtype='locations', data=LocRecs) #MeasSort=sorted(MeasRecs,key=lambda x: (x['specimen'], float(x['treat_ac_field']))) #MeasSort=sorted(MeasRecs,key=lambda x: float(x['treat_ac_field'])) #MeasOuts=pmag.measurements_methods3(MeasSort,noave) MeasOuts=pmag.measurements_methods3(MeasRecs,noave) con.add_magic_table_from_data(dtype='measurements', data=MeasOuts) con.write_table_to_file('specimens', custom_name=spec_file) con.write_table_to_file('samples', custom_name=samp_file) con.write_table_to_file('sites', custom_name=site_file) con.write_table_to_file('locations', custom_name=loc_file) con.write_table_to_file('measurements', custom_name=meas_file) return (True, meas_file)
def main(): """ NAME foldtest_magic.py DESCRIPTION does a fold test (Tauxe, 2010) on data INPUT FORMAT pmag_specimens format file, er_samples.txt format file (for bedding) SYNTAX foldtest_magic.py [command line options] OPTIONS -h prints help message and quits -f sites formatted file [default for 3.0 is sites.txt, for 2.5, pmag_sites.txt] -fsa samples formatted file -fsi sites formatted file -exc use criteria to set acceptance criteria (supported only for data model 3) -n NB, set number of bootstraps, default is 1000 -b MIN, MAX, set bounds for untilting, default is -10, 150 -fmt FMT, specify format - default is svg -sav saves plots and quits -DM NUM MagIC data model number (2 or 3, default 3) OUTPUT Geographic: is an equal area projection of the input data in original coordinates Stratigraphic: is an equal area projection of the input data in tilt adjusted coordinates % Untilting: The dashed (red) curves are representative plots of maximum eigenvalue (tau_1) as a function of untilting The solid line is the cumulative distribution of the % Untilting required to maximize tau for all the bootstrapped data sets. The dashed vertical lines are 95% confidence bounds on the % untilting that yields the most clustered result (maximum tau_1). Command line: prints out the bootstrapped iterations and finally the confidence bounds on optimum untilting. If the 95% conf bounds include 0, then a pre-tilt magnetization is indicated If the 95% conf bounds include 100, then a post-tilt magnetization is indicated If the 95% conf bounds exclude both 0 and 100, syn-tilt magnetization is possible as is vertical axis rotation or other pathologies """ if '-h' in sys.argv: # check if help is needed print(main.__doc__) sys.exit() # graceful quit kappa = 0 dir_path = pmag.get_named_arg("-WD", ".") nboot = int(float(pmag.get_named_arg("-n", 1000))) # number of bootstraps fmt = pmag.get_named_arg("-fmt", "svg") data_model_num = int(float(pmag.get_named_arg("-DM", 3))) if data_model_num == 3: infile = pmag.get_named_arg("-f", 'sites.txt') orfile = 'samples.txt' site_col = 'site' dec_col = 'dir_dec' inc_col = 'dir_inc' tilt_col = 'dir_tilt_correction' dipkey, azkey = 'bed_dip', 'bed_dip_direction' crit_col = 'criterion' critfile = 'criteria.txt' else: infile = pmag.get_named_arg("-f", 'pmag_sites.txt') orfile = 'er_samples.txt' site_col = 'er_site_name' dec_col = 'site_dec' inc_col = 'site_inc' tilt_col = 'site_tilt_correction' dipkey, azkey = 'sample_bed_dip', 'sample_bed_dip_direction' crit_col = 'pmag_criteria_code' critfile = 'pmag_criteria.txt' if '-sav' in sys.argv: plot = 1 else: plot = 0 if '-b' in sys.argv: ind = sys.argv.index('-b') untilt_min = int(sys.argv[ind + 1]) untilt_max = int(sys.argv[ind + 2]) else: untilt_min, untilt_max = -10, 150 if '-fsa' in sys.argv: orfile = pmag.get_named_arg("-fsa", "") elif '-fsi' in sys.argv: orfile = pmag.get_named_arg("-fsi", "") if data_model_num == 3: dipkey, azkey = 'bed_dip', 'bed_dip_direction' else: dipkey, azkey = 'site_bed_dip', 'site_bed_dip_direction' else: if data_model_num == 3: orfile = 'sites.txt' else: orfile = 'pmag_sites.txt' orfile = pmag.resolve_file_name(orfile, dir_path) infile = pmag.resolve_file_name(infile, dir_path) critfile = pmag.resolve_file_name(critfile, dir_path) df = pd.read_csv(infile, sep='\t', header=1) # keep only records with tilt_col data = df.copy() data = data[data[tilt_col].notnull()] data = data.where(data.notnull(), "") # turn into pmag data list data = list(data.T.apply(dict)) # get orientation data if data_model_num == 3: # often orientation will be in infile (sites table) if os.path.split(orfile)[1] == os.path.split(infile)[1]: ordata = df[df[azkey].notnull()] ordata = ordata[ordata[dipkey].notnull()] ordata = list(ordata.T.apply(dict)) # sometimes orientation might be in a sample file instead else: ordata = pd.read_csv(orfile, sep='\t', header=1) ordata = list(ordata.T.apply(dict)) else: ordata, file_type = pmag.magic_read(orfile) if '-exc' in sys.argv: crits, file_type = pmag.magic_read(critfile) SiteCrits = [] for crit in crits: if crit[crit_col] == "DE-SITE": SiteCrits.append(crit) #break # get to work # PLTS = {'geo': 1, 'strat': 2, 'taus': 3} # make plot dictionary if not set_env.IS_WIN: pmagplotlib.plot_init(PLTS['geo'], 5, 5) pmagplotlib.plot_init(PLTS['strat'], 5, 5) pmagplotlib.plot_init(PLTS['taus'], 5, 5) if data_model_num == 2: GEOrecs = pmag.get_dictitem(data, tilt_col, '0', 'T') else: GEOrecs = data if len(GEOrecs) > 0: # have some geographic data num_dropped = 0 DIDDs = [] # set up list for dec inc dip_direction, dip for rec in GEOrecs: # parse data dip, dip_dir = 0, -1 Dec = float(rec[dec_col]) Inc = float(rec[inc_col]) orecs = pmag.get_dictitem(ordata, site_col, rec[site_col], 'T') if len(orecs) > 0: if orecs[0][azkey] != "": dip_dir = float(orecs[0][azkey]) if orecs[0][dipkey] != "": dip = float(orecs[0][dipkey]) if dip != 0 and dip_dir != -1: if '-exc' in sys.argv: keep = 1 for site_crit in SiteCrits: crit_name = site_crit['table_column'].split('.')[1] if crit_name and crit_name in rec.keys( ) and rec[crit_name]: # get the correct operation (<, >=, =, etc.) op = OPS[site_crit['criterion_operation']] # then make sure the site record passes if op(float(rec[crit_name]), float(site_crit['criterion_value'])): keep = 0 if keep == 1: DIDDs.append([Dec, Inc, dip_dir, dip]) else: num_dropped += 1 else: DIDDs.append([Dec, Inc, dip_dir, dip]) if num_dropped: print( "-W- Dropped {} records because each failed one or more criteria" .format(num_dropped)) else: print('no geographic directional data found') sys.exit() pmagplotlib.plot_eq(PLTS['geo'], DIDDs, 'Geographic') data = np.array(DIDDs) D, I = pmag.dotilt_V(data) TCs = np.array([D, I]).transpose() pmagplotlib.plot_eq(PLTS['strat'], TCs, 'Stratigraphic') if plot == 0: pmagplotlib.draw_figs(PLTS) Percs = list(range(untilt_min, untilt_max)) Cdf, Untilt = [], [] plt.figure(num=PLTS['taus']) print('doing ', nboot, ' iterations...please be patient.....') for n in range( nboot ): # do bootstrap data sets - plot first 25 as dashed red line if n % 50 == 0: print(n) Taus = [] # set up lists for taus PDs = pmag.pseudo(DIDDs) if kappa != 0: for k in range(len(PDs)): d, i = pmag.fshdev(kappa) dipdir, dip = pmag.dodirot(d, i, PDs[k][2], PDs[k][3]) PDs[k][2] = dipdir PDs[k][3] = dip for perc in Percs: tilt = np.array([1., 1., 1., 0.01 * perc]) D, I = pmag.dotilt_V(PDs * tilt) TCs = np.array([D, I]).transpose() ppars = pmag.doprinc(TCs) # get principal directions Taus.append(ppars['tau1']) if n < 25: plt.plot(Percs, Taus, 'r--') # tilt that gives maximum tau Untilt.append(Percs[Taus.index(np.max(Taus))]) Cdf.append(float(n) / float(nboot)) plt.plot(Percs, Taus, 'k') plt.xlabel('% Untilting') plt.ylabel('tau_1 (red), CDF (green)') Untilt.sort() # now for CDF of tilt of maximum tau plt.plot(Untilt, Cdf, 'g') lower = int(.025 * nboot) upper = int(.975 * nboot) plt.axvline(x=Untilt[lower], ymin=0, ymax=1, linewidth=1, linestyle='--') plt.axvline(x=Untilt[upper], ymin=0, ymax=1, linewidth=1, linestyle='--') tit = '%i - %i %s' % (Untilt[lower], Untilt[upper], 'Percent Unfolding') print(tit) plt.title(tit) if plot == 0: pmagplotlib.draw_figs(PLTS) ans = input('S[a]ve all figures, <Return> to quit \n ') if ans != 'a': print("Good bye") sys.exit() files = {} for key in list(PLTS.keys()): files[key] = ('foldtest_' + '%s' % (key.strip()[:2]) + '.' + fmt) pmagplotlib.save_plots(PLTS, files)
def main(): """ NAME thellier_magic.py DESCRIPTION plots Thellier-Thellier data in version 3.0 format Reads saved interpretations from a specimen formatted table, default: specimens.txt SYNTAX thellier_magic.py [command line options] OPTIONS -h prints help message and quits -f MEAS, set measurements input file, default is 'measurements.txt' -WD: directory to output files to (default : current directory) Note: if using Windows, all figures will output to current directory -ID: directory to read files from (default : same as -WD) -fsp PRIOR, set specimens.txt prior interpretations file, default is 'specimens.txt' -fmt [svg,png,jpg], format for images - default is svg -sav, saves plots without review (in format specified by -fmt key or default) -spc SPEC, plots single specimen SPEC, saves plot with specified format with optional -b bounds and quits -n SPECIMENS, number of specimens to plot OUTPUT figures: ALL: numbers refer to temperature steps in command line window 1) Arai plot: closed circles are zero-field first/infield open circles are infield first/zero-field triangles are pTRM checks squares are pTRM tail checks VDS is vector difference sum diamonds are bounds for interpretation 2) Zijderveld plot: closed (open) symbols are X-Y (X-Z) planes X rotated to NRM direction 3) (De/Re)Magnetization diagram: circles are NRM remaining squares are pTRM gained 4) equal area projections: green triangles are pTRM gained direction red (purple) circles are lower(upper) hemisphere of ZI step directions blue (cyan) squares are lower(upper) hemisphere IZ step directions 5) Optional: TRM acquisition 6) Optional: TDS normalization command line window: list is: temperature step numbers, temperatures (C), Dec, Inc, Int (units of measuements) list of possible commands: type letter followed by return to select option saving of plots creates image files with specimen, plot type as name """ # # parse command line options # if '-h' in sys.argv: print(main.__doc__) sys.exit() dir_path = pmag.get_named_arg("-WD", default_val=".") input_dir_path = pmag.get_named_arg('-ID', "") input_dir_path, dir_path = pmag.fix_directories(input_dir_path, dir_path) meas_file = pmag.get_named_arg( "-f", default_val="measurements.txt") #spec_file = pmag.get_named_arg( # "-fsp", default_val="specimens.txt") #crit_file = pmag.get_named_arg("-fcr", default_val="criteria.txt") #spec_file = os.path.join(dir_path, spec_file) #crit_file = os.path.join(dir_path, crit_file) meas_file = pmag.resolve_file_name(meas_file, input_dir_path) fmt = pmag.get_named_arg("-fmt", "svg") save_plots = False interactive = True if '-sav' in sys.argv: save_plots = True interactive=False spec = pmag.get_named_arg("-spc", default_val="") n_specs = pmag.get_named_arg("-n", default_val="all") try: n_specs = int(n_specs) except ValueError: pass ipmag.thellier_magic(meas_file, dir_path, input_dir_path, spec, n_specs, save_plots, fmt, interactive)
def main(): """ NAME foldtest_magic.py DESCRIPTION does a fold test (Tauxe, 2010) on data INPUT FORMAT pmag_specimens format file, er_samples.txt format file (for bedding) SYNTAX foldtest_magic.py [command line options] OPTIONS -h prints help message and quits -f sites formatted file [default for 3.0 is sites.txt, for 2.5, pmag_sites.txt] -fsa samples formatted file -fsi sites formatted file -exc use criteria to set acceptance criteria (supported only for data model 3) -n NB, set number of bootstraps, default is 1000 -b MIN, MAX, set bounds for untilting, default is -10, 150 -fmt FMT, specify format - default is svg -sav saves plots and quits -DM NUM MagIC data model number (2 or 3, default 3) OUTPUT Geographic: is an equal area projection of the input data in original coordinates Stratigraphic: is an equal area projection of the input data in tilt adjusted coordinates % Untilting: The dashed (red) curves are representative plots of maximum eigenvalue (tau_1) as a function of untilting The solid line is the cumulative distribution of the % Untilting required to maximize tau for all the bootstrapped data sets. The dashed vertical lines are 95% confidence bounds on the % untilting that yields the most clustered result (maximum tau_1). Command line: prints out the bootstrapped iterations and finally the confidence bounds on optimum untilting. If the 95% conf bounds include 0, then a pre-tilt magnetization is indicated If the 95% conf bounds include 100, then a post-tilt magnetization is indicated If the 95% conf bounds exclude both 0 and 100, syn-tilt magnetization is possible as is vertical axis rotation or other pathologies """ if '-h' in sys.argv: # check if help is needed print(main.__doc__) sys.exit() # graceful quit kappa = 0 dir_path = pmag.get_named_arg("-WD", ".") nboot = int(float(pmag.get_named_arg("-n", 1000))) # number of bootstraps fmt = pmag.get_named_arg("-fmt", "svg") data_model_num = int(float(pmag.get_named_arg("-DM", 3))) if data_model_num == 3: infile = pmag.get_named_arg("-f", 'sites.txt') orfile = 'samples.txt' site_col = 'site' dec_col = 'dir_dec' inc_col = 'dir_inc' tilt_col = 'dir_tilt_correction' dipkey, azkey = 'bed_dip', 'bed_dip_direction' crit_col = 'criterion' critfile = 'criteria.txt' else: infile = pmag.get_named_arg("-f", 'pmag_sites.txt') orfile = 'er_samples.txt' site_col = 'er_site_name' dec_col = 'site_dec' inc_col = 'site_inc' tilt_col = 'site_tilt_correction' dipkey, azkey = 'sample_bed_dip', 'sample_bed_dip_direction' crit_col = 'pmag_criteria_code' critfile = 'pmag_criteria.txt' if '-sav' in sys.argv: plot = 1 else: plot = 0 if '-b' in sys.argv: ind = sys.argv.index('-b') untilt_min = int(sys.argv[ind+1]) untilt_max = int(sys.argv[ind+2]) else: untilt_min, untilt_max = -10, 150 if '-fsa' in sys.argv: orfile = pmag.get_named_arg("-fsa", "") elif '-fsi' in sys.argv: orfile = pmag.get_named_arg("-fsi", "") if data_model_num == 3: dipkey, azkey = 'bed_dip', 'bed_dip_direction' else: dipkey, azkey = 'site_bed_dip', 'site_bed_dip_direction' else: if data_model_num == 3: orfile = 'sites.txt' else: orfile = 'pmag_sites.txt' orfile = pmag.resolve_file_name(orfile, dir_path) infile = pmag.resolve_file_name(infile, dir_path) critfile = pmag.resolve_file_name(critfile, dir_path) df = pd.read_csv(infile, sep='\t', header=1) # keep only records with tilt_col data = df.copy() data = data[data[tilt_col].notnull()] data = data.where(data.notnull(), "") # turn into pmag data list data = list(data.T.apply(dict)) # get orientation data if data_model_num == 3: # often orientation will be in infile (sites table) if os.path.split(orfile)[1] == os.path.split(infile)[1]: ordata = df[df[azkey].notnull()] ordata = ordata[ordata[dipkey].notnull()] ordata = list(ordata.T.apply(dict)) # sometimes orientation might be in a sample file instead else: ordata = pd.read_csv(orfile, sep='\t', header=1) ordata = list(ordata.T.apply(dict)) else: ordata, file_type = pmag.magic_read(orfile) if '-exc' in sys.argv: crits, file_type = pmag.magic_read(critfile) SiteCrits = [] for crit in crits: if crit[crit_col] == "DE-SITE": SiteCrits.append(crit) #break # get to work # PLTS = {'geo': 1, 'strat': 2, 'taus': 3} # make plot dictionary if not set_env.IS_WIN: pmagplotlib.plot_init(PLTS['geo'], 5, 5) pmagplotlib.plot_init(PLTS['strat'], 5, 5) pmagplotlib.plot_init(PLTS['taus'], 5, 5) if data_model_num == 2: GEOrecs = pmag.get_dictitem(data, tilt_col, '0', 'T') else: GEOrecs = data if len(GEOrecs) > 0: # have some geographic data num_dropped = 0 DIDDs = [] # set up list for dec inc dip_direction, dip for rec in GEOrecs: # parse data dip, dip_dir = 0, -1 Dec = float(rec[dec_col]) Inc = float(rec[inc_col]) orecs = pmag.get_dictitem( ordata, site_col, rec[site_col], 'T') if len(orecs) > 0: if orecs[0][azkey] != "": dip_dir = float(orecs[0][azkey]) if orecs[0][dipkey] != "": dip = float(orecs[0][dipkey]) if dip != 0 and dip_dir != -1: if '-exc' in sys.argv: keep = 1 for site_crit in SiteCrits: crit_name = site_crit['table_column'].split('.')[1] if crit_name and crit_name in rec.keys() and rec[crit_name]: # get the correct operation (<, >=, =, etc.) op = OPS[site_crit['criterion_operation']] # then make sure the site record passes if op(float(rec[crit_name]), float(site_crit['criterion_value'])): keep = 0 if keep == 1: DIDDs.append([Dec, Inc, dip_dir, dip]) else: num_dropped += 1 else: DIDDs.append([Dec, Inc, dip_dir, dip]) if num_dropped: print("-W- Dropped {} records because each failed one or more criteria".format(num_dropped)) else: print('no geographic directional data found') sys.exit() pmagplotlib.plot_eq(PLTS['geo'], DIDDs, 'Geographic') data = np.array(DIDDs) D, I = pmag.dotilt_V(data) TCs = np.array([D, I]).transpose() pmagplotlib.plot_eq(PLTS['strat'], TCs, 'Stratigraphic') if plot == 0: pmagplotlib.draw_figs(PLTS) Percs = list(range(untilt_min, untilt_max)) Cdf, Untilt = [], [] plt.figure(num=PLTS['taus']) print('doing ', nboot, ' iterations...please be patient.....') for n in range(nboot): # do bootstrap data sets - plot first 25 as dashed red line if n % 50 == 0: print(n) Taus = [] # set up lists for taus PDs = pmag.pseudo(DIDDs) if kappa != 0: for k in range(len(PDs)): d, i = pmag.fshdev(kappa) dipdir, dip = pmag.dodirot(d, i, PDs[k][2], PDs[k][3]) PDs[k][2] = dipdir PDs[k][3] = dip for perc in Percs: tilt = np.array([1., 1., 1., 0.01*perc]) D, I = pmag.dotilt_V(PDs*tilt) TCs = np.array([D, I]).transpose() ppars = pmag.doprinc(TCs) # get principal directions Taus.append(ppars['tau1']) if n < 25: plt.plot(Percs, Taus, 'r--') # tilt that gives maximum tau Untilt.append(Percs[Taus.index(np.max(Taus))]) Cdf.append(float(n) / float(nboot)) plt.plot(Percs, Taus, 'k') plt.xlabel('% Untilting') plt.ylabel('tau_1 (red), CDF (green)') Untilt.sort() # now for CDF of tilt of maximum tau plt.plot(Untilt, Cdf, 'g') lower = int(.025*nboot) upper = int(.975*nboot) plt.axvline(x=Untilt[lower], ymin=0, ymax=1, linewidth=1, linestyle='--') plt.axvline(x=Untilt[upper], ymin=0, ymax=1, linewidth=1, linestyle='--') tit = '%i - %i %s' % (Untilt[lower], Untilt[upper], 'Percent Unfolding') print(tit) plt.title(tit) if plot == 0: pmagplotlib.draw_figs(PLTS) ans = input('S[a]ve all figures, <Return> to quit \n ') if ans != 'a': print("Good bye") sys.exit() files = {} for key in list(PLTS.keys()): files[key] = ('foldtest_'+'%s' % (key.strip()[:2])+'.'+fmt) pmagplotlib.save_plots(PLTS, files)
def main(): """ NAME lnp_magic.py DESCRIPTION makes equal area projections site by site from specimen formatted file with Fisher confidence ellipse using McFadden and McElhinny (1988) technique for combining lines and planes SYNTAX lnp_magic [command line options] INPUT takes magic formatted specimens file OUPUT prints site_name n_lines n_planes K alpha95 dec inc R OPTIONS -h prints help message and quits -f FILE: specify input file, default is 'specimens.txt', ('pmag_specimens.txt' for legacy data model 2) -fsa FILE: specify samples file, required to plot by site for data model 3 (otherwise will plot by sample) default is 'samples.txt' -crd [s,g,t]: specify coordinate system, [s]pecimen, [g]eographic, [t]ilt adjusted default is specimen -fmt [svg,png,jpg] format for plots, default is svg -sav save plots and quit -P: do not plot -F FILE, specify output file of dec, inc, alpha95 data for plotting with plotdi_a and plotdi_e -exc use criteria in criteria table # NOT IMPLEMENTED -DM NUMBER MagIC data model (2 or 3, default 3) """ if '-h' in sys.argv: print(main.__doc__) sys.exit() dir_path = pmag.get_named_arg("-WD", ".") data_model = int(float(pmag.get_named_arg("-DM", 3))) fmt = pmag.get_named_arg("-fmt", 'svg') if data_model == 2: in_file = pmag.get_named_arg('-f', 'pmag_specimens.txt') crit_file = "pmag_criteria.txt" else: in_file = pmag.get_named_arg('-f', 'specimens.txt') samp_file = pmag.get_named_arg('-fsa', 'samples.txt') crit_file = "criteria.txt" in_file = pmag.resolve_file_name(in_file, dir_path) dir_path = os.path.split(in_file)[0] if data_model == 3: samp_file = pmag.resolve_file_name(samp_file, dir_path) if '-crd' in sys.argv: ind = sys.argv.index("-crd") crd = sys.argv[ind+1] if crd == 's': coord = "-1" if crd == 'g': coord = "0" if crd == 't': coord = "100" else: coord = "-1" out_file = pmag.get_named_arg('-F', '') if out_file: out = open(dir_path+'/'+out_file, 'w') if '-P' in sys.argv: make_plots = 0 # do not plot else: make_plots = 1 # do plot if '-sav' in sys.argv: plot = 1 # save plots and quit else: plot = 0 # show plots intereactively (if make_plots) # if data_model == 2: Specs, file_type = pmag.magic_read(in_file) if 'specimens' not in file_type: print('Error opening ', in_file, file_type) sys.exit() else: fnames = {'specimens': in_file, 'samples': samp_file} con = cb.Contribution(dir_path, read_tables=['samples', 'specimens'], custom_filenames=fnames) con.propagate_name_down('site', 'specimens') if 'site' in con.tables['specimens'].df.columns: site_col = 'site' else: site_col = 'sample' tilt_corr_col = "dir_tilt_correction" mad_col = "dir_mad_free" alpha95_col = "dir_alpha95" site_alpha95_col = "dir_alpha95" dec_col = "dir_dec" inc_col = "dir_inc" num_meas_col = "dir_n_measurements" k_col = "dir_k" cols = [site_col, tilt_corr_col, mad_col, alpha95_col, dec_col, inc_col] con.tables['specimens'].front_and_backfill(cols) con.tables['specimens'].df = con.tables['specimens'].df.where(con.tables['specimens'].df.notnull(), "") Specs = con.tables['specimens'].convert_to_pmag_data_list() ## using criteria file was never fully implemented #if '-exc' in sys.argv: # Crits, file_type = pmag.magic_read(pmag.resolve_file_name(crit_file, dir_path)) # for crit in Crits: # if mad_col in crit: # M = float(crit['specimen_mad']) # if num_meas_col in crit: # N = float(crit['specimen_n']) # if site_alpha95_col in crit and 'site' in crit: # acutoff = float(crit['site_alpha95']) # if k_col in crit: # kcutoff = float(crit['site_k']) #else: # Crits = "" sitelist = [] # initialize some variables FIG = {} # plot dictionary FIG['eqarea'] = 1 # eqarea is figure 1 M, N, acutoff, kcutoff = 180., 1, 180., 0. if data_model == 2: site_col = 'er_site_name' tilt_corr_col = "specimen_tilt_correction" mad_col = "specimen_mad" alpha95_col = 'specimen_alpha95' dec_col = "specimen_dec" inc_col = "specimen_inc" num_meas_col = "specimen_n" site_alpha95_col = "site_alpha95" else: # data model 3 pass for rec in Specs: if rec[site_col] not in sitelist: sitelist.append(rec[site_col]) sitelist.sort() if make_plots == 1: EQ = {} EQ['eqarea'] = 1 for site in sitelist: pmagplotlib.plot_init(EQ['eqarea'], 4, 4) print(site) data = [] for spec in Specs: if tilt_corr_col not in list(spec.keys()): spec[tilt_corr_col] = '-1' # assume unoriented if spec[site_col] == site: if mad_col not in list(spec.keys()) or spec[mad_col] == "": if alpha95_col in list(spec.keys()) and spec[alpha95_col] != "": spec[mad_col] = spec[alpha95_col] else: spec[mad_col] = '180' if not spec[num_meas_col]: continue if (float(spec[tilt_corr_col]) == float(coord)) and (float(spec[mad_col]) <= M) and (float(spec[num_meas_col]) >= N): rec = {} for key in list(spec.keys()): rec[key] = spec[key] rec["dec"] = float(spec[dec_col]) rec["inc"] = float(spec[inc_col]) rec["tilt_correction"] = spec[tilt_corr_col] data.append(rec) if len(data) > 2: fpars = pmag.dolnp(data, 'specimen_direction_type') print("Site lines planes kappa a95 dec inc") print(site, fpars["n_lines"], fpars["n_planes"], fpars["K"], fpars["alpha95"], fpars["dec"], fpars["inc"], fpars["R"]) if out_file != "": if float(fpars["alpha95"]) <= acutoff and float(fpars["K"]) >= kcutoff: out.write('%s %s %s\n' % (fpars["dec"], fpars['inc'], fpars['alpha95'])) print('% tilt correction: ', coord) if make_plots == 1: files = {} files['eqarea'] = site+'_'+crd+'_'+'eqarea'+'.'+fmt pmagplotlib.plot_lnp(EQ['eqarea'], site, data, fpars, 'specimen_direction_type') if plot == 0: pmagplotlib.draw_figs(EQ) ans = input( "s[a]ve plot, [q]uit, <return> to continue:\n ") if ans == "a": pmagplotlib.save_plots(EQ, files) if ans == "q": sys.exit() else: pmagplotlib.save_plots(EQ, files) else: print('skipping site - not enough data with specified coordinate system')
def main(): """ NAME strip_magic.py DESCRIPTION plots various parameters versus depth or age SYNTAX strip_magic.py [command line optins] OPTIONS -h prints help message and quits -DM NUM: specify data model num, options 2 (legacy) or 3 (default) -f FILE: specify input magic format file from magic,default='pmag_results.txt' supported types=[pmag_specimens, pmag_samples, pmag_sites, pmag_results, magic_web] -obj [sit,sam,all]: specify object to site,sample,all for pmag_result table, default is all -fmt [svg,png,jpg], format for images - default is svg -x [age,pos]: specify whether age or stratigraphic position -y [dec,inc,int,chi,lat,lon,vdm,vadm] (lat and lon are VGP lat and lon) -Iex: plot the expected inc at lat - only available for results with lat info in file -ts TS amin amax: plot the GPTS for the time interval between amin and amax (numbers in Ma) TS: [ck95, gts04] -mcd method_code, specify method code, default is first one encountered -sav save plot and quit NOTES when x and/or y are not specified, a list of possibilities will be presented to the user for choosing """ if '-h' in sys.argv: print(main.__doc__) sys.exit() xaxis, xplotind, yplotind = "", 0, 0 # (0 for strat pos) yaxis, Xinc = "", "" plot = 0 obj = 'all' data_model_num = int(pmag.get_named_arg("-DM", 3)) # 2.5 keys if data_model_num == 2: supported = [ 'pmag_specimens', 'pmag_samples', 'pmag_sites', 'pmag_results', 'magic_web' ] # available file types Depth_keys = [ 'specimen_core_depth', 'specimen_height', 'specimen_elevation', 'specimen_composite_depth', 'sample_core_depth', 'sample_height', 'sample_elevation', 'sample_composite_depth', 'site_core_depth', 'site_height', 'site_elevation', 'site_composite_depth', 'average_height' ] Age_keys = [ 'specimen_inferred_age', 'sample_inferred_age', 'site_inferred_age', 'average_age' ] Unit_keys = { 'specimen_inferred_age': 'specimen_inferred_age_unit', 'sample_inferred_age': 'sample_inferred_age_unit', 'site_inferred_age': 'site_inferred_age_unit', 'average_age': 'average_age_unit' } Dec_keys = [ 'measurement_dec', 'specimen_dec', 'sample_dec', 'site_dec', 'average_dec' ] Inc_keys = [ 'measurement_inc', 'specimen_inc', 'sample_inc', 'site_inc', 'average_inc' ] Int_keys = [ 'measurement_magnitude', 'measurement_magn_moment', 'measurement_magn_volume', 'measurement_magn_mass', 'specimen_int', 'specimen_int_rel', 'sample_int', 'sample_int_rel', 'site_int', 'site_int_rel', 'average_int', 'average_int_rel' ] Chi_keys = ['measurement_chi_volume', 'measurement_chi_mass'] Lat_keys = ['sample_lat', 'site_lat', 'average_lat'] VLat_keys = ['vgp_lat'] VLon_keys = ['vgp_lon'] Vdm_keys = ['vdm'] Vadm_keys = ['vadm'] method_col_name = "magic_method_codes" else: # 3.0 keys supported = ["specimens", "samples", "sites", "locations"] # available file types Depth_keys = ["height", "core_depth", "elevation", "composite_depth"] Age_keys = ["age"] Unit_keys = {"age": "age"} Chi_keys = ["susc_chi_volume", "susc_chi_mass"] Int_keys = [ "magn_moment", "magn_volume", "magn_mass", "int_abs", "int_rel" ] Inc_keys = ["dir_inc"] Dec_keys = ["dir_dec"] Lat_Keys = ["lat"] VLat_keys = ["vgp_lat", "pole_lat"] VLon_keys = ["vgp_lon", "pole_lon"] Vdm_keys = ["vdm", "pdm"] Vadm_keys = ["vadm", "padm"] method_col_name = "method_codes" # X_keys = [Age_keys, Depth_keys] Y_keys = [ Dec_keys, Inc_keys, Int_keys, Chi_keys, VLat_keys, VLon_keys, Vdm_keys, Vadm_keys ] method, fmt = "", 'svg' FIG = {'strat': 1} plotexp, pTS = 0, 0 dir_path = pmag.get_named_arg("-WD", ".") # default files if data_model_num == 3: res_file = pmag.get_named_arg("-f", "sites.txt") else: res_file = pmag.get_named_arg("-f", "pmag_results.txt") res_file = pmag.resolve_file_name(res_file, dir_path) if '-fmt' in sys.argv: ind = sys.argv.index('-fmt') fmt = sys.argv[ind + 1] if '-obj' in sys.argv: ind = sys.argv.index('-obj') obj = sys.argv[ind + 1] if '-x' in sys.argv: ind = sys.argv.index('-x') xaxis = sys.argv[ind + 1] if '-y' in sys.argv: ind = sys.argv.index('-y') yaxis = sys.argv[ind + 1] if yaxis == 'dec': ykeys = Dec_keys if yaxis == 'inc': ykeys = Inc_keys if yaxis == 'int': ykeys = Int_keys if yaxis == 'chi': ykeys = Chi_keys if yaxis == 'lat': ykeys = VLat_keys if yaxis == 'lon': ykeys = VLon_keys if yaxis == 'vdm': ykeys = Vdm_keys if yaxis == 'vadm': ykeys = Vadm_keys if '-mcd' in sys.argv: ind = sys.argv.index('-mcd') method = sys.argv[ind + 1] if '-ts' in sys.argv: ind = sys.argv.index('-ts') ts = sys.argv[ind + 1] amin = float(sys.argv[ind + 2]) amax = float(sys.argv[ind + 3]) pTS = 1 if '-Iex' in sys.argv: plotexp = 1 if '-sav' in sys.argv: plot = 1 # # # get data read in Results, file_type = pmag.magic_read(res_file) if file_type not in supported: print("Unsupported file type ({}), try again".format(file_type)) sys.exit() PltObjs = ['all'] if data_model_num == 2: if file_type == 'pmag_results': # find out what to plot for rec in Results: resname = rec['pmag_result_name'].split() if 'Sample' in resname and 'sam' not in PltObjs: PltObjs.append('sam') if 'Site' in resname and 'sit' not in PltObjs: PltObjs.append('sit') methcodes = [] # need to know all the measurement types from method_codes if "magic_method_codes" in list(Results[0].keys()): for rec in Results: meths = rec["magic_method_codes"].split(":") for meth in meths: if meth.strip() not in methcodes and 'LP' in meth: # look for the lab treatments methcodes.append(meth.strip()) # # initialize some variables X_unit = "" # Unit for age or depth plotting (meters if depth) Xplots, Yplots = [], [] Xunits = [] yplotind, xplotind = 0, 0 # # step through possible plottable keys # if xaxis == "" or yaxis == "": for key in list(Results[0].keys()): for keys in X_keys: for xkeys in keys: if key in xkeys: for ResRec in Results: if ResRec[key] != "": # only plot something if there is something to plot! Xplots.append(key) break for keys in Y_keys: for pkeys in keys: if key in pkeys: for ResRec in Results: if ResRec[key] != "": Yplots.append(key) break X, Y = [], [] for plt in Xplots: if plt in Age_keys and 'age' not in X: X.append('age') if plt in Depth_keys and 'pos' not in X: X.append('pos') for plt in Yplots: if plt in Dec_keys and 'dec' not in Y: Y.append('dec') if plt in Inc_keys and 'inc' not in Y: Y.append('inc') if plt in Int_keys and 'int' not in Y: Y.append('int') if plt in Chi_keys and 'chi' not in Y: Y.append('chi') if plt in VLat_keys and 'lat' not in Y: Y.append('lat') if plt in VLon_keys and 'lon' not in Y: Y.append('lon') if plt in Vadm_keys and 'vadm' not in Y: Y.append('vadm') if plt in Vdm_keys and 'vdm' not in Y: Y.append('vdm') if file_type == 'pmag_results': print('available objects for plotting: ', PltObjs) print('available X plots: ', X) print('available Y plots: ', Y) print('available method codes: ', methcodes) f = open(dir_path + '/.striprc', 'w') for x in X: f.write('x:' + x + '\n') for y in Y: f.write('y:' + y + '\n') for m in methcodes: f.write('m:' + m + '\n') for obj in PltObjs: f.write('obj:' + obj + '\n') sys.exit() if plotexp == 1: for lkey in Lat_keys: for key in list(Results[0].keys()): if key == lkey: lat = float(Results[0][lkey]) Xinc = [pmag.pinc(lat), -pmag.pinc(lat)] break if Xinc == "": print('can not plot expected inc for site - lat unknown') if method != "" and method not in methcodes: print('your method not available, but these are: ') print(methcodes) print('use ', methcodes[0], '? ^D to quit') if xaxis == 'age': for akey in Age_keys: for key in list(Results[0].keys()): if key == akey: Xplots.append(key) Xunits.append(Unit_keys[key]) if xaxis == 'pos': for dkey in Depth_keys: for key in list(Results[0].keys()): if key == dkey: Xplots.append(key) if len(Xplots) == 0: print('desired X axis information not found') sys.exit() if xaxis == 'age': age_unit = Results[0][Xunits[0]] if len(Xplots) > 1: print('multiple X axis keys found, using: ', Xplots[xplotind]) for ykey in ykeys: for key in list(Results[0].keys()): if key == ykey: Yplots.append(key) if len(Yplots) == 0: print('desired Y axis information not found') sys.exit() if len(Yplots) > 1: print('multiple Y axis keys found, using: ', Yplots[yplotind]) # check if age or depth info if len(Xplots) == 0: print("Must have either age or height info to plot ") sys.exit() # # check for variable to plot # # # determine X axis (age or depth) # if xaxis == "age": plotind = "1" if method == "": try: method = methcodes[0] except IndexError: method = "" if xaxis == 'pos': xlab = "Stratigraphic Height (meters)" else: xlab = "Age (" + age_unit + ")" Xkey = Xplots[xplotind] Ykey = Yplots[yplotind] ylab = Ykey # # collect the data for plotting XY = [] isign = 1. # if float(Results[0][Xkey])/float(Results[-1][Xkey])>0 and float(Results[0][Xkey])<0: # isign=-1. # x axis all same sign and negative, take positive (e.g.,for depth in core) # xlab="Stratigraphic Position (meters)" # else: # isign=1. for rec in Results: if "magic_method_codes" in list(rec.keys()): meths = rec["magic_method_codes"].split(":") if method in meths: # make sure it is desired lab treatment step if obj == 'all' and rec[Xkey].strip() != "": XY.append([isign * float(rec[Xkey]), float(rec[Ykey])]) elif rec[Xkey].strip() != "": name = rec['pmag_result_name'].split() if obj == 'sit' and "Site" in name: XY.append([isign * float(rec[Xkey]), float(rec[Ykey])]) if obj == 'sam' and "Sample" in name: XY.append([isign * float(rec[Xkey]), float(rec[Ykey])]) elif method == "": if obj == 'all' and rec[Xkey].strip() != "": XY.append([isign * float(rec[Xkey]), float(rec[Ykey])]) elif rec[Xkey].strip() != "": name = rec['pmag_result_name'].split() if obj == 'sit' and "Site" in name: XY.append([isign * float(rec[Xkey]), float(rec[Ykey])]) if obj == 'sam' and "Sample" in name: XY.append([isign * float(rec[Xkey]), float(rec[Ykey])]) else: print("Something wrong with your plotting choices") break XY.sort() title = "" if "er_locations_names" in list(Results[0].keys()): title = Results[0]["er_location_names"] if "er_locations_name" in list(Results[0].keys()): title = Results[0]["er_location_name"] labels = [xlab, ylab, title] pmagplotlib.plot_init(FIG['strat'], 10, 5) pmagplotlib.plot_strat(FIG['strat'], XY, labels) # plot them if plotexp == 1: pmagplotlib.plot_hs(FIG['strat'], Xinc, 'b', '--') if yaxis == 'inc' or yaxis == 'lat': pmagplotlib.plot_hs(FIG['strat'], [0], 'b', '-') pmagplotlib.plot_hs(FIG['strat'], [-90, 90], 'g', '-') if pTS == 1: FIG['ts'] = 2 pmagplotlib.plot_init(FIG['ts'], 10, 5) pmagplotlib.plot_ts(FIG['ts'], [amin, amax], ts) files = {} for key in list(FIG.keys()): files[key] = key + '.' + fmt if pmagplotlib.isServer: black = '#000000' purple = '#800080' files = {} files['strat'] = xaxis + '_' + yaxis + '_.' + fmt files['ts'] = 'ts.' + fmt titles = {} titles['strat'] = 'Depth/Time Series Plot' titles['ts'] = 'Time Series Plot' FIG = pmagplotlib.add_borders(FIG, titles, black, purple) pmagplotlib.save_plots(FIG, files) elif plot == 1: pmagplotlib.save_plots(FIG, files) else: pmagplotlib.draw_figs(FIG) ans = input(" S[a]ve to save plot, [q]uit without saving: ") if ans == "a": pmagplotlib.save_plots(FIG, files)
def main(): """ NAME irmaq_magic.py DESCRIPTION plots IRM acquisition curves from measurements file SYNTAX irmaq_magic [command line options] INPUT takes magic formatted magic_measurements.txt files OPTIONS -h prints help message and quits -f FILE: specify input file, default is: magic_measurements.txt/measurements.txt -obj OBJ: specify object [loc, sit, sam, spc] for plot, default is by location -N ; do not normalize by last point - use original units -fmt [png,jpg,eps,pdf] set plot file format [default is svg] -sav save plot[s] and quit -DM MagIC data model number, default is 3 NOTE loc: location (study); sit: site; sam: sample; spc: specimen """ FIG = {} # plot dictionary FIG['exp'] = 1 # exp is figure 1 dir_path = './' plot, fmt = 0, 'svg' units = 'T', XLP = [] norm = 1 LP = "LP-IRM" if len(sys.argv) > 1: if '-h' in sys.argv: print(main.__doc__) sys.exit() data_model = int(pmag.get_named_arg("-DM", 3)) if '-N' in sys.argv: norm = 0 if '-sav' in sys.argv: plot = 1 if '-fmt' in sys.argv: ind = sys.argv.index("-fmt") fmt = sys.argv[ind + 1] if data_model == 3: in_file = pmag.get_named_arg("-f", 'measurements.txt') else: in_file = pmag.get_named_arg("-f", 'magic_measurements.txt') if '-WD' in sys.argv: ind = sys.argv.index('-WD') dir_path = sys.argv[ind + 1] dir_path = os.path.realpath(dir_path) in_file = pmag.resolve_file_name(in_file, dir_path) if '-WD' not in sys.argv: dir_path = os.path.split(in_file)[0] plot_by = pmag.get_named_arg("-obj", "loc") if data_model == 3: plot_key = 'location' if plot_by == 'sit': plot_key = 'site' if plot_by == 'sam': plot_key = 'sample' if plot_by == 'spc': plot_key = 'specimen' else: plot_key = 'er_location_name' if plot_by == 'sit': plot_key = 'er_site_name' if plot_by == 'sam': plot_key = 'er_sample_name' if plot_by == 'spc': plot_key = 'er_specimen_name' # set defaults and get more information if needed if data_model == 3: dmag_key = 'treat_dc_field' else: dmag_key = 'treatment_dc_field' # if data_model == 3 and plot_key != 'specimen': # gonna need to read in more files print('-W- You are trying to plot measurements by {}'.format(plot_key)) print(' By default, this information is not available in your measurement file.') print(' Trying to acquire this information from {}'.format(dir_path)) con = cb.Contribution(dir_path) meas_df = con.propagate_location_to_measurements() if meas_df is None: print('-W- No data found in {}'.format(dir_path)) return if plot_key not in meas_df.columns: print('-W- Could not find required data.') print(' Try a different plot key.') return else: print('-I- Found {} information, continuing with plotting'.format(plot_key)) # need to take the data directly from the contribution here, to keep # location/site/sample columns in the measurements table data = con.tables['measurements'].convert_to_pmag_data_list() file_type = "measurements" else: data, file_type = pmag.magic_read(in_file) # read in data sids = pmag.get_specs(data) pmagplotlib.plot_init(FIG['exp'], 6, 6) # # # find desired intensity data # # get plotlist # plotlist = [] if data_model == 3: intlist = ['magn_moment', 'magn_volume', 'magn_mass', 'magnitude'] else: intlist = ['measurement_magnitude', 'measurement_magn_moment', 'measurement_magn_volume', 'measurement_magn_mass'] IntMeths = [] # get all the records with this lab protocol #print('data', len(data)) #print('data[0]', data[0]) if data_model == 3: data = pmag.get_dictitem(data, 'method_codes', LP, 'has') else: data = pmag.get_dictitem(data, 'magic_method_codes', LP, 'has') Ints = {} NoInts, int_key = 1, "" for key in intlist: # get all non-blank data for intensity type Ints[key] = pmag.get_dictitem(data, key, '', 'F') if len(Ints[key]) > 0: NoInts = 0 if int_key == "": int_key = key if NoInts == 1: print('No intensity information found') sys.exit() for rec in Ints[int_key]: if rec[plot_key] not in plotlist: plotlist.append(rec[plot_key]) plotlist.sort() for plt in plotlist: print(plt) INTblock = [] # get data with right intensity info whose plot_key matches plot data = pmag.get_dictitem(Ints[int_key], plot_key, plt, 'T') # get a list of specimens with appropriate data sids = pmag.get_specs(data) if len(sids) > 0: title = data[0][plot_key] for s in sids: INTblock = [] # get data for each specimen if data_model == 3: sdata = pmag.get_dictitem(data, 'specimen', s, 'T') else: sdata = pmag.get_dictitem(data, 'er_specimen_name', s, 'T') for rec in sdata: INTblock.append([float(rec[dmag_key]), 0, 0, float(rec[int_key]), 1, 'g']) pmagplotlib.plot_mag(FIG['exp'], INTblock, title, 0, units, norm) files = {} for key in list(FIG.keys()): files[key] = title + '_' + LP + '.' + fmt if plot == 0: pmagplotlib.draw_figs(FIG) ans = input(" S[a]ve to save plot, [q]uit, Return to continue: ") if ans == 'q': sys.exit() if ans == "a": pmagplotlib.save_plots(FIG, files) if plt != plotlist[-1]: # if it isn't the last plot, init the next one pmagplotlib.plot_init(FIG['exp'], 6, 6) else: pmagplotlib.save_plots(FIG, files) pmagplotlib.clearFIG(FIG['exp'])
def main(): """ NAME irmaq_magic.py DESCRIPTION plots IRM acquisition curves from measurements file SYNTAX irmaq_magic [command line options] INPUT takes magic formatted magic_measurements.txt files OPTIONS -h prints help message and quits -f FILE: specify input file, default is: magic_measurements.txt/measurements.txt -obj OBJ: specify object [loc, sit, sam, spc] for plot, default is by location -N ; do not normalize by last point - use original units -fmt [png,jpg,eps,pdf] set plot file format [default is svg] -sav save plot[s] and quit -DM MagIC data model number, default is 3 NOTE loc: location (study); sit: site; sam: sample; spc: specimen """ FIG = {} # plot dictionary FIG['exp'] = 1 # exp is figure 1 dir_path = './' plot, fmt = 0, 'svg' units = 'T', XLP = [] norm = 1 LP = "LP-IRM" if len(sys.argv) > 1: if '-h' in sys.argv: print(main.__doc__) sys.exit() data_model = int(pmag.get_named_arg("-DM", 3)) if '-N' in sys.argv: norm = 0 if '-sav' in sys.argv: plot = 1 if '-fmt' in sys.argv: ind = sys.argv.index("-fmt") fmt = sys.argv[ind + 1] if data_model == 3: in_file = pmag.get_named_arg("-f", 'measurements.txt') else: in_file = pmag.get_named_arg("-f", 'magic_measurements.txt') if '-WD' in sys.argv: ind = sys.argv.index('-WD') dir_path = sys.argv[ind + 1] dir_path = os.path.realpath(dir_path) in_file = pmag.resolve_file_name(in_file, dir_path) if '-WD' not in sys.argv: dir_path = os.path.split(in_file)[0] plot_by = pmag.get_named_arg("-obj", "loc") if data_model == 3: plot_key = 'location' if plot_by == 'sit': plot_key = 'site' if plot_by == 'sam': plot_key = 'sample' if plot_by == 'spc': plot_key = 'specimen' else: plot_key = 'er_location_name' if plot_by == 'sit': plot_key = 'er_site_name' if plot_by == 'sam': plot_key = 'er_sample_name' if plot_by == 'spc': plot_key = 'er_specimen_name' # set defaults and get more information if needed if data_model == 3: dmag_key = 'treat_dc_field' else: dmag_key = 'treatment_dc_field' # if data_model == 3 and plot_key != 'specimen': # gonna need to read in more files print('-W- You are trying to plot measurements by {}'.format(plot_key)) print( ' By default, this information is not available in your measurement file.' ) print( ' Trying to acquire this information from {}'.format(dir_path)) con = cb.Contribution(dir_path) meas_df = con.propagate_location_to_measurements() if meas_df is None: print('-W- No data found in {}'.format(dir_path)) return if plot_key not in meas_df.columns: print('-W- Could not find required data.') print(' Try a different plot key.') return else: print('-I- Found {} information, continuing with plotting'.format( plot_key)) # need to take the data directly from the contribution here, to keep # location/site/sample columns in the measurements table data = con.tables['measurements'].convert_to_pmag_data_list() file_type = "measurements" else: data, file_type = pmag.magic_read(in_file) # read in data sids = pmag.get_specs(data) pmagplotlib.plot_init(FIG['exp'], 6, 6) # # # find desired intensity data # # get plotlist # plotlist = [] if data_model == 3: intlist = ['magn_moment', 'magn_volume', 'magn_mass', 'magnitude'] else: intlist = [ 'measurement_magnitude', 'measurement_magn_moment', 'measurement_magn_volume', 'measurement_magn_mass' ] IntMeths = [] # get all the records with this lab protocol #print('data', len(data)) #print('data[0]', data[0]) if data_model == 3: data = pmag.get_dictitem(data, 'method_codes', LP, 'has') else: data = pmag.get_dictitem(data, 'magic_method_codes', LP, 'has') Ints = {} NoInts, int_key = 1, "" for key in intlist: # get all non-blank data for intensity type Ints[key] = pmag.get_dictitem(data, key, '', 'F') if len(Ints[key]) > 0: NoInts = 0 if int_key == "": int_key = key if NoInts == 1: print('No intensity information found') sys.exit() for rec in Ints[int_key]: if rec[plot_key] not in plotlist: plotlist.append(rec[plot_key]) plotlist.sort() for plt in plotlist: print(plt) INTblock = [] # get data with right intensity info whose plot_key matches plot data = pmag.get_dictitem(Ints[int_key], plot_key, plt, 'T') # get a list of specimens with appropriate data sids = pmag.get_specs(data) if len(sids) > 0: title = data[0][plot_key] for s in sids: INTblock = [] # get data for each specimen if data_model == 3: sdata = pmag.get_dictitem(data, 'specimen', s, 'T') else: sdata = pmag.get_dictitem(data, 'er_specimen_name', s, 'T') for rec in sdata: INTblock.append( [float(rec[dmag_key]), 0, 0, float(rec[int_key]), 1, 'g']) pmagplotlib.plot_mag(FIG['exp'], INTblock, title, 0, units, norm) files = {} for key in list(FIG.keys()): files[key] = title + '_' + LP + '.' + fmt if plot == 0: pmagplotlib.draw_figs(FIG) ans = input(" S[a]ve to save plot, [q]uit, Return to continue: ") if ans == 'q': sys.exit() if ans == "a": pmagplotlib.save_plots(FIG, files) if plt != plotlist[ -1]: # if it isn't the last plot, init the next one pmagplotlib.plot_init(FIG['exp'], 6, 6) else: pmagplotlib.save_plots(FIG, files) pmagplotlib.clearFIG(FIG['exp'])
def main(): """ NAME revtest_magic.py DESCRIPTION calculates bootstrap statistics to test for antipodality INPUT FORMAT takes dec/inc data from sites table SYNTAX revtest_magic.py [command line options] OPTION -h prints help message and quits -f FILE, sets pmag_sites filename on command line -crd [s,g,t], set coordinate system, default is geographic -exc use criteria file to set acceptance criteria (only available for data model 3) -fmt [svg,png,jpg], sets format for image output -sav saves plot and quits -DM [2, 3] MagIC data model num, default is 3 """ if '-h' in sys.argv: # check if help is needed print(main.__doc__) sys.exit() # graceful quit dir_path = pmag.get_named_arg("-WD", ".") coord = pmag.get_named_arg("-crd", "0") # default to geographic coordinates if coord == 's': coord = '-1' elif coord == 'g': coord = '0' elif coord == 't': coord = '100' fmt = pmag.get_named_arg("-fmt", "svg") if '-sav' in sys.argv: plot = 1 data_model = int(float(pmag.get_named_arg("-DM"))) if data_model == 2: infile = pmag.get_named_arg("-f", "pmag_sites.txt") critfile = "pmag_criteria.txt" tilt_corr_col = 'site_tilt_correction' dec_col = "site_dec" inc_col = "site_inc" crit_code_col = "pmag_criteria_code" else: infile = pmag.get_named_arg("-f", "sites.txt") critfile = "criteria.txt" tilt_corr_col = "dir_tilt_correction" dec_col = "dir_dec" inc_col = "dir_inc" crit_code_col = "criterion" D = [] # infile = pmag.resolve_file_name(infile, dir_path) dir_path = os.path.split(infile)[0] critfile = pmag.resolve_file_name(critfile, dir_path) # if data_model == 2: Accept = ['site_k', 'site_alpha95', 'site_n', 'site_n_lines'] else: Accept = ['dir_k', 'dir_alpha95', 'dir_n_samples', 'dir_n_specimens_line'] data, file_type = pmag.magic_read(infile) if 'sites' not in file_type: print("Error opening file", file_type) sys.exit() # ordata,file_type=pmag.magic_read(orfile) SiteCrits = [] if '-exc' in sys.argv and data_model != 2: crits, file_type = pmag.magic_read(critfile) for crit in crits: if crit[crit_code_col] == "DE-SITE": SiteCrit = crit SiteCrits.append(SiteCrit) elif '-exc' in sys.argv and data_model == 2: print('-W- You have selected the -exc option, which is not available with MagIC data model 2.') for rec in data: if rec[tilt_corr_col] == coord: Dec = float(rec[dec_col]) Inc = float(rec[inc_col]) if '-exc' in sys.argv and data_model != 2: fail = False for SiteCrit in SiteCrits: for key in Accept: if key not in SiteCrit['table_column']: continue if key not in rec: continue if SiteCrit['criterion_value'] != "": op = OPS[SiteCrit['criterion_operation']] if not op(float(rec[key]), float(SiteCrit['criterion_value'])): fail = True if not fail: D.append([Dec, Inc, 1.]) else: D.append([Dec, Inc, 1.]) # set up plots CDF = {'X': 1, 'Y': 2, 'Z': 3} pmagplotlib.plot_init(CDF['X'], 5, 5) pmagplotlib.plot_init(CDF['Y'], 5, 5) pmagplotlib.plot_init(CDF['Z'], 5, 5) # # flip reverse mode # D1, D2 = pmag.flip(D) counter, NumSims = 0, 500 # # get bootstrapped means for each data set # if len(D1) < 5 or len(D2) < 5: print('not enough data in two different modes for reversals test') sys.exit() print('doing first mode, be patient') BDI1 = pmag.di_boot(D1) print('doing second mode, be patient') BDI2 = pmag.di_boot(D2) pmagplotlib.plot_com(CDF, BDI1, BDI2, [""]) files = {} for key in list(CDF.keys()): files[key] = 'REV'+'_'+key+'.'+fmt if plot == 0: pmagplotlib.draw_figs(CDF) ans = input("s[a]ve plots, [q]uit: ") if ans == 'a': pmagplotlib.save_plots(CDF, files) else: pmagplotlib.save_plots(CDF, files) sys.exit()
def main(): """ NAME eqarea_magic.py DESCRIPTION makes equal area projections from declination/inclination data SYNTAX eqarea_magic.py [command line options] INPUT takes magic formatted sites, samples, specimens, or measurements OPTIONS -h prints help message and quits -f FILE: specify input magic format file from magic, default='sites.txt' supported types=[measurements, specimens, samples, sites] -fsp FILE: specify specimen file name, (required if you want to plot measurements by sample) default='specimens.txt' -fsa FILE: specify sample file name, (required if you want to plot specimens by site) default='samples.txt' -fsi FILE: specify site file name, default='sites.txt' -obj OBJ: specify level of plot [all, sit, sam, spc], default is all -crd [s,g,t]: specify coordinate system, [s]pecimen, [g]eographic, [t]ilt adjusted default is geographic, unspecified assumed geographic -fmt [svg,png,jpg] format for output plots -ell [F,K,B,Be,Bv] plot Fisher, Kent, Bingham, Bootstrap ellipses or Boostrap eigenvectors -c plot as colour contour -sav save plot and quit quietly NOTE all: entire file; sit: site; sam: sample; spc: specimen """ # initialize some default variables FIG = {} # plot dictionary FIG['eqarea'] = 1 # eqarea is figure 1 plotE = 0 plt = 0 # default to not plotting verbose = pmagplotlib.verbose # extract arguments from sys.argv if '-h' in sys.argv: print(main.__doc__) sys.exit() dir_path = pmag.get_named_arg_from_sys("-WD", default_val=".") pmagplotlib.plot_init(FIG['eqarea'],5,5) in_file = pmag.get_named_arg_from_sys("-f", default_val="sites.txt") in_file = pmag.resolve_file_name(in_file, dir_path) if "-WD" not in sys.argv: dir_path = os.path.split(in_file)[0] #full_in_file = os.path.join(dir_path, in_file) plot_by = pmag.get_named_arg_from_sys("-obj", default_val="all").lower() spec_file = pmag.get_named_arg_from_sys("-fsp", default_val="specimens.txt") samp_file = pmag.get_named_arg_from_sys("-fsa", default_val="samples.txt") site_file = pmag.get_named_arg_from_sys("-fsi", default_val="sites.txt") if plot_by == 'all': plot_key = 'all' elif plot_by == 'sit': plot_key = 'site' elif plot_by == 'sam': plot_key = 'sample' elif plot_by == 'spc': plot_key = 'specimen' else: plot_by = 'all' plot_key = 'all' if '-c' in sys.argv: contour = 1 else: contour = 0 if '-sav' in sys.argv: plt = 1 verbose = 0 if '-ell' in sys.argv: plotE = 1 ind = sys.argv.index('-ell') ell_type = sys.argv[ind+1] ell_type = pmag.get_named_arg_from_sys("-ell", "F") dist = ell_type.upper() # if dist type is unrecognized, use Fisher if dist not in ['F', 'K', 'B', 'BE', 'BV']: dist = 'F' if dist == "BV": FIG['bdirs'] = 2 pmagplotlib.plot_init(FIG['bdirs'],5,5) crd = pmag.get_named_arg_from_sys("-crd", default_val="g") if crd == "s": coord = "-1" elif crd == "t": coord = "100" else: coord = "0" fmt = pmag.get_named_arg_from_sys("-fmt", "svg") dec_key = 'dir_dec' inc_key = 'dir_inc' tilt_key = 'dir_tilt_correction' #Dir_type_keys=['','site_direction_type','sample_direction_type','specimen_direction_type'] # fnames = {"specimens": spec_file, "samples": samp_file, 'sites': site_file} contribution = nb.Contribution(dir_path, custom_filenames=fnames, single_file=in_file) try: contribution.propagate_location_to_samples() contribution.propagate_location_to_specimens() contribution.propagate_location_to_measurements() except KeyError as ex: pass # the object that contains the DataFrame + useful helper methods: table_name = list(contribution.tables.keys())[0] data_container = contribution.tables[table_name] # the actual DataFrame: data = data_container.df if plot_key != "all" and plot_key not in data.columns: print("-E- You can't plot by {} with the data provided".format(plot_key)) return # add tilt key into DataFrame columns if it isn't there already if tilt_key not in data.columns: data.loc[:, tilt_key] = None if verbose: print(len(data), ' records read from ', in_file) # find desired dec,inc data: dir_type_key = '' # # get plotlist if not plotting all records # plotlist=[] if plot_key != "all": # return all where plot_key is not blank if plot_key not in data.columns: print('Can\'t plot by "{}". That header is not in infile: {}'.format(plot_key, in_file)) return plots = data[data[plot_key].notnull()] plotlist = plots[plot_key].unique() # grab unique values else: plotlist.append('All') for plot in plotlist: if verbose: print(plot) if plot == 'All': # plot everything at once plot_data = data else: # pull out only partial data plot_data = data[data[plot_key] == plot] DIblock = [] GCblock = [] # SLblock, SPblock = [], [] title = plot mode = 1 k = 0 if dec_key not in plot_data.columns: print("-W- No dec/inc data") continue # get all records where dec & inc values exist plot_data = plot_data[plot_data[dec_key].notnull() & plot_data[inc_key].notnull()] if plot_data.empty: continue # this sorting out is done in get_di_bock #if coord == '0': # geographic, use records with no tilt key (or tilt_key 0) # cond1 = plot_data[tilt_key].fillna('') == coord # cond2 = plot_data[tilt_key].isnull() # plot_data = plot_data[cond1 | cond2] #else: # not geographic coordinates, use only records with correct tilt_key # plot_data = plot_data[plot_data[tilt_key] == coord] # get metadata for naming the plot file locations = data_container.get_name('location', df_slice=plot_data) site = data_container.get_name('site', df_slice=plot_data) sample = data_container.get_name('sample', df_slice=plot_data) specimen = data_container.get_name('specimen', df_slice=plot_data) # make sure method_codes is in plot_data if 'method_codes' not in plot_data.columns: plot_data['method_codes'] = '' # get data blocks DIblock = data_container.get_di_block(df_slice=plot_data, tilt_corr=coord, excl=['DE-BFP']) #SLblock = [[ind, row['method_codes']] for ind, row in plot_data.iterrows()] # get great circles great_circle_data = data_container.get_records_for_code('DE-BFP', incl=True, use_slice=True, sli=plot_data) if len(great_circle_data) > 0: gc_cond = great_circle_data[tilt_key] == coord GCblock = [[float(row[dec_key]), float(row[inc_key])] for ind, row in great_circle_data[gc_cond].iterrows()] #SPblock = [[ind, row['method_codes']] for ind, row in great_circle_data[gc_cond].iterrows()] if len(DIblock) > 0: if contour == 0: pmagplotlib.plotEQ(FIG['eqarea'], DIblock, title) else: pmagplotlib.plotEQcont(FIG['eqarea'], DIblock) else: pmagplotlib.plotNET(FIG['eqarea']) if len(GCblock)>0: for rec in GCblock: pmagplotlib.plotC(FIG['eqarea'], rec, 90., 'g') if len(DIblock) == 0 and len(GCblock) == 0: if verbose: print("no records for plotting") continue #sys.exit() if plotE == 1: ppars = pmag.doprinc(DIblock) # get principal directions nDIs, rDIs, npars, rpars = [], [], [], [] for rec in DIblock: angle=pmag.angle([rec[0],rec[1]],[ppars['dec'],ppars['inc']]) if angle>90.: rDIs.append(rec) else: nDIs.append(rec) if dist=='B': # do on whole dataset etitle="Bingham confidence ellipse" bpars=pmag.dobingham(DIblock) for key in list(bpars.keys()): if key!='n' and verbose: print(" ",key, '%7.1f'%(bpars[key])) if key=='n' and verbose: print(" ",key, ' %i'%(bpars[key])) npars.append(bpars['dec']) npars.append(bpars['inc']) npars.append(bpars['Zeta']) npars.append(bpars['Zdec']) npars.append(bpars['Zinc']) npars.append(bpars['Eta']) npars.append(bpars['Edec']) npars.append(bpars['Einc']) if dist=='F': etitle="Fisher confidence cone" if len(nDIs)>2: fpars=pmag.fisher_mean(nDIs) for key in list(fpars.keys()): if key!='n' and verbose: print(" ",key, '%7.1f'%(fpars[key])) if key=='n' and verbose: print(" ",key, ' %i'%(fpars[key])) mode+=1 npars.append(fpars['dec']) npars.append(fpars['inc']) npars.append(fpars['alpha95']) # Beta npars.append(fpars['dec']) isign=old_div(abs(fpars['inc']),fpars['inc']) npars.append(fpars['inc']-isign*90.) #Beta inc npars.append(fpars['alpha95']) # gamma npars.append(fpars['dec']+90.) # Beta dec npars.append(0.) #Beta inc if len(rDIs)>2: fpars=pmag.fisher_mean(rDIs) if verbose: print("mode ",mode) for key in list(fpars.keys()): if key!='n' and verbose: print(" ",key, '%7.1f'%(fpars[key])) if key=='n' and verbose: print(" ",key, ' %i'%(fpars[key])) mode+=1 rpars.append(fpars['dec']) rpars.append(fpars['inc']) rpars.append(fpars['alpha95']) # Beta rpars.append(fpars['dec']) isign=old_div(abs(fpars['inc']),fpars['inc']) rpars.append(fpars['inc']-isign*90.) #Beta inc rpars.append(fpars['alpha95']) # gamma rpars.append(fpars['dec']+90.) # Beta dec rpars.append(0.) #Beta inc if dist=='K': etitle="Kent confidence ellipse" if len(nDIs)>3: kpars=pmag.dokent(nDIs,len(nDIs)) if verbose: print("mode ",mode) for key in list(kpars.keys()): if key!='n' and verbose: print(" ",key, '%7.1f'%(kpars[key])) if key=='n' and verbose: print(" ",key, ' %i'%(kpars[key])) mode+=1 npars.append(kpars['dec']) npars.append(kpars['inc']) npars.append(kpars['Zeta']) npars.append(kpars['Zdec']) npars.append(kpars['Zinc']) npars.append(kpars['Eta']) npars.append(kpars['Edec']) npars.append(kpars['Einc']) if len(rDIs)>3: kpars=pmag.dokent(rDIs,len(rDIs)) if verbose: print("mode ",mode) for key in list(kpars.keys()): if key!='n' and verbose: print(" ",key, '%7.1f'%(kpars[key])) if key=='n' and verbose: print(" ",key, ' %i'%(kpars[key])) mode+=1 rpars.append(kpars['dec']) rpars.append(kpars['inc']) rpars.append(kpars['Zeta']) rpars.append(kpars['Zdec']) rpars.append(kpars['Zinc']) rpars.append(kpars['Eta']) rpars.append(kpars['Edec']) rpars.append(kpars['Einc']) else: # assume bootstrap if dist=='BE': if len(nDIs)>5: BnDIs=pmag.di_boot(nDIs) Bkpars=pmag.dokent(BnDIs,1.) if verbose: print("mode ",mode) for key in list(Bkpars.keys()): if key!='n' and verbose: print(" ",key, '%7.1f'%(Bkpars[key])) if key=='n' and verbose: print(" ",key, ' %i'%(Bkpars[key])) mode+=1 npars.append(Bkpars['dec']) npars.append(Bkpars['inc']) npars.append(Bkpars['Zeta']) npars.append(Bkpars['Zdec']) npars.append(Bkpars['Zinc']) npars.append(Bkpars['Eta']) npars.append(Bkpars['Edec']) npars.append(Bkpars['Einc']) if len(rDIs)>5: BrDIs=pmag.di_boot(rDIs) Bkpars=pmag.dokent(BrDIs,1.) if verbose: print("mode ",mode) for key in list(Bkpars.keys()): if key!='n' and verbose: print(" ",key, '%7.1f'%(Bkpars[key])) if key=='n' and verbose: print(" ",key, ' %i'%(Bkpars[key])) mode+=1 rpars.append(Bkpars['dec']) rpars.append(Bkpars['inc']) rpars.append(Bkpars['Zeta']) rpars.append(Bkpars['Zdec']) rpars.append(Bkpars['Zinc']) rpars.append(Bkpars['Eta']) rpars.append(Bkpars['Edec']) rpars.append(Bkpars['Einc']) etitle="Bootstrapped confidence ellipse" elif dist=='BV': sym={'lower':['o','c'],'upper':['o','g'],'size':3,'edgecolor':'face'} if len(nDIs)>5: BnDIs=pmag.di_boot(nDIs) pmagplotlib.plotEQsym(FIG['bdirs'],BnDIs,'Bootstrapped Eigenvectors', sym) if len(rDIs)>5: BrDIs=pmag.di_boot(rDIs) if len(nDIs)>5: # plot on existing plots pmagplotlib.plotDIsym(FIG['bdirs'],BrDIs,sym) else: pmagplotlib.plotEQ(FIG['bdirs'],BrDIs,'Bootstrapped Eigenvectors') if dist=='B': if len(nDIs)> 3 or len(rDIs)>3: pmagplotlib.plotCONF(FIG['eqarea'],etitle,[],npars,0) elif len(nDIs)>3 and dist!='BV': pmagplotlib.plotCONF(FIG['eqarea'],etitle,[],npars,0) if len(rDIs)>3: pmagplotlib.plotCONF(FIG['eqarea'],etitle,[],rpars,0) elif len(rDIs)>3 and dist!='BV': pmagplotlib.plotCONF(FIG['eqarea'],etitle,[],rpars,0) for key in list(FIG.keys()): files = {} filename = pmag.get_named_arg_from_sys('-fname') if filename: # use provided filename filename+= '.' + fmt elif pmagplotlib.isServer: # use server plot naming convention filename='LO:_'+locations+'_SI:_'+site+'_SA:_'+sample+'_SP:_'+specimen+'_CO:_'+crd+'_TY:_'+key+'_.'+fmt elif plot_key == 'all': filename = 'all' if 'location' in plot_data.columns: locs = plot_data['location'].unique() loc_string = "_".join([loc.replace(' ', '_') for loc in locs]) filename += "_" + loc_string filename += "_" + crd + "_" + key filename += ".{}".format(fmt) else: # use more readable naming convention filename = '' # fix this if plot_by is location , for example use_names = {'location': [locations], 'site': [locations, site], 'sample': [locations, site, sample], 'specimen': [locations, site, sample, specimen]} use = use_names[plot_key] use.extend([crd, key]) for item in use: #[locations, site, sample, specimen, crd, key]: if item: item = item.replace(' ', '_') filename += item + '_' if filename.endswith('_'): filename = filename[:-1] filename += ".{}".format(fmt) files[key]=filename if pmagplotlib.isServer: black = '#000000' purple = '#800080' titles={} titles['eq']='Equal Area Plot' FIG = pmagplotlib.addBorders(FIG,titles,black,purple) pmagplotlib.saveP(FIG,files) if plt: pmagplotlib.saveP(FIG,files) continue if verbose: pmagplotlib.drawFIGS(FIG) ans=input(" S[a]ve to save plot, [q]uit, Return to continue: ") if ans == "q": sys.exit() if ans == "a": pmagplotlib.saveP(FIG,files) continue
def convert(**kwargs): # initialize some stuff methcode = "LP-NO" phi, theta, peakfield, labfield = 0, 0, 0, 0 pTRM, MD = 0, 0 dec = [315, 225, 180, 135, 45, 90, 270, 270, 270, 90, 180, 180, 0, 0, 0] inc = [0, 0, 0, 0, 0, -45, -45, 0, 45, 45, 45, -45, -90, -45, 45] tdec = [0, 90, 0, 180, 270, 0, 0, 90, 0] tinc = [0, 0, 90, 0, 0, -90, 0, 0, 90] missing = 1 demag = "N" citations = 'This study' fmt = 'old' Samps = [] trm = 0 irm = 0 #get args user = kwargs.get('user', '') dir_path = kwargs.get('dir_path', '.') output_dir_path = dir_path meas_file = kwargs.get('meas_file', 'measurements.txt') # measurement outfile meas_file = pmag.resolve_file_name(meas_file, output_dir_path) spec_file = kwargs.get('spec_file', 'specimens.txt') # specimen outfile spec_file = pmag.resolve_file_name(spec_file, output_dir_path) samp_file = kwargs.get('samp_file', 'samples.txt') # sample outfile samp_file = pmag.resolve_file_name(samp_file, output_dir_path) site_file = kwargs.get('site_file', 'sites.txt') # site outfile site_file = pmag.resolve_file_name(site_file, output_dir_path) loc_file = kwargs.get('loc_file', 'locations.txt') # location outfile loc_file = pmag.resolve_file_name(loc_file, output_dir_path) mag_file = kwargs.get('mag_file', '') mag_file = pmag.resolve_file_name(mag_file, dir_path) labfield = kwargs.get('labfield', '') if labfield: labfield = float(labfield) * 1e-6 else: labfield = 0 phi = kwargs.get('phi', 0) if phi: phi = float(phi) else: phi = 0 theta = kwargs.get('theta', 0) if theta: theta = float(theta) else: theta = 0 peakfield = kwargs.get('peakfield', 0) if peakfield: peakfield = float(peakfield) * 1e-3 else: peakfield = 0 specnum = kwargs.get('specnum', 0) samp_con = kwargs.get('samp_con', '1') location = kwargs.get('location', 'unknown') samp_infile = kwargs.get('samp_infile', '') syn = kwargs.get('syn', 0) institution = kwargs.get('institution', '') syntype = kwargs.get('syntype', '') inst = kwargs.get('inst', '') noave = kwargs.get('noave', 0) codelist = kwargs.get('codelist', '') coil = kwargs.get('coil', '') cooling_rates = kwargs.get('cooling_rates', '') lat = kwargs.get('lat', '') lon = kwargs.get('lon', '') timezone = kwargs.get('timezone', 'UTC') # make sure all initial values are correctly set up (whether they come from the command line or a GUI) if samp_infile: Samps, file_type = pmag.magic_read(samp_infile) if coil: coil = str(coil) methcode = "LP-IRM" irmunits = "V" if coil not in ["1", "2", "3"]: print(__doc__) print('not a valid coil specification') return False, '{} is not a valid coil specification'.format(coil) if mag_file: lines = pmag.open_file(mag_file) if not lines: print("you must provide a valid mag_file") return False, "you must provide a valid mag_file" if not mag_file: print(__doc__) print("mag_file field is required option") return False, "mag_file field is required option" if specnum != 0: specnum = -specnum if "4" == samp_con[0]: if "-" not in samp_con: print( "naming convention option [4] must be in form 4-Z where Z is an integer" ) print('---------------') return False, "naming convention option [4] must be in form 4-Z where Z is an integer" else: Z = samp_con.split("-")[1] samp_con = "4" if "7" == samp_con[0]: if "-" not in samp_con: print("option [7] must be in form 7-Z where Z is an integer") return False, "option [7] must be in form 7-Z where Z is an integer" else: Z = samp_con.split("-")[1] samp_con = "7" else: Z = 0 if codelist: codes = codelist.split(':') if "AF" in codes: demag = 'AF' if '-dc' not in sys.argv: methcode = "LT-AF-Z" if '-dc' in sys.argv: methcode = "LT-AF-I" if "T" in codes: demag = "T" if '-dc' not in sys.argv: methcode = "LT-T-Z" if '-dc' in sys.argv: methcode = "LT-T-I" if "I" in codes: methcode = "LP-IRM" irmunits = "mT" if "I3d" in codes: methcode = "LT-T-Z:LP-IRM-3D" if "S" in codes: demag = "S" methcode = "LP-PI-TRM:LP-PI-ALT-AFARM" trm_labfield = labfield ans = input("DC lab field for ARM step: [50uT] ") if ans == "": arm_labfield = 50e-6 else: arm_labfield = float(ans) * 1e-6 ans = input("temperature for total trm step: [600 C] ") if ans == "": trm_peakT = 600 + 273 # convert to kelvin else: trm_peakT = float(ans) + 273 # convert to kelvin if "G" in codes: methcode = "LT-AF-G" if "D" in codes: methcode = "LT-AF-D" if "TRM" in codes: demag = "T" trm = 1 if "CR" in codes: demag = "T" cooling_rate_experiment = 1 cooling_rates_list = cooling_rates.split( ',') # command_line does not exist in this code #if command_line: # ind=sys.argv.index("CR") # cooling_rates=sys.argv[ind+1] # cooling_rates_list=cooling_rates.split(',') #else: # cooling_rates_list=str(cooling_rates).split(',') if demag == "T" and "ANI" in codes: methcode = "LP-AN-TRM" if demag == "T" and "CR" in codes: methcode = "LP-CR-TRM" if demag == "AF" and "ANI" in codes: methcode = "LP-AN-ARM" if labfield == 0: labfield = 50e-6 if peakfield == 0: peakfield = .180 MeasRecs, SpecRecs, SampRecs, SiteRecs, LocRecs = [], [], [], [], [] version_num = pmag.get_version() ################################## for line in lines: instcode = "" if len(line) > 2: MeasRec, SpecRec, SampRec, SiteRec, LocRec = {}, {}, {}, {}, {} MeasRec['software_packages'] = version_num MeasRec["description"] = "" MeasRec["treat_temp"] = '%8.3e' % (273) # room temp in kelvin MeasRec["meas_temp"] = '%8.3e' % (273) # room temp in kelvin MeasRec["treat_ac_field"] = '0' MeasRec["treat_dc_field"] = '0' MeasRec["treat_dc_field_phi"] = '0' MeasRec["treat_dc_field_theta"] = '0' meas_type = "LT-NO" rec = line.split() try: float(rec[0]) print("No specimen name for line #%d in the measurement file" % lines.index(line)) continue except ValueError: pass if rec[1] == ".00": rec[1] = "0.00" treat = rec[1].split('.') if methcode == "LP-IRM": if irmunits == 'mT': labfield = float(treat[0]) * 1e-3 else: labfield = pmag.getfield(irmunits, coil, treat[0]) if rec[1][0] != "-": phi, theta = 0., 90. else: phi, theta = 0., -90. meas_type = "LT-IRM" MeasRec["treat_dc_field"] = '%8.3e' % (labfield) MeasRec["treat_dc_field_phi"] = '%7.1f' % (phi) MeasRec["treat_dc_field_theta"] = '%7.1f' % (theta) if len(rec) > 6: code1 = rec[6].split( ';') # break e.g., 10/15/02;7:45 indo date and time if len(code1) == 2: # old format with AM/PM missing = 0 code2 = code1[0].split('/') # break date into mon/day/year code3 = rec[7].split( ';' ) # break e.g., AM;C34;200 into time;instr/axes/measuring pos;number of measurements yy = int(code2[2]) if yy < 90: yyyy = str(2000 + yy) else: yyyy = str(1900 + yy) mm = int(code2[0]) if mm < 10: mm = "0" + str(mm) else: mm = str(mm) dd = int(code2[1]) if dd < 10: dd = "0" + str(dd) else: dd = str(dd) time = code1[1].split(':') hh = int(time[0]) if code3[0] == "PM": hh = hh + 12 if hh < 10: hh = "0" + str(hh) else: hh = str(hh) min = int(time[1]) if min < 10: min = "0" + str(min) else: min = str(min) dt = yyyy + ":" + mm + ":" + dd + ":" + hh + ":" + min + ":00" local = pytz.timezone(timezone) naive = datetime.datetime.strptime(dt, "%Y:%m:%d:%H:%M:%S") local_dt = local.localize(naive, is_dst=None) utc_dt = local_dt.astimezone(pytz.utc) MeasRec["timestamp"] = utc_dt.strftime( "%Y-%m-%dT%H:%M:%S") + "Z" if inst == "": if code3[1][0] == 'C': instcode = 'SIO-bubba' if code3[1][0] == 'G': instcode = 'SIO-flo' else: instcode = '' MeasRec["meas_n_orient"] = code3[1][2] elif len(code1) > 2: # newest format (cryo7 or later) if "LP-AN-ARM" not in methcode: labfield = 0 fmt = 'new' date = code1[0].split('/') # break date into mon/day/year yy = int(date[2]) if yy < 90: yyyy = str(2000 + yy) else: yyyy = str(1900 + yy) mm = int(date[0]) if mm < 10: mm = "0" + str(mm) else: mm = str(mm) dd = int(date[1]) if dd < 10: dd = "0" + str(dd) else: dd = str(dd) time = code1[1].split(':') hh = int(time[0]) if hh < 10: hh = "0" + str(hh) else: hh = str(hh) min = int(time[1]) if min < 10: min = "0" + str(min) else: min = str(min) dt = yyyy + ":" + mm + ":" + dd + ":" + hh + ":" + min + ":00" local = pytz.timezone(timezone) naive = datetime.datetime.strptime(dt, "%Y:%m:%d:%H:%M:%S") local_dt = local.localize(naive, is_dst=None) utc_dt = local_dt.astimezone(pytz.utc) MeasRec["timestamp"] = utc_dt.strftime( "%Y-%m-%dT%H:%M:%S") + "Z" if inst == "": if code1[6][0] == 'C': instcode = 'SIO-bubba' if code1[6][0] == 'G': instcode = 'SIO-flo' else: instcode = '' if len(code1) > 1: MeasRec["meas_n_orient"] = code1[6][2] else: MeasRec["meas_n_orient"] = code1[ 7] # takes care of awkward format with bubba and flo being different if user == "": user = code1[5] if code1[2][-1] == 'C': demag = "T" if code1[4] == 'microT' and float( code1[3] ) != 0. and "LP-AN-ARM" not in methcode: labfield = float(code1[3]) * 1e-6 if code1[2] == 'mT' and methcode != "LP-IRM": demag = "AF" if code1[4] == 'microT' and float(code1[3]) != 0.: labfield = float(code1[3]) * 1e-6 if code1[ 4] == 'microT' and labfield != 0. and meas_type != "LT-IRM": phi, theta = 0., -90. if demag == "T": meas_type = "LT-T-I" if demag == "AF": meas_type = "LT-AF-I" MeasRec["treat_dc_field"] = '%8.3e' % (labfield) MeasRec["treat_dc_field_phi"] = '%7.1f' % (phi) MeasRec["treat_dc_field_theta"] = '%7.1f' % (theta) if code1[ 4] == '' or labfield == 0. and meas_type != "LT-IRM": if demag == 'T': meas_type = "LT-T-Z" if demag == "AF": meas_type = "LT-AF-Z" MeasRec["treat_dc_field"] = '0' if syn == 0: specimen = rec[0] MeasRec["specimen"] = specimen if specnum != 0: sample = rec[0][:specnum] else: sample = rec[0] if samp_infile and Samps: # if samp_infile was provided AND yielded sample data samp = pmag.get_dictitem(Samps, 'sample', sample, 'T') if len(samp) > 0: location = samp[0]["location"] site = samp[0]["site"] else: location = '' site = '' else: site = pmag.parse_site(sample, samp_con, Z) if location != '' and location not in [ x['location'] if 'location' in list(x.keys()) else '' for x in LocRecs ]: LocRec['location'] = location LocRec['lat_n'] = lat LocRec['lat_s'] = lat LocRec['lon_e'] = lon LocRec['lon_w'] = lon LocRecs.append(LocRec) if site != '' and site not in [ x['site'] if 'site' in list(x.keys()) else '' for x in SiteRecs ]: SiteRec['location'] = location SiteRec['site'] = site SiteRec['lat'] = lat SiteRec['lon'] = lon SiteRecs.append(SiteRec) if sample != '' and sample not in [ x['sample'] if 'sample' in list(x.keys()) else '' for x in SampRecs ]: SampRec['site'] = site SampRec['sample'] = sample SampRecs.append(SampRec) if specimen != '' and specimen not in [ x['specimen'] if 'specimen' in list(x.keys()) else '' for x in SpecRecs ]: SpecRec["specimen"] = specimen SpecRec['sample'] = sample SpecRecs.append(SpecRec) else: specimen = rec[0] MeasRec["specimen"] = specimen if specnum != 0: sample = rec[0][:specnum] else: sample = rec[0] site = pmag.parse_site(sample, samp_con, Z) if location != '' and location not in [ x['location'] if 'location' in list(x.keys()) else '' for x in LocRecs ]: LocRec['location'] = location LocRec['lat_n'] = lat LocRec['lat_s'] = lat LocRec['lon_e'] = lon LocRec['lon_w'] = lon LocRecs.append(LocRec) if site != '' and site not in [ x['site'] if 'site' in list(x.keys()) else '' for x in SiteRecs ]: SiteRec['location'] = location SiteRec['site'] = site SiteRec['lat'] = lat SiteRec['lon'] = lon SiteRecs.append(SiteRec) if sample != '' and sample not in [ x['sample'] if 'sample' in list(x.keys()) else '' for x in SampRecs ]: SampRec['site'] = site SampRec['sample'] = sample SampRecs.append(SampRec) if specimen != '' and specimen not in [ x['specimen'] if 'specimen' in list(x.keys()) else '' for x in SpecRecs ]: SpecRec["specimen"] = specimen SpecRec['sample'] = sample SpecRecs.append(SpecRec) SampRec["institution"] = institution SampRec["material_type"] = syntype #MeasRec["sample"]=sample if float(rec[1]) == 0: pass elif demag == "AF": if methcode != "LP-AN-ARM": MeasRec["treat_ac_field"] = '%8.3e' % ( float(rec[1]) * 1e-3) # peak field in tesla if meas_type == "LT-AF-Z": MeasRec["treat_dc_field"] = '0' else: # AARM experiment if treat[1][0] == '0': meas_type = "LT-AF-Z:LP-AN-ARM:" MeasRec["treat_ac_field"] = '%8.3e' % ( peakfield) # peak field in tesla MeasRec["treat_dc_field"] = '%8.3e' % (0) if labfield != 0 and methcode != "LP-AN-ARM": print( "Warning - inconsistency in mag file with lab field - overriding file with 0" ) else: meas_type = "LT-AF-I:LP-AN-ARM" ipos = int(treat[0]) - 1 MeasRec["treat_dc_field_phi"] = '%7.1f' % (dec[ipos]) MeasRec["treat_dc_field_theta"] = '%7.1f' % (inc[ipos]) MeasRec["treat_dc_field"] = '%8.3e' % (labfield) MeasRec["treat_ac_field"] = '%8.3e' % ( peakfield) # peak field in tesla elif demag == "T" and methcode == "LP-AN-TRM": MeasRec["treat_temp"] = '%8.3e' % (float(treat[0]) + 273. ) # temp in kelvin if treat[1][0] == '0': meas_type = "LT-T-Z:LP-AN-TRM" MeasRec["treat_dc_field"] = '%8.3e' % (0) MeasRec["treat_dc_field_phi"] = '0' MeasRec["treat_dc_field_theta"] = '0' else: MeasRec["treat_dc_field"] = '%8.3e' % (labfield) if treat[1][ 0] == '7': # alteration check as final measurement meas_type = "LT-PTRM-I:LP-AN-TRM" else: meas_type = "LT-T-I:LP-AN-TRM" # find the direction of the lab field in two ways: # (1) using the treatment coding (XX.1=+x, XX.2=+y, XX.3=+z, XX.4=-x, XX.5=-y, XX.6=-z) ipos_code = int(treat[1][0]) - 1 # (2) using the magnetization DEC = float(rec[4]) INC = float(rec[5]) if INC < 45 and INC > -45: if DEC > 315 or DEC < 45: ipos_guess = 0 if DEC > 45 and DEC < 135: ipos_guess = 1 if DEC > 135 and DEC < 225: ipos_guess = 3 if DEC > 225 and DEC < 315: ipos_guess = 4 else: if INC > 45: ipos_guess = 2 if INC < -45: ipos_guess = 5 # prefer the guess over the code ipos = ipos_guess MeasRec["treat_dc_field_phi"] = '%7.1f' % (tdec[ipos]) MeasRec["treat_dc_field_theta"] = '%7.1f' % (tinc[ipos]) # check it if ipos_guess != ipos_code and treat[1][0] != '7': print( "-E- ERROR: check specimen %s step %s, ATRM measurements, coding does not match the direction of the lab field!" % (rec[0], ".".join(list(treat)))) elif demag == "S": # Shaw experiment if treat[1][1] == '0': if int(treat[0]) != 0: MeasRec["treat_ac_field"] = '%8.3e' % ( float(treat[0]) * 1e-3) # AF field in tesla MeasRec["treat_dc_field"] = '0' meas_type = "LT-AF-Z" # first AF else: meas_type = "LT-NO" MeasRec["treat_ac_field"] = '0' MeasRec["treat_dc_field"] = '0' elif treat[1][1] == '1': if int(treat[0]) == 0: MeasRec["treat_ac_field"] = '%8.3e' % ( peakfield) # peak field in tesla MeasRec["treat_dc_field"] = '%8.3e' % (arm_labfield) MeasRec["treat_dc_field_phi"] = '%7.1f' % (phi) MeasRec["treat_dc_field_theta"] = '%7.1f' % (theta) meas_type = "LT-AF-I" else: MeasRec["treat_ac_field"] = '%8.3e' % ( float(treat[0]) * 1e-3) # AF field in tesla MeasRec["treat_dc_field"] = '0' meas_type = "LT-AF-Z" elif treat[1][1] == '2': if int(treat[0]) == 0: MeasRec["treat_ac_field"] = '0' MeasRec["treat_dc_field"] = '%8.3e' % (trm_labfield) MeasRec["treat_dc_field_phi"] = '%7.1f' % (phi) MeasRec["treat_dc_field_theta"] = '%7.1f' % (theta) MeasRec["treat_temp"] = '%8.3e' % (trm_peakT) meas_type = "LT-T-I" else: MeasRec["treat_ac_field"] = '%8.3e' % ( float(treat[0]) * 1e-3) # AF field in tesla MeasRec["treat_dc_field"] = '0' meas_type = "LT-AF-Z" elif treat[1][1] == '3': if int(treat[0]) == 0: MeasRec["treat_ac_field"] = '%8.3e' % ( peakfield) # peak field in tesla MeasRec["treat_dc_field"] = '%8.3e' % (arm_labfield) MeasRec["treat_dc_field_phi"] = '%7.1f' % (phi) MeasRec["treat_dc_field_theta"] = '%7.1f' % (theta) meas_type = "LT-AF-I" else: MeasRec["treat_ac_field"] = '%8.3e' % ( float(treat[0]) * 1e-3) # AF field in tesla MeasRec["treat_dc_field"] = '0' meas_type = "LT-AF-Z" # Cooling rate experient # added by rshaar elif demag == "T" and methcode == "LP-CR-TRM": MeasRec["treat_temp"] = '%8.3e' % (float(treat[0]) + 273. ) # temp in kelvin if treat[1][0] == '0': meas_type = "LT-T-Z:LP-CR-TRM" MeasRec["treat_dc_field"] = '%8.3e' % (0) MeasRec["treat_dc_field_phi"] = '0' MeasRec["treat_dc_field_theta"] = '0' else: MeasRec["treat_dc_field"] = '%8.3e' % (labfield) if treat[1][ 0] == '7': # alteration check as final measurement meas_type = "LT-PTRM-I:LP-CR-TRM" else: meas_type = "LT-T-I:LP-CR-TRM" MeasRec["treat_dc_field_phi"] = '%7.1f' % ( phi) # labfield phi MeasRec["treat_dc_field_theta"] = '%7.1f' % ( theta) # labfield theta indx = int(treat[1][0]) - 1 # alteration check matjed as 0.7 in the measurement file if indx == 6: cooling_time = cooling_rates_list[-1] else: cooling_time = cooling_rates_list[indx] MeasRec[ "description"] = "cooling_rate" + ":" + cooling_time + ":" + "K/min" noave = 1 elif demag != 'N': if len(treat) == 1: treat.append('0') MeasRec["treat_temp"] = '%8.3e' % (float(treat[0]) + 273. ) # temp in kelvin if trm == 0: # demag=T and not trmaq if treat[1][0] == '0': meas_type = "LT-T-Z" else: MeasRec["treat_dc_field"] = '%8.3e' % ( labfield ) # labfield in tesla (convert from microT) MeasRec["treat_dc_field_phi"] = '%7.1f' % ( phi) # labfield phi MeasRec["treat_dc_field_theta"] = '%7.1f' % ( theta) # labfield theta if treat[1][0] == '1': meas_type = "LT-T-I" # in-field thermal step if treat[1][0] == '2': meas_type = "LT-PTRM-I" # pTRM check pTRM = 1 if treat[1][0] == '3': MeasRec[ "treat_dc_field"] = '0' # this is a zero field step meas_type = "LT-PTRM-MD" # pTRM tail check else: labfield = float(treat[1]) * 1e-6 MeasRec["treat_dc_field"] = '%8.3e' % ( labfield) # labfield in tesla (convert from microT) MeasRec["treat_dc_field_phi"] = '%7.1f' % ( phi) # labfield phi MeasRec["treat_dc_field_theta"] = '%7.1f' % ( theta) # labfield theta meas_type = "LT-T-I:LP-TRM" # trm acquisition experiment MeasRec["dir_csd"] = rec[2] MeasRec["magn_moment"] = '%10.3e' % (float(rec[3]) * 1e-3 ) # moment in Am^2 (from emu) MeasRec["dir_dec"] = rec[4] MeasRec["dir_inc"] = rec[5] MeasRec["instrument_codes"] = instcode MeasRec["analysts"] = user MeasRec["citations"] = citations if "LP-IRM-3D" in methcode: meas_type = methcode #MeasRec["method_codes"]=methcode.strip(':') MeasRec["method_codes"] = meas_type MeasRec["quality"] = 'g' if 'std' in rec[0]: MeasRec["standard"] = 's' else: MeasRec["standard"] = 'u' MeasRec["treat_step_num"] = '1' #print MeasRec['treat_temp'] MeasRecs.append(MeasRec) con = nb.Contribution(output_dir_path, read_tables=[]) # create MagIC tables con.add_magic_table_from_data(dtype='specimens', data=SpecRecs) con.add_magic_table_from_data(dtype='samples', data=SampRecs) con.add_magic_table_from_data(dtype='sites', data=SiteRecs) con.add_magic_table_from_data(dtype='locations', data=LocRecs) MeasOuts = pmag.measurements_methods3(MeasRecs, noave) con.add_magic_table_from_data(dtype='measurements', data=MeasOuts) # write MagIC tables to file con.tables['specimens'].write_magic_file(custom_name=spec_file) con.tables['samples'].write_magic_file(custom_name=samp_file) con.tables['sites'].write_magic_file(custom_name=site_file) con.tables['locations'].write_magic_file(custom_name=loc_file) meas_file = con.tables['measurements'].write_magic_file( custom_name=meas_file) return True, meas_file