import seisobs
sfile_directory = 'TEST_'
cat = seisobs.seis2cat(sfile_directory)

cat

"""
Explanation: Intro
Seisobs is a simple python package to read seisan s-files, in Nordic format into obspy catalog objects. Once an Obspy Catalog is instantiated it can be saved to several useful formats, including quakeML. See the obspy docs for more details.
Installation
Just run the setup script in the seisobs directory:
bash
python setup.py install
or use pip and install from github:
bash
pip install git+https://github.com/d-chambers/seisobs
Quick Start
To read an entire directory of S files into one catalog object simply do:
End of explanation
"""


spec1 = seisobs.specs.specs['1']

"""
Explanation: This should have taken about 20 seconds to read in 50 files. A bit slow so hopefully you don't have to read thousands of s-files very often.
To convert a directory of sfiles into a directory of quakeML files you can use the seis2disk function (seisobs.seis2disk). This is probably the best route to take if you need to convert a large number of files because seisobs loads, converts, and saves one file at time to avoid excessive memory usage. 
How it works
Seisobs has two modules:


Core : where the heavy lifting is done and main classes are defined. 


Specs : where the fixed width file specifications are stored and a few helper classes defined.


In the seisobs.specs module each line type has instance of the seisobs.specs.Spec class. These are contained in the specs dictionary where each key is the linetype as a string. So for linetype 1:
End of explanation
"""


print ('colspecs\n')
print (spec1.colspec)
print ('\n')
print ('colnames\n')
print (spec1.colname)
print('\n')
print ('colformat\n')
print (spec1.colformat)


"""
Explanation: There are a few important attributes of the class:
    1. colspecs : the start and stop line width for a field
    2. colname : a string to identify the field
    3. colformat : a format string (eg '%2d') that indicates expected field type
    4. validate : a function that takes a pandas series as input and raises errors if any invalid values are encountered
for example:
End of explanation
"""


example_line_1 = ' 1996  625 0337 31.0 L  61.689   3.259 15.0  TES 35 3.0 3.3LTES 3.0CTES 3.2LNAO1'
sline = seisobs.core.Sline(example_line_1)
sline

"""
Explanation: Names that start with bla indicate a blank field is expected (will raise value error if it isn't).
Next an instance of seisobs.core.Sline is initiated with takes a raw line from an s-file and classifies it, then uses the appropriate Spec instance to load the data into a pandas series. For example,
End of explanation
"""


