try:
from drawnmr import draw
except ModuleNotFoundError:
import sys, os
sys.path.append( os.getcwd()+os.sep+"..")
print(sys.path)
['', '/Users/tlinnet/anaconda/envs/py36/lib/python36.zip', '/Users/tlinnet/anaconda/envs/py36/lib/python3.6', '/Users/tlinnet/anaconda/envs/py36/lib/python3.6/lib-dynload', '/Users/tlinnet/anaconda/envs/py36/lib/python3.6/site-packages', '/Users/tlinnet/anaconda/envs/py36/lib/python3.6/site-packages/IPython/extensions', '/Users/tlinnet/.ipython', '/Users/tlinnet/software/drawnmr/examples/..']
from drawnmr import draw
import nmrglue as ng
import bokeh.plotting as bplt
from bokeh.models import Range1d
# Get data
import os, os.path
ng_dir = 'nmrglue_data/s4_2d_plotting'
if not os.path.exists(ng_dir):
print("No %s. Downloading."%ng_dir)
import urllib.request, zipfile
zipf = 'jbnmr_s4_2d_plotting.zip'
urllib.request.urlretrieve('https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/nmrglue/%s'%zipf, zipf)
with zipfile.ZipFile(zipf,"r") as zip_ref:
zip_ref.extractall("nmrglue_data")
os.remove(zipf)
# Specify data
ng_ft2 = 'nmrglue_data/s4_2d_plotting/test.ft2'
# read in data
ng_dic, ng_data = ng.pipe.read(ng_ft2)
# Pass to figure class
fig2d = draw.fig2d(ng_dic, ng_data)
# Change contour_start
fig2d.contour_start = 85e3
# Get the bokeh figure
fig= fig2d.get_fig()
# Alter the figure after creation
#fig.xaxis.axis_label = "Nonsense"
# Set limits for view
fig.x_range = Range1d(183.5, 167.5)
fig.y_range = Range1d(139.5, 95.5)
# Set larger image size
fig.plot_width = 800
fig.plot_height = 800
peaks = fig2d.get_peakpick(pthres=200e3)
print(peaks.head())
x_ppm y_ppm x_p y_p cID VOL zs 0 175.266401 131.102998 4081 788 1 14297425.0 339577.93750 1 173.809599 130.187133 4111 807 2 14197980.0 339726.21875 2 174.295200 129.946116 4101 812 3 10963096.0 288179.81250 3 173.081198 127.535946 4126 862 4 36947544.0 316585.34375 4 175.217841 126.764691 4082 878 5 18468114.0 360951.87500
# Get output. Either to Jupyter notebook or html file
if fig2d.isnotebook:
from bokeh.io import output_notebook
output_notebook()
bplt.show(fig, notebook_handle=True)
else:
# Save to html
filename = "nmrglue_s4_2d_plotting.html"
bplt.output_file(filename)
bplt.save(fig)
# And auto open
import webbrowser, os
webbrowser.open('file://' + os.path.realpath(filename))
#fig2d.change_contour_start(200e3)