MTtools: tools for working with MT response functions

MTpy.core.MTtools.adaptiveNotchFilter(bx,df,notches=[50,100],notchradius=.3,freqrad=.9)[source]

will apply a notch filter to the array bx by finding the nearest peak around the supplied notch locations. The filter is a zero-phase Chebyshev type 1 bandstop filter with minimal ripples.

Inputs:
bx = array to filter df = sampling frequency notches = list of notches to filter notchradius = radius of the notch in frequency domain freqrad = radius for searching for peak about notch rp = ripple of Chebyshev type 1 filter, lower numbers means less ripples
Outputs:
bx = filtered array filtlst = location of notches and power difference
MTpy.core.MTtools.combineEdifiles(edifile1, edifile2, nread1, nread2)[source]

combineEdifiles(edifile1,edifile2,read1,read2) will combine edifile1 with edifile2 according to read1 and read2. It will combine frequencies, impedance and tipper.

Note nread1 is from the start for edifile1 and nread2 is from end for edifile2.

Inputs:

edifile1 = full path to edifile with the largest frequencies edifile2 = full path to edifile with smallest frequencies, longest

periods
nread1 = integer of number of frequencies to read in from edifile1.
Index is from the start, ie [0:nread1]
nread2 = integer of number of frequencies to read in from edifile2.
Index is from end of frequencies, ie [-nread2:]
Outputs:
newedifile = full path to new edifile, which is saved to edifile1 with
a c before .edi
MTpy.core.MTtools.combineFewFiles(dirpath, station, starttime, endtime, cachelength, complst=['BX', 'BY', 'BZ', 'EX', 'EY'], d=0, fdict=None)[source]

combineFewFiles(dirpath,station,starttime,endtime,cachelength, complst=[‘BX’,’BY’,’BZ’,’EX’,’EY’],d=0) Will combine files in a directory path (dirpath) that have a given start and end time in the form of (HHMMSS). It looks for files at cachelength then decimates the data by d. Input:

dirpath = directory path to folder where files to combine reside station = station name starttime = start time as 6 character string hhmmss endtime = end time as 6 character string hhmmss cachelength = cacherate of each file as 6 character string hhmmss complst = components to combine d = decimation factor, if no decimation enter as 0 or 1
Output:
cfilelst = list of combined files with full path for each component
files are saved as dirpathCombHHtoHHd(d)stationHHtoHH.comp
fileslst = list of files that were combined including length of each
file.
MTpy.core.MTtools.combineFiles(dirpath,station,daydict,complst=['EX','EY','BX','BY','BZ'])[source]

will combine files from different days into one file.

Inputs:

dirpath = directory path where station files are station = name of station daylst = list of information to combine files with a dictionary for

each day with keys:
day = utc day (thee character string) start = start time in (‘hhmmss’) stop = end time in(‘hhmmss’) filt = ‘Filtered’ if time series was filtered

cacherate = length of file (‘hhmmss’) dec = decimation factor (0 for none) complst = list of components to combine fdict = dictionary for adaptiveNotchFilter

Outputs:
cfilelst = list of combined files with full path as
dirpath/station/Combdaylst[0]todaylst[-1]
MTpy.core.MTtools.convertCounts2Units(filenames, eyn='n', lpyn='n', egain=1.0, dlgain=1.0, exlen=100.0, eylen=100.0, magtype='lp', zadj=2)[source]

convertCounts2Units(filenames,eyn=’n’,lpyn=’n’,egain=1.0,dlgain=1.0,exlen=100.,eylen=100., magtype=’lp’,zadj=2) will convert a set of files given by filenames with parameters defined: filenames, eyn => electric channels converted y or n lpyn => long period magnetic channels converted y or n egain => electric gain dlgain => data logger gain exlen => ex length (m) eylen => ey length (m) magtype => magnetic sensor type lp for longperiod or bb for broadband zadj => bz adjusting parameter for bartington sensor

MTpy.core.MTtools.convertE(efield, dlgain, egain, dlength)[source]

Convert the electric field from counts to units of microV/m. efield is a list, dlgain is gain applied by data logger(verylow=2.5, low=1, high=.1), egain is interface box gain (10,100),dlength is the dipole length of that component.

Inputs:
efield = 1d array of electric field measurements dlgain = data logger gain (very low= 2.5,low = 1, high = .1) egain = gain from interface box dlength = length of dipole in (m)
Outputs:
efieldc = scaled electric field 1D array
MTpy.core.MTtools.convertfiles(dirpath, folder, infodict, fmt='%.6g')[source]

convertfiles will convert data of counts from data logger to units.

MTpy.core.MTtools.convertlpB(bfield, dlgain=1, zadj=1)[source]

