Skip to content

Instantly share code, notes, and snippets.

@forstater
Created June 28, 2016 20:23
Show Gist options
  • Save forstater/3277f38b22efa2eafb33d2b67ce282cd to your computer and use it in GitHub Desktop.
Save forstater/3277f38b22efa2eafb33d2b67ce282cd to your computer and use it in GitHub Desktop.
Function to query and filter multistate events.
'''
Author: Jacob Forstater
Description: Workflow to clean up multistate events
- Filters out NStates <2
- Filters out any event with StateResTime < minValue
- Supplys this back as a 2D flattened Array
Log:
JF 20160602 initial version
'''
def multistateFilter(myDB, myQueryArgs="NStates>=2 and NStates <6 and ResTime> 0.02", minStateLength=0.02):
tempData=pd.DataFrame(query(myDB,"select BlockDepth, StateResTime from metadata where ProcessingStatus='normal' and "+str(myQueryArgs)))
tempData=tempData.rename(columns={0:'BD',1:'StateResTime'})
minLenFilter=lambda x: np.min(x)>=minStateLength
bdReturn=np.hstack(tempData[tempData.StateResTime.map(minLenFilter)].BD)
stateResReturn=np.hstack(tempData[tempData.StateResTime.map(minLenFilter)].StateResTime)
return np.stack([bdReturn,stateResReturn],axis=-1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment