def main(): """ NAME di_tilt.py DESCRIPTION rotates geographic coordinate dec, inc data to stratigraphic coordinates using the dip and dip direction (strike+90, dip if dip to right of strike) INPUT FORMAT declination inclination dip_direction dip SYNTAX di_tilt.py [-h][-i][-f FILE] [< filename ] OPTIONS -h prints help message and quits -i for interactive data entry -f FILE command line entry of file name -F OFILE, specify output file, default is standard output OUTPUT: declination inclination """ if '-h' in sys.argv: print main.__doc__ sys.exit() if '-F' in sys.argv: ind = sys.argv.index('-F') ofile = sys.argv[ind + 1] out = open(ofile, 'w') print ofile, ' opened for output' else: ofile = "" if '-i' in sys.argv: # interactive flag while 1: try: Dec = float(raw_input("Declination: <cntl-D> to quit ")) except: print "\n Good-bye\n" sys.exit() Inc = float(raw_input("Inclination: ")) Dip_dir = float(raw_input("Dip direction: ")) Dip = float(raw_input("Dip: ")) print '%7.1f %7.1f' % (pmag.dotilt(Dec, Inc, Dip_dir, Dip)) elif '-f' in sys.argv: ind = sys.argv.index('-f') file = sys.argv[ind + 1] data = numpy.loadtxt(file) else: data = numpy.loadtxt( sys.stdin, dtype=numpy.float) # read in the data from the datafile D, I = pmag.dotilt_V(data) for k in range(len(D)): if ofile == "": print '%7.1f %7.1f' % (D[k], I[k]) else: out.write('%7.1f %7.1f\n' % (D[k], I[k]))
def main(): """ NAME di_tilt.py DESCRIPTION rotates geographic coordinate dec, inc data to stratigraphic coordinates using the dip and dip direction (strike+90, dip if dip to right of strike) INPUT FORMAT declination inclination dip_direction dip SYNTAX di_tilt.py [-h][-i][-f FILE] [< filename ] OPTIONS -h prints help message and quits -i for interactive data entry -f FILE command line entry of file name -F OFILE, specify output file, default is standard output OUTPUT: declination inclination """ if "-h" in sys.argv: print main.__doc__ sys.exit() if "-F" in sys.argv: ind = sys.argv.index("-F") ofile = sys.argv[ind + 1] out = open(ofile, "w") print ofile, " opened for output" else: ofile = "" if "-i" in sys.argv: # interactive flag while 1: try: Dec = float(raw_input("Declination: <cntl-D> to quit ")) except: print "\n Good-bye\n" sys.exit() Inc = float(raw_input("Inclination: ")) Dip_dir = float(raw_input("Dip direction: ")) Dip = float(raw_input("Dip: ")) print "%7.1f %7.1f" % (pmag.dotilt(Dec, Inc, Dip_dir, Dip)) elif "-f" in sys.argv: ind = sys.argv.index("-f") file = sys.argv[ind + 1] data = numpy.loadtxt(file) else: data = numpy.loadtxt(sys.stdin, dtype=numpy.float) # read in the data from the datafile D, I = pmag.dotilt_V(data) for k in range(len(D)): if ofile == "": print "%7.1f %7.1f" % (D[k], I[k]) else: out.write("%7.1f %7.1f\n" % (D[k], I[k]))
def main(): """ NAME zeq_magic.py DESCRIPTION reads in magic_measurements formatted file, makes plots of remanence decay during demagnetization experiments. Reads in prior interpretations saved in a pmag_specimens formatted file [and allows re-interpretations of best-fit lines and planes and saves (revised or new) interpretations in a pmag_specimens file. interpretations are saved in the coordinate system used. Also allows judicious editting of measurements to eliminate "bad" measurements. These are marked as such in the magic_measurements input file. they are NOT deleted, just ignored. ] Bracketed part not yet implemented SYNTAX zeq_magic.py [command line options] OPTIONS -h prints help message and quits -f MEASFILE: sets measurements format input file, default: measurements.txt -fsp SPECFILE: sets specimens format file with prior interpreations, default: specimens.txt -fsa SAMPFILE: sets samples format file sample=>site information, default: samples.txt -fsi SITEFILE: sets sites format file with site=>location informationprior interpreations, default: samples.txt -Fp PLTFILE: sets filename for saved plot, default is name_type.fmt (where type is zijd, eqarea or decay curve) -crd [s,g,t]: sets coordinate system, g=geographic, t=tilt adjusted, default: specimen coordinate system -spc SPEC plots single specimen SPEC, saves plot with specified format with optional -dir settings and quits -dir [L,P,F][beg][end]: sets calculation type for principal component analysis, default is none beg: starting step for PCA calculation end: ending step for PCA calculation [L,P,F]: calculation type for line, plane or fisher mean must be used with -spc option -fmt FMT: set format of saved plot [png,svg,jpg] -A: suppresses averaging of replicate measurements, default is to average -sav: saves all plots without review SCREEN OUTPUT: Specimen, N, a95, StepMin, StepMax, Dec, Inc, calculation type """ # initialize some variables doave, e, b = 1, 0, 0 # average replicates, initial end and beginning step intlist = ['magn_moment', 'magn_volume', 'magn_mass', 'magnitude'] plots, coord = 0, 's' noorient = 0 version_num = pmag.get_version() verbose = pmagplotlib.verbose calculation_type, fmt = "", "svg" user, spec_keys, locname = "", [], '' geo, tilt, ask = 0, 0, 0 PriorRecs = [] # empty list for prior interpretations backup = 0 specimen = "" # can skip everything and just plot one specimen with bounds e,b if '-h' in sys.argv: print(main.__doc__) sys.exit() dir_path = pmag.get_named_arg_from_sys("-WD", default_val=os.getcwd()) meas_file = pmag.get_named_arg_from_sys("-f", default_val="measurements.txt") 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") #meas_file = os.path.join(dir_path, meas_file) #spec_file = os.path.join(dir_path, spec_file) #samp_file = os.path.join(dir_path, samp_file) #site_file = os.path.join(dir_path, site_file) plot_file = pmag.get_named_arg_from_sys("-Fp", default_val="") crd = pmag.get_named_arg_from_sys("-crd", default_val="s") if crd == "s": coord = "-1" elif crd == "t": coord = "100" else: coord = "0" fmt = pmag.get_named_arg_from_sys("-fmt", "svg") specimen = pmag.get_named_arg_from_sys("-spc", default_val="") beg_pca, end_pca = "", "" if '-dir' in sys.argv: ind = sys.argv.index('-dir') direction_type = sys.argv[ind + 1] beg_pca = int(sys.argv[ind + 2]) end_pca = int(sys.argv[ind + 3]) if direction_type == 'L': calculation_type = 'DE-BFL' if direction_type == 'P': calculation_type = 'DE-BFP' if direction_type == 'F': calculation_type = 'DE-FM' if '-A' in sys.argv: doave = 0 if '-sav' in sys.argv: plots, verbose = 1, 0 # first_save = 1 fnames = { 'measurements': meas_file, 'specimens': spec_file, 'samples': samp_file, 'sites': site_file } contribution = nb.Contribution( dir_path, custom_filenames=fnames, read_tables=['measurements', 'specimens', 'samples', 'sites']) # # import specimens specimen_cols = [ 'analysts', 'aniso_ftest', 'aniso_ftest12', 'aniso_ftest23', 'aniso_s', 'aniso_s_mean', 'aniso_s_n_measurements', 'aniso_s_sigma', 'aniso_s_unit', 'aniso_tilt_correction', 'aniso_type', 'aniso_v1', 'aniso_v2', 'aniso_v3', 'citations', 'description', 'dir_alpha95', 'dir_comp', 'dir_dec', 'dir_inc', 'dir_mad_free', 'dir_n_measurements', 'dir_tilt_correction', 'experiments', 'geologic_classes', 'geologic_types', 'hyst_bc', 'hyst_bcr', 'hyst_mr_moment', 'hyst_ms_moment', 'int_abs', 'int_b', 'int_b_beta', 'int_b_sigma', 'int_corr', 'int_dang', 'int_drats', 'int_f', 'int_fvds', 'int_gamma', 'int_mad_free', 'int_md', 'int_n_measurements', 'int_n_ptrm', 'int_q', 'int_rsc', 'int_treat_dc_field', 'lithologies', 'meas_step_max', 'meas_step_min', 'meas_step_unit', 'method_codes', 'sample', 'software_packages', 'specimen' ] if 'specimens' in contribution.tables: # contribution.propagate_name_down('sample','measurements') spec_container = contribution.tables['specimens'] prior_spec_data = spec_container.get_records_for_code( 'LP-DIR', strict_match=False ) # look up all prior directional interpretations # # tie sample names to measurement data # else: spec_container, prior_spec_data = None, [] # # import samples for orientation info # if 'samples' in contribution.tables: # contribution.propagate_name_down('site','measurements') contribution.propagate_cols( col_names=['azimuth', 'dip', 'orientation_flag'], target_df_name='measurements', source_df_name='samples') # # define figure numbers for equal area, zijderveld, # and intensity vs. demagnetiztion step respectively # ZED = {} ZED['eqarea'], ZED['zijd'], ZED['demag'] = 1, 2, 3 pmagplotlib.plot_init(ZED['eqarea'], 6, 6) pmagplotlib.plot_init(ZED['zijd'], 6, 6) pmagplotlib.plot_init(ZED['demag'], 6, 6) # save_pca=0 angle, direction_type, setangle = "", "", 0 # create measurement dataframe # meas_container = contribution.tables['measurements'] meas_data = meas_container.df # meas_data = meas_data[meas_data['method_codes'].str.contains( 'LT-NO|LT-AF-Z|LT-T-Z|LT-M-Z') == True] # fish out steps for plotting meas_data = meas_data[meas_data['method_codes'].str.contains( 'AN|ARM|LP-TRM|LP-PI-ARM') == False] # strip out unwanted experiments intensity_types = [ col_name for col_name in meas_data.columns if col_name in intlist ] # plot first intensity method found - normalized to initial value anyway - # doesn't matter which used int_key = intensity_types[0] # get all the non-null intensity records of the same type meas_data = meas_data[meas_data[int_key].notnull()] if 'flag' not in meas_data.columns: meas_data['flag'] = 'g' # set the default flag to good # need to treat LP-NO specially for af data, treatment should be zero, # otherwise 273. meas_data['treatment'] = meas_data['treat_ac_field'].where( cond=meas_data['treat_ac_field'] != '0', other=meas_data['treat_temp']) meas_data['ZI'] = 1 # initialize these to one meas_data['instrument_codes'] = "" # initialize these to blank # for unusual case of microwave power.... if 'treat_mw_power' in meas_data.columns: meas_data.loc[ meas_data.treat_mw_power != 0, 'treatment'] = meas_data.treat_mw_power * meas_data.treat_mw_time # # get list of unique specimen names from measurement data # # this is a list of all the specimen names specimen_names = meas_data.specimen.unique() specimen_names = specimen_names.tolist() specimen_names.sort() # # set up new DataFrame for this sessions specimen interpretations # data_container = nb.MagicDataFrame(dtype='specimens', columns=specimen_cols) # this is for interpretations from this session current_spec_data = data_container.df locname = 'LookItUp' if specimen == "": k = 0 else: k = specimen_names.index(specimen) # let's look at the data now while k < len(specimen_names): # set the current specimen for plotting this_specimen = specimen_names[k] if verbose and this_specimen != "": print(this_specimen, k + 1, 'out of ', len(specimen_names)) if setangle == 0: angle = "" this_specimen_measurements = meas_data[ meas_data['specimen'].str.contains( this_specimen) == True] # fish out this specimen this_specimen_measurements = this_specimen_measurements[ this_specimen_measurements['flag'].str.contains( 'g') == True] # fish out this specimen if len(this_specimen_measurements) != 0: # if there are measurements # # set up datablock [[treatment,dec, inc, int, direction_type],[....]] # # # figure out the method codes # units, methods, title = "", "", this_specimen # this is a list of all the specimen method codes` meas_meths = this_specimen_measurements.method_codes.unique() tr = pd.to_numeric(this_specimen_measurements.treatment).tolist() if set(tr) == set([0]): k += 1 continue for m in meas_meths: if 'LT-AF-Z' in m: units = 'T' # units include tesla tr[0] = 0 if 'LT-T-Z' in m: units = units + ":K" # units include kelvin if 'LT-M-Z' in m: units = units + ':J' # units include joules tr[0] = 0 units = units.strip(':') # strip off extra colons if 'LP-' in m: methods = methods + ":" + m decs = pd.to_numeric(this_specimen_measurements.dir_dec).tolist() incs = pd.to_numeric(this_specimen_measurements.dir_inc).tolist() # # fix the coordinate system # if coord != '-1': # need to transform coordinates to geographic azimuths = pd.to_numeric(this_specimen_measurements.azimuth ).tolist() # get the azimuths # get the azimuths dips = pd.to_numeric(this_specimen_measurements.dip).tolist() dirs = [decs, incs, azimuths, dips] # this transposes the columns and rows of the list of lists dirs_geo = np.array(list(map(list, list(zip(*dirs))))) decs, incs = pmag.dogeo_V(dirs_geo) if coord == '100': # need to do tilt correction too bed_dip_dirs = pd.to_numeric( this_specimen_measurements.bed_dip_dir).tolist( ) # get the azimuths bed_dips = pd.to_numeric(this_specimen_measurements.bed_dip ).tolist() # get the azimuths dirs = [decs, incs, bed_dip_dirs, bed_dips] # this transposes the columns and rows of the list of lists dirs_tilt = np.array(list(map(list, list(zip(*dirs))))) decs, incs = pmag.dotilt_V(dirs_tilt) title = title + '_t' else: title = title + '_g' if angle == "": angle = decs[0] ints = pd.to_numeric(this_specimen_measurements[int_key]).tolist() ZI = this_specimen_measurements.ZI.tolist() flags = this_specimen_measurements.flag.tolist() codes = this_specimen_measurements.instrument_codes.tolist() datalist = [tr, decs, incs, ints, ZI, flags, codes] # this transposes the columns and rows of the list of lists datablock = list(map(list, list(zip(*datalist)))) pmagplotlib.plotZED(ZED, datablock, angle, title, units) if verbose: pmagplotlib.drawFIGS(ZED) # # collect info for current_specimen_interpretation dictionary # if beg_pca == "" and len(prior_spec_data) != 0: # # find prior interpretation # prior_specimen_interpretations = prior_spec_data[ prior_spec_data['specimen'].str.contains( this_specimen) == True] beg_pcas = pd.to_numeric(prior_specimen_interpretations. meas_step_min.values).tolist() end_pcas = pd.to_numeric(prior_specimen_interpretations. meas_step_max.values).tolist() spec_methods = prior_specimen_interpretations.method_codes.tolist( ) # step through all prior interpretations and plot them for ind in range(len(beg_pcas)): spec_meths = spec_methods[ind].split(':') for m in spec_meths: if 'DE-BFL' in m: calculation_type = 'DE-BFL' # best fit line if 'DE-BFP' in m: calculation_type = 'DE-BFP' # best fit plane if 'DE-FM' in m: calculation_type = 'DE-FM' # fisher mean if 'DE-BFL-A' in m: calculation_type = 'DE-BFL-A' # anchored best fit line start, end = tr.index(beg_pcas[ind]), tr.index( end_pcas[ind] ) # getting the starting and ending points # calculate direction/plane mpars = pmag.domean(datablock, start, end, calculation_type) if mpars["specimen_direction_type"] != "Error": # put it on the plot pmagplotlib.plotDir(ZED, mpars, datablock, angle) if verbose: pmagplotlib.drawFIGS(ZED) else: start, end = int(beg_pca), int(end_pca) # calculate direction/plane mpars = pmag.domean(datablock, start, end, calculation_type) if mpars["specimen_direction_type"] != "Error": # put it on the plot pmagplotlib.plotDir(ZED, mpars, datablock, angle) if verbose: pmagplotlib.drawFIGS(ZED) if plots == 1 or specimen != "": if plot_file == "": basename = title else: basename = plot_file files = {} for key in list(ZED.keys()): files[key] = basename + '_' + key + '.' + fmt pmagplotlib.saveP(ZED, files) if specimen != "": sys.exit() if verbose: recnum = 0 for plotrec in datablock: if units == 'T': print('%s: %i %7.1f %s %8.3e %7.1f %7.1f %s' % (plotrec[5], recnum, plotrec[0] * 1e3, " mT", plotrec[3], plotrec[1], plotrec[2], plotrec[6])) if units == "K": print('%s: %i %7.1f %s %8.3e %7.1f %7.1f %s' % (plotrec[5], recnum, plotrec[0] - 273, ' C', plotrec[3], plotrec[1], plotrec[2], plotrec[6])) if units == "J": print('%s: %i %7.1f %s %8.3e %7.1f %7.1f %s' % (plotrec[5], recnum, plotrec[0], ' J', plotrec[3], plotrec[1], plotrec[2], plotrec[6])) if 'K' in units and 'T' in units: if plotrec[0] >= 1.: print('%s: %i %7.1f %s %8.3e %7.1f %7.1f %s' % (plotrec[5], recnum, plotrec[0] - 273, ' C', plotrec[3], plotrec[1], plotrec[2], plotrec[6])) if plotrec[0] < 1.: print('%s: %i %7.1f %s %8.3e %7.1f %7.1f %s' % (plotrec[5], recnum, plotrec[0] * 1e3, " mT", plotrec[3], plotrec[1], plotrec[2], plotrec[6])) recnum += 1 # we have a current interpretation elif mpars["specimen_direction_type"] != "Error": # # create a new specimen record for the interpreation for this # specimen this_specimen_interpretation = { col: "" for col in specimen_cols } # this_specimen_interpretation["analysts"]=user this_specimen_interpretation['software_packages'] = version_num this_specimen_interpretation['specimen'] = this_specimen this_specimen_interpretation["method_codes"] = calculation_type this_specimen_interpretation["meas_step_unit"] = units this_specimen_interpretation["meas_step_min"] = tr[start] this_specimen_interpretation["meas_step_max"] = tr[end] this_specimen_interpretation["dir_dec"] = '%7.1f' % ( mpars['specimen_dec']) this_specimen_interpretation["dir_inc"] = '%7.1f' % ( mpars['specimen_inc']) this_specimen_interpretation["dir_dang"] = '%7.1f' % ( mpars['specimen_dang']) this_specimen_interpretation["dir_n_measurements"] = '%i' % ( mpars['specimen_n']) this_specimen_interpretation["dir_tilt_correction"] = coord methods = methods.replace(" ", "") if "T" in units: methods = methods + ":LP-DIR-AF" if "K" in units: methods = methods + ":LP-DIR-T" if "J" in units: methods = methods + ":LP-DIR-M" this_specimen_interpretation["method_codes"] = methods.strip( ':') this_specimen_interpretation[ "experiments"] = this_specimen_measurements.experiment.unique( )[0] # # print some stuff # if calculation_type != 'DE-FM': this_specimen_interpretation["dir_mad_free"] = '%7.1f' % ( mpars['specimen_mad']) this_specimen_interpretation["dir_alpha95"] = '' if verbose: if units == 'K': print( '%s %i %7.1f %7.1f %7.1f %7.1f %7.1f %7.1f %s \n' % (this_specimen_interpretation["specimen"], int(this_specimen_interpretation[ "dir_n_measurements"]), float(this_specimen_interpretation[ "dir_mad_free"]), float( this_specimen_interpretation["dir_dang"]), float(this_specimen_interpretation[ "meas_step_min"]) - 273, float(this_specimen_interpretation[ "meas_step_max"]) - 273, float( this_specimen_interpretation["dir_dec"]), float( this_specimen_interpretation["dir_inc"]), calculation_type)) elif units == 'T': print( '%s %i %7.1f %7.1f %7.1f %7.1f %7.1f %7.1f %s \n' % (this_specimen_interpretation["specimen"], int(this_specimen_interpretation[ "dir_n_measurements"]), float(this_specimen_interpretation[ "dir_mad_free"]), float( this_specimen_interpretation["dir_dang"]), float(this_specimen_interpretation[ "meas_step_min"]) * 1e3, float(this_specimen_interpretation[ "meas_step_max"]) * 1e3, float( this_specimen_interpretation["dir_dec"]), float( this_specimen_interpretation["dir_inc"]), calculation_type)) elif 'T' in units and 'K' in units: if float(this_specimen_interpretation[ 'meas_step_min']) < 1.0: min = float(this_specimen_interpretation[ 'meas_step_min']) * 1e3 else: min = float(this_specimen_interpretation[ 'meas_step_min']) - 273 if float(this_specimen_interpretation[ 'meas_step_max']) < 1.0: max = float(this_specimen_interpretation[ 'meas_step_max']) * 1e3 else: max = float(this_specimen_interpretation[ 'meas_step_max']) - 273 print( '%s %i %7.1f %i %i %7.1f %7.1f %7.1f %s \n' % (this_specimen_interpretation["specimen"], int(this_specimen_interpretation[ "dir_n_measurements"]), float(this_specimen_interpretation[ "dir_mad_free"]), float( this_specimen_interpretation["dir_dang"]), min, max, float( this_specimen_interpretation["dir_dec"]), float( this_specimen_interpretation["dir_inc"]), calculation_type)) else: print( '%s %i %7.1f %7.1f %7.1f %7.1f %7.1f %7.1f %s \n' % (this_specimen_interpretation["specimen"], int(this_specimen_interpretation[ "dir_n_measurements"]), float(this_specimen_interpretation[ "dir_mad_free"]), float( this_specimen_interpretation["dir_dang"]), float(this_specimen_interpretation[ "meas_step_min"]), float(this_specimen_interpretation[ "meas_step_max"]), float( this_specimen_interpretation["dir_dec"]), float( this_specimen_interpretation["dir_inc"]), calculation_type)) else: this_specimen_interpretation["dir_alpha95"] = '%7.1f' % ( mpars['specimen_alpha95']) this_specimen_interpretation["dir_mad_free"] = '' if verbose: if 'K' in units: print( '%s %i %7.1f %7.1f %7.1f %7.1f %7.1f %7.1f %s \n' % (this_specimen_interpretation["specimen"], int(this_specimen_interpretation[ "dir_n_measurments"]), float(this_specimen_interpretation[ "dir_mad_free"]), float( this_specimen_interpretation["dir_dang"]), float(this_specimen_interpretation[ "meas_step_min"]) - 273, float(this_specimen_interpretation[ "meas_step_max"]) - 273, float( this_specimen_interpretation["dir_dec"]), float( this_specimen_interpretation["dir_inc"]), calculation_type)) elif 'T' in units: print( '%s %i %7.1f %7.1f %7.1f %7.1f %7.1f %7.1f %s \n' % (this_specimen_interpretation["specimen"], int(this_specimen_interpretation[ "dir_n_measurements"]), float(this_specimen_interpretation[ "dir_alpha95"]), float( this_specimen_interpretation["dir_dang"]), float(this_specimen_interpretation[ "meas_step_min"]) * 1e3, float(this_specimen_interpretation[ "meas_step_max"]) * 1e3, float( this_specimen_interpretation["dir_dec"]), float( this_specimen_interpretation["dir_inc"]), calculation_type)) elif 'T' in units and 'K' in units: if float(this_specimen_interpretation[ 'meas_step_min']) < 1.0: min = float(this_specimen_interpretation[ 'meas_step_min']) * 1e3 else: min = float(this_specimen_interpretation[ 'meas_step_min']) - 273 if float(this_specimen_interpretation[ 'meas_step_max']) < 1.0: max = float(this_specimen_interpretation[ 'meas_step_max']) * 1e3 else: max = float(this_specimen_interpretation[ 'meas_step_max']) - 273 print('%s %i %7.1f %i %i %7.1f %7.1f %s \n' % ( this_specimen_interpretation["specimen"], int(this_specimen_interpretation[ "dir_n_measurements"]), float( this_specimen_interpretation["dir_alpha95"] ), min, max, float(this_specimen_interpretation["dir_dec"]), float(this_specimen_interpretation["dir_inc"]), calculation_type)) else: print( '%s %i %7.1f %7.1f %7.1f %7.1f %7.1f %s \n' % (this_specimen_interpretation["specimen"], int(this_specimen_interpretation[ "dir_n_measurements"]), float(this_specimen_interpretation[ "dir_alpha95"]), float(this_specimen_interpretation[ "meas_step_min"]), float(this_specimen_interpretation[ "meas_step_max"]), float( this_specimen_interpretation["dir_dec"]), float( this_specimen_interpretation["dir_inc"]), calculation_type)) if verbose: saveit = input("Save this interpretation? [y]/n \n") # START HERE # # if len(current_spec_data)==0: # no interpretations yet for this session # print "no current interpretation" # beg_pca,end_pca="","" # calculation_type="" # get the ones that meet the current coordinate system else: print("no data") if verbose: input('Ready for next specimen ') k += 1
def main(): """ NAME foldtest.py DESCRIPTION does a fold test (Tauxe, 2010) on data INPUT FORMAT dec inc dip_direction dip SYNTAX foldtest.py [command line options] OPTIONS -h prints help message and quits -f FILE file with input data -F FILE for confidence bounds on fold test -u ANGLE (circular standard deviation) for uncertainty on bedding poles -b MIN MAX bounds for quick search of percent untilting [default is -10 to 150%] -n NB number of bootstrap samples [default is 1000] -fmt FMT, specify format - default is svg -sav save figures and quit INPUT FILE Dec Inc Dip_Direction Dip in space delimited file OUTPUT PLOTS 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 post-tilt magnetization is indicated If the 95% conf bounds include 100, then a pre-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 Geographic: is an equal area projection of the input data in OPTIONAL OUTPUT FILE: The output file has the % untilting within the 95% confidence bounds nd the number of bootstrap samples """ kappa=0 fmt,plot='svg',0 nb=1000 # number of bootstraps min,max=-10,150 if '-h' in sys.argv: # check if help is needed print(main.__doc__) sys.exit() # graceful quit if '-F' in sys.argv: ind=sys.argv.index('-F') outfile=open(sys.argv[ind+1],'w') else: outfile="" if '-f' in sys.argv: ind=sys.argv.index('-f') file=sys.argv[ind+1] DIDDs=numpy.loadtxt(file) else: print(main.__doc__) sys.exit() if '-fmt' in sys.argv: ind=sys.argv.index('-fmt') fmt=sys.argv[ind+1] if '-sav' in sys.argv:plot=1 if '-b' in sys.argv: ind=sys.argv.index('-b') min=int(sys.argv[ind+1]) max=int(sys.argv[ind+2]) if '-n' in sys.argv: ind=sys.argv.index('-n') nb=int(sys.argv[ind+1]) if '-u' in sys.argv: ind=sys.argv.index('-u') csd=float(sys.argv[ind+1]) kappa=(81. / csd)**2 # # get to work # PLTS={'geo':1,'strat':2,'taus':3} # make plot dictionary pmagplotlib.plot_init(PLTS['geo'],5,5) pmagplotlib.plot_init(PLTS['strat'],5,5) pmagplotlib.plot_init(PLTS['taus'],5,5) pmagplotlib.plot_eq(PLTS['geo'],DIDDs,'Geographic') D,I=pmag.dotilt_V(DIDDs) TCs=numpy.array([D,I]).transpose() pmagplotlib.plot_eq(PLTS['strat'],TCs,'Stratigraphic') if not set_env.IS_WIN: if plot==0:pmagplotlib.draw_figs(PLTS) Percs=list(range(min,max)) Cdf,Untilt=[],[] pylab.figure(num=PLTS['taus']) print('doing ',nb,' iterations...please be patient.....') for n in range(nb): # 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=numpy.array([1.,1.,1.,0.01*perc]) D,I=pmag.dotilt_V(PDs*tilt) TCs=numpy.array([D,I]).transpose() ppars=pmag.doprinc(TCs) # get principal directions Taus.append(ppars['tau1']) if n<25:pylab.plot(Percs,Taus,'r--') Untilt.append(Percs[Taus.index(numpy.max(Taus))]) # tilt that gives maximum tau Cdf.append(float(n) / float(nb)) pylab.plot(Percs,Taus,'k') pylab.xlabel('% Untilting') pylab.ylabel('tau_1 (red), CDF (green)') Untilt.sort() # now for CDF of tilt of maximum tau pylab.plot(Untilt,Cdf,'g') lower=int(.025*nb) upper=int(.975*nb) pylab.axvline(x=Untilt[lower],ymin=0,ymax=1,linewidth=1,linestyle='--') pylab.axvline(x=Untilt[upper],ymin=0,ymax=1,linewidth=1,linestyle='--') tit= '%i - %i %s'%(Untilt[lower],Untilt[upper],'Percent Unfolding') print(tit) print('range of all bootstrap samples: ', Untilt[0], ' - ', Untilt[-1]) pylab.title(tit) outstring= '%i - %i; %i\n'%(Untilt[lower],Untilt[upper],nb) if outfile!="":outfile.write(outstring) files={} for key in list(PLTS.keys()): files[key]=('foldtest_'+'%s'%(key.strip()[:2])+'.'+fmt) if plot==0: pmagplotlib.draw_figs(PLTS) ans= input('S[a]ve all figures, <Return> to quit ') if ans!='a': print("Good bye") sys.exit() pmagplotlib.save_plots(PLTS,files)
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 di_rot.py DESCRIPTION rotates set of directions to new coordinate system SYNTAX di_rot.py [command line options] OPTIONS -h prints help message and quits -f specify input file, default is standard input -F specify output file, default is standard output -D D specify Dec of new coordinate system, default is 0 -I I specify Inc of new coordinate system, default is 90 INTPUT/OUTPUT dec inc [space delimited] """ D,I=0.,90. outfile="" infile="" if '-h' in sys.argv: print main.__doc__ sys.exit() if '-f' in sys.argv: ind=sys.argv.index('-f') infile=sys.argv[ind+1] data=numpy.loadtxt(infile) else: data=numpy.loadtxt(sys.stdin,dtype=numpy.float) if '-F' in sys.argv: ind=sys.argv.index('-F') outfile=sys.argv[ind+1] out=open(outfile,'w') if '-D' in sys.argv: ind=sys.argv.index('-D') D=float(sys.argv[ind+1]) if '-I' in sys.argv: ind=sys.argv.index('-I') I=float(sys.argv[ind+1]) if len(data.shape)>1: # 2-D array N=data.shape[0] DipDir,Dip=numpy.ones(N,dtype=numpy.float).transpose()*(D-180.),numpy.ones(N,dtype=numpy.float).transpose()*(90.-I) data=data.transpose() data=numpy.array([data[0],data[1],DipDir ,Dip]).transpose() drot,irot=pmag.dotilt_V(data) drot=(drot-180.)%360. # for k in range(N): if outfile=="": print '%7.1f %7.1f ' % (drot[k],irot[k]) else: out.write('%7.1f %7.1f\n' % (drot[k],irot[k])) else: d,i=pmag.dotilt(data[0],data[1],(D-180.),90.-I) if outfile=="": print '%7.1f %7.1f ' % ((d-180.)%360.,i) else: out.write('%7.1f %7.1f\n' % ((d-180.)%360.,i))
def main(): """ NAME foldtest.py DESCRIPTION does a fold test (Tauxe, 2010) on data INPUT FORMAT dec inc dip_direction dip SYNTAX foldtest.py [command line options] OPTIONS -h prints help message and quits -f FILE file with input data -F FILE for confidence bounds on fold test -u ANGLE (circular standard deviation) for uncertainty on bedding poles -b MIN MAX bounds for quick search of percent untilting [default is -10 to 150%] -n NB number of bootstrap samples [default is 1000] -fmt FMT, specify format - default is svg -sav save figures and quit INPUT FILE Dec Inc Dip_Direction Dip in space delimited file OUTPUT PLOTS 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 post-tilt magnetization is indicated If the 95% conf bounds include 100, then a pre-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 Geographic: is an equal area projection of the input data in OPTIONAL OUTPUT FILE: The output file has the % untilting within the 95% confidence bounds nd the number of bootstrap samples """ kappa = 0 fmt, plot = 'svg', 0 nb = 1000 # number of bootstraps min, max = -10, 150 if '-h' in sys.argv: # check if help is needed print main.__doc__ sys.exit() # graceful quit if '-F' in sys.argv: ind = sys.argv.index('-F') outfile = open(sys.argv[ind + 1], 'w') else: outfile = "" if '-f' in sys.argv: ind = sys.argv.index('-f') file = sys.argv[ind + 1] DIDDs = numpy.loadtxt(file) else: print main.__doc__ sys.exit() if '-fmt' in sys.argv: ind = sys.argv.index('-fmt') fmt = sys.argv[ind + 1] if '-sav' in sys.argv: plot = 1 if '-b' in sys.argv: ind = sys.argv.index('-b') min = int(sys.argv[ind + 1]) max = int(sys.argv[ind + 2]) if '-n' in sys.argv: ind = sys.argv.index('-n') nb = int(sys.argv[ind + 1]) if '-u' in sys.argv: ind = sys.argv.index('-u') csd = float(sys.argv[ind + 1]) kappa = (81. / csd)**2 # # get to work # PLTS = {'geo': 1, 'strat': 2, 'taus': 3} # make plot dictionary pmagplotlib.plot_init(PLTS['geo'], 5, 5) pmagplotlib.plot_init(PLTS['strat'], 5, 5) pmagplotlib.plot_init(PLTS['taus'], 5, 5) pmagplotlib.plotEQ(PLTS['geo'], DIDDs, 'Geographic') D, I = pmag.dotilt_V(DIDDs) TCs = numpy.array([D, I]).transpose() pmagplotlib.plotEQ(PLTS['strat'], TCs, 'Stratigraphic') if plot == 0: pmagplotlib.drawFIGS(PLTS) Percs = range(min, max) Cdf, Untilt = [], [] pylab.figure(num=PLTS['taus']) print 'doing ', nb, ' iterations...please be patient.....' for n in range( nb): # 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 = numpy.array([1., 1., 1., 0.01 * perc]) D, I = pmag.dotilt_V(PDs * tilt) TCs = numpy.array([D, I]).transpose() ppars = pmag.doprinc(TCs) # get principal directions Taus.append(ppars['tau1']) if n < 25: pylab.plot(Percs, Taus, 'r--') Untilt.append(Percs[Taus.index( numpy.max(Taus))]) # tilt that gives maximum tau Cdf.append(float(n) / float(nb)) pylab.plot(Percs, Taus, 'k') pylab.xlabel('% Untilting') pylab.ylabel('tau_1 (red), CDF (green)') Untilt.sort() # now for CDF of tilt of maximum tau pylab.plot(Untilt, Cdf, 'g') lower = int(.025 * nb) upper = int(.975 * nb) pylab.axvline(x=Untilt[lower], ymin=0, ymax=1, linewidth=1, linestyle='--') pylab.axvline(x=Untilt[upper], ymin=0, ymax=1, linewidth=1, linestyle='--') tit = '%i - %i %s' % (Untilt[lower], Untilt[upper], 'Percent Unfolding') print tit print 'range of all bootstrap samples: ', Untilt[0], ' - ', Untilt[-1] pylab.title(tit) outstring = '%i - %i; %i\n' % (Untilt[lower], Untilt[upper], nb) if outfile != "": outfile.write(outstring) files = {} for key in PLTS.keys(): files[key] = ('foldtest_' + '%s' % (key.strip()[:2]) + '.' + fmt) if plot == 0: pmagplotlib.drawFIGS(PLTS) ans = raw_input('S[a]ve all figures, <Return> to quit ') if ans != 'a': print "Good bye" sys.exit() pmagplotlib.saveP(PLTS, files)
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 zeq_magic.py DESCRIPTION reads in magic_measurements formatted file, makes plots of remanence decay during demagnetization experiments. Reads in prior interpretations saved in a pmag_specimens formatted file [and allows re-interpretations of best-fit lines and planes and saves (revised or new) interpretations in a pmag_specimens file. interpretations are saved in the coordinate system used. Also allows judicious editting of measurements to eliminate "bad" measurements. These are marked as such in the magic_measurements input file. they are NOT deleted, just ignored. ] Bracketed part not yet implemented SYNTAX zeq_magic.py [command line options] OPTIONS -h prints help message and quits -f MEASFILE: sets measurements format input file, default: measurements.txt -fsp SPECFILE: sets specimens format file with prior interpreations, default: specimens.txt -fsa SAMPFILE: sets samples format file sample=>site information, default: samples.txt -fsi SITEFILE: sets sites format file with site=>location informationprior interpreations, default: samples.txt -Fp PLTFILE: sets filename for saved plot, default is name_type.fmt (where type is zijd, eqarea or decay curve) -crd [s,g,t]: sets coordinate system, g=geographic, t=tilt adjusted, default: specimen coordinate system -spc SPEC plots single specimen SPEC, saves plot with specified format with optional -dir settings and quits -dir [L,P,F][beg][end]: sets calculation type for principal component analysis, default is none beg: starting step for PCA calculation end: ending step for PCA calculation [L,P,F]: calculation type for line, plane or fisher mean must be used with -spc option -fmt FMT: set format of saved plot [png,svg,jpg] -A: suppresses averaging of replicate measurements, default is to average -sav: saves all plots without review SCREEN OUTPUT: Specimen, N, a95, StepMin, StepMax, Dec, Inc, calculation type """ # initialize some variables doave, e, b = 1, 0, 0 # average replicates, initial end and beginning step intlist = ['magn_moment', 'magn_volume', 'magn_mass', 'magnitude'] plots, coord = 0, 's' noorient = 0 version_num = pmag.get_version() verbose = pmagplotlib.verbose calculation_type, fmt = "", "svg" user, spec_keys, locname = "", [], '' geo, tilt, ask = 0, 0, 0 PriorRecs = [] # empty list for prior interpretations backup = 0 specimen = "" # can skip everything and just plot one specimen with bounds e,b if '-h' in sys.argv: print(main.__doc__) sys.exit() dir_path = pmag.get_named_arg_from_sys("-WD", default_val=os.getcwd()) meas_file = pmag.get_named_arg_from_sys( "-f", default_val="measurements.txt") 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") #meas_file = os.path.join(dir_path, meas_file) #spec_file = os.path.join(dir_path, spec_file) #samp_file = os.path.join(dir_path, samp_file) #site_file = os.path.join(dir_path, site_file) plot_file = pmag.get_named_arg_from_sys("-Fp", default_val="") crd = pmag.get_named_arg_from_sys("-crd", default_val="s") if crd == "s": coord = "-1" elif crd == "t": coord = "100" else: coord = "0" fmt = pmag.get_named_arg_from_sys("-fmt", "svg") specimen = pmag.get_named_arg_from_sys("-spc", default_val="") beg_pca, end_pca = "", "" if '-dir' in sys.argv: ind = sys.argv.index('-dir') direction_type = sys.argv[ind + 1] beg_pca = int(sys.argv[ind + 2]) end_pca = int(sys.argv[ind + 3]) if direction_type == 'L': calculation_type = 'DE-BFL' if direction_type == 'P': calculation_type = 'DE-BFP' if direction_type == 'F': calculation_type = 'DE-FM' if '-A' in sys.argv: doave = 0 if '-sav' in sys.argv: plots, verbose = 1, 0 # first_save = 1 fnames = {'measurements': meas_file, 'specimens': spec_file, 'samples': samp_file, 'sites': site_file} contribution = nb.Contribution(dir_path, custom_filenames=fnames, read_tables=[ 'measurements', 'specimens', 'samples', 'sites']) # # import specimens specimen_cols = ['analysts', 'aniso_ftest', 'aniso_ftest12', 'aniso_ftest23', 'aniso_s', 'aniso_s_mean', 'aniso_s_n_measurements', 'aniso_s_sigma', 'aniso_s_unit', 'aniso_tilt_correction', 'aniso_type', 'aniso_v1', 'aniso_v2', 'aniso_v3', 'citations', 'description', 'dir_alpha95', 'dir_comp', 'dir_dec', 'dir_inc', 'dir_mad_free', 'dir_n_measurements', 'dir_tilt_correction', 'experiments', 'geologic_classes', 'geologic_types', 'hyst_bc', 'hyst_bcr', 'hyst_mr_moment', 'hyst_ms_moment', 'int_abs', 'int_b', 'int_b_beta', 'int_b_sigma', 'int_corr', 'int_dang', 'int_drats', 'int_f', 'int_fvds', 'int_gamma', 'int_mad_free', 'int_md', 'int_n_measurements', 'int_n_ptrm', 'int_q', 'int_rsc', 'int_treat_dc_field', 'lithologies', 'meas_step_max', 'meas_step_min', 'meas_step_unit', 'method_codes', 'sample', 'software_packages', 'specimen'] if 'specimens' in contribution.tables: # contribution.propagate_name_down('sample','measurements') spec_container = contribution.tables['specimens'] if 'method_codes' not in spec_container.df.columns: spec_container.df['method_codes'] = None prior_spec_data = spec_container.get_records_for_code( 'LP-DIR', strict_match=False) # look up all prior directional interpretations # # tie sample names to measurement data # else: spec_container, prior_spec_data = None, [] # # import samples for orientation info # if ('samples' in contribution.tables) and ('specimens' in contribution.tables): # contribution.propagate_name_down('site','measurements') contribution.propagate_cols(col_names=[ 'azimuth', 'dip', 'orientation_quality'], target_df_name='measurements', source_df_name='samples') # # define figure numbers for equal area, zijderveld, # and intensity vs. demagnetiztion step respectively # ZED = {} ZED['eqarea'], ZED['zijd'], ZED['demag'] = 1, 2, 3 pmagplotlib.plot_init(ZED['eqarea'], 6, 6) pmagplotlib.plot_init(ZED['zijd'], 6, 6) pmagplotlib.plot_init(ZED['demag'], 6, 6) # save_pca=0 angle, direction_type, setangle = "", "", 0 # create measurement dataframe # meas_container = contribution.tables['measurements'] meas_data = meas_container.df # meas_data = meas_data[meas_data['method_codes'].str.contains( 'LT-NO|LT-AF-Z|LT-T-Z|LT-M-Z') == True] # fish out steps for plotting meas_data = meas_data[meas_data['method_codes'].str.contains( 'AN|ARM|LP-TRM|LP-PI-ARM') == False] # strip out unwanted experiments intensity_types = [ col_name for col_name in meas_data.columns if col_name in intlist] intensity_types = [ col_name for col_name in intensity_types if any(meas_data[col_name])] if not len(intensity_types): print('-W- No intensity columns found') return # plot first non-empty intensity method found - normalized to initial value anyway - # doesn't matter which used int_key = intensity_types[0] # get all the non-null intensity records of the same type meas_data = meas_data[meas_data[int_key].notnull()] if 'flag' not in meas_data.columns: meas_data['flag'] = 'g' # set the default flag to good # need to treat LP-NO specially for af data, treatment should be zero, # otherwise 273. meas_data['treatment'] = meas_data['treat_ac_field'].where( cond=meas_data['treat_ac_field'] != 0, other=meas_data['treat_temp']) meas_data['ZI'] = 1 # initialize these to one meas_data['instrument_codes'] = "" # initialize these to blank # for unusual case of microwave power.... if 'treat_mw_power' in meas_data.columns: meas_data.loc[ (meas_data.treat_mw_power != 0) & (meas_data.treat_mw_power) & (meas_data.treat_mw_time), 'treatment'] = meas_data.treat_mw_power * meas_data.treat_mw_time # # get list of unique specimen names from measurement data # # this is a list of all the specimen names specimen_names = meas_data.specimen.unique() specimen_names = specimen_names.tolist() specimen_names.sort() # # set up new DataFrame for this sessions specimen interpretations # data_container = nb.MagicDataFrame( dtype='specimens', columns=specimen_cols) # this is for interpretations from this session current_spec_data = data_container.df locname = 'LookItUp' if specimen == "": k = 0 else: k = specimen_names.index(specimen) # let's look at the data now while k < len(specimen_names): mpars = None # set the current specimen for plotting this_specimen = specimen_names[k] # reset beginning/end pca if plotting more than one specimen if not specimen: beg_pca, end_pca = "", "" if verbose and this_specimen != "": print(this_specimen, k + 1, 'out of ', len(specimen_names)) if setangle == 0: angle = "" this_specimen_measurements = meas_data[meas_data['specimen'].str.contains( this_specimen) == True] # fish out this specimen this_specimen_measurements = this_specimen_measurements[this_specimen_measurements['flag'].str.contains( 'g') == True] # fish out this specimen if len(this_specimen_measurements) != 0: # if there are measurements # # set up datablock [[treatment,dec, inc, int, direction_type],[....]] # # # figure out the method codes # units, methods, title = "", "", this_specimen # this is a list of all the specimen method codes` meas_meths = this_specimen_measurements.method_codes.unique() tr = pd.to_numeric(this_specimen_measurements.treatment).tolist() if set(tr) == set([0]): k += 1 continue for m in meas_meths: if 'LT-AF-Z' in m: units = 'T' # units include tesla tr[0] = 0 if 'LT-T-Z' in m: units = units + ":K" # units include kelvin if 'LT-M-Z' in m: units = units + ':J' # units include joules tr[0] = 0 units = units.strip(':') # strip off extra colons if 'LP-' in m: methods = methods + ":" + m decs = pd.to_numeric(this_specimen_measurements.dir_dec).tolist() incs = pd.to_numeric(this_specimen_measurements.dir_inc).tolist() # # fix the coordinate system # if coord != '-1': # need to transform coordinates to geographic azimuths = pd.to_numeric( this_specimen_measurements.azimuth).tolist() # get the azimuths # get the azimuths dips = pd.to_numeric(this_specimen_measurements.dip).tolist() dirs = [decs, incs, azimuths, dips] # this transposes the columns and rows of the list of lists dirs_geo = np.array(list(map(list, list(zip(*dirs))))) decs, incs = pmag.dogeo_V(dirs_geo) if coord == '100': # need to do tilt correction too bed_dip_dirs = pd.to_numeric( this_specimen_measurements.bed_dip_dir).tolist() # get the azimuths bed_dips = pd.to_numeric( this_specimen_measurements.bed_dip).tolist() # get the azimuths dirs = [decs, incs, bed_dip_dirs, bed_dips] # this transposes the columns and rows of the list of lists dirs_tilt = np.array(list(map(list, list(zip(*dirs))))) decs, incs = pmag.dotilt_V(dirs_tilt) title = title + '_t' else: title = title + '_g' if angle == "": angle = decs[0] ints = pd.to_numeric(this_specimen_measurements[int_key]).tolist() ZI = this_specimen_measurements.ZI.tolist() flags = this_specimen_measurements.flag.tolist() codes = this_specimen_measurements.instrument_codes.tolist() datalist = [tr, decs, incs, ints, ZI, flags, codes] # this transposes the columns and rows of the list of lists datablock = list(map(list, list(zip(*datalist)))) pmagplotlib.plotZED(ZED, datablock, angle, title, units) if verbose: pmagplotlib.drawFIGS(ZED) # # collect info for current_specimen_interpretation dictionary # # # find prior interpretation # prior_specimen_interpretations = prior_spec_data[prior_spec_data['specimen'].str.contains(this_specimen) == True] if (beg_pca == "") and (len(prior_specimen_interpretations) != 0): if len(prior_specimen_interpretations)>0: beg_pcas = pd.to_numeric( prior_specimen_interpretations.meas_step_min.values).tolist() end_pcas = pd.to_numeric( prior_specimen_interpretations.meas_step_max.values).tolist() spec_methods = prior_specimen_interpretations.method_codes.tolist() # step through all prior interpretations and plot them for ind in range(len(beg_pcas)): spec_meths = spec_methods[ind].split(':') for m in spec_meths: if 'DE-BFL' in m: calculation_type = 'DE-BFL' # best fit line if 'DE-BFP' in m: calculation_type = 'DE-BFP' # best fit plane if 'DE-FM' in m: calculation_type = 'DE-FM' # fisher mean if 'DE-BFL-A' in m: calculation_type = 'DE-BFL-A' # anchored best fit line start, end = tr.index(beg_pcas[ind]), tr.index( end_pcas[ind]) # getting the starting and ending points # calculate direction/plane mpars = pmag.domean( datablock, start, end, calculation_type) if mpars["specimen_direction_type"] != "Error": # put it on the plot pmagplotlib.plotDir(ZED, mpars, datablock, angle) if verbose: pmagplotlib.drawFIGS(ZED) else: try: start, end = int(beg_pca), int(end_pca) except ValueError: beg_pca = 0 end_pca = len(datablock) - 1 start, end = int(beg_pca), int(end_pca) # calculate direction/plane try: mpars = pmag.domean(datablock, start, end, calculation_type) except Exception as ex: print('-I- Problem with {}'.format(this_specimen)) print(' ', ex) print(' Skipping') k += 1 continue if mpars["specimen_direction_type"] != "Error": # put it on the plot pmagplotlib.plotDir(ZED, mpars, datablock, angle) if verbose: pmagplotlib.drawFIGS(ZED) if plots == 1 or specimen != "": if plot_file == "": basename = title else: basename = plot_file files = {} for key in list(ZED.keys()): files[key] = basename + '_' + key + '.' + fmt pmagplotlib.saveP(ZED, files) if specimen != "": sys.exit() if verbose: recnum = 0 for plotrec in datablock: if units == 'T': print('%s: %i %7.1f %s %8.3e %7.1f %7.1f %s' % ( plotrec[5], recnum, plotrec[0] * 1e3, " mT", plotrec[3], plotrec[1], plotrec[2], plotrec[6])) if units == "K": print('%s: %i %7.1f %s %8.3e %7.1f %7.1f %s' % ( plotrec[5], recnum, plotrec[0] - 273, ' C', plotrec[3], plotrec[1], plotrec[2], plotrec[6])) if units == "J": print('%s: %i %7.1f %s %8.3e %7.1f %7.1f %s' % ( plotrec[5], recnum, plotrec[0], ' J', plotrec[3], plotrec[1], plotrec[2], plotrec[6])) if 'K' in units and 'T' in units: if plotrec[0] >= 1.: print('%s: %i %7.1f %s %8.3e %7.1f %7.1f %s' % ( plotrec[5], recnum, plotrec[0] - 273, ' C', plotrec[3], plotrec[1], plotrec[2], plotrec[6])) if plotrec[0] < 1.: print('%s: %i %7.1f %s %8.3e %7.1f %7.1f %s' % ( plotrec[5], recnum, plotrec[0] * 1e3, " mT", plotrec[3], plotrec[1], plotrec[2], plotrec[6])) recnum += 1 # we have a current interpretation elif mpars["specimen_direction_type"] != "Error": # # create a new specimen record for the interpreation for this # specimen this_specimen_interpretation = { col: "" for col in specimen_cols} # this_specimen_interpretation["analysts"]=user this_specimen_interpretation['software_packages'] = version_num this_specimen_interpretation['specimen'] = this_specimen this_specimen_interpretation["method_codes"] = calculation_type this_specimen_interpretation["meas_step_unit"] = units this_specimen_interpretation["meas_step_min"] = tr[start] this_specimen_interpretation["meas_step_max"] = tr[end] this_specimen_interpretation["dir_dec"] = '%7.1f' % ( mpars['specimen_dec']) this_specimen_interpretation["dir_inc"] = '%7.1f' % ( mpars['specimen_inc']) this_specimen_interpretation["dir_dang"] = '%7.1f' % ( mpars['specimen_dang']) this_specimen_interpretation["dir_n_measurements"] = '%i' % ( mpars['specimen_n']) this_specimen_interpretation["dir_tilt_correction"] = coord methods = methods.replace(" ", "") if "T" in units: methods = methods + ":LP-DIR-AF" if "K" in units: methods = methods + ":LP-DIR-T" if "J" in units: methods = methods + ":LP-DIR-M" this_specimen_interpretation["method_codes"] = methods.strip( ':') this_specimen_interpretation["experiments"] = this_specimen_measurements.experiment.unique()[ 0] # # print some stuff # if calculation_type != 'DE-FM': this_specimen_interpretation["dir_mad_free"] = '%7.1f' % ( mpars['specimen_mad']) this_specimen_interpretation["dir_alpha95"] = '' if verbose: if units == 'K': print('%s %i %7.1f %7.1f %7.1f %7.1f %7.1f %7.1f %s \n' % (this_specimen_interpretation["specimen"], int(this_specimen_interpretation["dir_n_measurements"]), float(this_specimen_interpretation["dir_mad_free"]), float(this_specimen_interpretation["dir_dang"]), float( this_specimen_interpretation["meas_step_min"]) - 273, float(this_specimen_interpretation["meas_step_max"]) - 273, float(this_specimen_interpretation["dir_dec"]), float(this_specimen_interpretation["dir_inc"]), calculation_type)) elif units == 'T': print('%s %i %7.1f %7.1f %7.1f %7.1f %7.1f %7.1f %s \n' % (this_specimen_interpretation["specimen"], int(this_specimen_interpretation["dir_n_measurements"]), float(this_specimen_interpretation["dir_mad_free"]), float(this_specimen_interpretation["dir_dang"]), float( this_specimen_interpretation["meas_step_min"]) * 1e3, float(this_specimen_interpretation["meas_step_max"]) * 1e3, float(this_specimen_interpretation["dir_dec"]), float(this_specimen_interpretation["dir_inc"]), calculation_type)) elif 'T' in units and 'K' in units: if float(this_specimen_interpretation['meas_step_min']) < 1.0: min = float( this_specimen_interpretation['meas_step_min']) * 1e3 else: min = float( this_specimen_interpretation['meas_step_min']) - 273 if float(this_specimen_interpretation['meas_step_max']) < 1.0: max = float( this_specimen_interpretation['meas_step_max']) * 1e3 else: max = float( this_specimen_interpretation['meas_step_max']) - 273 print('%s %i %7.1f %i %i %7.1f %7.1f %7.1f %s \n' % (this_specimen_interpretation["specimen"], int(this_specimen_interpretation["dir_n_measurements"]), float(this_specimen_interpretation["dir_mad_free"]), float( this_specimen_interpretation["dir_dang"]), min, max, float(this_specimen_interpretation["dir_dec"]), float(this_specimen_interpretation["dir_inc"]), calculation_type)) else: print('%s %i %7.1f %7.1f %7.1f %7.1f %7.1f %7.1f %s \n' % (this_specimen_interpretation["specimen"], int(this_specimen_interpretation["dir_n_measurements"]), float(this_specimen_interpretation["dir_mad_free"]), float(this_specimen_interpretation["dir_dang"]), float( this_specimen_interpretation["meas_step_min"]), float(this_specimen_interpretation["meas_step_max"]), float(this_specimen_interpretation["dir_dec"]), float(this_specimen_interpretation["dir_inc"]), calculation_type)) else: this_specimen_interpretation["dir_alpha95"] = '%7.1f' % ( mpars['specimen_alpha95']) this_specimen_interpretation["dir_mad_free"] = '' if verbose: if 'K' in units: print('%s %i %7.1f %7.1f %7.1f %7.1f %7.1f %7.1f %s \n' % (this_specimen_interpretation["specimen"], int(this_specimen_interpretation["dir_n_measurments"]), float(this_specimen_interpretation["dir_mad_free"]), float(this_specimen_interpretation["dir_dang"]), float( this_specimen_interpretation["meas_step_min"]) - 273, float(this_specimen_interpretation["meas_step_max"]) - 273, float(this_specimen_interpretation["dir_dec"]), float(this_specimen_interpretation["dir_inc"]), calculation_type)) elif 'T' in units: print('%s %i %7.1f %7.1f %7.1f %7.1f %7.1f %7.1f %s \n' % (this_specimen_interpretation["specimen"], int(this_specimen_interpretation["dir_n_measurements"]), float(this_specimen_interpretation["dir_alpha95"]), float(this_specimen_interpretation["dir_dang"]), float( this_specimen_interpretation["meas_step_min"]) * 1e3, float(this_specimen_interpretation["meas_step_max"]) * 1e3, float(this_specimen_interpretation["dir_dec"]), float(this_specimen_interpretation["dir_inc"]), calculation_type)) elif 'T' in units and 'K' in units: if float(this_specimen_interpretation['meas_step_min']) < 1.0: min = float( this_specimen_interpretation['meas_step_min']) * 1e3 else: min = float( this_specimen_interpretation['meas_step_min']) - 273 if float(this_specimen_interpretation['meas_step_max']) < 1.0: max = float( this_specimen_interpretation['meas_step_max']) * 1e3 else: max = float( this_specimen_interpretation['meas_step_max']) - 273 print('%s %i %7.1f %i %i %7.1f %7.1f %s \n' % (this_specimen_interpretation["specimen"], int(this_specimen_interpretation["dir_n_measurements"]), float( this_specimen_interpretation["dir_alpha95"]), min, max, float(this_specimen_interpretation["dir_dec"]), float(this_specimen_interpretation["dir_inc"]), calculation_type)) else: print('%s %i %7.1f %7.1f %7.1f %7.1f %7.1f %s \n' % (this_specimen_interpretation["specimen"], int(this_specimen_interpretation["dir_n_measurements"]), float(this_specimen_interpretation["dir_alpha95"]), float( this_specimen_interpretation["meas_step_min"]), float(this_specimen_interpretation["meas_step_max"]), float(this_specimen_interpretation["dir_dec"]), float(this_specimen_interpretation["dir_inc"]), calculation_type)) if verbose: saveit = input("Save this interpretation? [y]/n \n") # START HERE # # if len(current_spec_data)==0: # no interpretations yet for this session # print "no current interpretation" # beg_pca,end_pca="","" # calculation_type="" # get the ones that meet the current coordinate system else: print("no data") if verbose: res = input(' <return> for next specimen, [q]uit ') if res == 'q': return k += 1
def main(): """ NAME zeq_magic.py DESCRIPTION reads in magic_measurements formatted file, makes plots of remanence decay during demagnetization experiments. Reads in prior interpretations saved in a pmag_specimens formatted file [and allows re-interpretations of best-fit lines and planes and saves (revised or new) interpretations in a pmag_specimens file. interpretations are saved in the coordinate system used. Also allows judicious editting of measurements to eliminate "bad" measurements. These are marked as such in the magic_measurements input file. they are NOT deleted, just ignored. ] Bracketed part not yet implemented SYNTAX zeq_magic.py [command line options] OPTIONS -h prints help message and quits -f MEASFILE: sets measurements format input file, default: measurements.txt -fsp SPECFILE: sets specimens format file with prior interpreations, default: specimens.txt -fsa SAMPFILE: sets samples format file sample=>site information, default: samples.txt -fsi SITEFILE: sets sites format file with site=>location informationprior interpreations, default: samples.txt -Fp PLTFILE: sets filename for saved plot, default is name_type.fmt (where type is zijd, eqarea or decay curve) -crd [s,g,t]: sets coordinate system, g=geographic, t=tilt adjusted, default: specimen coordinate system -spc SPEC plots single specimen SPEC, saves plot with specified format with optional -dir settings and quits -dir [L,P,F][beg][end]: sets calculation type for principal component analysis, default is none beg: starting step for PCA calculation end: ending step for PCA calculation [L,P,F]: calculation type for line, plane or fisher mean must be used with -spc option -fmt FMT: set format of saved plot [png,svg,jpg] -A: suppresses averaging of replicate measurements, default is to average -sav: saves all plots without review SCREEN OUTPUT: Specimen, N, a95, StepMin, StepMax, Dec, Inc, calculation type """ # initialize some variables doave, e, b = 1, 0, 0 # average replicates, initial end and beginning step intlist = ['magn_moment', 'magn_volume', 'magn_mass', 'magnitude'] plots, coord = 0, 's' noorient = 0 version_num = pmag.get_version() verbose = pmagplotlib.verbose calculation_type, fmt = "", "svg" spec_keys = [] geo, tilt, ask = 0, 0, 0 PriorRecs = [] # empty list for prior interpretations backup = 0 specimen = "" # can skip everything and just plot one specimen with bounds e,b if '-h' in sys.argv: print(main.__doc__) sys.exit() dir_path = pmag.get_named_arg("-WD", default_val=os.getcwd()) meas_file = pmag.get_named_arg("-f", default_val="measurements.txt") 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") #meas_file = os.path.join(dir_path, meas_file) #spec_file = os.path.join(dir_path, spec_file) #samp_file = os.path.join(dir_path, samp_file) #site_file = os.path.join(dir_path, site_file) plot_file = pmag.get_named_arg("-Fp", default_val="") crd = pmag.get_named_arg("-crd", default_val="s") if crd == "s": coord = "-1" elif crd == "t": coord = "100" else: coord = "0" saved_coord = coord fmt = pmag.get_named_arg("-fmt", "svg") specimen = pmag.get_named_arg("-spc", default_val="") #if specimen: # just save plot and exit # plots, verbose = 1, 0 beg_pca, end_pca = "", "" if '-dir' in sys.argv: ind = sys.argv.index('-dir') direction_type = sys.argv[ind + 1] beg_pca = int(sys.argv[ind + 2]) end_pca = int(sys.argv[ind + 3]) if direction_type == 'L': calculation_type = 'DE-BFL' if direction_type == 'P': calculation_type = 'DE-BFP' if direction_type == 'F': calculation_type = 'DE-FM' if '-A' in sys.argv: doave = 0 if '-sav' in sys.argv: plots, verbose = 1, 0 # first_save = 1 fnames = { 'measurements': meas_file, 'specimens': spec_file, 'samples': samp_file, 'sites': site_file } contribution = cb.Contribution( dir_path, custom_filenames=fnames, read_tables=['measurements', 'specimens', 'samples', 'sites']) # # import specimens if 'measurements' not in contribution.tables: print('-W- No measurements table found in your working directory') return specimen_cols = [ 'analysts', 'aniso_ftest', 'aniso_ftest12', 'aniso_ftest23', 'aniso_s', 'aniso_s_mean', 'aniso_s_n_measurements', 'aniso_s_sigma', 'aniso_s_unit', 'aniso_tilt_correction', 'aniso_type', 'aniso_v1', 'aniso_v2', 'aniso_v3', 'citations', 'description', 'dir_alpha95', 'dir_comp', 'dir_dec', 'dir_inc', 'dir_mad_free', 'dir_n_measurements', 'dir_tilt_correction', 'experiments', 'geologic_classes', 'geologic_types', 'hyst_bc', 'hyst_bcr', 'hyst_mr_moment', 'hyst_ms_moment', 'int_abs', 'int_b', 'int_b_beta', 'int_b_sigma', 'int_corr', 'int_dang', 'int_drats', 'int_f', 'int_fvds', 'int_gamma', 'int_mad_free', 'int_md', 'int_n_measurements', 'int_n_ptrm', 'int_q', 'int_rsc', 'int_treat_dc_field', 'lithologies', 'meas_step_max', 'meas_step_min', 'meas_step_unit', 'method_codes', 'sample', 'software_packages', 'specimen' ] if 'specimens' in contribution.tables: contribution.propagate_name_down('sample', 'measurements') # add location/site info to measurements table for naming plots if pmagplotlib.isServer: contribution.propagate_name_down('site', 'measurements') contribution.propagate_name_down('location', 'measurements') spec_container = contribution.tables['specimens'] if 'method_codes' not in spec_container.df.columns: spec_container.df['method_codes'] = None prior_spec_data = spec_container.get_records_for_code( 'LP-DIR', strict_match=False ) # look up all prior directional interpretations # # tie sample names to measurement data # else: spec_container, prior_spec_data = None, [] # # import samples for orientation info # if 'samples' in contribution.tables: samp_container = contribution.tables['samples'] samps = samp_container.df samp_data = samps.to_dict( 'records' ) # convert to list of dictionaries for use with get_orient else: samp_data = [] #if ('samples' in contribution.tables) and ('specimens' in contribution.tables): # # contribution.propagate_name_down('site','measurements') # contribution.propagate_cols(col_names=[ # 'azimuth', 'dip', 'orientation_quality','bed_dip','bed_dip_direction'], target_df_name='measurements', source_df_name='samples') ## # define figure numbers for equal area, zijderveld, # and intensity vs. demagnetiztion step respectively # ZED = {} ZED['eqarea'], ZED['zijd'], ZED['demag'] = 1, 2, 3 pmagplotlib.plot_init(ZED['eqarea'], 6, 6) pmagplotlib.plot_init(ZED['zijd'], 6, 6) pmagplotlib.plot_init(ZED['demag'], 6, 6) # save_pca=0 angle, direction_type, setangle = "", "", 0 # create measurement dataframe # meas_container = contribution.tables['measurements'] meas_data = meas_container.df # meas_data = meas_data[meas_data['method_codes'].str.contains( 'LT-NO|LT-AF-Z|LT-T-Z|LT-M-Z') == True] # fish out steps for plotting meas_data = meas_data[meas_data['method_codes'].str.contains( 'AN|ARM|LP-TRM|LP-PI-ARM') == False] # strip out unwanted experiments intensity_types = [ col_name for col_name in meas_data.columns if col_name in intlist ] intensity_types = [ col_name for col_name in intensity_types if any(meas_data[col_name]) ] if not len(intensity_types): print('-W- No intensity columns found') return # plot first non-empty intensity method found - normalized to initial value anyway - # doesn't matter which used int_key = intensity_types[0] # get all the non-null intensity records of the same type meas_data = meas_data[meas_data[int_key].notnull()] if 'quality' not in meas_data.columns: meas_data['quality'] = 'g' # set the default flag to good # need to treat LP-NO specially for af data, treatment should be zero, # otherwise 273. #meas_data['treatment'] = meas_data['treat_ac_field'].where( # cond=meas_data['treat_ac_field'] != 0, other=meas_data['treat_temp']) meas_data['treatment'] = meas_data['treat_ac_field'].where( cond=meas_data['treat_ac_field'].astype(bool), other=meas_data['treat_temp']) meas_data['ZI'] = 1 # initialize these to one meas_data['instrument_codes'] = "" # initialize these to blank # for unusual case of microwave power.... if 'treat_mw_power' in meas_data.columns: meas_data.loc[ (meas_data.treat_mw_power != 0) & (meas_data.treat_mw_power) & (meas_data.treat_mw_time), 'treatment'] = meas_data.treat_mw_power * meas_data.treat_mw_time # # get list of unique specimen names from measurement data # # this is a list of all the specimen names specimen_names = meas_data.specimen.unique() specimen_names = specimen_names.tolist() specimen_names.sort() # # set up new DataFrame for this sessions specimen interpretations # data_container = cb.MagicDataFrame(dtype='specimens', columns=specimen_cols) # this is for interpretations from this session current_spec_data = data_container.df if specimen == "": k = 0 else: k = specimen_names.index(specimen) # let's look at the data now while k < len(specimen_names): mpars = {"specimen_direction_type": "Error"} # set the current specimen for plotting this_specimen = specimen_names[k] # reset beginning/end pca if plotting more than one specimen if not specimen: beg_pca, end_pca = "", "" if verbose and this_specimen != "": print(this_specimen, k + 1, 'out of ', len(specimen_names)) if setangle == 0: angle = "" this_specimen_measurements = meas_data[ meas_data['specimen'].str.contains(this_specimen).astype( bool)] # fish out this specimen this_specimen_measurements = this_specimen_measurements[ -this_specimen_measurements['quality'].str.contains('b').astype( bool)] # remove bad measurements if len(this_specimen_measurements) != 0: # if there are measurements meas_list = this_specimen_measurements.to_dict( 'records') # get a list of dictionaries this_sample = "" if coord != '-1' and 'sample' in meas_list[0].keys( ): # look up sample name this_sample = pmag.get_dictitem(meas_list, 'specimen', this_specimen, 'T') if len(this_sample) > 0: this_sample = this_sample[0]['sample'] # # set up datablock [[treatment,dec, inc, int, direction_type],[....]] # # # figure out the method codes # units, methods, title = "", "", this_specimen if pmagplotlib.isServer: try: loc = this_specimen_measurements.loc[:, 'location'].values[0] except: loc = "" try: site = this_specimen_measurements.loc[:, 'site'].values[0] except: site = "" try: samp = this_specimen_measurements.loc[:, 'sample'].values[0] except: samp = "" title = "LO:_{}_SI:_{}_SA:_{}_SP:_{}_".format( loc, site, samp, this_specimen) # this is a list of all the specimen method codes meas_meths = this_specimen_measurements.method_codes.unique() tr = pd.to_numeric(this_specimen_measurements.treatment).tolist() if any(cb.is_null(treat, False) for treat in tr): print( '-W- Missing required values in measurements.treatment for {}, skipping' .format(this_specimen)) if specimen: return k += 1 continue if set(tr) == set([0]): print( '-W- Missing required values in measurements.treatment for {}, skipping' .format(this_specimen)) if specimen: return k += 1 continue for m in meas_meths: if 'LT-AF-Z' in m and 'T' not in units: units = 'T' # units include tesla tr[0] = 0 if 'LT-T-Z' in m and 'K' not in units: units = units + ":K" # units include kelvin if 'LT-M-Z' in m and 'J' not in units: units = units + ':J' # units include joules tr[0] = 0 units = units.strip(':') # strip off extra colons if 'LP-' in m: methods = methods + ":" + m decs = pd.to_numeric(this_specimen_measurements.dir_dec).tolist() incs = pd.to_numeric(this_specimen_measurements.dir_inc).tolist() # # fix the coordinate system # # revert to original coordinate system coord = saved_coord if coord != '-1': # need to transform coordinates to geographic # get the azimuth or_info, az_type = pmag.get_orient(samp_data, this_sample, data_model=3) if 'azimuth' in or_info.keys() and cb.not_null( or_info['azimuth']): #azimuths = pd.to_numeric( # this_specimen_measurements.azimuth).tolist() #dips = pd.to_numeric(this_specimen_measurements.dip).tolist() azimuths = len(decs) * [or_info['azimuth']] dips = len(decs) * [or_info['dip']] # if azimuth/dip is missing, plot using specimen coordinates instead else: azimuths, dips = [], [] if any([cb.is_null(az) for az in azimuths if az != 0]): coord = '-1' print("-W- Couldn't find azimuth and dip for {}".format( this_specimen)) print(" Plotting with specimen coordinates instead") elif any([cb.is_null(dip) for dip in dips if dip != 0]): coord = '-1' print("-W- Couldn't find azimuth and dip for {}".format( this_specimen)) print(" Plotting with specimen coordinates instead") else: coord = saved_coord # if azimuth and dip were found, continue with geographic coordinates if coord != "-1" and len(azimuths) > 0: dirs = [decs, incs, azimuths, dips] # this transposes the columns and rows of the list of lists dirs_geo = np.array(list(map(list, list(zip(*dirs))))) decs, incs = pmag.dogeo_V(dirs_geo) if coord == '100' and 'bed_dip_direction' in or_info.keys( ) and or_info[ 'bed_dip_direction'] != "": # need to do tilt correction too bed_dip_dirs = len(decs) * [ or_info['bed_dip_direction'] ] bed_dips = len(decs) * [or_info['bed_dip']] #bed_dip_dirs = pd.to_numeric( # this_specimen_measurements.bed_dip_direction).tolist() # get the azimuths #bed_dips = pd.to_numeric( # this_specimen_measurements.bed_dip).tolist() # get the azimuths dirs = [decs, incs, bed_dip_dirs, bed_dips] ## this transposes the columns and rows of the list of lists dirs_tilt = np.array(list(map(list, list(zip(*dirs))))) decs, incs = pmag.dotilt_V(dirs_tilt) if pmagplotlib.isServer: title = title + "CO:_t_" else: title = title + '_t' else: if pmagplotlib.isServer: title = title + "CO:_g_" else: title = title + '_g' if angle == "": angle = decs[0] ints = pd.to_numeric(this_specimen_measurements[int_key]).tolist() ZI = this_specimen_measurements.ZI.tolist() flags = this_specimen_measurements.quality.tolist() codes = this_specimen_measurements.instrument_codes.tolist() datalist = [tr, decs, incs, ints, ZI, flags, codes] # this transposes the columns and rows of the list of lists datablock = list(map(list, list(zip(*datalist)))) pmagplotlib.plot_zed(ZED, datablock, angle, title, units) if verbose and not set_env.IS_WIN: pmagplotlib.draw_figs(ZED) # # collect info for current_specimen_interpretation dictionary # # # find prior interpretation # prior_specimen_interpretations = [] if len(prior_spec_data): prior_specimen_interpretations = prior_spec_data[ prior_spec_data['specimen'].str.contains( this_specimen) == True] if (beg_pca == "") and (len(prior_specimen_interpretations) != 0): if len(prior_specimen_interpretations) > 0: beg_pcas = pd.to_numeric(prior_specimen_interpretations. meas_step_min.values).tolist() end_pcas = pd.to_numeric(prior_specimen_interpretations. meas_step_max.values).tolist() spec_methods = prior_specimen_interpretations.method_codes.tolist( ) # step through all prior interpretations and plot them for ind in range(len(beg_pcas)): spec_meths = spec_methods[ind].split(':') for m in spec_meths: if 'DE-BFL' in m: calculation_type = 'DE-BFL' # best fit line if 'DE-BFP' in m: calculation_type = 'DE-BFP' # best fit plane if 'DE-FM' in m: calculation_type = 'DE-FM' # fisher mean if 'DE-BFL-A' in m: calculation_type = 'DE-BFL-A' # anchored best fit line if len(beg_pcas) != 0: try: # getting the starting and ending points start, end = tr.index(beg_pcas[ind]), tr.index( end_pcas[ind]) mpars = pmag.domean(datablock, start, end, calculation_type) except ValueError: print( '-W- Specimen record contains invalid start/stop bounds:' ) mpars['specimen_direction_type'] = "Error" # calculate direction/plane if mpars["specimen_direction_type"] != "Error": # put it on the plot pmagplotlib.plot_dir(ZED, mpars, datablock, angle) if verbose and not set_env.IS_WIN: pmagplotlib.draw_figs(ZED) ### SKIP if no prior interpretation - this section should not be used: # else: # try: # start, end = int(beg_pca), int(end_pca) # except ValueError: # beg_pca = 0 # end_pca = len(datablock) - 1 # start, end = int(beg_pca), int(end_pca) # # # calculate direction/plane # try: # mpars = pmag.domean(datablock, start, end, calculation_type) # except Exception as ex: # print('-I- Problem with {}'.format(this_specimen)) # print(' ', ex) # print(' Skipping') # continue # k += 1 # if mpars["specimen_direction_type"] != "Error": # # put it on the plot # pmagplotlib.plot_dir(ZED, mpars, datablock, angle) # if verbose: # pmagplotlib.draw_figs(ZED) if plots == 1 or specimen != "": if plot_file == "": basename = title else: basename = plot_file files = {} for key in list(ZED.keys()): files[key] = basename + '_' + key + '.' + fmt if pmagplotlib.isServer: files[key] = basename + "TY:_{}_.".format(key) + fmt pmagplotlib.save_plots(ZED, files) if specimen != "": sys.exit() if verbose: recnum = 0 for plotrec in datablock: if units == 'T': print('%s: %i %7.1f %s %8.3e %7.1f %7.1f %s' % (plotrec[5], recnum, plotrec[0] * 1e3, " mT", plotrec[3], plotrec[1], plotrec[2], plotrec[6])) if units == "K": print('%s: %i %7.1f %s %8.3e %7.1f %7.1f %s' % (plotrec[5], recnum, plotrec[0] - 273, ' C', plotrec[3], plotrec[1], plotrec[2], plotrec[6])) if units == "J": print('%s: %i %7.1f %s %8.3e %7.1f %7.1f %s' % (plotrec[5], recnum, plotrec[0], ' J', plotrec[3], plotrec[1], plotrec[2], plotrec[6])) if 'K' in units and 'T' in units: if plotrec[0] >= 1.: print('%s: %i %7.1f %s %8.3e %7.1f %7.1f %s' % (plotrec[5], recnum, plotrec[0] - 273, ' C', plotrec[3], plotrec[1], plotrec[2], plotrec[6])) if plotrec[0] < 1.: print('%s: %i %7.1f %s %8.3e %7.1f %7.1f %s' % (plotrec[5], recnum, plotrec[0] * 1e3, " mT", plotrec[3], plotrec[1], plotrec[2], plotrec[6])) recnum += 1 # we have a current interpretation elif mpars["specimen_direction_type"] != "Error": # # create a new specimen record for the interpreation for this # specimen this_specimen_interpretation = { col: "" for col in specimen_cols } # this_specimen_interpretation["analysts"]=user this_specimen_interpretation['software_packages'] = version_num this_specimen_interpretation['specimen'] = this_specimen this_specimen_interpretation["method_codes"] = calculation_type this_specimen_interpretation["meas_step_unit"] = units this_specimen_interpretation["meas_step_min"] = tr[start] this_specimen_interpretation["meas_step_max"] = tr[end] this_specimen_interpretation["dir_dec"] = '%7.1f' % ( mpars['specimen_dec']) this_specimen_interpretation["dir_inc"] = '%7.1f' % ( mpars['specimen_inc']) this_specimen_interpretation["dir_dang"] = '%7.1f' % ( mpars['specimen_dang']) this_specimen_interpretation["dir_n_measurements"] = '%i' % ( mpars['specimen_n']) this_specimen_interpretation["dir_tilt_correction"] = coord methods = methods.replace(" ", "") if "T" in units: methods = methods + ":LP-DIR-AF" if "K" in units: methods = methods + ":LP-DIR-T" if "J" in units: methods = methods + ":LP-DIR-M" this_specimen_interpretation["method_codes"] = methods.strip( ':') this_specimen_interpretation[ "experiments"] = this_specimen_measurements.experiment.unique( )[0] # # print some stuff # if calculation_type != 'DE-FM': this_specimen_interpretation["dir_mad_free"] = '%7.1f' % ( mpars['specimen_mad']) this_specimen_interpretation["dir_alpha95"] = '' if verbose: if units == 'K': print( '%s %i %7.1f %7.1f %7.1f %7.1f %7.1f %7.1f %s \n' % (this_specimen_interpretation["specimen"], int(this_specimen_interpretation[ "dir_n_measurements"]), float(this_specimen_interpretation[ "dir_mad_free"]), float( this_specimen_interpretation["dir_dang"]), float(this_specimen_interpretation[ "meas_step_min"]) - 273, float(this_specimen_interpretation[ "meas_step_max"]) - 273, float( this_specimen_interpretation["dir_dec"]), float( this_specimen_interpretation["dir_inc"]), calculation_type)) elif units == 'T': print( '%s %i %7.1f %7.1f %7.1f %7.1f %7.1f %7.1f %s \n' % (this_specimen_interpretation["specimen"], int(this_specimen_interpretation[ "dir_n_measurements"]), float(this_specimen_interpretation[ "dir_mad_free"]), float( this_specimen_interpretation["dir_dang"]), float(this_specimen_interpretation[ "meas_step_min"]) * 1e3, float(this_specimen_interpretation[ "meas_step_max"]) * 1e3, float( this_specimen_interpretation["dir_dec"]), float( this_specimen_interpretation["dir_inc"]), calculation_type)) elif 'T' in units and 'K' in units: if float(this_specimen_interpretation[ 'meas_step_min']) < 1.0: min = float(this_specimen_interpretation[ 'meas_step_min']) * 1e3 else: min = float(this_specimen_interpretation[ 'meas_step_min']) - 273 if float(this_specimen_interpretation[ 'meas_step_max']) < 1.0: max = float(this_specimen_interpretation[ 'meas_step_max']) * 1e3 else: max = float(this_specimen_interpretation[ 'meas_step_max']) - 273 print( '%s %i %7.1f %i %i %7.1f %7.1f %7.1f %s \n' % (this_specimen_interpretation["specimen"], int(this_specimen_interpretation[ "dir_n_measurements"]), float(this_specimen_interpretation[ "dir_mad_free"]), float( this_specimen_interpretation["dir_dang"]), min, max, float( this_specimen_interpretation["dir_dec"]), float( this_specimen_interpretation["dir_inc"]), calculation_type)) else: print( '%s %i %7.1f %7.1f %7.1f %7.1f %7.1f %7.1f %s \n' % (this_specimen_interpretation["specimen"], int(this_specimen_interpretation[ "dir_n_measurements"]), float(this_specimen_interpretation[ "dir_mad_free"]), float( this_specimen_interpretation["dir_dang"]), float(this_specimen_interpretation[ "meas_step_min"]), float(this_specimen_interpretation[ "meas_step_max"]), float( this_specimen_interpretation["dir_dec"]), float( this_specimen_interpretation["dir_inc"]), calculation_type)) else: this_specimen_interpretation["dir_alpha95"] = '%7.1f' % ( mpars['specimen_alpha95']) this_specimen_interpretation["dir_mad_free"] = '' if verbose: if 'K' in units: print( '%s %i %7.1f %7.1f %7.1f %7.1f %7.1f %7.1f %s \n' % (this_specimen_interpretation["specimen"], int(this_specimen_interpretation[ "dir_n_measurments"]), float(this_specimen_interpretation[ "dir_mad_free"]), float( this_specimen_interpretation["dir_dang"]), float(this_specimen_interpretation[ "meas_step_min"]) - 273, float(this_specimen_interpretation[ "meas_step_max"]) - 273, float( this_specimen_interpretation["dir_dec"]), float( this_specimen_interpretation["dir_inc"]), calculation_type)) elif 'T' in units: print( '%s %i %7.1f %7.1f %7.1f %7.1f %7.1f %7.1f %s \n' % (this_specimen_interpretation["specimen"], int(this_specimen_interpretation[ "dir_n_measurements"]), float(this_specimen_interpretation[ "dir_alpha95"]), float( this_specimen_interpretation["dir_dang"]), float(this_specimen_interpretation[ "meas_step_min"]) * 1e3, float(this_specimen_interpretation[ "meas_step_max"]) * 1e3, float( this_specimen_interpretation["dir_dec"]), float( this_specimen_interpretation["dir_inc"]), calculation_type)) elif 'T' in units and 'K' in units: if float(this_specimen_interpretation[ 'meas_step_min']) < 1.0: min = float(this_specimen_interpretation[ 'meas_step_min']) * 1e3 else: min = float(this_specimen_interpretation[ 'meas_step_min']) - 273 if float(this_specimen_interpretation[ 'meas_step_max']) < 1.0: max = float(this_specimen_interpretation[ 'meas_step_max']) * 1e3 else: max = float(this_specimen_interpretation[ 'meas_step_max']) - 273 print('%s %i %7.1f %i %i %7.1f %7.1f %s \n' % ( this_specimen_interpretation["specimen"], int(this_specimen_interpretation[ "dir_n_measurements"]), float( this_specimen_interpretation["dir_alpha95"] ), min, max, float(this_specimen_interpretation["dir_dec"]), float(this_specimen_interpretation["dir_inc"]), calculation_type)) else: print( '%s %i %7.1f %7.1f %7.1f %7.1f %7.1f %s \n' % (this_specimen_interpretation["specimen"], int(this_specimen_interpretation[ "dir_n_measurements"]), float(this_specimen_interpretation[ "dir_alpha95"]), float(this_specimen_interpretation[ "meas_step_min"]), float(this_specimen_interpretation[ "meas_step_max"]), float( this_specimen_interpretation["dir_dec"]), float( this_specimen_interpretation["dir_inc"]), calculation_type)) if verbose: saveit = input("Save this interpretation? [y]/n \n") else: print("no data", this_specimen) if verbose: pmagplotlib.draw_figs(ZED) #res = input(' <return> for next specimen, [q]uit ') res = input("S[a]ve plots, [q]uit, or <return> to continue ") if res == 'a': files = { plot_type: this_specimen + "_" + plot_type + "." + fmt for plot_type in ZED } pmagplotlib.save_plots(ZED, files) print("") if res == 'q': return k += 1
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 pmag_sites formatted file [default is pmag_sites.txt] -fsa er_samples formatted file [default is er_samples.txt] -fsi er_sites formatted file -exc use pmag_criteria.txt to set acceptance criteria -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 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 """ kappa = 0 nb = 1000 # number of bootstraps min, max = -10, 150 dir_path = '.' infile, orfile = 'pmag_sites.txt', 'er_samples.txt' critfile = 'pmag_criteria.txt' dipkey, azkey = 'sample_bed_dip', 'sample_bed_dip_direction' fmt = 'svg' plot = 0 if '-WD' in sys.argv: ind = sys.argv.index('-WD') dir_path = sys.argv[ind + 1] if '-h' in sys.argv: # check if help is needed print(main.__doc__) sys.exit() # graceful quit if '-n' in sys.argv: ind = sys.argv.index('-n') nb = int(sys.argv[ind + 1]) if '-fmt' in sys.argv: ind = sys.argv.index('-fmt') fmt = sys.argv[ind + 1] if '-sav' in sys.argv: plot = 1 if '-b' in sys.argv: ind = sys.argv.index('-b') min = int(sys.argv[ind + 1]) max = int(sys.argv[ind + 2]) if '-f' in sys.argv: ind = sys.argv.index('-f') infile = sys.argv[ind + 1] if '-fsa' in sys.argv: ind = sys.argv.index('-fsa') orfile = sys.argv[ind + 1] elif '-fsi' in sys.argv: ind = sys.argv.index('-fsi') orfile = sys.argv[ind + 1] dipkey, azkey = 'site_bed_dip', 'site_bed_dip_direction' orfile = dir_path + '/' + orfile infile = dir_path + '/' + infile critfile = dir_path + '/' + critfile data, file_type = pmag.magic_read(infile) ordata, file_type = pmag.magic_read(orfile) if '-exc' in sys.argv: crits, file_type = pmag.magic_read(critfile) for crit in crits: if crit['pmag_criteria_code'] == "DE-SITE": SiteCrit = crit break # get to work # PLTS = {'geo': 1, 'strat': 2, 'taus': 3} # make plot dictionary pmagplotlib.plot_init(PLTS['geo'], 5, 5) pmagplotlib.plot_init(PLTS['strat'], 5, 5) pmagplotlib.plot_init(PLTS['taus'], 5, 5) GEOrecs = pmag.get_dictitem(data, 'site_tilt_correction', '0', 'T') if len(GEOrecs) > 0: # have some geographic data DIDDs = [] # set up list for dec inc dip_direction, dip for rec in GEOrecs: # parse data dip, dip_dir = 0, -1 Dec = float(rec['site_dec']) Inc = float(rec['site_inc']) orecs = pmag.get_dictitem(ordata, 'er_site_name', rec['er_site_name'], '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 key in list(SiteCrit.keys()): if 'site' in key and SiteCrit[key] != "" and rec[ key] != "" and key != 'site_alpha95': if float(rec[key]) < float(SiteCrit[key]): keep = 0 print(rec['er_site_name'], key, rec[key]) if key == 'site_alpha95' and SiteCrit[ key] != "" and rec[key] != "": if float(rec[key]) > float(SiteCrit[key]): keep = 0 if keep == 1: DIDDs.append([Dec, Inc, dip_dir, dip]) else: DIDDs.append([Dec, Inc, dip_dir, dip]) else: print('no geographic directional data found') sys.exit() pmagplotlib.plotEQ(PLTS['geo'], DIDDs, 'Geographic') data = numpy.array(DIDDs) D, I = pmag.dotilt_V(data) TCs = numpy.array([D, I]).transpose() pmagplotlib.plotEQ(PLTS['strat'], TCs, 'Stratigraphic') if plot == 0: pmagplotlib.drawFIGS(PLTS) Percs = list(range(min, max)) Cdf, Untilt = [], [] pylab.figure(num=PLTS['taus']) print('doing ', nb, ' iterations...please be patient.....') for n in range( nb): # 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 = numpy.array([1., 1., 1., 0.01 * perc]) D, I = pmag.dotilt_V(PDs * tilt) TCs = numpy.array([D, I]).transpose() ppars = pmag.doprinc(TCs) # get principal directions Taus.append(ppars['tau1']) if n < 25: pylab.plot(Percs, Taus, 'r--') Untilt.append(Percs[Taus.index( numpy.max(Taus))]) # tilt that gives maximum tau Cdf.append(old_div(float(n), float(nb))) pylab.plot(Percs, Taus, 'k') pylab.xlabel('% Untilting') pylab.ylabel('tau_1 (red), CDF (green)') Untilt.sort() # now for CDF of tilt of maximum tau pylab.plot(Untilt, Cdf, 'g') lower = int(.025 * nb) upper = int(.975 * nb) pylab.axvline(x=Untilt[lower], ymin=0, ymax=1, linewidth=1, linestyle='--') pylab.axvline(x=Untilt[upper], ymin=0, ymax=1, linewidth=1, linestyle='--') tit = '%i - %i %s' % (Untilt[lower], Untilt[upper], 'Percent Unfolding') print(tit) pylab.title(tit) if plot == 0: pmagplotlib.drawFIGS(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.saveP(PLTS, files)
def main(): """ NAME di_rot.py DESCRIPTION rotates set of directions to new coordinate system SYNTAX di_rot.py [command line options] OPTIONS -h prints help message and quits -f specify input file, default is standard input -F specify output file, default is standard output -D D specify Dec of new coordinate system, default is 0 -I I specify Inc of new coordinate system, default is 90 INTPUT/OUTPUT dec inc [space delimited] """ D, I = 0., 90. outfile = "" infile = "" if '-h' in sys.argv: print main.__doc__ sys.exit() if '-f' in sys.argv: ind = sys.argv.index('-f') infile = sys.argv[ind + 1] data = numpy.loadtxt(infile) else: data = numpy.loadtxt(sys.stdin, dtype=numpy.float) if '-F' in sys.argv: ind = sys.argv.index('-F') outfile = sys.argv[ind + 1] out = open(outfile, 'w') if '-D' in sys.argv: ind = sys.argv.index('-D') D = float(sys.argv[ind + 1]) if '-I' in sys.argv: ind = sys.argv.index('-I') I = float(sys.argv[ind + 1]) if len(data.shape) > 1: # 2-D array N = data.shape[0] DipDir, Dip = numpy.ones(N, dtype=numpy.float).transpose() * ( D - 180.), numpy.ones(N, dtype=numpy.float).transpose() * (90. - I) data = data.transpose() data = numpy.array([data[0], data[1], DipDir, Dip]).transpose() drot, irot = pmag.dotilt_V(data) drot = (drot - 180.) % 360. # for k in range(N): if outfile == "": print '%7.1f %7.1f ' % (drot[k], irot[k]) else: out.write('%7.1f %7.1f\n' % (drot[k], irot[k])) else: d, i = pmag.dotilt(data[0], data[1], (D - 180.), 90. - I) if outfile == "": print '%7.1f %7.1f ' % ((d - 180.) % 360., i) else: out.write('%7.1f %7.1f\n' % ((d - 180.) % 360., i))
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 pmag_sites formatted file [default is pmag_sites.txt] -fsa er_samples formatted file [default is er_samples.txt] -fsi er_sites formatted file -exc use pmag_criteria.txt to set acceptance criteria -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 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 """ kappa=0 nb=1000 # number of bootstraps min,max=-10,150 dir_path='.' infile,orfile='pmag_sites.txt','er_samples.txt' critfile='pmag_criteria.txt' dipkey,azkey='sample_bed_dip','sample_bed_dip_direction' fmt='svg' plot=0 if '-WD' in sys.argv: ind=sys.argv.index('-WD') dir_path=sys.argv[ind+1] if '-h' in sys.argv: # check if help is needed print main.__doc__ sys.exit() # graceful quit if '-n' in sys.argv: ind=sys.argv.index('-n') nb=int(sys.argv[ind+1]) if '-fmt' in sys.argv: ind=sys.argv.index('-fmt') fmt=sys.argv[ind+1] if '-sav' in sys.argv:plot=1 if '-b' in sys.argv: ind=sys.argv.index('-b') min=int(sys.argv[ind+1]) max=int(sys.argv[ind+2]) if '-f' in sys.argv: ind=sys.argv.index('-f') infile=sys.argv[ind+1] if '-fsa' in sys.argv: ind=sys.argv.index('-fsa') orfile=sys.argv[ind+1] elif '-fsi' in sys.argv: ind=sys.argv.index('-fsi') orfile=sys.argv[ind+1] dipkey,azkey='site_bed_dip','site_bed_dip_direction' orfile=dir_path+'/'+orfile infile=dir_path+'/'+infile critfile=dir_path+'/'+critfile data,file_type=pmag.magic_read(infile) ordata,file_type=pmag.magic_read(orfile) if '-exc' in sys.argv: crits,file_type=pmag.magic_read(critfile) for crit in crits: if crit['pmag_criteria_code']=="DE-SITE": SiteCrit=crit break # get to work # PLTS={'geo':1,'strat':2,'taus':3} # make plot dictionary pmagplotlib.plot_init(PLTS['geo'],5,5) pmagplotlib.plot_init(PLTS['strat'],5,5) pmagplotlib.plot_init(PLTS['taus'],5,5) GEOrecs=pmag.get_dictitem(data,'site_tilt_correction','0','T') if len(GEOrecs)>0: # have some geographic data DIDDs= [] # set up list for dec inc dip_direction, dip for rec in GEOrecs: # parse data dip,dip_dir=0,-1 Dec=float(rec['site_dec']) Inc=float(rec['site_inc']) orecs=pmag.get_dictitem(ordata,'er_site_name',rec['er_site_name'],'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 key in SiteCrit.keys(): if 'site' in key and SiteCrit[key]!="" and rec[key]!="" and key!='site_alpha95': if float(rec[key])<float(SiteCrit[key]): keep=0 print rec['er_site_name'],key,rec[key] if key=='site_alpha95' and SiteCrit[key]!="" and rec[key]!="": if float(rec[key])>float(SiteCrit[key]): keep=0 if keep==1: DIDDs.append([Dec,Inc,dip_dir,dip]) else: DIDDs.append([Dec,Inc,dip_dir,dip]) else: print 'no geographic directional data found' sys.exit() pmagplotlib.plotEQ(PLTS['geo'],DIDDs,'Geographic') data=numpy.array(DIDDs) D,I=pmag.dotilt_V(data) TCs=numpy.array([D,I]).transpose() pmagplotlib.plotEQ(PLTS['strat'],TCs,'Stratigraphic') if plot==0:pmagplotlib.drawFIGS(PLTS) Percs=range(min,max) Cdf,Untilt=[],[] pylab.figure(num=PLTS['taus']) print 'doing ',nb,' iterations...please be patient.....' for n in range(nb): # 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=numpy.array([1.,1.,1.,0.01*perc]) D,I=pmag.dotilt_V(PDs*tilt) TCs=numpy.array([D,I]).transpose() ppars=pmag.doprinc(TCs) # get principal directions Taus.append(ppars['tau1']) if n<25:pylab.plot(Percs,Taus,'r--') Untilt.append(Percs[Taus.index(numpy.max(Taus))]) # tilt that gives maximum tau Cdf.append(float(n)/float(nb)) pylab.plot(Percs,Taus,'k') pylab.xlabel('% Untilting') pylab.ylabel('tau_1 (red), CDF (green)') Untilt.sort() # now for CDF of tilt of maximum tau pylab.plot(Untilt,Cdf,'g') lower=int(.025*nb) upper=int(.975*nb) pylab.axvline(x=Untilt[lower],ymin=0,ymax=1,linewidth=1,linestyle='--') pylab.axvline(x=Untilt[upper],ymin=0,ymax=1,linewidth=1,linestyle='--') tit= '%i - %i %s'%(Untilt[lower],Untilt[upper],'Percent Unfolding') print tit pylab.title(tit) if plot==0: pmagplotlib.drawFIGS(PLTS) ans= raw_input('S[a]ve all figures, <Return> to quit \n ') if ans!='a': print "Good bye" sys.exit() files={} for key in PLTS.keys(): files[key]=('foldtest_'+'%s'%(key.strip()[:2])+'.'+fmt) pmagplotlib.saveP(PLTS,files)