Convert the magnetic field from counts to units of microV/nT. bfield is a list of numbers. dlain is amount of gain applied by data logger(verylow=2.5,low=1, high=.1)

Inputs:
bfield = 1D array of long period data dlgain = data logger gain (very low= 2.5,low = 1, high = .1) zadj = Bz adjustment if using corrected Bartingtons
Outputs:
bfieldc = scaled bfield 1D array
MTpy.core.MTtools.dctrend(f)[source]

dctrend(f) will remove a dc trend from the function f.

MTpy.core.MTtools.decimatef(farray, m)[source]

Will decimate a function by the factor m. First an 8th order Cheybechev type I filter with a cuttoff frequency of .8/m is applied in both directions to minimize any phase distortion and remove any aliasing. If m is greater than 10, decimatef will be called multiple times.

MTpy.core.MTtools.filter(f, fcutoff=10.0, w=10.0, dt=0.001)[source]

Will apply a sinc filter of width w to the function f by multipling in the frequency domain. Returns filtered function

MTpy.core.MTtools.getStationInfo(stationinfofile, station, mapversion=23)[source]

getStationInfo(stationinfofile,station) returns info for the nominated station from the stationinfofile as a dictionary with key words in the hdrinfo.

MTpy.core.MTtools.getnum(numberlst)[source]

get number from string list and put it into an array

MTpy.core.MTtools.imp2resphase(z, freq, zvar=None, ffactor=1)[source]

imp2resphase(z,zvar,freq) will convert impedances z[4,3,len(freq)] to resistivities (ohm-m) and phases (deg) as well as the errors of each. Note the phase is calculated using arctan2 putting the phase in the correct quadrant. The xy component is placed into the positive quadrant by adding 180 deg. INPUTS:

