예제 #1
0
def convertbirrpoutput(stationname,
                       datadir,
                       survey_configfile,
                       birrp_configfile=None,
                       instr_response_file=None):

    edifn = None
    cohfn = None

    try:
        datadir = op.realpath(op.abspath(datadir))
        if not op.isdir(datadir):
            raise
    except:
        sys.exit('Directory not existing: {0}'.format(datadir))

    try:
        survey_configfile = op.abspath(survey_configfile)
        if not op.isfile(survey_configfile):
            raise
    except:
        sys.exit(
            'Survey config file does not exist: {0}'.format(survey_configfile))

    if birrp_configfile is not None:
        try:
            birrp_configfile = op.abspath(birrp_configfile)
            if not op.isfile(birrp_configfile):
                raise
        except:
            print('Birrp config file not existing: {0} - using generic values'\
                ''.format(birrp_configfile))
            birrp_configfile = None

    if instr_response_file is not None:
        try:

            ir_fn = op.abspath(instr_response_file)
            # print irfn,instr_response_file
            if not op.isfile(ir_fn):
                raise
        except:
            sys.exit(
                'Instrument response file does not exist: {0}'.format(ir_fn))
        try:
            instr_resp = np.loadtxt(ir_fn)
            if np.shape(instr_resp)[1] != 3:
                raise
            if len(np.shape(instr_resp)) != 2:
                raise
            if np.shape(instr_resp)[0] < 2:
                raise
        except:
            sys.exit('\n\t!!! Instrument response file has wrong format !!!\n'
                     '\nNeeds 3 columns and at least 2 rows containing complex'
                     ' valued transfer function:\n\n\tfrequency, real,'
                     ' imaginary\n\n')

        try:
            cohfn = MTbp.convert2coh(stationname, datadir)
        except:
            try:
                print('trying to find files for uppercase stationname')
                cohfn = MTbp.convert2coh(stationname.upper(), datadir)
            except:
                cohfn = None
                print('Could not generate coherence file')
        try:
            edifn = MTbp.convert2edi_incl_instrument_correction(
                stationname, datadir, survey_configfile, birrp_configfile,
                ir_fn)

        except:
            raise
            try:
                edifn = MTbp.convert2edi_incl_instrument_correction(
                    stationname.upper(), datadir, survey_configfile,
                    birrp_configfile, ir_fn)
            except:
                edifn = None
                print('Could not generate EDI file')

        return edifn, cohfn

    try:
        cohfn = MTbp.convert2coh(stationname, datadir)
    except:
        try:
            print('trying to find files for uppercase stationname')
            cohfn = MTbp.convert2coh(stationname.upper(), datadir)
        except:
            cohfn = None
            print('Could not generate coherence file')

    try:
        edifn = MTbp.convert2edi(stationname, datadir, survey_configfile,
                                 birrp_configfile)
    except:
        try:
            edifn = MTbp.convert2edi(stationname.upper(), datadir,
                                     survey_configfile, birrp_configfile)

        except:
            raise
            print('Could not generate EDI file')
            edifn = None

    return edifn, cohfn
