def azdip_magic(orient_file='orient.txt', samp_file="samples.txt", samp_con="1", Z=1, method_codes='FS-FD', location_name='unknown', append=False, output_dir='.', input_dir='.', data_model=3):
    """
    takes space delimited AzDip file and converts to MagIC formatted tables

    Parameters
    __________
        orient_file : name of azdip formatted input file
        samp_file : name of samples.txt formatted output file
        samp_con :  integer of sample orientation convention
            [1] XXXXY: where XXXX is an arbitrary length site designation and Y
                is the single character sample designation.  e.g., TG001a is the
                first sample from site TG001.    [default]
            [2] XXXX-YY: YY sample from site XXXX (XXX, YY of arbitary length)
            [3] XXXX.YY: YY sample from site XXXX (XXX, YY of arbitary length)
            [4-Z] XXXX[YYY]:  YYY is sample designation with Z characters from site XXX
            [5] site name same as sample
            [6] site name entered in site_name column in the orient.txt format input file  -- NOT CURRENTLY SUPPORTED
            [7-Z] [XXXX]YYY:  XXXX is site designation with Z characters with sample name XXXXYYYY

        method_codes :  colon delimited string with the following as desired
             FS-FD field sampling done with a drill
             FS-H field sampling done with hand samples
             FS-LOC-GPS  field location done with GPS
             FS-LOC-MAP  field location done with map
             SO-POM   a Pomeroy orientation device was used
             SO-ASC   an ASC orientation device was used
             SO-MAG   orientation with magnetic compass
        location_name : location of samples
        append : boolean.  if True, append to the output file
        output_dir : path to output file directory
        input_dir : path to input file directory
        data_model : MagIC data model.

    INPUT FORMAT
        Input files must be space delimited:
            Samp  Az Dip Strike Dip
        Orientation convention:
             Lab arrow azimuth = mag_azimuth; Lab arrow dip = 90-field_dip
                e.g. field_dip is degrees from horizontal of drill direction
         Magnetic declination convention:
             Az is already corrected in file

    """
    #
    # initialize variables
    #
    data_model = int(data_model)
    if (data_model != 3) and (samp_file == "samples.txt"):
        samp_file = "er_samples.txt"
    if (data_model == 2) and (samp_file == "er_samples.txt"):
        samp_file = "samples.txt"
    DEBUG = 0
    version_num = pmag.get_version()
    or_con, corr = "3", "1"
    # date of sampling, latitude (pos North), longitude (pos East)
    date, lat, lon = "", "", ""
    bed_dip, bed_dip_dir = "", ""
    participantlist = ""
    sites = []   # list of site names
    Lats, Lons = [], []  # list of latitudes and longitudes
    # lists of Sample records and Site records
    SampRecs, SiteRecs, ImageRecs, imagelist = [], [], [], []
    average_bedding = "1", 1, "0"
    newbaseline, newbeddir, newbeddip = "", "", ""
    delta_u = "0"
    sclass, lithology, type = "", "", ""
    newclass, newlith, newtype = '', '', ''
    user = ""
    corr == "3"
    DecCorr = 0.
    samp_file = pmag.resolve_file_name(samp_file, output_dir)
    orient_file = pmag.resolve_file_name(orient_file, input_dir)
    input_dir = os.path.split(orient_file)[0]
    output_dir = os.path.split(samp_file)[0]
    #
    #
    if append:
        try:
            SampRecs, file_type = pmag.magic_read(samp_file)
            print("sample data to be appended to: ", samp_file)
        except:
            print('problem with existing samp file: ',
                  samp_file, ' will create new')
    #
    # read in file to convert
    #
    azfile = open(orient_file, 'r')
    AzDipDat = azfile.readlines()
    azfile.close()
    if not AzDipDat:
        return False, 'No data in orientation file, please try again'
    azfile.close()
    SampOut, samplist = [], []
    for line in AzDipDat:
        orec = line.split()
        if len(orec) > 2:
            labaz, labdip = pmag.orient(float(orec[1]), float(orec[2]), or_con)
            bed_dip = float(orec[4])
            if bed_dip != 0:
                bed_dip_dir = float(orec[3]) - \
                    90.  # assume dip to right of strike
            else:
                bed_dip_dir = float(orec[3])  # assume dip to right of strike
            MagRec = {}
            MagRec["er_location_name"] = location_name
            MagRec["er_citation_names"] = "This study"
    #
    # parse information common to all orientation methods
    #
            MagRec["er_sample_name"] = orec[0]
            MagRec["sample_bed_dip"] = '%7.1f' % (bed_dip)
            MagRec["sample_bed_dip_direction"] = '%7.1f' % (bed_dip_dir)
            MagRec["sample_dip"] = '%7.1f' % (labdip)
            MagRec["sample_azimuth"] = '%7.1f' % (labaz)
            methods = method_codes.replace(" ", "").split(":")
            OR = 0
            for method in methods:
                method_type = method.split("-")
                if "SO" in method_type:
                    OR = 1
            if OR == 0:
                method_codes = method_codes + ":SO-NO"
            MagRec["magic_method_codes"] = method_codes
            # parse out the site name
            site = pmag.parse_site(orec[0], samp_con, Z)
            MagRec["er_site_name"] = site
            MagRec['magic_software_packages'] = version_num
            SampOut.append(MagRec)
            if MagRec['er_sample_name'] not in samplist:
                samplist.append(MagRec['er_sample_name'])
    for samp in SampRecs:
        if samp not in samplist:
            SampOut.append(samp)
    Samps, keys = pmag.fillkeys(SampOut)
    if data_model == 2:
        # write to file
        pmag.magic_write(samp_file, Samps, "er_samples")
    else:
        # translate sample records to MagIC 3
        Samps3 = []
        for samp in Samps:
            Samps3.append(map_magic.mapping(
                samp, map_magic.samp_magic2_2_magic3_map))
        # write to file
        pmag.magic_write(samp_file, Samps3, "samples")
    print("Data saved in ", samp_file)
    return True, None
