diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 1bc87f19a75ebeec1b0f4efc381c15a59272730c..1a8631b23923924ea173c7f6ce0d564eba4cfe2f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -20,6 +20,14 @@ stages: before_script: - pip install -e .[dev] +linting: + image: python:3.6 + tags: + - passoft + stage: test + script: + - flake8 --ignore=F403,F405,F821,F841,W504 ckMseed + python3.6: image: python:3.6 tags: diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 193a7bb2a2fa3eb9b0243bc28b42a52bd24496d9..49d28de1c79dd4ad0d301dcbf0295a32fd66b1ea 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -45,7 +45,8 @@ articles, and such. Submit Feedback ~~~~~~~~~~~~~~~ -The best way to send feedback is to file an issue at https://git.passcal.nmt.edu/passoft/ckmseed/issues. +The best way to send feedback is to file an issue at +https://git.passcal.nmt.edu/passoft/ckmseed/issues. If you are proposing a feature: @@ -59,31 +60,31 @@ Get Started! Ready to contribute? Here's how to set up `ckmseed` for local development. -1. Cone the `ckmseed` repo:: +1. Clone the `ckmseed` repo: $ git clone https://git.passcal.nmt.edu/passoft/ckmseed.git -3. Install your local copy:: +2. Install your local copy: $ pip install -e .[dev] -4. Create a branch for local development:: +3. Create a branch for local development: $ git checkout -b name-of-your-bugfix-or-feature Now you can make your changes locally. -5. When you're done making changes, check that your changes pass the - tests:: +4. When you're done making changes, check that your changes pass the + tests: $ python setup.py test -6. Commit your changes and push your branch to GitHub:: +5. Commit your changes and push your branch to GitHub: $ git add . $ git commit -m "Your detailed description of your changes." $ git push origin name-of-your-bugfix-or-feature -7. Submit a merge request through the Gitlab website. +6. Submit a merge request through the Gitlab website. Pull Request Guidelines ----------------------- @@ -94,13 +95,13 @@ Before you submit a merge request, check that it meets these guidelines: 2. If the merge request adds functionality, the docs should be updated. Put your new functionality into a function with a docstring, and add the feature to the list in README.rst. -3. The pull request should work for Python 2.7 +3. The pull request should work for Python 3.[6,7,8] Tips ---- To run a subset of tests:: - $ python -m unittest tests.test_ckmseed + $ python -m unittest Deploying --------- @@ -111,4 +112,3 @@ Then run:: $ git push $ git push --tags - diff --git a/HISTORY.rst b/HISTORY.rst index 90d08eb78806d768c55f288e79589f3298c5a8fc..c231f4d1d7488314c3008966feb9a805739e2918 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -11,3 +11,18 @@ History ------------------ * 2nd release on new build system. + +2020.211 (2020-07-29) +------------------ +* Removed use of lstrip() in ckMseed.py +* Fixed issue with exec and variable scope in LibTrace.py + (see GetBlk() and PutBlk()) +* Updated to work with Python 3 +* Added a unit test to test ckMseed import +* Updated list of platform specific dependencies to be installed when pip + installing ckMseed (see setup.py) +* Installed and tested ckMseed against Python3.[6,7,8] using tox +* Formatted Python code to conform to the PEP8 style guide +* Created conda packages for ckMseed that can run on Python3.[6,7,8] +* Updated .gitlab-ci.yml to run a linter and unit tests for Python3.[6,7,8] + in GitLab CI pipeline diff --git a/MANIFEST.in b/MANIFEST.in index 965b2dda7db7c49f68857dc3aea9af37e30a745e..2387d6e279b924229fa0c8c485eeeebf49784996 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -5,7 +5,5 @@ include LICENSE include README.rst recursive-include tests * -recursive-exclude * __pycache__ -recursive-exclude * *.py[co] -recursive-include docs *.rst conf.py Makefile make.bat *.jpg *.png *.gif +recursive-include docs *.rst conf.py diff --git a/Makefile b/Makefile deleted file mode 100644 index baf3e1ba728681000dc26e11d48434d17f9f899b..0000000000000000000000000000000000000000 --- a/Makefile +++ /dev/null @@ -1,89 +0,0 @@ -.PHONY: clean clean-test clean-pyc clean-build docs help -.DEFAULT_GOAL := help - -define BROWSER_PYSCRIPT -import os, webbrowser, sys - -try: - from urllib import pathname2url -except: - from urllib.request import pathname2url - -webbrowser.open("file://" + pathname2url(os.path.abspath(sys.argv[1]))) -endef -export BROWSER_PYSCRIPT - -define PRINT_HELP_PYSCRIPT -import re, sys - -for line in sys.stdin: - match = re.match(r'^([a-zA-Z_-]+):.*?## (.*)$$', line) - if match: - target, help = match.groups() - print("%-20s %s" % (target, help)) -endef -export PRINT_HELP_PYSCRIPT - -BROWSER := python -c "$$BROWSER_PYSCRIPT" - -help: - @python -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST) - -clean: clean-build clean-pyc clean-test ## remove all build, test, coverage and Python artifacts - -clean-build: ## remove build artifacts - rm -fr build/ - rm -fr dist/ - rm -fr .eggs/ - find . -name '*.egg-info' -exec rm -fr {} + - find . -name '*.egg' -exec rm -f {} + - -clean-pyc: ## remove Python file artifacts - find . -name '*.pyc' -exec rm -f {} + - find . -name '*.pyo' -exec rm -f {} + - find . -name '*~' -exec rm -f {} + - find . -name '__pycache__' -exec rm -fr {} + - -clean-test: ## remove test and coverage artifacts - rm -fr .tox/ - rm -f .coverage - rm -fr htmlcov/ - rm -fr .pytest_cache - -lint: ## check style with flake8 - flake8 ckmseed tests - -test: ## run tests quickly with the default Python - python setup.py test - - -test-all: ## run tests on every Python version with tox - tox - -coverage: ## check code coverage quickly with the default Python - coverage run --source ckmseed setup.py test - coverage report -m - coverage html - $(BROWSER) htmlcov/index.html - -docs: ## generate Sphinx HTML documentation, including API docs - rm -f docs/ckmseed.rst - rm -f docs/modules.rst - sphinx-apidoc -o docs/ ckmseed - $(MAKE) -C docs clean - $(MAKE) -C docs html - $(BROWSER) docs/_build/html/index.html - -servedocs: docs ## compile the docs watching for changes - watchmedo shell-command -p '*.rst' -c '$(MAKE) -C docs html' -R -D . - -release: dist ## package and upload a release - twine upload dist/* - -dist: clean ## builds source and wheel package - python setup.py sdist - python setup.py bdist_wheel - ls -l dist - -install: clean ## install the package to the active Python's site-packages - python setup.py install diff --git a/README.rst b/README.rst index e5b78962843c4b707017fc95fc393e49e5880387..e0575e45faaa722df086bc4d154ad252f00ccb28 100644 --- a/README.rst +++ b/README.rst @@ -2,23 +2,11 @@ ckMseed ======= +* Description: Find and review MSEED files -Find and review MSEED files. - +* Usage: ckMseed + ckMseed -# + ckMseed -h + ckMseed [-d DataDirs] [-s] [-v] [-V] * Free software: GNU General Public License v3 (GPLv3) - - - -Features --------- - -* TODO - -Credits -------- - -This package was created with Cookiecutter_ and the `passoft/cookiecutter`_ project template. - -.. _Cookiecutter: https://github.com/audreyr/cookiecutter -.. _`passoft/cookiecutter`: https://git.passcal.nmt.edu/passoft/cookiecutter diff --git a/ckMseed/LibTrace.py b/ckMseed/LibTrace.py index c6423951a75ff35779a149d22b84b2f43747fc70..1eaea52d0dca969f2601f48cae39d99763df6a3d 100755 --- a/ckMseed/LibTrace.py +++ b/ckMseed/LibTrace.py @@ -26,7 +26,7 @@ # MSEED # created UbytetoStr to decompose Ubyte to bit fields # modified blks 200, 201, 300, 310, 320, 390 and fixhdr to utilize - + # 2004.295 # Modification # Author: bcb @@ -41,7 +41,8 @@ # added blockette 2000 to Mseed class # Blockettes with BTime time definitions now pass the BTime # as a tuple within the blk list -# changed unpack formats to use native byte order with standard size & alignment +# changed unpack formats to use native byte order with standard size & +# alignment ########################## # 2005.035 @@ -50,9 +51,10 @@ # # added check for endianess in Mseed & Segy classes, self.ByteOrder # changed all unpack formats to reflect above change in Mseed & Segy classes -# NOTE: for mseed it is possible to have mixed endianess (e.g. little-endian headers -# and big-endian data). At this time, this library does not handle data and makes -# the determination of endianess based soley on the header. +# NOTE: for mseed it is possible to have mixed endianess (e.g. little-endian +# headers and big-endian data). At this time, this library does not +# handle data and makes the determination of endianess based soley on +# the header. ########################## # 2005.138 @@ -60,7 +62,8 @@ # Author: bcb # # added -# Mseed.Pad, Mseed.FlagStrtoInt, Mseed.WriteFixedHdr and all of Mseed.Writeblk??? +# Mseed.Pad, Mseed.FlagStrtoInt, Mseed.WriteFixedHdr and all of +# Mseed.Writeblk??? # fixed improper casting of Time Correction in Mseed.fixedhdr to signed long ########################## # 2006.179 @@ -113,21 +116,32 @@ # # corrected typo from DHQaul to DHQual # added local variables to class Mseed -try: - import exceptions -except: - pass -import os, string, sys, struct, time +########################## +# modification +# version: 2020.211 +# author: Maeva Pourpoint +# +# Fixed issue with exec and variable scope (see GetBlk() and PutBlk()) +########################## + +import os +import string +import struct +import sys +import time + SPACE = " " -#VERSION = "2008.204" +# VERSION = "2008.204" + class futils: """ file utilities class """ - def __init__(self,infile): - self.infile = open(infile, 'r+b') + + def __init__(self, infile): + self.infile = open(infile, 'rb') def close(self): self.infile.close() @@ -136,141 +150,169 @@ class futils: return self.infile.tell() ######################################################### + + class FixedHeader: """ mseed fixhdr """ - #first 20char - textblk=timeblk=sampblk=miscblk=[] - textblk=[] - Serial=DHQual=Res=Stat=Chan=Loc=Net=None + # first 20char + textblk = timeblk = sampblk = miscblk = [] + textblk = [] + Serial = DHQual = Res = Stat = Chan = Loc = Net = None # 20:30 - timeblk=[] - Year=Day=Hour=Min=Sec=Micro=None + timeblk = [] + Year = Day = Hour = Min = Sec = Micro = None # 30:36 - sampblk=[] - NumSamp=SampFact=SampMult=None + sampblk = [] + NumSamp = SampFact = SampMult = None # 36:48 - miscblk=[] - act=io=DataDHQualFL=numblock=timcorr=bdata=bbblock=None + miscblk = [] + act = io = DataDHQualFL = numblock = timcorr = bdata = bbblock = None + ######################################################### + + class Mseed(futils): def __init__(self, infile): """ - initialize file, determine byteorder, sizes, time, and load first fixed header + initialize file, determine byteorder, sizes, time, and load first fixed + header """ - self.type=self.rate=None + self.type = self.rate = None try: - futils.__init__(self,infile) - #local variable to class - self.infileseek=self.infile.seek - self.infilewrite=self.infile.write - self.infileread=self.infile.read - self.sunpack=struct.unpack - self.spack=struct.pack + futils.__init__(self, infile) + # local variable to class + self.infileseek = self.infile.seek + self.infilewrite = self.infile.write + self.infileread = self.infile.read + self.sunpack = struct.unpack + self.spack = struct.pack self.byteorder = self.ByteOrder() if self.byteorder != "unknown": - #otherwise it might be mseed + # otherwise it might be mseed self.type = "mseed" # read 1st fixed header in file - hdrs=self.fixedhdr() - (self.filesize,self.blksize)=self.sizes() - (self.numblocks, odd_size)=divmod(self.filesize,self.blksize) + hdrs = self.fixedhdr() + (self.filesize, self.blksize) = self.sizes() + (self.numblocks, odd_size) = divmod( + self.filesize, self.blksize) if odd_size: pass # starttime of trace -## self.time = string.join(list(map(str, (self.FH.Year, self.FH.Day, self.FH.Hour, \ -## self.FH.Min, self.FH.Sec))), ":") - templist = list(map(str,(self.FH.Year, self.FH.Day, self.FH.Hour, self.FH.Min, self.FH.Sec))) + # self.time = string.join(list(map(str, (self.FH.Year, + # self.FH.Day, + # self.FH.Hour, + # self.FH.Min, + # self.FH.Sec))), ":") + templist = list(map(str, (self.FH.Year, self.FH.Day, + self.FH.Hour, self.FH.Min, + self.FH.Sec))) self.time = ":".join(templist) - - except: + except Exception: pass ######################################################### - def isMseed(self) : + + def isMseed(self): """ - determines if processed file is mseed (return 1) or unknown type (return 0) + determines if processed file is mseed (return 1) or unknown type + (return 0) """ - #if we don't know byteorder it must not be mseed - if self.byteorder == "unknown": return 0 - else: return 1 + # if we don't know byteorder it must not be mseed + if self.byteorder == "unknown": + return 0 + else: + return 1 ######################################################### + def idhdr(self): """ trace id info """ - return self.type, self.FH.Stat, self.FH.Chan, self.FH.Loc, self.FH.Net, self.time, self.rate + return (self.type, self.FH.Stat, self.FH.Chan, self.FH.Loc, + self.FH.Net, self.time, self.rate) ######################################################### + def FirstLastTime(self): """ returns first and last block times in epoch """ - try : - #get first fixed header and calculate beginning epoch + try: + # get first fixed header and calculate beginning epoch btime_str = time.strptime(self.time, '%Y:%j:%H:%M:%S') bepoch = time.mktime(btime_str) + (self.FH.Micro * 0.0001) - #figure out where the end of the file is and read the last fixed header - # and calculate eepoch - (numblocks, odd_size)=divmod(self.filesize, self.blksize) - self.infileseek(-self.blksize,2) + # figure out where the end of the file is and read the last fixed + # header and calculate eepoch + (numblocks, odd_size) = divmod(self.filesize, self.blksize) + self.infileseek(-self.blksize, 2) loc = self.infile.tell() - etime=self.btime2time(loc) + etime = self.btime2time(loc) etime_str = time.strptime(etime, '%Y:%j:%H:%M:%S') eepoch = time.mktime(etime_str) + (self.FH.Micro * 0.0001) - # return bepoch, eepoch except Exception as e: return e + ######################################################### + def tracelength(self): """ returns tracelength in seconds """ - try : - #get first fixed header and calculate beginning epoch - (bepoch, eepoch)=self.FirstLastTime() + try: + # get first fixed header and calculate beginning epoch + (bepoch, eepoch) = self.FirstLastTime() -# #here I have to get the last few samples and calculate how much time is accounted for - self.infileseek(-self.blksize+30,2) - sampblock=self.infileread(2) + # here I have to get the last few samples and calculate how much + # time is accounted for + self.infileseek(-self.blksize + 30, 2) + sampblock = self.infileread(2) fmtstr = self.fmt_order + "H" numsamp = self.sunpack(fmtstr, sampblock)[0] - lastsamples=(numsamp-1)/self.rate - return ((eepoch+lastsamples) - bepoch ) - except: + lastsamples = (numsamp - 1) / self.rate + return ((eepoch + lastsamples) - bepoch) + except Exception: pass + ######################################################### - def btime2time(self, seekval=0) : + + def btime2time(self, seekval=0): """ reads file fixed header and returns time string from btime """ - try : - hdrs=self.fixedhdr(seekval) -## time = string.join(list(map(str, (self.FH.Year, self.FH.Day, self.FH.Hour, \ -## self.FH.Min, self.FH.Sec))), ":") - templist = list(map(str,(self.FH.Year, self.FH.Day, self.FH.Hour, self.FH.Min, self.FH.Sec))) + try: + hdrs = self.fixedhdr(seekval) + # time = string.join(list(map(str, (self.FH.Year, self.FH.Day, + # self.FH.Hour,self.FH.Min, + # self.FH.Sec))), ":") + templist = list(map(str, (self.FH.Year, self.FH.Day, self.FH.Hour, + self.FH.Min, self.FH.Sec))) time = ":".join(templist) return time - except: + except Exception: pass + ######################################################### - def idread(self, seekval=0) : + + def idread(self, seekval=0): """ read file as if it is mseed just pulling necessary info from fixed header """ - try : - hdrs=self.fixedhdr(seekval) - - return self.FH.Stat, self.FH.Chan, self.FH.Loc, self.FH.Net,\ - self.rate, self.FH.Year, self.FH.Day, self.FH.Hour, self.FH.Min, self.FH.Sec, self.FH.Micro - except : + try: + hdrs = self.fixedhdr(seekval) + return (self.FH.Stat, self.FH.Chan, self.FH.Loc, self.FH.Net, + self.rate, self.FH.Year, self.FH.Day, self.FH.Hour, + self.FH.Min, self.FH.Sec, self.FH.Micro) + except Exception: return + ######################################################### + def calcrate(self): """ this routine assumes that idread has been called first @@ -285,37 +327,39 @@ class Mseed(futils): If Sample rate factor < 0 and Sample rate Multiplier < 0, rate = 1/(Sampfact X Sampmult) """ - sampFact=float(self.FH.SampFact) - sampMult=float(self.FH.SampMult) - if sampFact > 0 and sampMult > 0 : + sampFact = float(self.FH.SampFact) + sampMult = float(self.FH.SampMult) + if sampFact > 0 and sampMult > 0: rate = sampFact * sampMult - elif sampFact > 0 and sampMult < 0 : - rate = -1.0 * (sampFact/sampMult) - elif sampFact < 0 and sampMult > 0 : - rate = -1.0 * (sampMult/sampFact) - elif sampFact < 0 and sampMult < 0 : - rate = 1.0/(sampFact * sampMult) - else : + elif sampFact > 0 and sampMult < 0: + rate = -1.0 * (sampFact / sampMult) + elif sampFact < 0 and sampMult > 0: + rate = -1.0 * (sampMult / sampFact) + elif sampFact < 0 and sampMult < 0: + rate = 1.0 / (sampFact * sampMult) + else: rate = sampFact return rate + ######################################################### - def ByteOrder(self, seekval=20) : + + def ByteOrder(self, seekval=20): """ read file as if it is mseed just pulling time info from fixed header and determine if it makes sense unpacked as big endian or little endian """ Order = "unknown" - try : - #seek to timeblock and read + try: + # seek to timeblock and read self.infileseek(seekval) - timeblock=self.infileread(10) - # timeblock=self.TraceBuffer[seekval:seekval+10] + timeblock = self.infileread(10) + # timeblock=self.TraceBuffer[seekval:seekval+10] - #assume big endian - (Year, Day, Hour, Min, Sec, junk, Micro)=\ - self.sunpack('>HHBBBBH',timeblock) - #test if big endian read makes sense + # assume big endian + (Year, Day, Hour, Min, Sec, junk, Micro) =\ + self.sunpack('>HHBBBBH', timeblock) + # test if big endian read makes sense if 1950 <= Year <= 2050 and \ 1 <= Day <= 366 and \ 0 <= Hour <= 23 and \ @@ -324,10 +368,10 @@ class Mseed(futils): Order = "big" self.fmt_order = ">" else: - #try little endian read - (Year, Day, Hour, Min, Sec, junk, Micro)=\ - self.sunpack('<HHBBBBH',timeblock) - #test if little endian read makes sense + # try little endian read + (Year, Day, Hour, Min, Sec, junk, Micro) =\ + self.sunpack('<HHBBBBH', timeblock) + # test if little endian read makes sense if 1950 <= Year <= 2050 and \ 1 <= Day <= 366 and \ 0 <= Hour <= 23 and \ @@ -335,41 +379,45 @@ class Mseed(futils): 0 <= Sec <= 59: Order = "little" self.fmt_order = "<" - except : + except Exception: pass return Order + ######################################################### + def sizes(self, seekval=0): """ Finds Blockette 1000 and returns file size & Data Record Length """ try: - #determine file size - self.infileseek(0,2) - filesize=self.infile.tell() - #proceed to seekval + # determine file size + self.infileseek(0, 2) + filesize = self.infile.tell() + # proceed to seekval self.infileseek(seekval) - #self.infileseek(39) - #assign number of blockettes and offset to next blockette - nblock=self.FH.miscblk[3] - nextblock=self.FH.miscblk[6] - n=0 - #find blockette 1000 + # self.infileseek(39) + # assign number of blockettes and offset to next blockette + nblock = self.FH.miscblk[3] + nextblock = self.FH.miscblk[6] + n = 0 + # find blockette 1000 while n < nblock: self.infileseek(nextblock) - (blktype, newblock)=self.typenxt(nextblock) + (blktype, newblock) = self.typenxt(nextblock) if not blktype: return None, None if blktype == 1000: - (type, next, encode,order,length,res)=self.blk1000(nextblock) + (type, next, encode, order, length, + res) = self.blk1000(nextblock) return filesize, 2**length - nextblock=newblock - n+=1 - except: + nextblock = newblock + n += 1 + except Exception: return None, None ######################################################### + def typenxt(self, seekval=0): """ Reads first 4 bytes of blockette @@ -378,25 +426,26 @@ class Mseed(futils): try: self.infileseek(seekval) fmtstr = self.fmt_order + "HH" - (type, next)=self.sunpack(fmtstr, self.infileread(4)) + (type, next) = self.sunpack(fmtstr, self.infileread(4)) - #reset back to beginning of blockette - self.infileseek(-4,1) + # reset back to beginning of blockette + self.infileseek(-4, 1) return type, next - except: + except Exception: return None, None ######################################################### + def setEndian(self, endianess=""): """ set format string for endian type """ if endianess == "big": - fmtorderstr=">" + fmtorderstr = ">" elif endianess == "little": - fmtorderstr="<" + fmtorderstr = "<" else: - fmtorderstr=self.fmt_order + fmtorderstr = self.fmt_order return fmtorderstr ######################################################### @@ -424,6 +473,7 @@ class Mseed(futils): # UBYTE 8 Unused for data (required for alignment)( # UWORD 16 .0001 seconds (0-9999) ######################################################### + def fixedhdr(self, seekval=0): """ Reads fixed header of 48 bytes (see SEED manual) @@ -457,52 +507,53 @@ class Mseed(futils): Offset to beginning of data (UWORD, 2) Offset to beginning of next blockette (UWORD, 2) """ - #local variable + # local variable # self.sunpack=self.sunpack try: del self.FH - except: + except Exception: pass self.FH = FixedHeader() try: self.infileseek(seekval) - fhblk=self.infileread(48) - #station info + fhblk = self.infileread(48) + # station info fmtstr = self.fmt_order + "6scc5s2s3s2s" - self.FH.textblk=self.sunpack(fmtstr,fhblk[0:20]) + self.FH.textblk = self.sunpack(fmtstr, fhblk[0:20]) - #time info + # time info fmtstr = self.fmt_order + "HHBBBBH" - self.FH.timeblk=self.sunpack(fmtstr,fhblk[20:30]) + self.FH.timeblk = self.sunpack(fmtstr, fhblk[20:30]) - #sample info + # sample info fmtstr = self.fmt_order + "Hhh" - self.FH.sampblk=self.sunpack(fmtstr, fhblk[30:36]) + self.FH.sampblk = self.sunpack(fmtstr, fhblk[30:36]) - #misc info + # misc info fmtstr = self.fmt_order + "BBBBlHH" - tmpblk=self.sunpack(fmtstr,fhblk[36:48]) - #decompose tmpblk[0-2] into bit fields, create miscblk + tmpblk = self.sunpack(fmtstr, fhblk[36:48]) + # decompose tmpblk[0-2] into bit fields, create miscblk for i in range(3): self.FH.miscblk = self.UbytetoStr(tmpblk, i) - tmpblk=self.FH.miscblk #recast tmpblk as list + tmpblk = self.FH.miscblk # recast tmpblk as list (self.FH.Serial, self.FH.DHQual, res, self.FH.Stat, self.FH.Loc, self.FH.Chan, self.FH.Net)\ - =self.FH.textblk + = self.FH.textblk # noqa: E501 (self.FH.Year, self.FH.Day, self.FH.Hour, self.FH.Min, self.FH.Sec, junk, self.FH.Micro)\ - =self.FH.timeblk + = self.FH.timeblk # noqa: E501 (self.FH.NumSamp, self.FH.SampFact, self.FH.SampMult)\ - =self.FH.sampblk - self.rate=self.calcrate() - - return self.FH.textblk, self.FH.timeblk, self.FH.sampblk, self.FH.miscblk -# return textblk,timeblk,sampblk,miscblk + = self.FH.sampblk + self.rate = self.calcrate() - except: + return (self.FH.textblk, self.FH.timeblk, self.FH.sampblk, + self.FH.miscblk) + # return textblk,timeblk,sampblk,miscblk + except Exception: print("error reading fixed header") pass ######################################################### + def WriteFixedHdr(self, hdrlist, seekval=0, endianess=""): """ Writes fixed header of 48 bytes (see SEED manual) @@ -511,68 +562,75 @@ class Mseed(futils): try: self.infileseek(seekval) - fmtorderstr=self.setEndian(endianess) - #station info - #left justify values - #fmtstr0 = fmtorderstr + "6scc5s2s3s2s" - - SeqNum=self.Pad(hdrlist[0][0], 6) #SeqNum - DQual=hdrlist[0][1] #DataQual - Res=hdrlist[0][2] #Reserved - Stat=self.Pad(hdrlist[0][3], 5) #Stat - Loc=self.Pad(hdrlist[0][4], 2) #Loc - Chan=self.Pad(hdrlist[0][5], 3) #Chan - Net=self.Pad(hdrlist[0][6], 2) #Net - - #time info - #fmtstr1 = fmtorderstr + "HHBBBBH" - (Year, Day, Hour, Min, Sec, junk, Micro)=hdrlist[1] - Micro=int(Micro) - - #sample info - #fmtstr2 = fmtorderstr + "Hhh" - (NumSamp, SampFact, SampMult)=hdrlist[2] - - #misc info - #fmtstr3 = fmtorderstr + "BBBBlHH" - (actFlags, ioFlags, dqFlags, numblk, timecor, offsetData, offsetBlktt)=hdrlist[3] - #convert flag string to integer + fmtorderstr = self.setEndian(endianess) + # station info + # left justify values + # fmtstr0 = fmtorderstr + "6scc5s2s3s2s" + + SeqNum = self.Pad(hdrlist[0][0], 6) # SeqNum + DQual = hdrlist[0][1] # DataQual + Res = hdrlist[0][2] # Reserved + Stat = self.Pad(hdrlist[0][3], 5) # Stat + Loc = self.Pad(hdrlist[0][4], 2) # Loc + Chan = self.Pad(hdrlist[0][5], 3) # Chan + Net = self.Pad(hdrlist[0][6], 2) # Net + + # time info + # fmtstr1 = fmtorderstr + "HHBBBBH" + (Year, Day, Hour, Min, Sec, junk, Micro) = hdrlist[1] + Micro = int(Micro) + + # sample info + # fmtstr2 = fmtorderstr + "Hhh" + (NumSamp, SampFact, SampMult) = hdrlist[2] + + # misc info + # fmtstr3 = fmtorderstr + "BBBBlHH" + (actFlags, ioFlags, dqFlags, numblk, timecor, + offsetData, offsetBlktt) = hdrlist[3] + # convert flag string to integer actFlags = self.FlagStrtoInt(actFlags) ioFlags = self.FlagStrtoInt(ioFlags) dqFlags = self.FlagStrtoInt(dqFlags) - #pack fields - fmtstr= fmtorderstr + "6scc5s2s3s2sHHBBBBHHhhBBBBlHH" - pack_hdr=self.spack(fmtstr,SeqNum, DQual, Res, Stat, Loc, Chan, Net,\ - Year, Day, Hour, Min, Sec, junk, Micro,\ - NumSamp, SampFact, SampMult,\ - actFlags, ioFlags, dqFlags, numblk, timecor, offsetData, offsetBlktt) + # pack fields + fmtstr = fmtorderstr + "6scc5s2s3s2sHHBBBBHHhhBBBBlHH" + pack_hdr = self.spack(fmtstr, SeqNum, DQual, Res, Stat, Loc, Chan, + Net, Year, Day, Hour, Min, Sec, junk, Micro, + NumSamp, SampFact, SampMult, actFlags, + ioFlags, dqFlags, numblk, timecor, + offsetData, offsetBlktt) - #write header + # write header self.infilewrite(pack_hdr) return 48 - except: + except Exception: print("error writing fixed header") return 0 ######################################################### + def GetBlk(self, blknum, seekval=0): - ValidBlk=(100,200,201,300,310,320,390,395,400,405,500,1000,1001,2000) - if not blknum in ValidBlk: + ValidBlk = (100, 200, 201, 300, 310, 320, 390, + 395, 400, 405, 500, 1000, 1001, 2000) + if blknum not in ValidBlk: return 0 else: blk = locals() callcmd = "blk=self.blk" + str(blknum) + "(" + str(seekval) + ")" exec(callcmd, {}, blk) return blk + ######################################################### + def PutBlk(self, blknum, indata, endian, seekval=0): """ test for valid blockette, if true write blockette """ - ValidBlk=(100,200,201,300,310,320,390,395,400,405,500,1000,1001,2000) - if not blknum in ValidBlk: + ValidBlk = (100, 200, 201, 300, 310, 320, 390, + 395, 400, 405, 500, 1000, 1001, 2000) + if blknum not in ValidBlk: return 0 else: bytes_written = locals() @@ -580,444 +638,465 @@ class Mseed(futils): str(blknum) + "(indata" + "," + str(seekval) + ", endian)" exec(callcmd, {}, bytes_written) return bytes_written + ######################################################### + def blk100(self, seekval=0): """ Sample Rate Blockette 100 (12 bytes) Returns tuple - blk - Blockette type (UWORD, 2) - Next blockette's byte offset relative to fixed section of header - (UWORD, 2) - Actual sample rate (FLOAT, 4) - Flags (BYTE, 1) - Reserved (UBYTE, 3) + blk + Blockette type (UWORD, 2) + Next blockette's byte offset relative to fixed section of header + (UWORD, 2) + Actual sample rate (FLOAT, 4) + Flags (BYTE, 1) + Reserved (UBYTE, 3) """ self.infileseek(seekval) fmtstr = self.fmt_order + "HHfb3B" - blk=self.sunpack(fmtstr, self.infileread(12)) + blk = self.sunpack(fmtstr, self.infileread(12)) scrblk = self.UbytetoStr(blk, 3) - blk=scrblk + blk = scrblk return blk ######################################################### + def Writeblk100(self, inblk, seekval=0, endianess=""): """ writes Sample Rate Blockette 100 (12 bytes) - requires tuple inblk=(blkette, nextblk, actrate, flags, res0, res1, res2) + requires tuple inblk=(blkette, nextblk, actrate, flags, res0, res1, + res2) """ try: self.infileseek(seekval) - fmtorderstr=self.setEndian(endianess) + fmtorderstr = self.setEndian(endianess) fmtstr = fmtorderstr + "HHfb3B" (blkette, nextblk, actrate, flags, res0, res1, res2) = inblk - flags=self.FlagStrtoInt(flags) - pack_blk=self.spack(fmtstr, blkette, nextblk, actrate, flags, res0, res1, res2) + flags = self.FlagStrtoInt(flags) + pack_blk = self.spack(fmtstr, blkette, nextblk, + actrate, flags, res0, res1, res2) self.infilewrite(pack_blk) return 12 - except: + except Exception: print("error writing blockette 100") return 0 - ######################################################### + def blk200(self, seekval=0): """ Generic Event Detection Blockette 200 (52 bytes) Returns tuple - blk - Blockette type (UWORD, 2) - Next blockette's byte offset relative to fixed section of header - (UWORD, 2) - Signal amplitude (FLOAT, 4) - Signal period (FLOAT,4) - Background estimate (FLOAT,4) - Event detection flags (UBYTE, 1) - Reserved (UBYTE, 1) - Signal onset time (BTime expanded, 10) - Detector Name (CHAR*24) + blk + Blockette type (UWORD, 2) + Next blockette's byte offset relative to fixed section of header + (UWORD, 2) + Signal amplitude (FLOAT, 4) + Signal period (FLOAT,4) + Background estimate (FLOAT,4) + Event detection flags (UBYTE, 1) + Reserved (UBYTE, 1) + Signal onset time (BTime expanded, 10) + Detector Name (CHAR*24) """ self.infileseek(seekval) fmtstr = self.fmt_order + "HHfffBB" - blk1=self.sunpack(fmtstr, self.infileread(18)) + blk1 = self.sunpack(fmtstr, self.infileread(18)) fmtstr = self.fmt_order + "HHBBBBH" - timeblk=self.sunpack(fmtstr, self.infileread(10)) + timeblk = self.sunpack(fmtstr, self.infileread(10)) fmtstr = self.fmt_order + "24s" - blk2=self.sunpack(fmtstr, self.infileread(24)) + blk2 = self.sunpack(fmtstr, self.infileread(24)) # incorporate timeblk tuple into blk list tmpblk = list(blk1) tmpblk.append(timeblk) tmpblk = tmpblk + list(blk2) - #apply bit mask to Ubyte + # apply bit mask to Ubyte blk = self.UbytetoStr(tmpblk, 5) return blk ######################################################### + def Writeblk200(self, inblk, seekval=0, endianess=""): """ writes Generic Event Detection Blockette 200 (52 bytes) requires tuple inblk - inblk=(blkette, nextblk, amp, period, bg, flags, \ - Year, Day, Hour, Min, Sec, junk, Micro, charstr) + inblk=(blkette, nextblk, amp, period, bg, flags, Year, Day, Hour, Min, + Sec, junk, Micro, charstr) """ try: self.infileseek(seekval) - fmtorderstr=self.setEndian(endianess) + fmtorderstr = self.setEndian(endianess) fmtstr = fmtorderstr + "HHfffBBHHBBBBH24s" - (blkette, nextblk, amp, period, bg, flags, \ - Year, Day, Hour, Min, Sec, junk, Micro, charstr)=inblk - flags=FlagsStrtoInt(flags) - pack_blk=self.spack(fmtstr, blkette, nextblk, amp, period, bg, flags, \ - Year, Day, Hour, Min, Sec, junk, Micro, charstr) + (blkette, nextblk, amp, period, bg, flags, + Year, Day, Hour, Min, Sec, junk, Micro, charstr) = inblk + flags = FlagsStrtoInt(flags) + pack_blk = self.spack(fmtstr, blkette, nextblk, amp, period, bg, + flags, Year, Day, Hour, Min, Sec, junk, + Micro, charstr) self.infilewrite(pack_blk) return 52 - - except: + except Exception: print("error writing blockette 200") return 0 - ######################################################### + def blk201(self, seekval=0): """ Murdock Event Detection Blockette 201 (60 bytes) Returns tuple - blk - Blockette type (UWORD, 2) - Next blockette's byte offset relative to fixed section of header - (UWORD, 2) - Signal amplitude (FLOAT, 4) - Signal period (FLOAT,4) - Background estimate (FLOAT,4) - Event detection flags (UBYTE, 1) - Reserved (UBYTE, 1) - Signal onset time (BTime expanded, 10) - Signal-to-noise ration values (UBYTE*6) - Lookback value (UBYTE, 1) - Pick algorithym (UBYTE, 1) - Detector Name (CHAR*24) + blk + Blockette type (UWORD, 2) + Next blockette's byte offset relative to fixed section of header + (UWORD, 2) + Signal amplitude (FLOAT, 4) + Signal period (FLOAT,4) + Background estimate (FLOAT,4) + Event detection flags (UBYTE, 1) + Reserved (UBYTE, 1) + Signal onset time (BTime expanded, 10) + Signal-to-noise ration values (UBYTE*6) + Lookback value (UBYTE, 1) + Pick algorithym (UBYTE, 1) + Detector Name (CHAR*24) """ self.infileseek(seekval) fmtstr = self.fmt_order + "HHfffBB" - blk1=self.sunpack(fmtstr, self.infileread(18)) + blk1 = self.sunpack(fmtstr, self.infileread(18)) fmtstr = self.fmt_order + "HHBBBBH" - timeblk=self.sunpack(fmtstr, self.infileread(10)) + timeblk = self.sunpack(fmtstr, self.infileread(10)) fmtstr = self.fmt_order + "6BBB24s" - blk2=self.sunpack(fmtstr, self.infileread(32)) + blk2 = self.sunpack(fmtstr, self.infileread(32)) # incorporate timeblk tuple into blk list tmpblk = list(blk1) tmpblk.append(timeblk) tmpblk = tmpblk + list(blk2) - #apply bit mask to Ubyte + # apply bit mask to Ubyte blk = self.UbytetoStr(tmpblk, 5) return blk ######################################################### + def Writeblk201(self, inblk, seekval=0, endianess=""): """ writes Murdock Event Detection Blockette 201 (60 bytes) requires tuple inblk - inblk=(blkette, nextblk, amp, period, bg, flags, res, - Year, Day, Hour, Min, Sec, junk, Micro, SN0, SN1, SN2, SN3, SN4, SN5, loop, algo, Name) + inblk=(blkette, nextblk, amp, period, bg, flags, res, Year, Day, Hour, + Min, Sec, junk, Micro, SN0, SN1, SN2, SN3, SN4, SN5, loop, algo, + Name) """ try: self.infileseek(seekval) - fmtorderstr=self.setEndian(endianess) + fmtorderstr = self.setEndian(endianess) fmtstr = fmtorderstr + "HHfffBBHHBBBBH6BBB24s" - (blkette, nextblk, amp, period, bg, flags, res, \ - Year, Day, Hour, Min, Sec, junk, Micro, SN0, SN1, SN2, SN3, SN4, SN5, \ - loop, algo, Name)=inblk - flags=self.FlagStrtoInt(flags) - pack_blk=self.spack(fmtstr, blkette, nextblk, amp, period, bg, flags, res, \ - Year, Day, Hour, Min, Sec, junk, Micro, SN0, SN1, SN2, SN3, SN4, SN5, loop, algo, Name) + (blkette, nextblk, amp, period, bg, flags, res, Year, Day, Hour, + Min, Sec, junk, Micro, SN0, SN1, SN2, SN3, SN4, SN5, loop, algo, + Name) = inblk + flags = self.FlagStrtoInt(flags) + pack_blk = self.spack(fmtstr, blkette, nextblk, amp, period, bg, + flags, res, Year, Day, Hour, Min, Sec, junk, + Micro, SN0, SN1, SN2, SN3, SN4, SN5, loop, + algo, Name) self.infilewrite(pack_blk) return 60 - - except: + except Exception: print("error writing blockette 201") return 0 - ######################################################### + def blk300(self, seekval=0): """ Step Calibration Blockette 300 (60 bytes) Returns tuple - blk - Blockette type (UWORD, 2) - Next blockette's byte offset relative to fixed section of header - (UWORD, 2) - Beginning of calibration time (BTime expanded, 10) - Number of step calibrations (UBYTE, 1) - Calibrations flags (UBYTE, 1) - Step duration (ULONG, 4) - Interval durations (ULONG, 4) - Calibration signal amplitude (FLOAT, 4) - Channel with calibration input (CHAR*3) - Reserved (UBYTE, 1) - Reference amplitude (ULONG, 4) - Coupling (CHAR*12) - Rolloff (CHAR*12) + blk + Blockette type (UWORD, 2) + Next blockette's byte offset relative to fixed section of header + (UWORD, 2) + Beginning of calibration time (BTime expanded, 10) + Number of step calibrations (UBYTE, 1) + Calibrations flags (UBYTE, 1) + Step duration (ULONG, 4) + Interval durations (ULONG, 4) + Calibration signal amplitude (FLOAT, 4) + Channel with calibration input (CHAR*3) + Reserved (UBYTE, 1) + Reference amplitude (ULONG, 4) + Coupling (CHAR*12) + Rolloff (CHAR*12) """ self.infileseek(seekval) fmtstr = self.fmt_order + "HH" - blk1=self.sunpack(fmtstr, self.infileread(4)) + blk1 = self.sunpack(fmtstr, self.infileread(4)) fmtstr = self.fmt_order + "HHBBBBH" - timeblk=self.sunpack(fmtstr, self.infileread(10)) + timeblk = self.sunpack(fmtstr, self.infileread(10)) fmtstr = self.fmt_order + "BBIIf3sBI12s12s" - blk2=self.sunpack(fmtstr, self.infileread(46)) + blk2 = self.sunpack(fmtstr, self.infileread(46)) # incorporate timeblk tuple into blk list tmpblk = list(blk1) tmpblk.append(timeblk) tmpblk = tmpblk + list(blk2) - #apply bit mask to Ubyte + # apply bit mask to Ubyte blk = self.UbytetoStr(tmpblk, 4) return blk ######################################################### + def Writeblk300(self, inblk, seekval=0, endianess=""): """ writes Step Calibration Blockette 300 (60 bytes) requires tuples inblk - inblk=(blkette, nextblk, Year, Day, Hour, Min, Sec, junk, Micro, \ + inblk=(blkette, nextblk, Year, Day, Hour, Min, Sec, junk, Micro, numst, flags, dur, interv, amp, chan, res, ref, couple, rolloff) """ try: self.infileseek(seekval) - fmtorderstr=self.setEndian(endianess) + fmtorderstr = self.setEndian(endianess) fmtstr = fmtorderstr + "HHHHBBBBHBBIIf3sBI12s12s" - (blkette, nextblk, Year, Day, Hour, Min, Sec, junk, Micro, \ - numst, flags, dur, interv, amp, chan, res, ref, couple, rolloff)=inblk - flags=self.FlagStrtoInt(flags) - pack_blk=self.spack(fmtstr, blkette, nextblk, Year, Day, Hour, Min, Sec, junk, Micro, \ - numst, flags, dur, interv, amp, chan, res, ref, couple, rolloff) + (blkette, nextblk, Year, Day, Hour, Min, Sec, junk, Micro, numst, + flags, dur, interv, amp, chan, res, ref, couple, + rolloff) = inblk + flags = self.FlagStrtoInt(flags) + pack_blk = self.spack(fmtstr, blkette, nextblk, Year, Day, Hour, + Min, Sec, junk, Micro, numst, flags, dur, + interv, amp, chan, res, ref, couple, rolloff) self.infilewrite(pack_blk) return 60 - - except: + except Exception: print("error writing blockette 300") return 0 ######################################################### + def blk310(self, seekval=0): """ Sine Calibration Blockette 310 (60 bytes) Returns tuple - blk - Blockette type (UWORD, 2) - Next blockette's byte offset relative to fixed section of header - (UWORD, 2) - Beginning of calibration time (BTime expanded, 10) - Reserved (UBYTE, 1) - Calibrations flags (UBYTE, 1) - Calibration duration (ULONG, 4) - Period of signal (FLOAT, 4) - Amplitude of signal (FLOAT, 4) - Channel with calibration input (CHAR*3) - Reserved (UBYTE, 1) - Reference amplitued (ULONG, 4) - Coupling (CHAR*12) - Rolloff (CHAR*12) - + blk + Blockette type (UWORD, 2) + Next blockette's byte offset relative to fixed section of header + (UWORD, 2) + Beginning of calibration time (BTime expanded, 10) + Reserved (UBYTE, 1) + Calibrations flags (UBYTE, 1) + Calibration duration (ULONG, 4) + Period of signal (FLOAT, 4) + Amplitude of signal (FLOAT, 4) + Channel with calibration input (CHAR*3) + Reserved (UBYTE, 1) + Reference amplitued (ULONG, 4) + Coupling (CHAR*12) + Rolloff (CHAR*12) """ self.infileseek(seekval) fmtstr = self.fmt_order + "HH" - blk1=self.sunpack(fmtstr, self.infileread(4)) + blk1 = self.sunpack(fmtstr, self.infileread(4)) fmtstr = self.fmt_order + "HHBBBBH" - timeblk=self.sunpack(fmtstr, self.infileread(10)) + timeblk = self.sunpack(fmtstr, self.infileread(10)) fmtstr = self.fmt_order + "BBIff3sBI12s12s" - blk2=self.sunpack(fmtstr, self.infileread(46)) + blk2 = self.sunpack(fmtstr, self.infileread(46)) # incorporate timeblk tuple into blk list tmpblk = list(blk1) tmpblk.append(timeblk) tmpblk = tmpblk + list(blk2) - #apply bit mask to Ubyte + # apply bit mask to Ubyte blk = self.UbytetoStr(tmpblk, 4) return blk ######################################################### + def Writeblk310(self, inblk, seekval=0, endianess=""): """ writes Sine Calibration Blockette 310 (60 bytes) requires tuples inblk - inblk=(blkette, nextblk, Year, Day, Hour, Min, Sec, junk, Micro, \ - res, flags, dura,per,ampsig,chan, res2,refamp,coup,rolloff) + inblk=(blkette, nextblk, Year, Day, Hour, Min, Sec, junk, Micro, res, + flags, dura,per,ampsig,chan, res2,refamp,coup,rolloff) """ try: self.infileseek(seekval) - fmtorderstr=self.setEndian(endianess) + fmtorderstr = self.setEndian(endianess) fmtstr = fmtorderstr + "HHHHBBBBHBBIff3sBI12s12s" - (blkette, nextblk, Year, Day, Hour, Min, Sec, junk, Micro, \ - res, flags, dura,per,ampsig,chan, res2,refamp,coup,rolloff)=inblk - flags=self.FlagStrtoInt(flags) - pack_blk=self.spack(fmtstr, blkette, nextblk, Year, Day, Hour, Min, Sec, junk, Micro, \ - res, flags, dura,per,ampsig,chan, res2,refamp,coup,rolloff) + (blkette, nextblk, Year, Day, Hour, Min, Sec, junk, Micro, + res, flags, dura, per, ampsig, chan, res2, refamp, coup, + rolloff) = inblk + flags = self.FlagStrtoInt(flags) + pack_blk = self.spack(fmtstr, blkette, nextblk, Year, Day, Hour, + Min, Sec, junk, Micro, res, flags, dura, per, + ampsig, chan, res2, refamp, coup, rolloff) self.infilewrite(pack_blk) return 60 - - except: + except Exception: print("error writing blockette 310") return 0 ######################################################### + def blk320(self, seekval=0): """ Pseudo-random Calibraton Blockette 320 (64 bytes) Returns tuple - blk - Blockette type (UWORD, 2) - Next blockette's byte offset relative to fixed section of header - (UWORD, 2) - Beginning of calibration time (BTime expanded, 10) - Reserved (UBYTE, 1) - Calibrations flags (UBYTE, 1) - Calibration duration (ULONG, 4) - Peak-to-peak amplitude of steps (FLOAT, 4) - Channel with calibration input (CHAR*3) - Reserved (UBYTE, 1) - Reference amplitued (ULONG, 4) - Coupling (CHAR*12) - Rolloff (CHAR*12) - Noise type (CHAR*8) + blk + Blockette type (UWORD, 2) + Next blockette's byte offset relative to fixed section of header + (UWORD, 2) + Beginning of calibration time (BTime expanded, 10) + Reserved (UBYTE, 1) + Calibrations flags (UBYTE, 1) + Calibration duration (ULONG, 4) + Peak-to-peak amplitude of steps (FLOAT, 4) + Channel with calibration input (CHAR*3) + Reserved (UBYTE, 1) + Reference amplitued (ULONG, 4) + Coupling (CHAR*12) + Rolloff (CHAR*12) + Noise type (CHAR*8) """ self.infileseek(seekval) fmtstr = self.fmt_order + "HH" - blk1=self.sunpack(fmtstr, self.infileread(4)) + blk1 = self.sunpack(fmtstr, self.infileread(4)) fmtstr = self.fmt_order + "HHBBBBH" - timeblk=self.sunpack(fmtstr, self.infileread(10)) + timeblk = self.sunpack(fmtstr, self.infileread(10)) fmtstr = self.fmt_order + "BBIf3sBI12s12s8s" - blk2=self.sunpack(fmtstr, self.infileread(50)) + blk2 = self.sunpack(fmtstr, self.infileread(50)) # incorporate timeblk tuple into blk list tmpblk = list(blk1) tmpblk.append(timeblk) tmpblk = tmpblk + list(blk2) - #apply bit mask to Ubyte + # apply bit mask to Ubyte blk = self.UbytetoStr(tmpblk, 4) return blk ######################################################### + def Writeblk320(self, inblk, seekval=0, endianess=""): """ writes Pseudo-random Calibraton Blockette 320 (64 bytes) requires tuples inblk - inblk=(blkette, nextblk, Year, Day, Hour, Min, Sec, junk, Micro, \ + inblk=(blkette, nextblk, Year, Day, Hour, Min, Sec, junk, Micro, res, flags, dura,ptop,chan, res2,refamp,coup,rolloff,noise) """ try: self.infileseek(seekval) - fmtorderstr=self.setEndian(endianess) + fmtorderstr = self.setEndian(endianess) fmtstr = fmtorderstr + "HHHHBBBBHBBIf3sBI12s12s8s" - (blkette, nextblk, Year, Day, Hour, Min, Sec, junk, Micro, \ - res, flags, dura,ptop,chan, res2,refamp,coup,rolloff,noise)=inblk - flags=self.FlagStrtoInt(flags) - pack_blk=self.spack(fmtstr, blkette, nextblk, Year, Day, Hour, Min, Sec, junk, Micro, \ - res, flags, dura,ptop,chan, res2,refamp,coup,rolloff,noise) + (blkette, nextblk, Year, Day, Hour, Min, Sec, junk, Micro, + res, flags, dura, ptop, chan, res2, refamp, coup, rolloff, + noise) = inblk + flags = self.FlagStrtoInt(flags) + pack_blk = self.spack(fmtstr, blkette, nextblk, Year, Day, Hour, + Min, Sec, junk, Micro, res, flags, dura, + ptop, chan, res2, refamp, coup, rolloff, + noise) self.infilewrite(pack_blk) return 64 - - except: + except Exception: print("error writing blockette 320") return 0 ######################################################### + def blk390(self, seekval=0): """ Generic Calibraton Blockette 390 (28 bytes) Returns tuple - blk - Blockette type (UWORD, 2) - Next blockette's byte offset relative to fixed section of header - (UWORD, 2) - Beginning of calibration time (BTime expanded, 10) - Reserved (UBYTE, 1) - Calibrations flags (UBYTE, 1) - Calibration duration (ULONG, 4) - Calibration signal amplitude (FLOAT, 4) - Channel with calibration input (CHAR*3) - Reserved (UBYTE, 1) + blk + Blockette type (UWORD, 2) + Next blockette's byte offset relative to fixed section of header + (UWORD, 2) + Beginning of calibration time (BTime expanded, 10) + Reserved (UBYTE, 1) + Calibrations flags (UBYTE, 1) + Calibration duration (ULONG, 4) + Calibration signal amplitude (FLOAT, 4) + Channel with calibration input (CHAR*3) + Reserved (UBYTE, 1) """ self.infileseek(seekval) fmtstr = self.fmt_order + "HH" - blk1=self.sunpack(fmtstr, self.infileread(4)) + blk1 = self.sunpack(fmtstr, self.infileread(4)) fmtstr = self.fmt_order + "HHBBBBH" - timeblk=self.sunpack(fmtstr, self.infileread(10)) + timeblk = self.sunpack(fmtstr, self.infileread(10)) fmtstr = self.fmt_order + "BBIf3sB" - blk2=self.sunpack(fmtstr, self.infileread(14)) + blk2 = self.sunpack(fmtstr, self.infileread(14)) # incorporate timeblk tuple into blk list tmpblk = list(blk1) tmpblk.append(timeblk) tmpblk = tmpblk + list(blk2) - #apply bit mask to Ubyte + # apply bit mask to Ubyte blk = self.UbytetoStr(tmpblk, 4) return blk ######################################################### + def Writeblk390(self, inblk, seekval=0, endianess=""): """ writes Generic Calibraton Blockette 390 (28 bytes) requires tuples inblk - inblk=(blkette, nextblk, Year, Day, Hour, Min, Sec, junk, Micro, \ - res, flags, dura,amp,chan, res2) + inblk=(blkette, nextblk, Year, Day, Hour, Min, Sec, junk, Micro, + res, flags, dura,amp,chan, res2) """ try: self.infileseek(seekval) - fmtorderstr=self.setEndian(endianess) + fmtorderstr = self.setEndian(endianess) fmtstr = fmtorderstr + "HHHHBBBBHBBIf3sB" - (blkette, nextblk, Year, Day, Hour, Min, Sec, junk, Micro, \ - res, flags, dura,amp,chan, res2)=inblk - flags=self.FlagStrtoInt(flags) - pack_blk=self.spack(fmtstr, blkette, nextblk, Year, Day, Hour, Min, Sec, junk, Micro, \ - res, flags, dura,amp,chan, res2) + (blkette, nextblk, Year, Day, Hour, Min, Sec, junk, Micro, res, + flags, dura, amp, chan, res2) = inblk + flags = self.FlagStrtoInt(flags) + pack_blk = self.spack(fmtstr, blkette, nextblk, Year, Day, Hour, + Min, Sec, junk, Micro, res, flags, dura, + amp, chan, res2) self.infilewrite(pack_blk) return 28 - - except: + except Exception: print("error writing blockette 390") return 0 ######################################################### + def blk395(self, seekval=0): """ Calibraton Abort Blockette 395 (16 bytes) Returns tuple - blk - Blockette type (UWORD, 2) - Next blockette's byte offset relative to fixed section of header - (UWORD, 2) - End of calibration time (BTime expanded, 10) - Reserved (UBYTE, 2) + blk + Blockette type (UWORD, 2) + Next blockette's byte offset relative to fixed section of header + (UWORD, 2) + End of calibration time (BTime expanded, 10) + Reserved (UBYTE, 2) """ self.infileseek(seekval) fmtstr = self.fmt_order + "HHHHBBBBH2s" - blk=self.sunpack(fmtstr, self.infileread(16)) + blk = self.sunpack(fmtstr, self.infileread(16)) return list(blk) ######################################################### + def Writeblk395(self, inblk, seekval=0, endianess=""): """ writes Calibraton Abort Blockette 395 (16 bytes) @@ -1027,38 +1106,41 @@ class Mseed(futils): try: self.infileseek(seekval) - fmtorderstr=self.setEndian(endianess) + fmtorderstr = self.setEndian(endianess) fmtstr = fmtorderstr + "HHHHBBBBH2s" - (blkette, nextblk, Year, Day, Hour, Min, Sec, junk, Micro, res)=inblk - pack_blk=self.spack(fmtstr, blkette, nextblk, Year, Day, Hour, Min, Sec, junk, Micro, res) + (blkette, nextblk, Year, Day, Hour, Min, Sec, junk, Micro, + res) = inblk + pack_blk = self.spack(fmtstr, blkette, nextblk, Year, Day, Hour, + Min, Sec, junk, Micro, res) self.infilewrite(pack_blk) return 16 - - except: + except Exception: print("error writing blockette 395") return 0 ######################################################### + def blk400(self, seekval=0): """ Beam Blockette 400 (16 bytes) Returns tuple - blk - Blockette type (UWORD, 2) - Next blockette's byte offset relative to fixed section of header - (UWORD, 2) - Beam azimuth (degrees) (FLOAT, 4) - Beam slowness (sec/degree) (FLOAT, 4) - Beam configuration (UWORD, 2) - Reserved (UBYTE, 2) + blk + Blockette type (UWORD, 2) + Next blockette's byte offset relative to fixed section of header + (UWORD, 2) + Beam azimuth (degrees) (FLOAT, 4) + Beam slowness (sec/degree) (FLOAT, 4) + Beam configuration (UWORD, 2) + Reserved (UBYTE, 2) """ self.infileseek(seekval) fmtstr = self.fmt_order + "HHffH2B" - blk=self.sunpack(fmtstr, self.infileread(16)) + blk = self.sunpack(fmtstr, self.infileread(16)) return list(blk) ######################################################### + def Writeblk400(self, inblk, seekval=0, endianess=""): """ writes Beam Blockette 400 (16 bytes) @@ -1068,35 +1150,37 @@ class Mseed(futils): try: self.infileseek(seekval) - fmtorderstr=self.setEndian(endianess) + fmtorderstr = self.setEndian(endianess) fmtstr = fmtorderstr + "HHffH2B" - (blkette, nextblk, baz,bslw,bconf,res0,res1)=inblk - pack_blk=self.spack(fmtstr, blkette, nextblk, baz,bslw,bconf,res0,res1) + (blkette, nextblk, baz, bslw, bconf, res0, res1) = inblk + pack_blk = self.spack(fmtstr, blkette, nextblk, baz, bslw, bconf, + res0, res1) self.infilewrite(pack_blk) return 16 - - except: + except Exception: print("error writing blockette 400") return 0 ######################################################### + def blk405(self, seekval=0): """ Beam Delay Blockette 405 (6 bytes) Returns tuple - blk - Blockette type (UWORD, 2) - Next blockette's byte offset relative to fixed section of header - (UWORD, 2) - Array of delay values (UWORD, 2) + blk + Blockette type (UWORD, 2) + Next blockette's byte offset relative to fixed section of header + (UWORD, 2) + Array of delay values (UWORD, 2) """ self.infileseek(seekval) fmtstr = self.fmt_order + "HHH" - blk=self.sunpack(fmtstr, self.infileread(6)) + blk = self.sunpack(fmtstr, self.infileread(6)) return list(blk) ######################################################### + def Writeblk405(self, inblk, seekval=0, endianess=""): """ writes Beam Delay Blockette 405 (6 bytes) @@ -1106,43 +1190,43 @@ class Mseed(futils): try: self.infileseek(seekval) - fmtorderstr=self.setEndian(endianess) + fmtorderstr = self.setEndian(endianess) fmtstr = fmtorderstr + "HHH" - (blkette, nextblk, delay)=inblk - pack_blk=self.spack(fmtstr, blkette, nextblk, delay) + (blkette, nextblk, delay) = inblk + pack_blk = self.spack(fmtstr, blkette, nextblk, delay) self.infilewrite(pack_blk) return 6 - - except: + except Exception: print("error writing blockette 405") return 0 ######################################################### + def blk500(self, seekval=0): """ Timing Blockette 500 (200 bytes) Returns tuple - blk - Blockette type (UWORD, 2) - Next blockette's byte offset relative to fixed section of header - (UWORD, 2) - VCO correction (FLOAT, 4) - Time of exception (BTime expanded, 10) - microsec (UBYTE, 1) - Reception quality (UBYTE, 1) - Exception count (ULONG, 4) - Exception type (CHAR*16) - Clock model (CHAR*32) - Clock status (CHAR*128) + blk + Blockette type (UWORD, 2) + Next blockette's byte offset relative to fixed section of header + (UWORD, 2) + VCO correction (FLOAT, 4) + Time of exception (BTime expanded, 10) + microsec (UBYTE, 1) + Reception quality (UBYTE, 1) + Exception count (ULONG, 4) + Exception type (CHAR*16) + Clock model (CHAR*32) + Clock status (CHAR*128) """ self.infileseek(seekval) fmtstr = self.fmt_order + "HHf" - blk1=self.sunpack(fmtstr, self.infileread(8)) + blk1 = self.sunpack(fmtstr, self.infileread(8)) fmtstr = self.fmt_order + "HHBBBBH" - timeblk=self.sunpack(fmtstr,self.infileread(10)) + timeblk = self.sunpack(fmtstr, self.infileread(10)) fmtstr = self.fmt_order + "BBI16s32s128s" - blk2=self.sunpack(fmtstr, self.infileread(182)) + blk2 = self.sunpack(fmtstr, self.infileread(182)) # incorporate timeblk tuple into blk list blk = list(blk1) @@ -1152,50 +1236,53 @@ class Mseed(futils): return blk ######################################################### + def Writeblk500(self, inblk, seekval=0, endianess=""): """ writes Timing Blockette 500 (200 bytes) requires tuples inblk - inblk=(blkette, nextblk, vcocorr,Year, Day, Hour, Min, Sec, junk, Micro, Micro2, \ - qual,cnt,type,mod,stat) + inblk=(blkette, nextblk, vcocorr,Year, Day, Hour, Min, Sec, junk, + Micro, Micro2, qual,cnt,type,mod,stat) """ try: self.infileseek(seekval) - fmtorderstr=self.setEndian(endianess) + fmtorderstr = self.setEndian(endianess) fmtstr = fmtorderstr + "HHfHHBBBBHBBI16s32s128s" - (blkette, nextblk, vcocorr,Year, Day, Hour, Min, Sec, junk, Micro, Micro2, \ - qual,cnt,type,mod,stat)=inblk - pack_blk=self.spack(fmtstr, blkette, nextblk, vcocorr,Year, Day, Hour, Min, Sec, junk, Micro, Micro2, \ - qual,cnt,type,mod,stat) + (blkette, nextblk, vcocorr, Year, Day, Hour, Min, Sec, junk, + Micro, Micro2, qual, cnt, type, mod, stat) = inblk + pack_blk = self.spack(fmtstr, blkette, nextblk, vcocorr, Year, Day, + Hour, Min, Sec, junk, Micro, Micro2, qual, + cnt, type, mod, stat) self.infilewrite(pack_blk) return 200 - - except: + except Exception: print("error writing blockette 500") return 0 ######################################################### + def blk1000(self, seekval=0): """ Data Only SEED Blockette 1000 (8 bytes) Returns tuple - blk - Blockette type (UWORD, 2) - Next blockette's byte offset relative to fixed section of header - (UWORD, 2) - Encoding Format (BYTE, 1) - Word Order (UBYTE, 1) - Data Record Length (UBYTE, 1) - Reserved (UBYTE, 1) + blk + Blockette type (UWORD, 2) + Next blockette's byte offset relative to fixed section of header + (UWORD, 2) + Encoding Format (BYTE, 1) + Word Order (UBYTE, 1) + Data Record Length (UBYTE, 1) + Reserved (UBYTE, 1) """ self.infileseek(seekval) fmtstr = self.fmt_order + "HHbBBB" - blk=self.sunpack(fmtstr, self.infileread(8)) + blk = self.sunpack(fmtstr, self.infileread(8)) return list(blk) ######################################################### + def Writeblk1000(self, inblk, seekval=0, endianess=""): """ writes Data Only SEED Blockette 1000 (8 bytes) @@ -1205,37 +1292,40 @@ class Mseed(futils): try: self.infileseek(seekval) - fmtorderstr=self.setEndian(endianess) + fmtorderstr = self.setEndian(endianess) fmtstr = fmtorderstr + "HHbBBB" - (blkette, nextblk, fmt,order,length,res)=inblk - pack_blk=self.spack(fmtstr, blkette, nextblk, fmt,order,length,res) + (blkette, nextblk, fmt, order, length, res) = inblk + pack_blk = self.spack(fmtstr, blkette, nextblk, fmt, order, + length, res) self.infilewrite(pack_blk) return 8 - - except: + except Exception: print("error writing blockette 1000") return 0 ######################################################### + def blk1001(self, seekval=0): """ Data Extension Blockette 1001 (8 bytes) Returns tuple - blk - Blockette type (UWORD, 2) - Next blockette's byte offset relative to fixed section of header - (UWORD, 2) - Timing Quality (UBYTE, 1) - microsec (UBYTE, 1) - Reserved (UBYTE, 1) - Frame count (UBYTE, 1) + blk + Blockette type (UWORD, 2) + Next blockette's byte offset relative to fixed section of header + (UWORD, 2) + Timing Quality (UBYTE, 1) + microsec (UBYTE, 1) + Reserved (UBYTE, 1) + Frame count (UBYTE, 1) """ self.infileseek(seekval) fmtstr = self.fmt_order + "HHBBBB" - blk=self.sunpack(fmtstr, self.infileread(8)) + blk = self.sunpack(fmtstr, self.infileread(8)) return list(blk) + ######################################################### + def Writeblk1001(self, inblk, seekval=0, endianess=""): """ writes Data Extension Blockette 1001 (8 bytes) @@ -1245,106 +1335,110 @@ class Mseed(futils): try: self.infileseek(seekval) - fmtorderstr=self.setEndian(endianess) + fmtorderstr = self.setEndian(endianess) fmtstr = fmtorderstr + "HHBBBB" - (blkette, nextblk, tqual,micro,res,fcnt)=inblk - pack_blk=self.spack(fmtstr, blkette, nextblk, tqual,micro,res,fcnt) + (blkette, nextblk, tqual, micro, res, fcnt) = inblk + pack_blk = self.spack(fmtstr, blkette, nextblk, + tqual, micro, res, fcnt) self.infilewrite(pack_blk) return 8 - - except: + except Exception: print("error writing blockette 1001") return 0 ######################################################### + def blk2000(self, seekval=0): """ Variable Length Opaque Data Blockette Returns two tuples - blk, opaque - Blockette type (UWORD, 2) - Next blockette's byte offset relative to fixed section of header. Use 0 if no - more blockettes will follow. (UWORD, 2) - Total Blockette length kin Bytes (UWORD, 2) - Offset to Opaque Data (UWORD, 2) - Record number (ULONG, 4) - Data Word order (UBYTE, 1) - 0 = little endian (VAX or 80x86 byte order). - 1 = big endian (68000 or SPARC byte order). - Opaque Data flags (UBYTE, 1) - [bit 0] Opaque blockette orientation. - 0 = record oriented. - 1 = stream oriented. - [bit 1] Packaging bit. - 0 = Blockette 2000s from multiple SEED data records with different timetags - may be packaged into a single SEED data record. The exact original - timetag in each SEED Fixed Data Header is not required for each - blockette 2000. - 1= Blockette 2000s from multiple SEED data records with differing timetags - may NOT be repackaged into a single SEED data record. Set this bit - if the timetag in the SEED Fixed Data Header is required to properly - interpret the opaque data. - [bits 2-3] Opaque blockette fragmentation flags. - 00 = opaque record identified by record number is completely contained in - this opaque blockette. - 01 = first opaque blockette for record spanning multiple blockettes. - 11 = continuation blockette 2...N-1 of record spanning N blockettes. - 10 = final blockette for record spanning N blockettes. - [bits 4-5] File blockette information. - 00 = not file oriented. - 01 = first blockette of file. - 10 = continuation of file. - 11 = last blockette of file. - Number of Opaque Header fields (UBYTE, 1) - Opaque Data Header fields (VAR) - a Record type - b Vendor type - c Model type - d Software - e Firmware - Opaque Data Opaque - bytes of opaque data. Total length of opaque data - in bytes is blockette_length-15-length (opaque_data_header_string) - (Opaque) + blk, opaque + Blockette type (UWORD, 2) + Next blockette's byte offset relative to fixed section of header. + Use 0 if no more blockettes will follow. (UWORD, 2) + Total Blockette length kin Bytes (UWORD, 2) + Offset to Opaque Data (UWORD, 2) + Record number (ULONG, 4) + Data Word order (UBYTE, 1) + 0 = little endian (VAX or 80x86 byte order). + 1 = big endian (68000 or SPARC byte order). + Opaque Data flags (UBYTE, 1) + [bit 0] Opaque blockette orientation. + 0 = record oriented. + 1 = stream oriented. + [bit 1] Packaging bit. + 0 = Blockette 2000s from multiple SEED data records with + different timetags may be packaged into a single SEED data + record. The exact original timetag in each SEED Fixed Data + Header is not required for each blockette 2000. + 1= Blockette 2000s from multiple SEED data records with + differing timetags may NOT be repackaged into a single SEED + data record. Set this bit if the timetag in the SEED Fixed + Data Header is required to properly interpret the opaque data. + [bits 2-3] Opaque blockette fragmentation flags. + 00 = opaque record identified by record number is completely + contained in this opaque blockette. + 01 = first opaque blockette for record spanning multiple + blockettes. + 11 = continuation blockette 2...N-1 of record spanning N + blockettes. + 10 = final blockette for record spanning N blockettes. + [bits 4-5] File blockette information. + 00 = not file oriented. + 01 = first blockette of file. + 10 = continuation of file. + 11 = last blockette of file. + Number of Opaque Header fields (UBYTE, 1) + Opaque Data Header fields (VAR) + a Record type + b Vendor type + c Model type + d Software + e Firmware + Opaque Data Opaque - bytes of opaque data. Total length of opaque data + in bytes is blockette_length-15-length (opaque_data_header_string) + (Opaque) """ self.infileseek(seekval) fmtstr = self.fmt_order + "HHHHIBBB" - blk=self.sunpack(fmtstr, self.infileread(15)) - #decompose tmpblk[6] into bit fields, create blk + blk = self.sunpack(fmtstr, self.infileread(15)) + # decompose tmpblk[6] into bit fields, create blk tmpblk = self.UbytetoStr(blk, 6) - blk=tmpblk #recast blk as list + blk = tmpblk # recast blk as list - #Now decipher Opaque Header - charlist=[] - char="" + # Now decipher Opaque Header + charlist = [] + char = "" length_data_string = 0 - NumOpaqueHeaders=int(blk[7]) + NumOpaqueHeaders = int(blk[7]) fmtstr = self.fmt_order + "s" for i in range(NumOpaqueHeaders): - tmpchar="" + tmpchar = "" while tmpchar != "~": - tupchar=self.sunpack(fmtstr, self.infileread(1)) + tupchar = self.sunpack(fmtstr, self.infileread(1)) tmpchar = str(tupchar[0]) if tmpchar != "~": char = char + tmpchar length_data_string += 1 charlist.append(char) blk.append(charlist) -# opaque = "" -# rdbyte = int(tmpblk[2]) - 15 - length_data_string -# fmt = "=%ds" % rdbyte -# opaque=self.sunpack(fmt, self.infileread(rdbyte)) -# -# # -# print opaque -# # + # opaque = "" + # rdbyte = int(tmpblk[2]) - 15 - length_data_string + # fmt = "=%ds" % rdbyte + # opaque=self.sunpack(fmt, self.infileread(rdbyte)) + # + # print(opaque) + # return blk + ######################################################### + def UbytetoStr(self, tup, offset): """ converts unsign byte to string values """ - list=[] + list = [] strval = "" # mask bit fields and build string for i in range(8): @@ -1361,274 +1455,295 @@ class Mseed(futils): else: list.append(tup[i]) return list + ######################################################### + def FlagStrtoInt(self, flagstr): """ converts Flag String to Integer """ - flagint=0 - n=len(flagstr) - 1 + flagint = 0 + n = len(flagstr) - 1 for a in flagstr: if int(a): flagint = flagint + 2**n - n-=1 + n -= 1 return flagint ######################################################### + def Pad(self, var, num): """ pad header values to specified length with blank space right justified """ - varlength=len(var) + varlength = len(var) if varlength == num: return var elif varlength < num: - pad=num-varlength - newvar= var + SPACE*pad + pad = num - varlength + newvar = var + SPACE * pad return newvar ######################################################### -### END MSEED +# END MSEED ######################################################### class Segy(futils): def __init__(self, infile): - self.type=self.serial=self.chan=self.time=self.rate=None - futils.__init__(self,infile) + self.type = self.serial = self.chan = self.time = self.rate = None + futils.__init__(self, infile) # self.byteorder: byte order of input file. # "big" # "little" # or "unknown" self.byteorder = self.ByteOrder() - # self.fmt_order: companion to self.byteorder. Format string for stuct.pack + # self.fmt_order: companion to self.byteorder. Format string for + # stuct.pack # ">" big endian # "<" little endian ######################################################### - def isSegy(self) : + + def isSegy(self): """ determines if processed file is segy or unknown type """ - #if we don't know byteorder it must not be segy - if self.byteorder == "unknown": return 0 + # if we don't know byteorder it must not be segy + if self.byteorder == "unknown": + return 0 - #otherwise it might be segy + # otherwise it might be segy (Sserial, Schan, Srate, Syear, Sday, Shour, Smin, Ssec) = self.idread() - #we have already tested for a valid time in self.ByteOrder, this test is - #to ensure that we were able to read a complete idhdr header - if Sserial == Schan == Srate == Syear == Sday == Shour == \ - Smin == Ssec == None: return 0 - #if we're this far it must be segy + # we have already tested for a valid time in self.ByteOrder, this test + # is to ensure that we were able to read a complete idhdr header + if (Sserial == Schan == Srate == Syear == Sday == Shour == + Smin == Ssec is None): + return 0 + # if we're this far it must be segy self.type = "segy" if Sserial < 36864: self.serial = Sserial else: self.serial = self.to_hex(Sserial) - #self.time = string.join(list(map(str, (Syear, Sday, Shour, Smin, Ssec))), ":") - templist = list(map(str,(Syear, Sday, Shour, Smin, Ssec))) - self.time = ":".join(templist) + # self.time = string.join(list(map(str, (Syear, Sday, Shour, Smin, + # Ssec))), ":") + templist = list(map(str, (Syear, Sday, Shour, Smin, Ssec))) + self.time = ":".join(templist) self.chan = Schan self.rate = Srate return 1 ######################################################### + def idhdr(self): return self.type, self.serial, self.chan, self.time, self.rate ######################################################### + def tracelength(self): """ returns trace length in seconds """ self.infile.seek(228) fmtstr = self.fmt_order + "L" - numsamp=struct.unpack(fmtstr, self.infile.read(4))[0] - length=numsamp/self.rate + numsamp = struct.unpack(fmtstr, self.infile.read(4))[0] + length = numsamp / self.rate return length + ######################################################### - def idread(self) : + + def idread(self): """ Read file as if SEGY file trying to extract channel, time block, sample rate, and serial number """ - try : + try: self.infile.seek(0) - SH=self.infile.read(240) -# self.infile.seek(12) + SH = self.infile.read(240) + # self.infile.seek(12) fmtstr = self.fmt_order + "L" -# chan = struct.unpack(fmtstr, self.infile.read(4))[0] -# print chan - chan=struct.unpack(fmtstr, SH[12:16])[0] + # chan = struct.unpack(fmtstr, self.infile.read(4))[0] + # print(chan) + chan = struct.unpack(fmtstr, SH[12:16])[0] -# self.infile.seek(156) -# timeblock=self.infile.read(10) + # self.infile.seek(156) + # timeblock=self.infile.read(10) fmtstr = self.fmt_order + "HHHHH" -# (year,day,hour,min,sec)=struct.unpack(fmtstr, timeblock) - (year,day,hour,min,sec)=struct.unpack(fmtstr, SH[156:166]) + # (year,day,hour,min,sec)=struct.unpack(fmtstr, timeblock) + (year, day, hour, min, sec) = struct.unpack(fmtstr, SH[156:166]) -# self.infile.seek(200) + # self.infile.seek(200) fmtstr = self.fmt_order + "L" -# samp=struct.unpack(fmtstr, self.infile.read(4))[0] -# print samp - samp=struct.unpack(fmtstr, SH[200:204])[0] - rate = int(1/(samp/1e6)) + # samp=struct.unpack(fmtstr, self.infile.read(4))[0] + # print(samp) + samp = struct.unpack(fmtstr, SH[200:204])[0] + rate = int(1 / (samp / 1e6)) -# self.infile.seek(224) + # self.infile.seek(224) fmtstr = self.fmt_order + "H" -# serial = struct.unpack(fmtstr, self.infile.read(2))[0] - serial=struct.unpack(fmtstr, SH[224:226])[0] + # serial = struct.unpack(fmtstr, self.infile.read(2))[0] + serial = struct.unpack(fmtstr, SH[224:226])[0] return serial, chan, rate, year, day, hour, min, sec - except : + except Exception: return None, None, None, None, None, None, None, None ######################################################### - def ByteOrder(self, seekval=156) : + def ByteOrder(self, seekval=156): """ read file as if it is segy just pulling time info from header and determine if it makes sense unpacked as big endian or little endian """ Order = "unknown" - try : - #seek to timeblock and read + try: + # seek to timeblock and read self.infile.seek(seekval) - timeblock=self.infile.read(10) - - #assume big endian - (Year, Day, Hour, Min, Sec)=\ - struct.unpack('>HHHHH',timeblock) - #test if big endian read makes sense - if 1950 <= Year <= 2050 and \ - 1 <= Day <= 366 and \ - 0 <= Hour <= 23 and \ - 0 <= Min <= 59 and \ - 0 <= Sec <= 59: + timeblock = self.infile.read(10) + + # assume big endian + (Year, Day, Hour, Min, Sec) =\ + struct.unpack('>HHHHH', timeblock) + # test if big endian read makes sense + if (1950 <= Year <= 2050 and 1 <= Day <= 366 and + 0 <= Hour <= 23 and 0 <= Min <= 59 and 0 <= Sec <= 59): Order = "big" self.fmt_order = ">" else: - #try little endian read - (Year, Day, Hour, Min, Sec)=\ - struct.unpack('<HHHHH',timeblock) - #test if little endian read makes sense - if 1950 <= Year <= 2050 and \ - 1 <= Day <= 366 and \ - 0 <= Hour <= 23 and \ - 0 <= Min <= 59 and \ - 0 <= Sec <= 59: + # try little endian read + (Year, Day, Hour, Min, Sec) =\ + struct.unpack('<HHHHH', timeblock) + # test if little endian read makes sense + if (1950 <= Year <= 2050 and 1 <= Day <= 366 and + 0 <= Hour <= 23 and 0 <= Min <= 59 and 0 <= Sec <= 59): Order = "little" self.fmt_order = "<" - except : + except Exception: pass return Order + ######################################################### - def to_int(self, input) : + + def to_int(self, input): """ conversion routine from hex to integer """ - HEXCHAR=["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"] - hexnum=str(input) - retval=0 - input_length=len(hexnum) - for i in range(input_length) : - for index in range(len(HEXCHAR)) : - if string.upper(hexnum[i]) == HEXCHAR[index] : - retval=retval + index*(16**(input_length-(1+i))) + HEXCHAR = ["0", "1", "2", "3", "4", "5", "6", + "7", "8", "9", "A", "B", "C", "D", "E", "F"] + hexnum = str(input) + retval = 0 + input_length = len(hexnum) + for i in range(input_length): + for index in range(len(HEXCHAR)): + if string.upper(hexnum[i]) == HEXCHAR[index]: + retval = retval + index * (16**(input_length - (1 + i))) return retval ######################################################### - def to_hex(self, number) : + + def to_hex(self, number): """ conversion routine from integer to hex """ - retval=0 - hexnum=hex(number) + retval = 0 + hexnum = hex(number) return hexnum[2:] + + ######################################################### -### END SEGY +# END SEGY ######################################################### -if __name__ == "__main__" : +if __name__ == "__main__": VERSION = "2008.204" - filecnt=0 -# based on traverse routine in "python standard library", Lundh pg 34 - def GetTrace(DataDir) : + filecnt = 0 + # based on traverse routine in "python standard library", Lundh pg 34 + + def GetTrace(DataDir): global filecnt stack = [] - rwError=0 - for k in range(len(DataDir)) : + rwError = 0 + for k in range(len(DataDir)): stack.append(DataDir[k]) files = [] file_list = {} - errcnt=0 - while stack : + errcnt = 0 + while stack: directory = stack.pop() if not os.path.isdir(directory): - print("\n***WARNING*** Directory \"%s\" not found.\n" % directory) + print("\n***WARNING*** Directory \"%s\" not found.\n" % + directory) continue - # else : + # else : for file in os.listdir(directory): fullname = os.path.join(directory, file) if not os.access(fullname, 6): - rwError+=1 + rwError += 1 continue - if os.path.isfile(fullname) : - filecnt+=1 + if os.path.isfile(fullname): + filecnt += 1 try: newfile = Segy(fullname) if newfile.isSegy(): (type, serial, chan, time, rate) = newfile.idhdr() length = newfile.tracelength() - # length = "NULL" - file_list[fullname] = (type, serial, chan, time, rate, length, newfile.ByteOrder()) + # length = "NULL" + file_list[fullname] = (type, serial, chan, time, + rate, length, + newfile.ByteOrder()) newfile.close() - except: - rwError+=1 + except Exception: + rwError += 1 pass else: try: - newfile=Mseed(fullname) + newfile = Mseed(fullname) if newfile.isMseed(): try: - #simple test to determine if correct size file - filesize=newfile.filesize - blksize=newfile.blksize - (numblocks, odd_size)=divmod(filesize, blksize) + # simple test to determine if correct size + # file + filesize = newfile.filesize + blksize = newfile.blksize + (numblocks, odd_size) = divmod( + filesize, blksize) if odd_size: - rwError+=1 + rwError += 1 continue - except: - rwError+=1 + except Exception: + rwError += 1 continue - type=newfile.type - serial=string.strip(newfile.FH.Stat) - chan=string.strip(newfile.FH.Chan) - loc=string.strip(newfile.FH.Loc) - net=string.strip(newfile.FH.Net) - time=newfile.time - rate=newfile.rate + type = newfile.type + serial = string.strip(newfile.FH.Stat) + chan = string.strip(newfile.FH.Chan) + loc = string.strip(newfile.FH.Loc) + net = string.strip(newfile.FH.Net) + time = newfile.time + rate = newfile.rate length = newfile.tracelength() - # length = "NULL" - file_list[fullname] = (type, serial, chan, time, rate, length, newfile.ByteOrder()) + # length = "NULL" + file_list[fullname] = (type, serial, chan, + time, rate, length, + newfile.ByteOrder()) newfile.close() - except: - rwError+=1 + except Exception: + rwError += 1 pass - # if os.path.isdir(fullname) and not os.path.islink(fullname) : - if os.path.isdir(fullname) or (os.path.islink(fullname) and not os.path.isfile(fullname)): + # if os.path.isdir(fullname) and not os.path.islink(fullname) : + if (os.path.isdir(fullname) or (os.path.islink(fullname) and + not os.path.isfile(fullname))): stack.append(fullname) return file_list, rwError - if len(sys.argv) > 1 : - if sys.argv[1] == "-#" : + if len(sys.argv) > 1: + if sys.argv[1] == "-#": print(VERSION) sys.exit(1) - else : + else: print("Unknown arguement %s" % sys.argv[1:]) sys.exit(1) @@ -1636,28 +1751,30 @@ if __name__ == "__main__" : mseednum = 0 unknownnum = 0 Dirs = [] -# Dirs.append(",") + # Dirs.append(",") Dirs.append(".") -# Dirs.append("/Users/bruce/data/uniq") - (file_list,rwError) = GetTrace(Dirs) - for file in list(file_list.keys()) : + # Dirs.append("/Users/bruce/data/uniq") + (file_list, rwError) = GetTrace(Dirs) + for file in list(file_list.keys()): file_type = file_list[file][0] - if file_type == "segy" : + if file_type == "segy": segynum += 1 -# print "\n SEGY \n" -# print "segy: ", file_list[file][1], file_list[file][2], file_list[file][3], \ -# file_list[file][4], file_list[file][5], file_list[file][6] - elif file_type == "mseed" : -# if file_type == "mseed" : + # print("\n SEGY \n") + # print("segy: ", file_list[file][1], file_list[file][2], + # file_list[file][3], file_list[file][4], file_list[file][5], + # file_list[file][6]) + elif file_type == "mseed": + # if file_type == "mseed": mseednum += 1 -# print "\n MSEED \n" -# print "mseed: ", file_list[file][1], file_list[file][2], file_list[file][3], \ -# file_list[file][4], file_list[file][5], file_list[file][6] - - #else : - #unknownnum += 1 - #print "\n Format Not Recognized \n" + # print("\n MSEED \n") + # print("mseed: ", file_list[file][1], file_list[file][2], + # file_list[file][3], file_list[file][4], file_list[file][5], + # file_list[file][6]) + # else : + # unknownnum += 1 + # print("\n Format Not Recognized \n") print("\nTotal Files Found = %i " % filecnt) - print("SEGY Files Processed = %i \nMSEED Files Processed = %i" % (segynum, mseednum)) + print("SEGY Files Processed = %i \nMSEED Files Processed = %i" % + (segynum, mseednum)) print("Total RWErrors = %i " % rwError) print("Total Files Identified = %i" % len(file_list)) diff --git a/ckMseed/__init__.py b/ckMseed/__init__.py index 09ab33cc71e7a160cdb61cddd257163ecca96ea5..1199ab19cf17b46c3ab06f66ccd523bac22e2ad5 100644 --- a/ckMseed/__init__.py +++ b/ckMseed/__init__.py @@ -4,4 +4,4 @@ __author__ = """IRIS PASSCAL""" __email__ = 'software-support@passcal.nmt.edu' -__version__ = '2018.179' +__version__ = '2020.211' diff --git a/ckMseed/ckMseed.py b/ckMseed/ckMseed.py index 5523de767fe46fbff6e156119b582687334c5c5b..b2ba9d43556091b5dffd0466eae93de287ee3eb8 100755 --- a/ckMseed/ckMseed.py +++ b/ckMseed/ckMseed.py @@ -9,81 +9,110 @@ # date 2009.188 # # bug fix: -# modified to no longer create threads. Commented out all the lines with threading calls so this can -# later be noted where would be useful to add it in again. The reason for this is because everytime a thread -# was used it was defined, started and then joined immediately. Therefore, there was no reason for them -# to be threads at all, and it was breaking with Tk because the functions that were the targets for the threads -# weren't actually Tk/thread safe. -from __future__ import print_function - - -VERSION = "2018.232" - +# modified to no longer create threads. Commented out all the lines with +# threading calls so this can later be noted where would be useful to add it +# in again. The reason for this is because everytime a thread was used it was +# defined, started and then joined immediately. Therefore, there was no reason +# for them to be threads at all, and it was breaking with Tk because the +# functions that were the targets for the threads weren't actually Tk/thread +# safe. +################################################################ +# +# modification +# version: 2020.211 +# author: Maeva Pourpoint +# +# Updates to work under Python 3. +# Unit tests to ensure basic functionality. +# Code cleanup to conform to the PEP8 style guide. +# Directory cleanup (remove unused files introduced by Cookiecutter). +# Packaged with conda. +# Remove use of lstrip() in ReadAll() (lines 1148-1151). +################################################################ + +import os import Pmw +import string +import sys +import time - - -from operator import mod -from struct import pack from getopt import getopt -import os, sys, string, time -#import threading from glob import glob +from operator import mod from tkinter import * from tkinter.filedialog import * + from ckMseed.LibTrace import * +VERSION = "2020.211" + +# import threading SPACE = " " -DATALOC="" -#vars used for batchmode +# vars used for batchmode +BATCHMODE = 0 -BATCHMODE=0 def Usage(err=''): print(err) - print("Usage\ckMseed \nckMseed -#\nckMseed -h\nckMseed [-d DataDirs] [-s] [-v]") - print(" -d DataDirs - colon separated list of data directories [default: cwd]") + print("Usage\nckMseed \nckMseed -#\nckMseed -h\nckMseed [-d DataDirs] " + "[-s] [-v]") + print(" -d DataDirs - colon separated list of data directories " + "[default: cwd]") print(" -h Usage") - print(" -s Simple mode. Check and report endianess of first fixed header only") - print(" -v Check and report endianess of first fixed header and determine") + print(" -s Simple mode. Check and report endianess of first fixed " + "header only") + print(" -v Check and report endianess of first fixed header and " + "determine") print(" start times for first and last block of mseed file") print(" -V Read all header blockettes") - print(" NOTE: -s, -v, & -V are mutually exclusive.-V supercedes -v supercedes -s") - os._exit(0) - -# get commandline args -try: - opts, pargs = getopt(sys.argv[1:], 'hsvV#d:') - -except: - err="\nERROR: Invalid command line usage\n" - Usage(err) -else: - for flag, arg in opts: - if flag == "-h": - Usage() - if flag == "-d": - DATALOC=arg - if flag == "-s": - RunFlag="Simple" - if flag == "-v": - RunFlag="Verbose" - if flag == "-V": - RunFlag="Very Verbose" - if flag == "-#": - print(VERSION) - os._exit(0) - -print("\n", os.path.basename(sys.argv[0]), VERSION) -#print("opts=",opts) - -#From "Python and Tkinter Programming", J.E. Grayson, pg.103 + print(" NOTE: -s, -v, & -V are mutually exclusive.-V supercedes -v " + "supercedes -s") + + +def main(): + # get commandline args + try: + opts, pargs = getopt(sys.argv[1:], 'hsvV#d:') + except Exception: + err = "\nERROR: Invalid command line usage\n" + Usage(err) + sys.exit(1) + else: + Dataloc = "" + RunFlag = "" + for flag, arg in opts: + if flag == "-h": + Usage() + sys.exit(0) + if flag == "-d": + Dataloc = arg + if flag == "-s": + RunFlag = "Simple" + if flag == "-v": + RunFlag = "Verbose" + if flag == "-V": + RunFlag = "Very Verbose" + if flag == "-#": + print(VERSION) + sys.exit(0) + + print("\n", os.path.basename(sys.argv[0]), VERSION) + # print("opts=",opts) + + mw = MainWindow(title="ckMseed %s" % VERSION, Dataloc=Dataloc, + RunFlag=RunFlag) + mw.root.geometry("650x500") + mw.root.mainloop() + + +# From "Python and Tkinter Programming", J.E. Grayson, pg.103 class Command: - def __init__(self,func, *args, **kw): + def __init__(self, func, *args, **kw): self.func = func self.args = args self.kw = kw + def __call__(self, *args, **kw): args = self.args + args kw.update(self.kw) @@ -93,48 +122,56 @@ class Command: # Over ride some methods in FileDialog so we only select directories # From TraceBuilder.py, auth Steve Azevedo & Lloyd Carothers # -class DirectoryDialog (FileDialog) : - title="Directory Select" - def __init__ (self, root) : - FileDialog.__init__ (self, root) - #Only allow selection of directories (single click) - def files_select_event (self, e): +class DirectoryDialog(FileDialog): + + title = "Directory Select" + + def __init__(self, root): + FileDialog.__init__(self, root) + + # Only allow selection of directories (single click) + def files_select_event(self, e): pass - #Double click - def files_double_event (self, e): + # Double click + + def files_double_event(self, e): pass - #Make sure it's a directory and accessable - def ok_command (self) : - file = self.get_selection () - if not os.path.isdir (file) : - if not os.access (file, R_OK) : - self.root.bell () + # Make sure it's a directory and accessable + def ok_command(self): + file = self.get_selection() + if not os.path.isdir(file): + if not os.access(file, R_OK): + self.root.bell() file = None - self.quit (file) + self.quit(file) # main + + class MainWindow: - def __init__(self, title='', BatchFile=''): + def __init__(self, title='', BatchFile='', Dataloc="", RunFlag=""): self.root = Tk() Pmw.initialise(self.root) self.root.title(title) - #create balloon - self.balloon=Pmw.Balloon(self.root) + # create balloon + self.balloon = Pmw.Balloon(self.root) - #set timezone to UTC + # set timezone to UTC os.environ['TZ'] = 'GMT' time.tzname = ('GMT', 'GMT') - time.timezone=0 + time.timezone = 0 - #Start Global Variables + # Start Global Variables self.e_width = 24 - #Variables, lists, dictionaries associated with traces and trace headers + # Variables, lists, dictionaries associated with traces and trace + # headers + self.Dataloc = Dataloc self.DataDirs = StringVar() self.StatSel = StringVar() self.StatSelList = [] @@ -142,33 +179,33 @@ class MainWindow: self.PopUpHelp = IntVar() self.PopUpHelp.set(1) - self.StatChanLocDict={} + self.StatChanLocDict = {} - self.Savefile=StringVar() + self.Savefile = StringVar() self.Savefile.set("") - self.BigEndianKey=StringVar() + self.BigEndianKey = StringVar() self.BigEndianKey.set("") - self.LittleEndianKey=StringVar() + self.LittleEndianKey = StringVar() self.LittleEndianKey.set("") - self.BigEndianDict={} - self.LittleEndianDict={} - self.ErrorDict={} - self.NumLittleFiles=IntVar() - self.NumBigFiles=IntVar() + self.BigEndianDict = {} + self.LittleEndianDict = {} + self.ErrorDict = {} + self.NumLittleFiles = IntVar() + self.NumBigFiles = IntVar() self.NumLittleFiles.set(0) self.NumBigFiles.set(0) - self.ScanErrors=IntVar() + self.ScanErrors = IntVar() self.ScanErrors.set(0) - #set of vars watched for active threading event - self.RunScan=IntVar() + # set of vars watched for active threading event + self.RunScan = IntVar() self.RunScan.set(0) - #log vars and lists - self.ScanType=IntVar() + # log vars and lists + self.ScanType = IntVar() self.ScanType.set(0) self.ScanTypeList = [ ["Simple", 0], @@ -176,50 +213,45 @@ class MainWindow: ["Very Verbose", 2], ] - self.ErrorType=IntVar() + self.ErrorType = IntVar() self.ErrorType.set(0) - #log vars and lists - self.ErrorTypeList = [ - ["All", 0], - ["Read/Write", 1], - ["Size", 2], - ["Endian", 3], - ["Non-Unique", 4] - ] + # log vars and lists + self.ErrorTypeList = [["All", 0], ["Read/Write", 1], ["Size", 2], + ["Endian", 3], ["Non-Unique", 4]] - self.SaveAll=IntVar() + self.SaveAll = IntVar() self.SaveAll.set(0) - self.SaveInfo=IntVar() + self.SaveInfo = IntVar() self.SaveInfo.set(0) - self.SaveErrors=IntVar() + self.SaveErrors = IntVar() self.SaveErrors.set(0) - self.SaveErrorTraces=IntVar() + self.SaveErrorTraces = IntVar() self.SaveErrorTraces.set(0) - self.ErrorAll=[] - self.ErrorRW=[] - self.ErrorSize=[] - self.ErrorEndian=[] - self.ErrorUnique=[] - self.BigEndianPageName="" - self.LittleEndianPageName="" - self.ScanErrorsPageName="" -#####################new - - #if DATALOC not set on commandline set here - if DATALOC: - self.DataDirs.set(DATALOC) + self.ErrorAll = [] + self.ErrorRW = [] + self.ErrorSize = [] + self.ErrorEndian = [] + self.ErrorUnique = [] + self.BigEndianPageName = "" + self.LittleEndianPageName = "" + self.ScanErrorsPageName = "" + # new + + # if Dataloc not set on commandline set here + if self.Dataloc: + self.DataDirs.set(self.Dataloc) else: self.DataDirs.set(os.getcwd()) # if a batch file exists on the command line, # we just run necessary processes for modifying headers - self.BatchFile=StringVar() + self.BatchFile = StringVar() self.BatchFile.set(BatchFile) # If batchmode then launch from here and exit if BATCHMODE: - #address endian change first since unique i.e. no batchfile + # address endian change first since unique i.e. no batchfile print("Running in Batch Mode") if RunEndianBatch: print("Changing Endianess to: ", Endianess) @@ -229,8 +261,10 @@ class MainWindow: self.BuildTrcList() self.ChangeEndian() else: - if RunTimeBatch: print("Correcting Timing") - if RunHeaderBatch: print("Correcting Headers") + if RunTimeBatch: + print("Correcting Timing") + if RunHeaderBatch: + print("Correcting Headers") print("Using Template: ", self.BatchFile.get()) self.LoadTemplate() @@ -238,7 +272,8 @@ class MainWindow: if not self.UpdateTimeDict: print("No Timing Corrections in Template.\nDone") sys.exit(1) - print("Finding Files beneath directory: ", self.DataDirs.get()) + print("Finding Files beneath directory: ", + self.DataDirs.get()) self.BuildTrcList() self.RunApplyTimeCor.set(1) self.ApplyTimeCor() @@ -246,7 +281,8 @@ class MainWindow: if not self.UpdateHdrDict: print("No Header Corrections in Template.\nDone") sys.exit(1) - print("Finding Files beneath directory: ", self.DataDirs.get()) + print("Finding Files beneath directory: ", + self.DataDirs.get()) self.BuildTrcList() self.RunModHdrs.set(1) self.ModHdrs() @@ -256,59 +292,63 @@ class MainWindow: # Build GUI self.createMainButtons(self.root) self.createNoteBooks(self.root) + ######################################## - def createMainButtons(self,master): + + def createMainButtons(self, master): """ Build buttons for root window """ - #create info bar at bottom of root window + # create info bar at bottom of root window self.InfoString_l = Label(master, - bg = "yellow", - relief = "ridge") + bg="yellow", + relief="ridge") self.InfoString_l.pack(side='bottom', fill='x') - #persistent buttons across all tabs - self.Button_fm = Frame(master, relief = 'groove', borderwidth = 2) - self.Button_fm.pack(side = 'bottom', pady=5, fill = 'x') + # persistent buttons across all tabs + self.Button_fm = Frame(master, relief='groove', borderwidth=2) + self.Button_fm.pack(side='bottom', pady=5, fill='x') self.exit_b = Button(self.Button_fm, - text = "Exit", - relief = "ridge", - cursor = 'pirate', - command = Command(self.Exit), - activebackground= 'red', - activeforeground='black') + text="Exit", + relief="ridge", + cursor='pirate', + command=Command(self.Exit), + activebackground='red', + activeforeground='black') self.exit_b.pack(side='right', anchor='e') self.balloon.bind(self.exit_b, "Exit Program") self.SaveScan_b = Button(self.Button_fm, - text='Save Scan', - relief = "ridge", - activebackground='green', - command=Command(self.saveWidget, master) - ) + text='Save Scan', + relief="ridge", + activebackground='green', + command=Command(self.saveWidget, master)) self.SaveScan_b.pack(side='right', anchor='e') - self.balloon.bind(self.SaveScan_b, "Allows scan results to \nbe saved to a file") + self.balloon.bind( + self.SaveScan_b, "Allows scan results to \nbe saved to a file") self.PopUpHelp_cb = Checkbutton(self.Button_fm, - text="PopUp Help", - command=self.ToggleBalloons, - variable=self.PopUpHelp - ) + text="PopUp Help", + command=self.ToggleBalloons, + variable=self.PopUpHelp) self.PopUpHelp_cb.pack(side='left') self.balloon.bind(self.PopUpHelp_cb, "Toggles 'PopUp Help' on and off") ######################################## + def ToggleBalloons(self): """ turns balloon help on and off """ if self.PopUpHelp.get(): - self.balloon.configure(state = 'balloon') + self.balloon.configure(state='balloon') else: - self.balloon.configure(state = 'none') + self.balloon.configure(state='none') + ######################################## - def createNoteBooks(self,master): + + def createNoteBooks(self, master): """ Set up notebooks in root window """ @@ -317,6 +357,7 @@ class MainWindow: self.nb.pack(padx=5, pady=5, fill='both', expand=1) ######################################## + def buildRemainingNoteBooks(self): self.buildBigEndian(self.nb) self.buildLittleEndian(self.nb) @@ -324,147 +365,156 @@ class MainWindow: self.nb.pack(padx=5, pady=5, fill='both', expand=1) ################################################################## - def buildScan(self,master): + + def buildScan(self, master): """ Populate HdrList NoteBook - tab for selecting traces, building trace database, and correcting headers one key at a time + tab for selecting traces, building trace database, and correcting + headers one key at a time """ self.Scan_nb = master.add('Scan') - #buttons - self.Button_fm = Frame(self.Scan_nb, borderwidth = 2) - self.Button_fm.pack(side = 'bottom', padx= 5, pady=5, fill = 'x') - self.Scan_fm = Frame(self.Scan_nb, relief = 'groove', borderwidth = 2) + # buttons + self.Button_fm = Frame(self.Scan_nb, borderwidth=2) + self.Button_fm.pack(side='bottom', padx=5, pady=5, fill='x') + self.Scan_fm = Frame(self.Scan_nb, relief='groove', borderwidth=2) - #data directory find and clear buttons, and entry field - #button to build trace db - self.DataDirs_fm = Frame(self.Scan_nb, relief = 'groove', borderwidth = 2) - self.DataDirs_fm.pack(side = 'top', pady=5, fill = 'x') + # data directory find and clear buttons, and entry field + # button to build trace db + self.DataDirs_fm = Frame(self.Scan_nb, relief='groove', borderwidth=2) + self.DataDirs_fm.pack(side='top', pady=5, fill='x') self.DataDirs_l = Label(self.DataDirs_fm, text='Data Directories: ') self.DataDirs_l.pack(side='left') - self.balloon.bind(self.DataDirs_l, \ - "Search path(s) for finding mseed files. \nColon separate multiple entries") + self.balloon.bind(self.DataDirs_l, "Search path(s) for finding mseed " + "files. \nColon separate multiple entries") self.DataDirs_e = Entry(self.DataDirs_fm, - selectbackground = 'yellow', - textvariable = self.DataDirs) - self.DataDirs_e.pack(side='left', anchor='w',expand=1, fill='x') + selectbackground='yellow', + textvariable=self.DataDirs) + self.DataDirs_e.pack(side='left', anchor='w', expand=1, fill='x') self.ClearDataDir_b = Button(self.DataDirs_fm, - activebackground = 'orange', - relief = "ridge", - text = "Clear", - command = Command(self.setValue, self.DataDirs) - ) + activebackground='orange', + relief="ridge", + text="Clear", + command=Command(self.setValue, + self.DataDirs)) self.ClearDataDir_b.pack(side='right') - self.balloon.bind(self.ClearDataDir_b, \ - "Clears 'Data Directories' entry") + self.balloon.bind(self.ClearDataDir_b, + "Clears 'Data Directories' entry") self.FindDataDir_b = Button(self.DataDirs_fm, - activebackground = 'green', - relief = "ridge", - text = "Find", - command = Command(self.getPath, self.DataDirs, None) - ) + activebackground='green', + relief="ridge", + text="Find", + command=Command(self.getPath, + self.DataDirs, None)) self.FindDataDir_b.pack(side='right') - self.balloon.bind(self.FindDataDir_b, \ - "Dialog window to \nselect Data Directories") + self.balloon.bind(self.FindDataDir_b, + "Dialog window to \nselect Data Directories") - if not DATALOC: self.DataDirs.set(os.getcwd()) + if not self.Dataloc: + self.DataDirs.set(os.getcwd()) self.Scan_b = Button(self.DataDirs_fm, - activebackground = 'green', - relief = "ridge", - background='lightblue', - text = "Scan Traces", - command = Command(self.BuildTrcList) - ) + activebackground='green', + relief="ridge", + background='lightblue', + text="Scan Traces", + command=Command(self.BuildTrcList)) self.Scan_b.pack(side='right') - self.balloon.bind(self.Scan_b, \ - "Scan traces using \n'Data Directories' \nas top level directories") + self.balloon.bind(self.Scan_b, + "Scan traces using \n'Data Directories' \nas top " + "level directories") # station selection frame and entry box - self.StatSel_fm = Frame(self.Scan_nb, relief = 'groove', borderwidth = 2) - self.StatSel_fm.pack(side = 'top', pady=5, fill = 'x') - self.StatSel_l = Label(self.StatSel_fm, text='Scan only stations (colon separated list): ') + self.StatSel_fm = Frame(self.Scan_nb, relief='groove', borderwidth=2) + self.StatSel_fm.pack(side='top', pady=5, fill='x') + self.StatSel_l = Label(self.StatSel_fm, text="Scan only stations " + "(colon separated list): ") self.StatSel_l.pack(side='left') self.StatSel_e = Entry(self.StatSel_fm, - selectbackground = 'yellow', - textvariable = self.StatSel) - self.StatSel_e.pack(side='left', anchor='w',expand=1, fill='x') - self.balloon.bind(self.StatSel_e, "Filter trace search \nfor these stations") + selectbackground='yellow', + textvariable=self.StatSel) + self.StatSel_e.pack(side='left', anchor='w', expand=1, fill='x') + self.balloon.bind(self.StatSel_e, "Filter trace search \nfor these " + "stations") self.ClearStatSel_b = Button(self.StatSel_fm, - activebackground = 'orange', - relief = "ridge", - text = "Clear", - command = Command(self.setValue, self.StatSel) - ) + activebackground='orange', + relief="ridge", + text="Clear", + command=Command(self.setValue, + self.StatSel)) self.ClearStatSel_b.pack(side='right') self.balloon.bind(self.ClearStatSel_b, "Clear station filter") - #filters - self.RadButtons_fm = Frame(self.Scan_nb, relief = 'groove', borderwidth = 2) - self.RadButtons_fm.pack(side = 'top', pady=5, fill = 'x') + # filters + self.RadButtons_fm = Frame( + self.Scan_nb, relief='groove', borderwidth=2) + self.RadButtons_fm.pack(side='top', pady=5, fill='x') self.Scan_l = Label(self.RadButtons_fm, text='Scan Type: ') self.Scan_l.pack(side='left') - self.balloon.bind(self.Scan_l, "Simple - ID traces\nVerbose - Include Start/End Times\n"\ - "Very Verbose - Scan all blocks") + self.balloon.bind(self.Scan_l, "Simple - ID traces\nVerbose - Include " + "Start/End Times\nVery Verbose - Scan all blocks") for text, value in self.ScanTypeList: Radiobutton(self.RadButtons_fm, - text=text, - value=value, - variable=self.ScanType).pack(side='left', anchor='e') + text=text, + value=value, + variable=self.ScanType).pack(side='left', anchor='e') - #setup frame for station substitutions. to be filled later - Label(self.Scan_fm, text="Stat:Chan:Loc:Net:Sps Found").pack(side='top', fill='x') + # setup frame for station substitutions. to be filled later + Label(self.Scan_fm, text="Stat:Chan:Loc:Net:Sps Found").pack( + side='top', fill='x') self.ScanText = Pmw.ScrolledText(self.Scan_fm, borderframe=1) self.ScanText.pack(side='top', fill='x') - self.Scan_fm.pack(side = 'top', pady = 5, fill = 'x') - + self.Scan_fm.pack(side='top', pady=5, fill='x') self.ScanText.tag_config("odd", background="lightblue") self.ScanText.tag_config("head", background="yellow") ################################################################## - def buildBigEndian(self,master): + + def buildBigEndian(self, master): """ Populate Log NoteBook for keeping track of changes """ - lstr=str + lstr = str try: self.nb.delete(self.BigEndianPageName) - except Exception as e: + except Exception: pass - self.BigEndianPageName='Big Endian (' + lstr(self.NumBigFiles.get()) + ')' + self.BigEndianPageName = 'Big Endian (' + \ + lstr(self.NumBigFiles.get()) + ')' self.BE_nb = master.add(self.BigEndianPageName) self.BEDisplay_fm = Frame(self.BE_nb, relief='groove', borderwidth=2) self.BEDisplay_fm.grid() - self.BEDisplay_fm.columnconfigure(0,weight=1) - self.BEDisplay_fm.columnconfigure(1,weight=1) + self.BEDisplay_fm.columnconfigure(0, weight=1) + self.BEDisplay_fm.columnconfigure(1, weight=1) - keylist=list(self.BigEndianDict.keys()) + keylist = list(self.BigEndianDict.keys()) keylist.sort() if keylist: - keylist.insert(0,"All") + keylist.insert(0, "All") - Label(self.BEDisplay_fm, text="Display Traces Matching:").grid(row=0, column=0, sticky=E) + Label(self.BEDisplay_fm, text="Display Traces Matching:").grid( + row=0, column=0, sticky=E) Pmw.ComboBox(self.BEDisplay_fm, - history=0, - entry_width=self.e_width-5, - entry_textvariable=self.BigEndianKey, - scrolledlist_items=(keylist), - selectioncommand=Command(self.LoadBigEndianStat) - ).grid(row=0, column=1, sticky=W) - self.BEDisplayText = Pmw.ScrolledText(self.BEDisplay_fm,borderframe=1) + history=0, + entry_width=self.e_width - 5, + entry_textvariable=self.BigEndianKey, + scrolledlist_items=(keylist), + selectioncommand=Command(self.LoadBigEndianStat) + ).grid(row=0, column=1, sticky=W) + self.BEDisplayText = Pmw.ScrolledText(self.BEDisplay_fm, borderframe=1) self.BEDisplayText.grid(row=1, column=0, columnspan=2) - self.BEDisplayText.columnconfigure(0,weight=1) - self.BEDisplayText.columnconfigure(1,weight=1) + self.BEDisplayText.columnconfigure(0, weight=1) + self.BEDisplayText.columnconfigure(1, weight=1) - #tags used for highlighting log entries + # tags used for highlighting log entries self.BEDisplayText.tag_config('blue', foreground='blue') self.BEDisplayText.tag_config('dkgreen', foreground='darkgreen') self.BEDisplayText.tag_config('red', foreground='red') @@ -473,43 +523,45 @@ class MainWindow: self.BEDisplayText.tag_config("odd", background="lightblue") ################################################################## - def buildLittleEndian(self,master): + + def buildLittleEndian(self, master): """ Populate Log NoteBook for keeping track of changes """ - lstr=str + lstr = str try: self.nb.delete(self.LittleEndianPageName) - except: + except Exception: pass - self.LittleEndianPageName='Little Endian (' + lstr(self.NumLittleFiles.get()) + ')' + self.LittleEndianPageName = 'Little Endian (' + lstr( + self.NumLittleFiles.get()) + ')' self.LE_nb = master.add(self.LittleEndianPageName) self.LEDisplay_fm = Frame(self.LE_nb, relief='groove', borderwidth=2) self.LEDisplay_fm.grid() - self.LEDisplay_fm.columnconfigure(0,weight=1) - self.LEDisplay_fm.columnconfigure(1,weight=1) + self.LEDisplay_fm.columnconfigure(0, weight=1) + self.LEDisplay_fm.columnconfigure(1, weight=1) - keylist=list(self.LittleEndianDict.keys()) + keylist = list(self.LittleEndianDict.keys()) keylist.sort() if keylist: - keylist.insert(0,"All") + keylist.insert(0, "All") - Label(self.LEDisplay_fm, text="Display Traces Matching:").grid(row=0, column=0, sticky=E) + Label(self.LEDisplay_fm, text="Display Traces Matching:").grid( + row=0, column=0, sticky=E) Pmw.ComboBox(self.LEDisplay_fm, - history=0, - entry_width=self.e_width-5, - entry_textvariable=self.LittleEndianKey, - scrolledlist_items=(keylist), - selectioncommand=Command(self.LoadLittleEndianStat) - ).grid(row=0, column=1, sticky=W) - self.LEDisplayText = Pmw.ScrolledText(self.LEDisplay_fm,borderframe=1) + history=0, + entry_width=self.e_width - 5, + entry_textvariable=self.LittleEndianKey, + scrolledlist_items=(keylist), + selectioncommand=Command(self.LoadLittleEndianStat) + ).grid(row=0, column=1, sticky=W) + self.LEDisplayText = Pmw.ScrolledText(self.LEDisplay_fm, borderframe=1) self.LEDisplayText.grid(row=1, column=0, columnspan=2) - self.LEDisplayText.columnconfigure(0,weight=1) - self.LEDisplayText.columnconfigure(1,weight=1) - + self.LEDisplayText.columnconfigure(0, weight=1) + self.LEDisplayText.columnconfigure(1, weight=1) - #tags used for highlighting log entries + # tags used for highlighting log entries self.LEDisplayText.tag_config('blue', foreground='blue') self.LEDisplayText.tag_config('dkgreen', foreground='darkgreen') self.LEDisplayText.tag_config('red', foreground='red') @@ -518,45 +570,50 @@ class MainWindow: self.LEDisplayText.tag_config("odd", background="lightblue") ################################################################## - def buildError(self,master): + + def buildError(self, master): """ Populate Log NoteBook for keeping track of changes """ - lstr=str + lstr = str try: self.nb.delete(self.ScanErrorsPageName) - except: + except Exception: pass - self.ScanErrorsPageName='Errors (' + lstr(self.ScanErrors.get()) + ')' + self.ScanErrorsPageName = 'Errors (' + \ + lstr(self.ScanErrors.get()) + ')' self.Error_nb = master.add(self.ScanErrorsPageName) - self.ErrorDisplay_fm = Frame(self.Error_nb, relief='groove', borderwidth=2) + self.ErrorDisplay_fm = Frame( + self.Error_nb, relief='groove', borderwidth=2) self.ErrorDisplay_fm.pack(side='top', pady=5, fill='x') self.ErrorText = Pmw.ScrolledText(self.Error_nb, borderframe=1) - #log_filters - self.RadButtons_fm = Frame(self.Error_nb, relief = 'groove', borderwidth = 2) - self.RadButtons_fm.pack(side = 'top', pady=5, fill = 'x') + # log_filters + self.RadButtons_fm = Frame( + self.Error_nb, relief='groove', borderwidth=2) + self.RadButtons_fm.pack(side='top', pady=5, fill='x') self.ErrorDisplay_l = Label(self.RadButtons_fm, text='Display: ') self.ErrorDisplay_l.pack(side='left') self.balloon.bind(self.ErrorDisplay_l, "Filter Error messages") for text, value in self.ErrorTypeList: Radiobutton(self.RadButtons_fm, - text=text, - value=value, - command=Command(self.DisplayError), - variable=self.ErrorType).pack(side='left', anchor='e') + text=text, + value=value, + command=Command(self.DisplayError), + variable=self.ErrorType).pack(side='left', anchor='e') self.ErrorText.pack(side='bottom', fill='both', expand=1) - #tags used for highlighting log entries + # tags used for highlighting log entries self.ErrorText.tag_config('blue', foreground='blue') self.ErrorText.tag_config('dkgreen', foreground='darkgreen') self.ErrorText.tag_config('red', foreground='red') self.ErrorText.tag_config('black', foreground='black') ####################################### + def BuildTrcList(self): """ build a trace list using DataDirList as base directories @@ -565,35 +622,36 @@ class MainWindow: self.addTextInfoBar() self.ButtonState("disabled") - #kill warn window if it exist (i.e. user got here from self.Ignore) - #this may not longer be necessary + # kill warn window if it exist (i.e. user got here from self.Ignore) + # this may not longer be necessary try: self.killWindow(self.WarnWidget_tl) - except: + except Exception: pass - #clear text windows + # clear text windows try: self.ScanText.clear() self.BEDisplayText.clear() self.LEDisplayText.clear() self.ErrorText.clear() - except: + except Exception: pass - #initialize lists + # initialize lists self.DataDirList = [] self.StatSelList = [] - self.BigEndianDict={} - self.LittleEndianDict={} - n=0 + self.BigEndianDict = {} + self.LittleEndianDict = {} + # n = 0 - # split directory string & test they exist before launching into self.FindTrace + # split directory string & test they exist before launching into + # self.FindTrace # populate DataDirList - for idir in self.DataDirs.get().split(":") : + for idir in self.DataDirs.get().split(":"): dirlist = glob(idir) for newdir in dirlist: if not os.path.isdir(newdir): - err="***WARNING*** Directory " + newdir + " not found." + err = "***WARNING*** Directory " + newdir + " not found." self.addTextInfoBar(err, "red") self.ScanErrors.set(self.ScanErrors.get() + 1) self.ButtonState() @@ -604,8 +662,8 @@ class MainWindow: if self.StatSel.get() == "*" or self.StatSel.get() == "": pass else: - for statsel in self.StatSel.get().split(":") : - statsel=string.strip(statsel) + for statsel in self.StatSel.get().split(":"): + statsel = string.strip(statsel) self.StatSelList.append(statsel) # find & ID traces in DataDirList, setup various list for nb's @@ -619,10 +677,10 @@ class MainWindow: # stay here until thread dies # tRun.join() - numfiles=self.NumBigFiles.get() + self.NumLittleFiles.get() - numerrors=self.ScanErrors.get() - text= "\n" + str(numfiles) + " unique mseed files found. *** " \ - + str(numerrors) + " scan errors." + numfiles = self.NumBigFiles.get() + self.NumLittleFiles.get() + numerrors = self.ScanErrors.get() + text = "\n" + str(numfiles) + " unique mseed files found. *** " \ + + str(numerrors) + " scan errors." self.addTextInfoBar(text, "green") self.root.bell() @@ -635,8 +693,10 @@ class MainWindow: self.DisplayError() self.ButtonState() return + ####################################### - def LaunchFindTrace(self) : + + def LaunchFindTrace(self): """ separated out so FindTrace could be run as a thread @@ -650,55 +710,56 @@ class MainWindow: self.KillCancelTL(self.RunScan) ####################################### - def FindTrace(self, DataDir) : + + def FindTrace(self, DataDir): """ based on traverse routine in "python standard library", Lundh pg 34 """ - #local variables - #lstrip=string.strip ## deprecated in python 3 - #ljoin=string.join - lstrftime=time.strftime - lgmtime=time.gmtime - setScanErr=self.ScanErrors.set - getScanErr=self.ScanErrors.get - setBigFiles=self.NumBigFiles.set - setLittleFiles=self.NumLittleFiles.set - getBigFiles=self.NumBigFiles.get - getLittleFiles=self.NumLittleFiles.get + # local variables + # lstrip=string.strip ## deprecated in python 3 + # ljoin=string.join + lstrftime = time.strftime + lgmtime = time.gmtime + setScanErr = self.ScanErrors.set + getScanErr = self.ScanErrors.get + setBigFiles = self.NumBigFiles.set + setLittleFiles = self.NumLittleFiles.set + getBigFiles = self.NumBigFiles.get + getLittleFiles = self.NumLittleFiles.get # build stack of input directories stack = [] - for k in range(len(DataDir)) : + for k in range(len(DataDir)): if not DataDir[k] in stack: stack.append(DataDir[k]) # init several counters and dictionaries - self.BigEndianDict={} - self.LittleEndianDict={} - self.ErrorDict={} - self.StatChanLocDict={} + self.BigEndianDict = {} + self.LittleEndianDict = {} + self.ErrorDict = {} + self.StatChanLocDict = {} self.NumLittleFiles.set(0) self.NumBigFiles.set(0) self.ScanErrors.set(0) - self.ErrorAll=[] - self.ErrorRW=[] - self.ErrorSize=[] - self.ErrorEndian=[] - self.ErrorUnique=[] - scantype=self.ScanType.get() - - cnt=1 - #loop while directories still exist in stack - while stack : + self.ErrorAll = [] + self.ErrorRW = [] + self.ErrorSize = [] + self.ErrorEndian = [] + self.ErrorUnique = [] + scantype = self.ScanType.get() + + cnt = 1 + # loop while directories still exist in stack + while stack: directory = stack.pop() if not os.access(directory, 5): text = "Skipped: %s" % directory text1 = "\t\tAccess Error" - self.WriteError(text,"Read/Write","red") - self.WriteError(text1,"Read/Write","black") + self.WriteError(text, "Read/Write", "red") + self.WriteError(text1, "Read/Write", "black") setScanErr(getScanErr() + 1) continue try: - listfiles=(dir for dir in os.listdir(directory)) + listfiles = (dir for dir in os.listdir(directory)) except Exception as e: print("Directory Read Error: %s" % e) @@ -707,11 +768,11 @@ class MainWindow: while 1: try: - file=next(listfiles) + file = next(listfiles) except StopIteration: break - #respond to a cancel request + # respond to a cancel request if not self.RunScan.get(): break # keep user posted of progress @@ -719,267 +780,308 @@ class MainWindow: pass else: self.wait("Examining File: ", cnt) - #build up list of mseed files w/ full pathnames + # build up list of mseed files w/ full pathnames fullname = os.path.join(directory, file) - if os.path.isfile(fullname) : + if os.path.isfile(fullname): if not os.access(fullname, 6): - err= "ERROR: Read/Write permission denied." - err1="\t File:" + fullname - self.WriteError(err,"Read/Write","red") - self.WriteError(err1,"Read/Write") - self.AddToDict(self.ErrorDict, "Permission Error", directory,file) + err = "ERROR: Read/Write permission denied." + err1 = "\t File:" + fullname + self.WriteError(err, "Read/Write", "red") + self.WriteError(err1, "Read/Write") + self.AddToDict(self.ErrorDict, "Permission Error", + directory, file) setScanErr(getScanErr() + 1) continue try: msfile = Mseed(fullname) -## print("msfile.isMseed()=", msfile.isMseed()) -## print("msfile.time=", msfile.time,", msfile.rate=", msfile.rate) - if msfile.isMseed() : + # print("msfile.isMseed()=", msfile.isMseed()) + # print("msfile.time=", msfile.time,", msfile.rate=", + # msfile.rate) + if msfile.isMseed(): try: - #simple test to determine if correct size file - filesize=msfile.filesize - blksize=msfile.blksize - numblocks=msfile.numblocks - #print("filesize,blksize,numblocks=",filesize,blksize,numblocks) - except: - err= "ERROR: Cannot determine file and block sizes." - err1="\t File:" + fullname - self.WriteError(err,"Size","red") - self.WriteError(err1,"Size") - self.AddToDict(self.ErrorDict, "Size", directory,file) + # simple test to determine if correct size file + # filesize = msfile.filesize + # blksize = msfile.blksize + numblocks = msfile.numblocks + # print("filesize, blksize, numblocks=", + # filesize, blksize, numblocks) + except Exception: + err = ("ERROR: Cannot determine file and " + "block sizes.") + err1 = "\t File:" + fullname + self.WriteError(err, "Size", "red") + self.WriteError(err1, "Size") + self.AddToDict( + self.ErrorDict, "Size", directory, file) setScanErr(getScanErr() + 1) continue - #assign header info - type=msfile.type - rate=msfile.rate - tracetime=msfile.time -## print("rate=",rate,", tracetime=",tracetime) - stat=msfile.FH.Stat.strip().decode("utf-8") - chan=msfile.FH.Chan.strip().decode("utf-8") - loc=msfile.FH.Loc.strip().decode("utf-8") - net=msfile.FH.Net.strip().decode("utf-8") - # fileid=ljoin(list(map(str,(stat,chan,loc,net,rate))), ":") - templist = list(map(str,(stat,chan,loc,net,rate))) + # assign header info + # type = msfile.type + rate = msfile.rate + # tracetime = msfile.time + # print("rate=", rate, ", tracetime=", tracetime) + stat = msfile.FH.Stat.strip().decode("utf-8") + chan = msfile.FH.Chan.strip().decode("utf-8") + loc = msfile.FH.Loc.strip().decode("utf-8") + net = msfile.FH.Net.strip().decode("utf-8") + # fileid = ljoin(list(map(str, (stat, chan, loc, + # net, rate))), ":") + templist = list(map(str, (stat, chan, loc, net, + rate))) fileid = ":".join(templist) # print("fileid=",fileid) - - #window on specific stations if exist + # window on specific stations if exist if self.StatSelList: - if not stat in self.StatSelList: + if stat not in self.StatSelList: continue if not scantype: - filelist=[file] + filelist = [file] else: (startepoch, endepoch) = msfile.FirstLastTime() - endepoch+=1 - start = lstrftime('%Y:%j:%H:%M:%S', lgmtime(startepoch)) - end = lstrftime('%Y:%j:%H:%M:%S', lgmtime(endepoch)) + endepoch += 1 + start = lstrftime('%Y:%j:%H:%M:%S', + lgmtime(startepoch)) + end = lstrftime('%Y:%j:%H:%M:%S', + lgmtime(endepoch)) if scantype == 1: - filelist=[file,start,end] + filelist = [file, start, end] else: - blklist=self.ReadAll(msfile, numblocks,directory,file,fileid) - filelist=[file,start,end] + blklist - #print ("scantype=", scantype, ", filelist=", filelist) - ## dthomas 2018-08-27 when we click the Verbose radio button, we never get to this routine. - #build file list for fixing headers + blklist = self.ReadAll(msfile, + numblocks, + directory, + file, + fileid) + filelist = [file, start, end] + blklist + # print("scantype=", scantype, ", filelist=", + # filelist) + # dthomas 2018-08-27 when we click the Verbose + # radio button, we never get to this routine. + # build file list for fixing headers if not scantype: -# if not self.StatChanLocDict.has_key(fileid): - self.StatChanLocDict[fileid]=[] + # if not self.StatChanLocDict.has_key(fileid): + self.StatChanLocDict[fileid] = [] else: try: - if startepoch < self.StatChanLocDict[fileid][0][0]: - self.StatChanLocDict[fileid][0][0] = startepoch - if endepoch > self.StatChanLocDict[fileid][0][1]: - self.StatChanLocDict[fileid][0][1] = endepoch + if startepoch < self.StatChanLocDict[fileid][0][0]: # noqa: E501 + self.StatChanLocDict[fileid][0][0] =\ + startepoch + if endepoch > self.StatChanLocDict[fileid][0][1]: # noqa: E501 + self.StatChanLocDict[fileid][0][1] =\ + endepoch except KeyError: - self.StatChanLocDict[fileid]=[] - self.StatChanLocDict[fileid].append([startepoch,endepoch]) - - + self.StatChanLocDict[fileid] = [] + self.StatChanLocDict[fileid].append( + [startepoch, endepoch]) # build endian lists if msfile.byteorder == "big": setBigFiles(getBigFiles() + 1) - self.AddToDict(self.BigEndianDict,fileid,directory,filelist) + self.AddToDict(self.BigEndianDict, fileid, + directory, filelist) elif msfile.byteorder == "little": setLittleFiles(getLittleFiles() + 1) - self.AddToDict(self.LittleEndianDict,fileid,directory,filelist) + self.AddToDict(self.LittleEndianDict, fileid, + directory, filelist) msfile.close() except Exception as e: - err="ERROR: %s" % e - self.WriteError(err,"Read/Write","red") - err1= "\t File:" + fullname - self.WriteError(err1,"Read/Write") - self.AddToDict(self.ErrorDict, "Read/Write", directory,file) + err = "ERROR: %s" % e + self.WriteError(err, "Read/Write", "red") + err1 = "\t File:" + fullname + self.WriteError(err1, "Read/Write") + self.AddToDict( + self.ErrorDict, "Read/Write", directory, file) setScanErr(getScanErr() + 1) - cnt+=1 + cnt += 1 # add fullname to stack if it is a directory or link - if os.path.isdir(fullname) or (os.path.islink(fullname) and not os.path.isfile(fullname)): - if not fullname in stack: + if os.path.isdir(fullname) or (os.path.islink(fullname) and + not os.path.isfile(fullname)): + if fullname not in stack: stack.append(fullname) return ######################################################### + def UpdateScan(self): - if not self.StatChanLocDict: return + if not self.StatChanLocDict: + return self.ScanText.clear() - keylist=[] - keylist=list(self.StatChanLocDict.keys()) + keylist = [] + keylist = list(self.StatChanLocDict.keys()) keylist.sort() - header="Stat:Chan:Loc:Net:Sps Big Little Begin Time End Time" + header = ("Stat:Chan:Loc:Net:Sps Big Little Begin Time " + "End Time") self.ScanText.insert("end", """%s\n""" % header, "head") if keylist: - c=0 + c = 0 for key in keylist: - numBig=0 - numLittle=0 - numError=0 - numspace=22-len(key) + numBig = 0 + numLittle = 0 + # numError = 0 + numspace = 22 - len(key) if key in self.BigEndianDict: for dir in list(self.BigEndianDict[key].keys()): - numBig=numBig+len(self.BigEndianDict[key][dir]) + numBig = numBig + len(self.BigEndianDict[key][dir]) if key in self.LittleEndianDict: for dir in list(self.LittleEndianDict[key].keys()): - numLittle=numLittle+len(self.LittleEndianDict[key][dir]) - #if self.ErrorDict.has_key(key): - #for dir in self.ErrorDict[key].keys(): - #numError=numError+len(self.ErrorDict[key][dir]) - - text=key + numspace*SPACE - numspace=6-len(str(numBig)) - text=text + numspace*SPACE + str(numBig) - numspace=8-len(str(numLittle)) - text=text + numspace*SPACE + str(numLittle) - #numspace=8-len(str(numError)) - #text=text + numspace*SPACE + str(numError) + numLittle = numLittle + \ + len(self.LittleEndianDict[key][dir]) + # if self.ErrorDict.has_key(key): + # for dir in self.ErrorDict[key].keys(): + # numError=numError+len(self.ErrorDict[key][dir]) + + text = key + numspace * SPACE + numspace = 6 - len(str(numBig)) + text = text + numspace * SPACE + str(numBig) + numspace = 8 - len(str(numLittle)) + text = text + numspace * SPACE + str(numLittle) + # numspace=8-len(str(numError)) + # text=text + numspace*SPACE + str(numError) if not self.ScanType.get(): pass else: - start = time.strftime('%Y:%j:%H:%M:%S', time.gmtime(self.StatChanLocDict[key][0][0])) - end = time.strftime('%Y:%j:%H:%M:%S', time.gmtime(self.StatChanLocDict[key][0][1])) - #text=text + 3*SPACE + string.join(list(map(str,(start,end))), " ") # python 2 syntax - templist = list(map(str,(start,end))) - text = text + 3*SPACE + " ".join(templist) ## python 3 compatible - - if c : + start = time.strftime('%Y:%j:%H:%M:%S', time.gmtime( + self.StatChanLocDict[key][0][0])) + end = time.strftime('%Y:%j:%H:%M:%S', time.gmtime( + self.StatChanLocDict[key][0][1])) + # python 2 syntax + # text = text + 3*SPACE + \ + # string.join(list(map(str,(start,end))), " ") + templist = list(map(str, (start, end))) + text = (text + 3 * SPACE + + " ".join(templist)) # python 3 compatible + + if c: self.ScanText.insert("end", """%s\n""" % text, "odd") - c=0 - else : + c = 0 + else: self.ScanText.insert("end", """%s\n""" % text) - c+=1 + c += 1 return + ######################################################### - def LoadBigEndianStat(self,key): + + def LoadBigEndianStat(self, key): self.BEDisplayText.clear() - header=" Trace Name" - header2=" Start Time End Time Blockettes" + header = " Trace Name" + header2 = " Start Time End Time Blockettes" self.BEDisplayText.insert("end", """%s\n""" % header, "head") self.BEDisplayText.insert("end", """%s\n""" % header2, "head") - if not self.BigEndianDict: return - c=0 + if not self.BigEndianDict: + return + c = 0 if key == "All": for indexkey in list(self.BigEndianDict.keys()): text = "<" + indexkey + ">\n" self.BEDisplayText.insert('end', text, "blue") for directory in list(self.BigEndianDict[indexkey].keys()): - text2= " <" + directory + ">\n" + text2 = " <" + directory + ">\n" self.BEDisplayText.insert('end', text2, "dkgreen") for trace in self.BigEndianDict[indexkey][directory]: - text= 4*SPACE + str(trace[0]) + "\n" - #text=text + 6*SPACE + string.join(list(map(str,(trace[1:]))), " ") - templist = list(map(str,(trace[1:]))) - text=text + 6*SPACE + " ".join(templist) + text = 4 * SPACE + str(trace[0]) + "\n" + # text = text + 6*SPACE + \ + # string.join(list(map(str,(trace[1:]))), " ") + templist = list(map(str, (trace[1:]))) + text = text + 6 * SPACE + " ".join(templist) if c: - self.BEDisplayText.insert('end', text + "\n", "odd") - c=0 + self.BEDisplayText.insert('end', + text + "\n", "odd") + c = 0 else: self.BEDisplayText.insert('end', text + "\n") - c=1 - + c = 1 else: - numtrace=0 + numtrace = 0 text = "<" + key + ">\n" self.BEDisplayText.insert('end', text, "blue") for directory in list(self.BigEndianDict[key].keys()): - text2= " <" + directory + ">\n" + text2 = " <" + directory + ">\n" self.BEDisplayText.insert('end', text2, "dkgreen") for trace in self.BigEndianDict[key][directory]: - text= 4*SPACE + str(trace[0]) + "\n" - #text=text + 6*SPACE + string.join(list(map(str,(trace[1:]))), " ") - templist = list(map(str,(trace[1:]))) - text=text + 6*SPACE + " ".join(templist) + text = 4 * SPACE + str(trace[0]) + "\n" + # text = text + 6*SPACE + \ + # string.join(list(map(str,(trace[1:]))), " ") + templist = list(map(str, (trace[1:]))) + text = text + 6 * SPACE + " ".join(templist) if c: self.BEDisplayText.insert('end', text + "\n", "odd") - c=0 + c = 0 else: self.BEDisplayText.insert('end', text + "\n") - c=1 - numtrace+=1 - text="Displaying " + str(numtrace) + " traces" + c = 1 + numtrace += 1 + text = "Displaying " + str(numtrace) + " traces" self.addTextInfoBar(text, "green") return + ######################################################### - def LoadLittleEndianStat(self,key): + + def LoadLittleEndianStat(self, key): self.LEDisplayText.clear() - header=" Trace Name" - header2=" Start Time End Time Blockettes" + header = " Trace Name" + header2 = " Start Time End Time Blockettes" self.LEDisplayText.insert("end", """%s\n""" % header, "head") self.LEDisplayText.insert("end", """%s\n""" % header2, "head") - if not self.LittleEndianDict: return - c=0 + if not self.LittleEndianDict: + return + c = 0 if key == "All": for indexkey in list(self.LittleEndianDict.keys()): text = "<" + indexkey + ">\n" self.LEDisplayText.insert('end', text, "blue") for directory in list(self.LittleEndianDict[indexkey].keys()): - text2= " <" + directory + ">\n" + text2 = " <" + directory + ">\n" self.LEDisplayText.insert('end', text2, "dkgreen") for trace in self.LittleEndianDict[indexkey][directory]: - text= 4*SPACE + str(trace[0]) + "\n" - #text=text + 6*SPACE + string.join(list(map(str,(trace[1:]))), " ") - templist = list(map(str,(trace[1:]))) - text=text + 6*SPACE + " ".join(templist) + text = 4 * SPACE + str(trace[0]) + "\n" + # text = text + 6*SPACE + \ + # string.join(list(map(str,(trace[1:]))), " ") + templist = list(map(str, (trace[1:]))) + text = text + 6 * SPACE + " ".join(templist) if c: - self.LEDisplayText.insert('end', text + "\n", "odd") - c=0 + self.LEDisplayText.insert( + 'end', text + "\n", "odd") + c = 0 else: self.LEDisplayText.insert('end', text + "\n") - c=1 + c = 1 else: - numtrace=0 + numtrace = 0 text = "<" + key + ">\n" self.LEDisplayText.insert('end', text, "blue") for directory in list(self.LittleEndianDict[key].keys()): - text2= " <" + directory + ">\n" + text2 = " <" + directory + ">\n" self.LEDisplayText.insert('end', text2, "dkgreen") for trace in self.LittleEndianDict[key][directory]: - text= 4*SPACE + str(trace[0]) + "\n" - #text=text + 6*SPACE + string.join(list(map(str,(trace[1:]))), " ") - templist = list(map(str,(trace[1:]))) - text=text + 6*SPACE + " ".join(templist) + text = 4 * SPACE + str(trace[0]) + "\n" + # text = text + 6*SPACE + \ + # string.join(list(map(str,(trace[1:]))), " ") + templist = list(map(str, (trace[1:]))) + text = text + 6 * SPACE + " ".join(templist) if c: self.LEDisplayText.insert('end', text + "\n", "odd") - c=0 + c = 0 else: self.LEDisplayText.insert('end', text + "\n") - c=1 - numtrace+=1 - text="Displaying " + str(numtrace) + " traces" + c = 1 + numtrace += 1 + text = "Displaying " + str(numtrace) + " traces" self.addTextInfoBar(text, "green") return + ######################################################### + def WriteError(self, info, type="", color="black"): """ writes errors to appropriate list @@ -988,7 +1090,7 @@ class MainWindow: if info: print(info) else: - info=info + "\n" + info = info + "\n" self.ErrorAll.append((info, color)) if type == "Read/Write": @@ -1002,22 +1104,30 @@ class MainWindow: else: pass return + ################################################################## + def DisplayError(self): """ filters Error entries """ self.ErrorText.clear() - if self.ErrorType.get() == 0: textlist=self.ErrorAll - if self.ErrorType.get() == 1: textlist=self.ErrorRW - if self.ErrorType.get() == 2: textlist=self.ErrorSize - if self.ErrorType.get() == 3: textlist=self.ErrorEndian - if self.ErrorType.get() == 4: textlist=self.ErrorUnique + if self.ErrorType.get() == 0: + textlist = self.ErrorAll + if self.ErrorType.get() == 1: + textlist = self.ErrorRW + if self.ErrorType.get() == 2: + textlist = self.ErrorSize + if self.ErrorType.get() == 3: + textlist = self.ErrorEndian + if self.ErrorType.get() == 4: + textlist = self.ErrorUnique for (textcmd, color) in textlist: self.ErrorText.insert('end', textcmd, color) return ################################################################## + def AddToDict(self, inDict, id, inDir, inList): try: try: @@ -1032,81 +1142,86 @@ class MainWindow: return ################################################################## + def ReadAll(self, msfile, numblocks, inDir, inFile, old_fileid): """ attempts to read all blockettes and check for consistancy """ - #local variables - #lstrip=string.strip - #ljoin=string.join - lfixedhdr=msfile.fixedhdr - ltypenxt=msfile.typenxt - lGetBlk=msfile.GetBlk - lrate=msfile.rate + # local variables + # lstrip=string.strip + # ljoin=string.join + lfixedhdr = msfile.fixedhdr + ltypenxt = msfile.typenxt + lGetBlk = msfile.GetBlk + lrate = msfile.rate lstat = msfile.FH.Stat.strip().decode("utf-8") lchan = msfile.FH.Chan.strip().decode("utf-8") lloc = msfile.FH.Loc.strip().decode("utf-8") lnet = msfile.FH.Net.strip().decode("utf-8") fullname = os.path.join(inDir, inFile) - warn="" - blk_err=0 - blocks=[] - n=0 - blksize=msfile.blksize + warn = "" + # blk_err = 0 + blocks = [] + n = 0 + blksize = msfile.blksize while n < numblocks: - #read & rewrite fixed header - hdrs=lfixedhdr(n*blksize) - rate=lrate - stat=lstat - chan=lchan - loc=lloc - net=lnet - numblk=hdrs[3][3] - addseek=hdrs[3][6] - #fileid=ljoin(list(map(str,(stat,chan,loc,net,rate))), ":") - templist = list(map(str,(stat,chan,loc,net,rate))) + # read & rewrite fixed header + hdrs = lfixedhdr(n * blksize) + rate = lrate + stat = lstat + chan = lchan + loc = lloc + net = lnet + numblk = hdrs[3][3] + addseek = hdrs[3][6] + # fileid = ljoin(list(map(str,(stat,chan,loc,net,rate))), ":") + templist = list(map(str, (stat, chan, loc, net, rate))) fileid = ":".join(templist) if fileid != old_fileid: - warn="WARNING: Multiplexed miniseed file" - warn1="\tFile: " + fullname - b=0 - #loop over number of blockettes following fixed header at block n + warn = "WARNING: Multiplexed miniseed file" + warn1 = "\tFile: " + fullname + b = 0 + # loop over number of blockettes following fixed header at block n while b < numblk: - seekval=(n*blksize)+addseek - (blktype, next)=ltypenxt(seekval) - blklist=lGetBlk(blktype, seekval) + seekval = (n * blksize) + addseek + (blktype, next) = ltypenxt(seekval) + blklist = lGetBlk(blktype, seekval) if not blklist: - #if blockette error encountered bail - err= "Corrupt mseed: " + fullname + # if blockette error encountered bail + err = "Corrupt mseed: " + fullname self.WriteError(err, "Endian", "red") - err1= "\tRecord: " + str(n) + err1 = "\tRecord: " + str(n) self.WriteError(err1, "Endian") - err2= "\tUnrecognized Blockette: " + str(blktype) - self.AddToDict(self.ErrorDict, "Unrecognized Blockette", inDir,inFile) + err2 = "\tUnrecognized Blockette: " + str(blktype) + self.AddToDict(self.ErrorDict, "Unrecognized Blockette", + inDir, inFile) self.WriteError(err2, "Endian") return None else: - if not blktype in blocks: + if blktype not in blocks: blocks.append(blktype) - addseek=next - b+=1 - old_fileid=fileid - n+=1 + addseek = next + b += 1 + old_fileid = fileid + n += 1 if warn: self.WriteError(warn, "Unique", "red") self.WriteError(warn1, "Unique") - self.AddToDict(self.ErrorDict, "Multiplexed", inDir,inFile) + self.AddToDict(self.ErrorDict, "Multiplexed", inDir, inFile) self.ScanErrors.set(self.ScanErrors.get() + 1) return blocks ######################################################### + def Exit(self): """ a no questions asked exit """ sys.exit(0) + ######################################### + def killWindow(self, widget): """ Destroy Widget and Set InfoBar to Default @@ -1115,40 +1230,43 @@ class MainWindow: self.addTextInfoBar() ####################################### + def CancelTL(self, runvar, title): """ creates a window for canceling trace modifications """ - #disable all buttons that write to traces + # disable all buttons that write to traces self.ButtonState("disabled") self.Cancel_tl = Toplevel(self.root) self.Cancel_tl.title(title) self.Cancel_b = Button(self.Cancel_tl, - text="Cancel", - cursor='pirate', - relief = "ridge", - activebackground='red', - command= Command(self.KillCancelTL, runvar) - ) + text="Cancel", + cursor='pirate', + relief="ridge", + activebackground='red', + command=Command(self.KillCancelTL, runvar) + ) self.Cancel_b.pack(side='bottom', fill='x') self.Text_fm = Frame(self.Cancel_tl, - relief = 'groove', - borderwidth=2 - ) + relief='groove', + borderwidth=2 + ) self.Text_fm.pack(side='top', - fill='x', - pady=5 - ) + fill='x', + pady=5 + ) infotext = " " + title + " Active. Please Wait " Label(self.Text_fm, - text=infotext, - background='yellow' - ).pack(side='left', anchor='w') + text=infotext, + background='yellow' + ).pack(side='left', anchor='w') + ####################################### + def KillCancelTL(self, runvar): """ kills cancel window and unsets runvar @@ -1158,6 +1276,7 @@ class MainWindow: self.ButtonState() ####################################### + def setValue(self, var, value=''): """ Sets Value of var @@ -1165,18 +1284,22 @@ class MainWindow: var.set(value) ####################################### + def addTextInfoBar(self, str='', bg='yellow'): """ Adds Text To InfoBar """ - #only bell if error, e.g. color red - # don't ring bell if clearing text or progress info (e.g. color == yellow/lightblue) + # only bell if error, e.g. color red + # don't ring bell if clearing text or progress info (e.g. color == + # yellow/lightblue) if BATCHMODE: if str: - if string.count(str,'Examining') or string.count(str, 'Modifying') \ - or string.count(str,'Correcting') or string.count(str,'Remaining'): + if (string.count(str, 'Examining') or + string.count(str, 'Modifying') or + string.count(str, 'Correcting') or + string.count(str, 'Remaining')): print("\r" + str, end=' ') -# print ".", + # print(".",) sys.stdout.flush() else: print(str) @@ -1186,6 +1309,7 @@ class MainWindow: self.InfoString_l.configure(background=bg, text=str) ####################################### + def wait(self, words, cnt): """ puts words plus cnt to info bar @@ -1196,29 +1320,32 @@ class MainWindow: self.addTextInfoBar(txt, 'lightblue') ####################################### + def ButtonState(self, newstate="normal"): """ changes state of activity buttons """ - #buttons that should be deactivated during activity + # buttons that should be deactivated during activity ButtonList = ( self.Scan_b, self.SaveScan_b, self.FindDataDir_b - ) + ) for item in ButtonList: item.configure(state=newstate) + ########################################## - def getPath (self, var, clear=1) : + + def getPath(self, var, clear=1): """ Concatonate paths """ - self.var=var + self.var = var if clear: self.var.set('') - newpath_dd = DirectoryDialog (self.root) - self.path = newpath_dd.go (dir_or_file = os.getcwd()) - if self.path != None : + newpath_dd = DirectoryDialog(self.root) + self.path = newpath_dd.go(dir_or_file=os.getcwd()) + if self.path is not None: if self.var.get(): self.var.set(self.var.get() + ':') if len(self.path) == 1 and self.path[0] == "/": @@ -1229,22 +1356,25 @@ class MainWindow: self.var.set(self.var.get() + self.path) ####################################### + def saveWidget(self, master): """ Toplevel to save update dictionary or log text to file """ try: self.tl_State = self.saveWidget_tl.winfo_exists() - except: + except Exception: self.tl_State = 0 if self.tl_State == 1: self.saveWidget_tl.tkraise() else: # setup output file name - (year, month, day, hour, minute, second, weekday, yearday, daylight) = time.localtime(time.time()) - #now = string.join(list(map(str, (year, yearday, hour, minute))), ".") - templist = list(map(str,(year, yearday, hour, minute))) + (year, month, day, hour, minute, second, weekday, + yearday, daylight) = time.localtime(time.time()) + # now = string.join(list(map(str, (year, yearday, hour, minute))), + # ".") + templist = list(map(str, (year, yearday, hour, minute))) now = ".".join(templist) self.Savefile.set("ckMseed." + now) @@ -1255,78 +1385,77 @@ class MainWindow: self.saveWidget_tl.title(title) self.saveWidgetCancel_b = Button(self.saveWidget_tl, - text="Cancel", - cursor='pirate', - relief = "ridge", - activebackground='red', - command= Command(self.killWindow, self.saveWidget_tl) - ) + text="Cancel", + cursor='pirate', + relief="ridge", + activebackground='red', + command=Command(self.killWindow, + self.saveWidget_tl)) # noqa: E501 self.saveWidgetCancel_b.pack(side='bottom', fill='x') self.saveWidgetSave_b = Button(self.saveWidget_tl, - text="Save", - background='lightblue', - relief = "ridge", - activebackground='green', - command = Command(self.writeFile, self.saveWidget_tl, self.Savefile) - ) + text="Save", + background='lightblue', + relief="ridge", + activebackground='green', + command=Command(self.writeFile, + self.saveWidget_tl, + self.Savefile)) self.saveWidgetSave_b.pack(side='bottom', fill='x') - self.SelectButton_fm = Frame(self.saveWidget_tl, - relief = 'groove', - borderwidth=2 - ) - self.SelectButton_fm.pack(side='bottom', - fill='x', - pady=5 - ) - - self.SaveAll_cb=Checkbutton(self.SelectButton_fm, - text="All", - command=Command(self.ToggleSaveSelect), - padx=5, - pady=5, - variable=self.SaveAll).pack(side='left', fill='x') -# self.SaveAll.set(1) -# self.balloon.bind(self.SaveAll_cb, "All text") - - self.SaveInfo_cb=Checkbutton(self.SelectButton_fm, - text="Info", - padx=5, - pady=5, - variable=self.SaveInfo).pack(side='left', fill='x') -# self.balloon.bind(self.SaveInfo_cb, "Station ID only") - - self.SaveErrors_cb=Checkbutton(self.SelectButton_fm, - text="Errors", - padx=5, - pady=5, - variable=self.SaveErrors).pack(side='left', fill='x') -# self.balloon.bind(self.SaveErrors_cb, "All Error messages") - - self.SaveErrorTraces_cb=Checkbutton(self.SelectButton_fm, - text="Error Traces", - padx=5, - pady=5, - variable=self.SaveErrorTraces).pack(side='left', fill='x') -# self.balloon.bind(self.SaveErrorTraces_cb, "List of Error traces") + self.SelectButton_fm = Frame(self.saveWidget_tl, relief='groove', + borderwidth=2) + self.SelectButton_fm.pack(side='bottom', fill='x', pady=5) + + self.SaveAll_cb = Checkbutton(self.SelectButton_fm, + text="All", + command=Command(self.ToggleSaveSelect), # noqa: E501 + padx=5, + pady=5, + variable=self.SaveAll).pack(side='left', fill='x') # noqa: E501 + # self.SaveAll.set(1) + # self.balloon.bind(self.SaveAll_cb, "All text") + + self.SaveInfo_cb = Checkbutton(self.SelectButton_fm, + text="Info", + padx=5, + pady=5, + variable=self.SaveInfo).pack(side='left', fill='x') # noqa: E501 + # self.balloon.bind(self.SaveInfo_cb, "Station ID only") + + self.SaveErrors_cb = Checkbutton(self.SelectButton_fm, + text="Errors", + padx=5, + pady=5, + variable=self.SaveErrors).pack(side='left', fill='x') # noqa: E501 + # self.balloon.bind(self.SaveErrors_cb, "All Error messages") + + self.SaveErrorTraces_cb = Checkbutton(self.SelectButton_fm, + text="Error Traces", + padx=5, + pady=5, + variable=self.SaveErrorTraces).pack(side='left', fill='x') # noqa: E501 + # self.balloon.bind(self.SaveErrorTraces_cb, + # "List of Error traces") self.saveWidgetEntry_fm = Frame(self.saveWidget_tl, - relief = 'groove', - borderwidth=2 - ) + relief='groove', + borderwidth=2 + ) self.saveWidgetEntry_fm.pack(side='bottom', - fill='x', - pady=5 - ) + fill='x', + pady=5 + ) self.saveWidgetEntry_e = Entry(self.saveWidgetEntry_fm, - textvariable = self.Savefile, - width = box_length - ) - self.saveWidgetEntry_e.pack(side='left', anchor='w', fill='x', expand=1) + textvariable=self.Savefile, + width=box_length + ) + self.saveWidgetEntry_e.pack( + side='left', anchor='w', fill='x', expand=1) ########################################## + def ToggleSaveSelect(self): if self.SaveAll.get(): self.SaveInfo.set(1) @@ -1339,34 +1468,38 @@ class MainWindow: return ########################################## + def writeFile(self, master, file): """ Write File to disk """ - divider="///////////////////" + divider = "///////////////////" if os.path.isfile(file.get()): self.Continue_dl = Pmw.MessageDialog(master, - title = "WARNING", - defaultbutton = 1, - buttons = ('Overwrite', 'Cancel'), - message_text = 'The File exists!' - ) + title="WARNING", + defaultbutton=1, + buttons=('Overwrite', + 'Cancel'), + message_text="The File " + "exists!") self.Result = self.Continue_dl.activate() else: self.Result = "Overwrite" - if ( self.Result == "Cancel"): + if (self.Result == "Cancel"): self.addTextInfoBar() - elif ( self.Result == "Overwrite"): + elif (self.Result == "Overwrite"): master.destroy() - if not self.SaveAll.get() and not self.SaveInfo.get() and not self.SaveErrors.get() and\ - not self.SaveErrorTraces.get(): - oops="Nothing to save" + if (not self.SaveAll.get() and + not self.SaveInfo.get() and + not self.SaveErrors.get() and + not self.SaveErrorTraces.get()): + oops = "Nothing to save" self.addTextInfoBar(oops, 'orange') return try: - outfile=open(file.get(), "w") + outfile = open(file.get(), "w") if self.SaveAll.get() or self.SaveInfo.get(): @@ -1374,27 +1507,33 @@ class MainWindow: outfile.write("%s\n" % divider) outfile.write("%s\n" % "Trace Information") outfile.write("%s\n" % divider) - keylist=[] - keylist=list(self.StatChanLocDict.keys()) + keylist = [] + keylist = list(self.StatChanLocDict.keys()) keylist.sort() if keylist: for key in keylist: - numspace=24-len(key) + numspace = 24 - len(key) if not self.ScanType.get(): - text=key + text = key else: - start = time.strftime('%Y:%j:%H:%M:%S', time.gmtime(self.StatChanLocDict[key][0][0])) - end = time.strftime('%Y:%j:%H:%M:%S', time.gmtime(self.StatChanLocDict[key][0][1])) - #text=key + numspace*SPACE +string.join(list(map(str,(start,end))), " ") - templist = list(map(str,(start,end))) - text=key + numspace*SPACE + " ".join(templist) + start = time.strftime('%Y:%j:%H:%M:%S', + time.gmtime(self.StatChanLocDict[key][0][0])) # noqa: E501 + end = time.strftime('%Y:%j:%H:%M:%S', + time.gmtime(self.StatChanLocDict[key][0][1])) # noqa: E501 + # text=key + numspace*SPACE + \ + # string.join(list(map(str, + # (start,end))), + # " ") + templist = list(map(str, (start, end))) + text = key + numspace * \ + SPACE + " ".join(templist) outfile.write("%s\n" % text) else: outfile.close() os.unlink(file.get()) - oops="Nothing to save" + oops = "Nothing to save" self.addTextInfoBar(oops, 'orange') return @@ -1422,11 +1561,11 @@ class MainWindow: for indexkey in list(self.ErrorDict.keys()): text = "<" + indexkey + ">\n" outfile.write("%s" % text) - for directory in list(self.ErrorDict[indexkey].keys()): - text2= " <" + directory + ">\n" + for directory in list(self.ErrorDict[indexkey].keys()): # noqa: E501 + text2 = " <" + directory + ">\n" outfile.write("%s" % text2) - for trace in self.ErrorDict[indexkey][directory]: - text3="\t" + trace + "\n" + for trace in self.ErrorDict[indexkey][directory]: # noqa: E501 + text3 = "\t" + trace + "\n" outfile.write("%s" % text3) else: outfile.write("%s\n" % "NONE") @@ -1438,24 +1577,8 @@ class MainWindow: self.addTextInfoBar(err, 'red') return -########################################## - - def killWindow(self, widget): - """ - Destroy Widget and Set InfoBar to Default - """ - widget.destroy() -# self.addTextInfoBar() - - ################################################################## -def main(): - mw = MainWindow("ckMseed %s" % VERSION) - mw.root.geometry("650x500") - mw.root.mainloop() - #import profile - #profile.run('mw.root.mainloop()') -if __name__ == '__main__' : +if __name__ == '__main__': main() diff --git a/setup.cfg b/setup.cfg index 752c97dc8df0cf2ef553d7b59d81f494d5efbaf8..3e16c9aa4de92883ce48eebabea3688a4ead6f10 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,22 +1,5 @@ -[bumpversion] -current_version = 2018.179 -commit = True -tag = True - -[bumpversion:file:setup.py] -search = version='{current_version}' -replace = version='{new_version}' - -[bumpversion:file:ckmseed/__init__.py] -search = __version__ = '{current_version}' -replace = __version__ = '{new_version}' - -[bdist_wheel] -universal = 1 - [flake8] exclude = docs [aliases] # Define setup.py command aliases here - diff --git a/setup.py b/setup.py index 93699df23abfb9c154b0ad0a476f835faa3c318c..10d8f47c6844028b73c215f3cfe7f619bc13e98c 100644 --- a/setup.py +++ b/setup.py @@ -30,19 +30,12 @@ setup( 'ckmseed=ckMseed.ckMseed:main', ], }, - setup_requires = [], install_requires=['Pmw @ https://github.com/schrodinger/pmw-patched/archive/master.tar.gz'], + setup_requires=[], extras_require={ 'dev': [ - 'pip', - 'bumpversion', - 'wheel', - 'watchdog', 'flake8', 'tox', - 'coverage', - 'Sphinx', - 'twine', ] }, license="GNU General Public License v3", @@ -51,8 +44,7 @@ setup( keywords='ckmseed', name='ckmseed', packages=find_packages(include=['ckMseed']), - test_suite='tests', url='https://git.passcal.nmt.edu/passoft/ckmseed', - version='2018.179', + version='2020.211', zip_safe=False, ) diff --git a/tox.ini b/tox.ini index bf6c0725b91a09d47ebc02bcfec374415d4ecfc9..8e5e1761a907ae7dbc8dbc48243bd300b4c37b82 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,10 @@ [tox] -envlist = py36, py37, py38 +envlist = py36, py37, py38, flake8 + +[testenv:flake8] +basepython = python +deps = flake8 +commands = flake8 --ignore=F403,F405,F821,F841,W504 ckMseed [testenv] commands = python -m unittest