z=[[zxxreal,zxximag,zxxvar],...]], shape=(4,3,len(freq) OR z=[[[zxxr+1j*zxxi,zxyr+1j*zxyi],[zyx,zyy]]], shape=(len(freq),2,2) freq=frequency array zvar=[[[zxxvar,zyyvar],[zyxvar,zyyvar]]], shape=(len(freq),2,2) ffactor=fudge factor to make sure resistivities are the right order
OUTPUTS:
[[resxx,resxxvar],[resxy,resxyvar]...],[[phasexx,phasexxvar]...]
MTpy.core.MTtools.makeDayFoldersFromObservatoryData(obsdirpath, savepath, startday='000', d=10, ndays=10, df=1, complst=['BX', 'BY'], station='CNB', rowskip=6)[source]

makeDayFoldersFromObservatoryData will take observatory data and put it into day folders for processing.

Input:
obsdirpath = path to observatory data. If the observatory data comes
in one long file input the file, program know’s its a file by searching for the dot.
savepath = path to save the day files, should be in the same directory
as collected data. ie datapath/observatory_station_name

startday = UTC start day as a string of length 3 d = decimation factor of collected data sampling frequency to get to

observatory sampling frequency. So if you sampled at 1000 Hz and the observatory data is at 1 sec, d=1000

ndays = number of days, only used if observatory data is in one big file df = sampling frequency of observatory data in Hz complst = components to make into files, can add ‘BZ’ if you like station = station name of observatory data rowskip = number of rows to skip from observatory file, usually the

header ends at row 6.
Outputs:
files will be saved to savepath/day/Comb00to24ddf/station00to24ddf.cnb
MTpy.core.MTtools.makeKML(edipath, stationid=None, savepath=None, fs=0.9, style=None)[source]

makeKML will make a kml file for Google Earth to plot station locations relatively quickly

MTpy.core.MTtools.normalizeL2(f)[source]

normalizeL2(f) will return the function f normalized by the L2 norm -> f/(sqrt(sum(abs(x_i)^2))).

MTpy.core.MTtools.openMTfile(filename, gain=2.5, egain=10, dlength=[100, 100], magtype='lp', zadj=1)[source]

Open an MT file, convert counts to units and return an 1D-array. Make sure filename includes the entire path. gain (verylow=2.5,low=1, high=.1), egain same as gain, dlength is dipole length in m of EX,EY. magtype is the magnetic measurment type ‘lp’ for long period and ‘bb’ for broadband, zadj is an adjustment for lp instruments on the z channel

MTpy.core.MTtools.padzeros(f, npad=None)[source]

padzeros(f) will return a function that is padded with zeros to the next power of 2 for faster processing for fft or to length npad if given.

MTpy.core.MTtools.readStationInfo(stationinfofile)[source]

readStationInfo(stationinfofile) will read in a .txt (tab delimited) or .csv(comma delimited)file that has the following information: station name, latitude, longitude, elevation, date collected, components measured (a number: 4 for ex,ey,bx,by, 5 for ex,ey,bx,by,bz, 6 for ex,ey,bx,by,bz,tp), magnetic type (bb or lp), dipole lengths (m), data logger gain (very low=2.5,low=1,high=.1),interface box gain (10 or 100), bz correction for longperiod data and the bx,by,bz components as they were measured in the field. Use headers: station, lat, lon, elev, date, mcomps, magtype, ex, ey, dlgain, igain, lpbzcor, magori. Returns a list of the dictionaries with found information.

MTpy.core.MTtools.readedi(filename)[source]

readedi(edifile) will read in an edi file written in a format given by format given by http://www.dias.ie/mtnet/docs/ediformat.txt. Returns: lat,lon,frequency,Z[zreal+i*zimag],Zvar,tipper,tippervar (if applicable)

Input:
filename = full path to edifile
Output:
edidict = dictionary with keys:
station = station name lat = latitude lon = longitude frequency = frequency array z = impedance tensor as (nfreq,2,2) zvar = variance of impedance tensor as (nfreq,2,2) tipper = tipper as (nfreq,2,1) tippervar = tipper variance as (nfreq,2,1)
MTpy.core.MTtools.removePeriodicNoise(filename, dt, noiseperiods, cacherate=10, save='n')[source]

removePeriodicNoise will take average a window of length noise period and average the signal for as many windows that can fit within the data. This averaged window is convolved with a series of delta functions at each window location to create a noise time series. This is then subtracted from the data to get a ‘noise free’ time series.

Inputs:
filename = name of file to have periodic noise removed from
can be an array

dt = time sample rate (s) noiseperiods = a list of estimated periods with a range of values to

look around [[noiseperiod1,df1]...] where df1 is a fraction value find the peak about noiseperiod1 must be less than 1.

cacherate = length of file (min)

Outputs:
bxnf = filtered time series pn = periodic noise fitlst = list of peaks found
MTpy.core.MTtools.removeStaticShift(edifile, stol=0.2, dm=1000)[source]

removeStaticShift(edifile,stol=.2,dm=1000) will remove static shift by calculating the median of respones of near by stations, within dm. If the ratio of the station response to the median on either side of 1+-stol then the impedance tensor for that electric component will be corrected for static shift.

Inputs:
edifile = full path to edi file. Note nearby stations will be looked
for in the dirname of edifile. So have all edis in one folder
stol = ratio tolerance. If there is no static shift the ratio between
the response and the median response should be 1, but noise and other factors can be present so a tolerance arount 1 is assumed.
dm = nearby station radius in meters. If there is no station within
that radius then no static shift will be corrected for.
Outputs:
newedifile = full path to new edifile
MTpy.core.MTtools.rewriteedi(edifile, znew=None, zvarnew=None, freqnew=None, newfile='y', tipnew=None, tipvarnew=None, thetar=0, dr='n')[source]

rewriteedi(edifile) will rewrite an edifile say if it needs to be rotated or distortion removed.

Inputs:

edifile = full path to edifile to be rewritten znew = impedance tensor if a new one has been created zvarnew = errors in impedance tensor if a new one has been created freqnew = new frequency list if one has been created newfile = ‘y’ for yes or ‘n’ for no if you want a new file to be

created.

tipnew = new tipper array tipvarnew = new tipper error array thetar = rotation angle counter clockwise (N=0, E=-90) dr = ‘n’ if no distortion removal and ‘y’ for distortion removal

Outputs:
nedi = dirpath(edifile)+basename(edifile)+rw or dr if dr=’y’
MTpy.core.MTtools.rotateB(bx, by)[source]

rotateB(bx,by) will Rotate the magnetic field such that Bx is pointing to magnetic north and by to geomagnetic east. Assumes setup was orthogonal. Returns list of strings that are 8 significant digits.

MTpy.core.MTtools.rotateE(ex, ey, declination)[source]

Rotate the electric field to geographic north, ex & ey are lists, declination is in degrees

MTpy.core.MTtools.sigfigs(numstr, digits=8, fmt='g')[source]

sigfigs(numstr,digits=8,fmt=’g’) will return a string with the proper amount of significant digits for the input number, can be str or float.

MTpy.core.MTtools.sil(iniline)[source]

sil(iniline) will split a single line written in an .ini file for burpinterface and return the list of strings.

MTpy.core.MTtools.writeedi(z, zvar, freq, stationinfofile, station, edidir=None, rrstation=None, birrpdict=None)[source]

writeedi2(z,zvar,freq,stationinfofile,station,edidir=None,rrstation=None, birrpdict=None) will write an .edi file for a station. Returns full filepath.

Previous topic

BIRRPTools: an interface to BIRRP

Next topic

Z: calculate properties of impedance tensors

This Page