def azdip_magic ( orient_file = 'orient.txt' , samp_file = "samples.txt" , samp_con = "1" , Z = 1 , method_codes = 'FS-FD' , location_name = 'unknown' , append = False , output_dir = '.' , input_dir = '.' , data_model = 3 ) : data_model = int ( data_model ) if ( data_model != 3 ) and ( samp_file == "samples.txt" ) : samp_file = "er_samples.txt" if ( data_model == 2 ) and ( samp_file == "er_samples.txt" ) : samp_file = "samples.txt" DEBUG = 0 version_num = pmag . get_version ( ) or_con , corr = "3" , "1" date , lat , lon = "" , "" , "" bed_dip , bed_dip_dir = "" , "" participantlist = "" sites = [ ] Lats , Lons = [ ] , [ ] SampRecs , SiteRecs , ImageRecs , imagelist = [ ] , [ ] , [ ] , [ ] average_bedding = "1" , 1 , "0" newbaseline , newbeddir , newbeddip = "" , "" , "" delta_u = "0" sclass , lithology , type = "" , "" , "" newclass , newlith , newtype = '' , '' , '' user = "" corr == "3" DecCorr = 0. samp_file = pmag . resolve_file_name ( samp_file , output_dir ) orient_file = pmag . resolve_file_name ( orient_file , input_dir ) input_dir = os . path . split ( orient_file ) [ 0 ] output_dir = os . path . split ( samp_file ) [ 0 ] if append : try : SampRecs , file_type = pmag . magic_read ( samp_file ) print ( "sample data to be appended to: " , samp_file ) except : print ( 'problem with existing samp file: ' , samp_file , ' will create new' ) azfile = open ( orient_file , 'r' ) AzDipDat = azfile . readlines ( ) azfile . close ( ) if not AzDipDat : return False , 'No data in orientation file, please try again' azfile . close ( ) SampOut , samplist = [ ] , [ ] for line in AzDipDat : orec = line . split ( ) if len ( orec ) > 2 : labaz , labdip = pmag . orient ( float ( orec [ 1 ] ) , float ( orec [ 2 ] ) , or_con ) bed_dip = float ( orec [ 4 ] ) if bed_dip != 0 : bed_dip_dir = float ( orec [ 3 ] ) - 90. else : bed_dip_dir = float ( orec [ 3 ] ) MagRec = { } MagRec [ "er_location_name" ] = location_name MagRec [ "er_citation_names" ] = "This study" MagRec [ "er_sample_name" ] = orec [ 0 ] MagRec [ "sample_bed_dip" ] = '%7.1f' % ( bed_dip ) MagRec [ "sample_bed_dip_direction" ] = '%7.1f' % ( bed_dip_dir ) MagRec [ "sample_dip" ] = '%7.1f' % ( labdip ) MagRec [ "sample_azimuth" ] = '%7.1f' % ( labaz ) methods = method_codes . replace ( " " , "" ) . split ( ":" ) OR = 0 for method in methods : method_type = method . split ( "-" ) if "SO" in method_type : OR = 1 if OR == 0 : method_codes = method_codes + ":SO-NO" MagRec [ "magic_method_codes" ] = method_codes site = pmag . parse_site ( orec [ 0 ] , samp_con , Z ) MagRec [ "er_site_name" ] = site MagRec [ 'magic_software_packages' ] = version_num SampOut . append ( MagRec ) if MagRec [ 'er_sample_name' ] not in samplist : samplist . append ( MagRec [ 'er_sample_name' ] ) for samp in SampRecs : if samp not in samplist : SampOut . append ( samp ) Samps , keys = pmag . fillkeys ( SampOut ) if data_model == 2 : pmag . magic_write ( samp_file , Samps , "er_samples" ) else : Samps3 = [ ] for samp in Samps : Samps3 . append ( map_magic . mapping ( samp , map_magic . samp_magic2_2_magic3_map ) ) pmag . magic_write ( samp_file , Samps3 , "samples" ) print ( "Data saved in " , samp_file ) return True , None
takes space delimited AzDip file and converts to MagIC formatted tables

    Parameters
    __________
        orient_file : name of azdip formatted input file
        samp_file : name of samples.txt formatted output file
        samp_con :  integer of sample orientation convention
            [1] XXXXY: where XXXX is an arbitrary length site designation and Y
                is the single character sample designation.  e.g., TG001a is the
                first sample from site TG001.    [default]
            [2] XXXX-YY: YY sample from site XXXX (XXX, YY of arbitary length)
            [3] XXXX.YY: YY sample from site XXXX (XXX, YY of arbitary length)
            [4-Z] XXXX[YYY]:  YYY is sample designation with Z characters from site XXX
            [5] site name same as sample
            [6] site name entered in site_name column in the orient.txt format input file  -- NOT CURRENTLY SUPPORTED
            [7-Z] [XXXX]YYY:  XXXX is site designation with Z characters with sample name XXXXYYYY

        method_codes :  colon delimited string with the following as desired
             FS-FD field sampling done with a drill
             FS-H field sampling done with hand samples
             FS-LOC-GPS  field location done with GPS
             FS-LOC-MAP  field location done with map
             SO-POM   a Pomeroy orientation device was used
             SO-ASC   an ASC orientation device was used
             SO-MAG   orientation with magnetic compass
        location_name : location of samples
        append : boolean.  if True, append to the output file
        output_dir : path to output file directory
        input_dir : path to input file directory
        data_model : MagIC data model.

    INPUT FORMAT
        Input files must be space delimited:
            Samp  Az Dip Strike Dip
        Orientation convention:
             Lab arrow azimuth = mag_azimuth; Lab arrow dip = 90-field_dip
                e.g. field_dip is degrees from horizontal of drill direction
         Magnetic declination convention:
             Az is already corrected in file