# Path: swhlab/core.py
# def abfIDfromFname(fname):
# def abfProtocol(fname):
# def headerHTML(header,fname):
#     def __init__(self, fname, createFolder=False):
#     def setsweep(self, sweep=0, channel=0):
#     def sweepList(self):
#     def setsweeps(self):
#     def comments_load(self):
#     def generate_protocol(self):
#     def get_protocol(self,sweep):
#     def get_protocol_sequence(self,sweep):
#     def clamp_values(self,timePoint=0):
#     def epochTimes(self,nEpoch=2):
#     def average(self,t1=0,t2=None,setsweep=False):
#     def averageSweep(self,sweepFirst=0,sweepLast=None):
#     def kernel_gaussian(self, sizeMS, sigmaMS=None, forwardOnly=False):
#     def sweepYfiltered(self):
#     def sweepYsmartbase(self):
#     def phasicNet(self,biggestEvent=50,m1=.5,m2=None):
#     def output_touch(self):
#     def output_clean(self):
#     def inspect(self):
# class ABF:
#             Y = proto[step]['fEpochInitLevel']+proto[step]['fEpochLevelInc']*self.sweep
#         I1,I2=int(t1*self.pointsPerSec),int(t2*self.pointsPerSec)
#         Y=self.sweepYsmartbase()[int(m1):int(m2)]


import os
import sys
import pylab
import numpy as np
import time
import glob
import swhlab
from swhlab.core import common as cm #shorthand
"""Things here to webpage indexes of files."""



TEMPLATES={} #pythonic way to have HTML templates ready to go and read only once
for fname in glob.glob(swhlab.LOCALPATH+'/indexing/templates/template_*.html'):
    templateName=os.path.basename(fname).split("_")[1].replace('.html','')
    with open(fname) as f:
        TEMPLATES[templateName]=f.read()
for key in TEMPLATES:
    TEMPLATES[key]=TEMPLATES[key].replace("~STYLE~",TEMPLATES['style'])

print(" -- loaded data from %d HTML templates"%len(TEMPLATES))

def genPNGs(folder,files=None):
    """Convert each TIF to PNG. Return filenames of new PNGs."""
    if files is None:
        files=glob.glob(folder+"/*.*")
    new=[]
    for fname in files:
        ext=os.path.basename(fname).split(".")[-1].lower()
        if ext in ['tif','tiff']:
            if not os.path.exists(fname+".png"):
                print(" -- converting %s to PNG..."%os.path.basename(fname))

# Path: swhlab/core.py
# def abfIDfromFname(fname):
# def abfProtocol(fname):
# def headerHTML(header,fname):
#     def __init__(self, fname, createFolder=False):
#     def setsweep(self, sweep=0, channel=0):
#     def sweepList(self):
#     def setsweeps(self):
#     def comments_load(self):
#     def generate_protocol(self):
#     def get_protocol(self,sweep):
#     def get_protocol_sequence(self,sweep):
#     def clamp_values(self,timePoint=0):
#     def epochTimes(self,nEpoch=2):
#     def average(self,t1=0,t2=None,setsweep=False):
#     def averageSweep(self,sweepFirst=0,sweepLast=None):
#     def kernel_gaussian(self, sizeMS, sigmaMS=None, forwardOnly=False):
#     def sweepYfiltered(self):
#     def sweepYsmartbase(self):
#     def phasicNet(self,biggestEvent=50,m1=.5,m2=None):
#     def output_touch(self):
#     def output_clean(self):
#     def inspect(self):
# class ABF:
#             Y = proto[step]['fEpochInitLevel']+proto[step]['fEpochLevelInc']*self.sweep
#         I1,I2=int(t1*self.pointsPerSec),int(t2*self.pointsPerSec)
#         Y=self.sweepYsmartbase()[int(m1):int(m2)]


# Path: doc/oldcode/indexing/indexing.py
import os
import sys
import pylab
import numpy as np
import time
import glob
import swhlab
from swhlab.core import common as cm #shorthand

"""Things here to webpage indexes of files."""



TEMPLATES={} #pythonic way to have HTML templates ready to go and read only once
for fname in glob.glob(swhlab.LOCALPATH+'/indexing/templates/template_*.html'):
    templateName=os.path.basename(fname).split("_")[1].replace('.html','')
    with open(fname) as f:
        TEMPLATES[templateName]=f.read()
for key in TEMPLATES:
    TEMPLATES[key]=TEMPLATES[key].replace("~STYLE~",TEMPLATES['style'])

print(" -- loaded data from %d HTML templates"%len(TEMPLATES))

def genPNGs(folder,files=None):
    """Convert each TIF to PNG. Return filenames of new PNGs."""
    if files is None:
        files=glob.glob(folder+"/*.*")
    new=[]
    for fname in files:
        ext=os.path.basename(fname).split(".")[-1].lower()
        if ext in ['tif','tiff']:
            if not os.path.exists(fname+".png"):
                print(" -- converting %s to PNG..."%os.path.basename(fname))

                cm.image_convert(fname)