예제 #2
0
def convertbirrpoutput(stationname, datadir, survey_configfile,birrp_configfile=None,
                instr_response_file=None):

    edifn = None
    cohfn = None

    try:
        datadir = op.realpath(op.abspath(datadir))
        if not op.isdir(datadir):
            raise
    except:
        sys.exit('Directory not existing: {0}'.format(datadir))

    try:
        survey_configfile = op.abspath(survey_configfile)
        if not op.isfile(survey_configfile):
            raise
    except:
        sys.exit('Survey config file does not exist: {0}'.format(survey_configfile))

    if birrp_configfile is not None:
        try:
            birrp_configfile = op.abspath(birrp_configfile)
            if not op.isfile(birrp_configfile):
                raise
        except:
            print('Birrp config file not existing: {0} - using generic values'\
                                                    ''.format(birrp_configfile))
            birrp_configfile = None


    if instr_response_file is not None:
        try:
            
            ir_fn = op.abspath(instr_response_file)
            #print irfn,instr_response_file
            if not op.isfile(ir_fn):
                raise
        except:
            sys.exit('Instrument response file does not exist: {0}'.format(ir_fn))
        try:
            instr_resp = np.loadtxt(ir_fn)
            if np.shape(instr_resp)[1] != 3:
                raise
            if len(np.shape(instr_resp)) != 2 :
                raise
            if np.shape(instr_resp)[0] < 2:
                raise
        except:
            sys.exit('\n\t!!! Instrument response file has wrong format !!!\n'
                    '\nNeeds 3 columns and at least 2 rows containing complex'
                    ' valued transfer function:\n\n\tfrequency, real,'
                    ' imaginary\n\n')

        try:
            cohfn = MTbp.convert2coh(stationname, datadir)
        except:
            try:
                print('trying to find files for uppercase stationname')
                cohfn = MTbp.convert2coh(stationname.upper(), datadir) 
            except:
                cohfn =  None
                print('Could not generate coherence file')
        try:
            edifn = MTbp.convert2edi_incl_instrument_correction(stationname,\
                                                        datadir,\
                                                        survey_configfile,\
                                                        birrp_configfile,\
                                                        ir_fn)

        except:
            raise
            try:
                edifn = MTbp.convert2edi_incl_instrument_correction(stationname.upper(),\
                                                        datadir,\
                                                        survey_configfile,\
                                                        birrp_configfile,\
                                                        ir_fn)
            except:
                edifn = None
                print('Could not generate EDI file')
        
        return edifn, cohfn    
 

    try :
        cohfn = MTbp.convert2coh(stationname, datadir)
    except:
        try:
            print('trying to find files for uppercase stationname')
            cohfn = MTbp.convert2coh(stationname.upper(), datadir) 
        except:
            cohfn =  None
            print('Could not generate coherence file')

    try:
        edifn = MTbp.convert2edi(stationname,\
                        datadir,\
                        survey_configfile,\
                        birrp_configfile)
    except:
        try:
            edifn = MTbp.convert2edi(stationname.upper(),\
                            datadir,\
                            survey_configfile,\
                            birrp_configfile)
        
        except:
            raise
            print('Could not generate EDI file')
            edifn = None
    
    return edifn, cohfn    
예제 #3
0
def convertbirrp(stationname, datadir, survey_configfile,birrp_configfile=None,
                instr_response_file=None):

    edifn = None
    cohfn = None

    try:
        datadir = op.realpath(op.abspath(datadir))
        if not op.isdir(datadir):
            raise
    except:
        sys.exit('Directory not existing: {0}'.format(datadir))

    try:
        survey_configfile = op.abspath(survey_configfile)
        if not op.isfile(survey_configfile):
            raise
    except:
        sys.exit('Survey config file not existing: {0}'.format(survey_configfile))

    if birrp_configfile is not None:
        try:
            birrp_configfile = op.abspath(birrp_configfile)
            if not op.isfile(birrp_configfile):
                raise
        except:
            print 'Birrp config file not existing: {0} - using generic values'\
                                                    ''.format(birrp_configfile)
            birrp_configfile = None


    if instr_response_file is not None:
        try:
            ir_fn = op.abspath(instr_response_file)
            if not op.isfile(ir_fn):
                raise
        except:
            sys.exit('Instrument response file not existing: {0}'.format(ir_fn))

        try:
            cohfn = MTbp.convert2coh(stationname, datadir)
        except:
            try:
                cohfn = MTbp.convert2coh(stationname.upper(), datadir) 
            except:
                print 'Could not generate coherence file'


        try:
            edifn = MTbp.convert2edi_incl_instrument_correction(stationname,\
                                                        datadir,\
                                                        survey_configfile,\
                                                        birrp_configfile,\
                                                        ir_fn)
        except:
            try:
                edifn = MTbp.convert2edi_incl_instrument_correction(stationname.upper(),\
                                                        datadir,\
                                                        survey_configfile,\
                                                        birrp_configfile,\
                                                        ir_fn)
            except:
                print 'Could not generate EDI file'
        
        return edifn, cohfn    
 

    try:
        cohfn = MTbp.convert2coh(stationname, datadir)
    except:
        try:
            cohfn = MTbp.convert2coh(stationname.upper(), datadir) 
        except:
            print 'Could not generate coherence file'

    try:
        edifn = MTbp.convert2edi(stationname,\
                        datadir,\
                        survey_configfile,\
                        birrp_configfile)
    except:
        try:
            edifn = MTbp.convert2edi(stationname.upper(),\
                            datadir,\
                            survey_configfile,\
                            birrp_configfile)
        
        except:
            print 'Could not generate EDI file'
    
    return edifn, cohfn