Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. from pathlib import Path
  2. from pprint import pprint
  3.  
  4. import pandas as pd
  5. import numpy as np
  6.  
  7. from bokeh.plotting import figure, output_file, show, save
  8. from bokeh.models import ColumnDataSource
  9.  
  10. for source in Path('.').glob('*.csv'):
  11. print(source.stem)
  12. target = Path(source.stem + '.html')
  13. if target.exists():
  14. df = pd.read_csv(
  15. source,
  16. encoding='utf_16',
  17. sep=',\t',
  18. names=['Index', 'Detector', 'Magnitude', 'Unit', 'Time', 'Date'],
  19. na_values='OL',
  20. engine='python', #
  21. )
  22.  
  23. df['Time'] = pd.to_timedelta(df['Time']) # overload time as string to timestamp
  24. df['Seconds'] = df['Time'].dt.total_seconds() # time to seconds into day
  25. df['Seconds'] = df['Seconds'] - min(df['Seconds']) # shift to start the values at zero
  26. # df = df.set_index('Time')[['Magnitude']] #
  27.  
  28. df = df.where(df['Magnitude'] > 7.5) # where data less than value change to NA
  29. df = df.fillna(method='backfill', limit=25) # backfill NA values up to 25 counts
  30. df = df.dropna() # drop remaining NA rows
  31. pprint(df.describe())
  32. print('\n'*2)
  33.  
  34. output_file(target) # set the tartget file to target
  35.  
  36. # create a new plot with a title and axis labels
  37. p = figure(title=source.stem.capitalize(), x_axis_label='Seconds', y_axis_label='Voltage', width=1800, height=900)
  38.  
  39. p.line(x='Seconds', y='Magnitude', source=ColumnDataSource(df), line_width=2) # use Seconds and Mangitude data from df
  40.  
  41. save(p, title=source.stem) # Save p to configured output
  42. # show(p) # opens the html output with default browser
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement