Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
for species in dct:
if 'colour' not in dct[species]:
dct[species]['colour'] = 'k'
if 'alpha' not in dct[species]:
dct[species]['alpha'] = 0.5
return dct
if resolution is None:
if spectype != 'centroid':
resolution = autoresolution(realspec[0], realspec[1]) # calculate resolution
else:
resolution = 5000
simdict = checksimdict(simdict) # checks the simulation dictionary
for species in simdict: # generate Molecule object and set x and y lists
simdict[species]['colour'] = Colour(simdict[species]['colour'])
simdict[species]['mol'] = IPMolecule(
species,
resolution=resolution,
**ipmol_kwargs,
)
# simdict[species]['mol'] = Molecule(species, res=res, dropmethod='threshold')
if simtype == 'bar':
simdict[species]['x'], simdict[species]['y'] = simdict[species]['mol'].barip
if simtype == 'gaussian':
simdict[species]['x'], simdict[species]['y'] = simdict[species]['mol'].gausip
if mz == 'auto': # automatically determine m/z range
if verbose is True:
sys.stdout.write('Automatically determining m/z window')
mz = [10000000, 0]
for species in simdict:
for label in ax.get_xticklabels():
label.set_fontproperties(tickfont)
ax.tick_params(axis='y', length=settings['axwidth'] * 3, width=settings['axwidth'], direction='out', right='off')
for label in ax.get_yticklabels():
label.set_fontproperties(tickfont)
for axis in ["top", "bottom", "left", "right"]:
ax.spines[axis].set_linewidth(settings['axwidth'])
if settings['times'] is not None:
if len(settings['times']) != len(intensities):
raise IndexError('The numer of times provided do not match the number of traces provided.')
for ind, spec in enumerate(intensities): # plot traces
if settings['times'] is not None:
string = 't = ' + str(round(settings['times'][ind], 1)) + 'm'
ax.plot(wavelengths, spec, label=string, color=Colour(settings['colours'][ind]).mpl,
linewidth=settings['lw'])
else:
ax.plot(wavelengths, spec, color=Colour(settings['colours'][ind]).mpl, linewidth=settings['lw'])
if settings['times'] is not None:
ax.legend(loc=0, frameon=False)
ax.set_xlabel('wavelength (nm)', **font)
ax.set_ylabel('absorbance (a.u.)', **font)
if settings['padding'] is None:
pl.tight_layout(pad=0.5) # adjust subplots
elif type(settings['padding']) is list and len(settings['padding']) == 4:
pl.subplots_adjust(left=settings['padding'][0], right=settings['padding'][1], bottom=settings['padding'][2],
top=settings['padding'][3])
def validatergb(self, tup):
"""checks that values in an RGB tuple are valid"""
for val in tup:
if type(val) != int:
raise ValueError(
'One of the values in the RGB colour tuple is not an integer ("%s").\nPlease correct the value.\n%s' % (
str(val), self.__class__.__doc__))
elif val > self.rgb_scale or val < 0:
raise ValueError(
'One of the values in the RGB colour tuple (%s) is outside of the valid RGB range of 0-%d.\n%s' % (
str(val), self.rgb_scale, self.__class__.__doc__))
if __name__ == '__main__':
col = Colour((89, 89, 89))
col.printdetails()
mzml, sp, rtime = pyrsir(filename, sp, 1, **pyrsirkw)[:3] # run pyrsir
sstart = mzml.scan_index(scr[0]) # index of start scan
send = mzml.scan_index(scr[1]) # index of last scan
for key in sp:
sp[key]['raw'] = sp[key]['raw'][sstart:send + 1] # trim to scan range
for key in rtime:
rtime[key] = rtime[key][sstart:send + 1] # trim to scan range
spec = mzml.retrieve_scans(scr[0], scr[1], mz[0], mz[1], outside=True) # pull all spectra within scan range
sys.stdout.write('%s summing and normalizing species traces' % str(n))
sumkey = str(n) + 'sum'
normkey = str(n) + 'norm'
sumsp = []
for key in sp:
sp[key][sumkey] = bindata(n, sp[key]['raw']) # bin each species
sp[key]['colour'] = Colour(sp[key]['colour']).mpl # convert colour into matplotlib format
for ind, val in enumerate(sp[key][sumkey]): # for normalization
try:
sumsp[ind] += val
except IndexError:
sumsp.append(val)
for mode in mskeys:
sumkey = str(n) + 'sum' + mode
modekey = 'raw' + mode
if modekey in rtime.keys(): # if there is data for that mode
rtime[sumkey] = bindata(n, rtime[modekey], n)
for ind, val in enumerate(rtime[sumkey]):
rtime[sumkey][ind] = val - inj # shift time data to zero at injection point
for key in sp: # for each species
if sp[key]['affin'] in mskeys: # if species has affinity
spkey = str(n) + 'sum'
string += f'mass delta: {simdict[species]["delta"]}'
ax.text(
simdict[species]['x'][bpi],
top * 1.01,
string,
color=simdict[species]['colour'].mpl,
horizontalalignment='center',
**font
)
if spectype == 'continuum':
ax.plot(
realspec[0],
realspec[1],
linewidth=lw,
color=Colour(speccolour).mpl
)
elif spectype == 'centroid':
dist = []
for ind, val in enumerate(realspec[0]): # find distance between all adjacent m/z values
if ind == 0:
continue
dist.append(realspec[0][ind] - realspec[0][ind - 1])
dist = sum(dist) / len(dist) # average distance
ax.bar(
realspec[0],
realspec[1],
dist * 0.75,
linewidth=0,
color=Colour(speccolour).mpl,
align='center',
alpha=0.8