grsharman / detritalpy Goto Github PK
View Code? Open in Web Editor NEWA Python-based toolset for visualizing and analyzing detrital geo-thermochronologic data
License: Apache License 2.0
A Python-based toolset for visualizing and analyzing detrital geo-thermochronologic data
License: Apache License 2.0
Hello!
I just only want to use KDE function to make a plot and get the Age peak because of lack of age error's data.But I tried many times, despite get the plot,but i can't get the age peak.Even i download the PeakUtils.I hope you can help me researcher!
Thank you very much.
whatToPlot = 'relative' # Options: cumulative, relative, or both
separateSubplots = False # Set to True to plot each relative age distribution in a separate subplot (allows histogram and pie)
x1 = 50
x2 = 3500
plotLog = False # Set to True to plot the x-axis as a log scale
w = 10 # width of the plot
c = 4 # height of CDF panel
h = 'auto' # height of the relative panel (only required if separateSubplots is False). Options: 'auto' or an integer
xdif = 1 # Note: an interval of 1 Myr is recommended
plotCDF = False # Plot the CDF discretized at xdif interval
plotCPDP = False # Plot the cumulative PDP
plotCKDE = False # Plot the cumulative KDE
plotDKW = False # Plot the 95% confidence interval of the CDF (Dvoretsky-Kiefer-Wolfowitz inequality)
normPlots = False # Will normalize the PDP/KDE if equals True (if separateSubplots is True)
plotKDE = True # Set to True if want to plot KDE
colorKDE = True # Will color KDE according to same coloration as used in CDF plotting
colorKDEbyAge = True # Will color KDE according to age populations if set to True
bw = 'optimizedFixed' # Specify the KDE bandwidth. Options are 'optimizedFixed', 'optimizedVariable', or a number (bandwidth in Myr)
plotPDP = False # Set to True if want to plot PDP
colorPDP = False # Will color PDP according to same coloration as used in CDF plotting
colorPDPbyAge = False # Will color PDP according to age populations if set to True
plotColorBar = False # Color age categories as vertical bars, can add white bars to create blank space between other colored bars
plotHist = False # Set to True to plot a histogram (only available when separateSubplots is True)
b = 5 # Specify the histogram bin size (Myr)
plotPIE = False # Will plot a pie diagram (only available when separateSubplots is True)
agebins = [0, 23, 65, 85, 100, 135, 200, 300, 500, 4500]
agebinsc = ['slategray','royalblue','gold','red','darkred','purple','navy','gray','saddlebrown']
plotAgePeaks = True # Will identify and plot age peaks
agePeakOptions = ['KDE', 0.05, 5, 2, True] # [distType, threshold, minDist, minPeakSize, labels]
fig = dFunc.plotAll(sampleList, ages, errors, numGrains, labels, whatToPlot, separateSubplots, plotCDF, plotCPDP, plotCKDE,
plotDKW, normPlots, plotKDE, colorKDE, colorKDEbyAge, plotPDP, colorPDP, colorPDPbyAge, plotColorBar,
plotHist, plotLog, plotPIE, x1, x2, b, bw, xdif, agebins, agebinsc, w, c, h, plotAgePeaks, agePeakOptions,
CDFlw=3, KDElw=1, PDPlw=1)
An update in matplotlib v3.8 that no longer allows auto-removal of overlapping axes has resulted in issues with some of the detritalPy plotting functions. Recommend using matplotlib v3.7 or earlier until plotting functions in detritalPy are updated.
ValueError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_31596\4126944053.py in
58 agePeakOptions = ['KDE', 0.05, 5, 2, True] # [distType, threshold, minDist, minPeakSize, labels]
59
---> 60 fig = dFunc.plotAll(sampleList, ages, errors, numGrains, labels, whatToPlot, separateSubplots, plotCDF, plotCPDP, plotCKDE,
61 plotDKW, normPlots, plotKDE, colorKDE, colorKDEbyAge, plotPDP, colorPDP, colorPDPbyAge, plotColorBar,
62 plotHist, plotLog, plotPIE, x1, x2, b, bw, xdif, agebins, agebinsc, w, c, h, plotAgePeaks, agePeakOptions,
d:\anaconda3\lib\site-packages\detritalpy\detritalFuncs.py in plotAll(sampleList, ages, errors, numGrains, labels, whatToPlot, separateSubplots, plotCDF, plotCPDP, plotCKDE, plotDKW, normPlots, plotKDE, colorKDE, colorKDEbyAge, plotPDP, colorPDP, colorPDPbyAge, plotColorBar, plotHist, plotLog, plotPIE, x1, x2, b, bw, xdif, agebins, agebinsc, w, c, h, plotAgePeaks, agePeakOptions, CDFlw, KDElw, PDPlw, plotDepoAge, depoAge, plotAgesOnCDF, plotHeatMap, heatMapType, heatMap, PDP_ymax, KDE_ymax, agebinsc_alpha, colors, bw_x)
392
393 if separateSubplots:
--> 394 fig = plotAll_1(sampleList, ages, errors, numGrains, labels, whatToPlot, plotCDF, plotCPDP, plotCKDE, plotDKW, normPlots, plotKDE,
395 colorKDE, colorKDEbyAge, plotPDP, colorPDP, colorPDPbyAge, plotColorBar, plotHist, plotLog, plotPIE, x1, x2, b, bw, xdif, agebins,
396 agebinsc, w, c, plotAgePeaks, agePeakOptions, CDFlw, KDElw, PDPlw, plotDepoAge, depoAge, plotAgesOnCDF, plotHeatMap, heatMapType, heatMap,
d:\anaconda3\lib\site-packages\detritalpy\detritalFuncs.py in plotAll_1(sampleList, ages, errors, numGrains, labels, whatToPlot, plotCDF, plotCPDP, plotCKDE, plotDKW, normPlots, plotKDE, colorKDE, colorKDEbyAge, plotPDP, colorPDP, colorPDPbyAge, plotColorBar, plotHist, plotLog, plotPIE, x1, x2, b, bw, xdif, agebins, agebinsc, w, c, plotAgePeaks, agePeakOptions, CDFlw, KDElw, PDPlw, plotDepoAge, depoAge, plotAgesOnCDF, plotHeatMap, heatMapType, heatMap, PDP_ymax, KDE_ymax, agebinsc_alpha, colors, bw_x)
828 else:
829 if isinstance(x1, list) == False:
--> 830 axPDP.set_ylim([0, max(PDP[i])+max(PDP[i])*0.05])
831 else:
832 axPDP.set_ylim([0, PDPmax[i]+PDPmax[i]*0.05])
d:\anaconda3\lib\site-packages\matplotlib_api\deprecation.py in wrapper(*args, **kwargs)
452 "parameter will become keyword-only %(removal)s.",
...
-> 3572 raise ValueError("Axis limits cannot be NaN or Inf")
3573 return converted_limit
3574
ValueError: Axis limits cannot be NaN or Inf
Output is truncated. View as a scrollable element or open in a text editor. Adjust cell output settings...
The KDE algorithm (from statsmodels.nonparametric.kde import KDEUnivariate) returns an error if the "Best Age" values are not float.
I recently updated my python installation using conda (23.7.2) and I'm running numpy version 1.24.3 and detritalpy 1.3.36. I get the following error that np.float is deprecated when trying to plot KDE following the tutorial (when it worked prior to updating conda). The returned plot is empty.
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[4], line 52
49 agePeakOptions = ['KDE', 0.05, 5, 2, True] # [distType, threshold, minDist, minPeakSize, labels]
50 xdif=1
---> 52 fig = dFunc.plotAll(sampleList, ages, errors, numGrains, labels, whatToPlot, separateSubplots, plotCDF, plotCPDP, plotCKDE,
53 plotDKW, normPlots, plotKDE, colorKDE, colorKDEbyAge, plotPDP, colorPDP, colorPDPbyAge, plotColorBar,
54 plotHist, plotLog, plotPIE, x1, x2, b, bw, xdif, agebins, agebinsc, w, c, h, plotAgePeaks, agePeakOptions,
55 CDFlw=1, KDElw=1, PDPlw=1)
File ~\anaconda3\lib\site-packages\detritalpy\detritalFuncs.py:392, in plotAll(sampleList, ages, errors, numGrains, labels, whatToPlot, separateSubplots, plotCDF, plotCPDP, plotCKDE, plotDKW, normPlots, plotKDE, colorKDE, colorKDEbyAge, plotPDP, colorPDP, colorPDPbyAge, plotColorBar, plotHist, plotLog, plotPIE, x1, x2, b, bw, xdif, agebins, agebinsc, w, c, h, plotAgePeaks, agePeakOptions, CDFlw, KDElw, PDPlw, plotDepoAge, depoAge, plotAgesOnCDF, plotHeatMap, heatMapType, heatMap, PDP_ymax, KDE_ymax, agebinsc_alpha, colors, bw_x)
389 return None
391 if separateSubplots:
--> 392 fig = plotAll_1(sampleList, ages, errors, numGrains, labels, whatToPlot, plotCDF, plotCPDP, plotCKDE, plotDKW, normPlots, plotKDE,
393 colorKDE, colorKDEbyAge, plotPDP, colorPDP, colorPDPbyAge, plotColorBar, plotHist, plotLog, plotPIE, x1, x2, b, bw, xdif, agebins,
394 agebinsc, w, c, plotAgePeaks, agePeakOptions, CDFlw, KDElw, PDPlw, plotDepoAge, depoAge, plotAgesOnCDF, plotHeatMap, heatMapType, heatMap,
395 PDP_ymax, KDE_ymax, agebinsc_alpha, colors, bw_x)
396 else:
397 fig = plotAll_2(sampleList, ages, errors, numGrains, labels, whatToPlot, plotCDF, plotCPDP, plotCKDE, plotDKW, normPlots, plotKDE,
398 colorKDE, colorKDEbyAge, plotPDP, colorPDP, colorPDPbyAge, plotColorBar, plotHist, plotLog, plotPIE, x1, x2, b, bw, xdif, agebins,
399 agebinsc, w, c, h, CDFlw, KDElw, PDPlw, plotAgesOnCDF, agebinsc_alpha, colors, bw_x)
File ~\anaconda3\lib\site-packages\detritalpy\detritalFuncs.py:548, in plotAll_1(sampleList, ages, errors, numGrains, labels, whatToPlot, plotCDF, plotCPDP, plotCKDE, plotDKW, normPlots, plotKDE, colorKDE, colorKDEbyAge, plotPDP, colorPDP, colorPDPbyAge, plotColorBar, plotHist, plotLog, plotPIE, x1, x2, b, bw, xdif, agebins, agebinsc, w, c, plotAgePeaks, agePeakOptions, CDFlw, KDElw, PDPlw, plotDepoAge, depoAge, plotAgesOnCDF, plotHeatMap, heatMapType, heatMap, PDP_ymax, KDE_ymax, agebinsc_alpha, colors, bw_x)
545 if (whatToPlot == 'both' or whatToPlot == 'relative'):
546 # Cycle through each sample for normalized plots
547 if plotKDE or (plotHeatMap and heatMapType == 'KDE'):
--> 548 KDE_age, KDE = KDEcalcAges(ages=ages, x1=0, x2=4500, xdif=xdif, bw=bw, bw_x=bw_x, cumulative=False)
549 if plotPDP or (plotHeatMap and heatMapType == 'PDP'):
550 PDP_age, PDP = PDPcalcAges(ages=ages, errors=errors, x1=0, x2=4500, xdif=xdif, cumulative=False)
File ~\anaconda3\lib\site-packages\detritalpy\detritalFuncs.py:3356, in KDEcalcAges(ages, x1, x2, xdif, bw, bw_x, cumulative)
3353 if bw_x is not None:
3354 print('Warning: If a bandwidth x-axis split is desired, must specify bandwidth values to use by placing bw in a list: e.g., bw=[2.5, 10]')
-> 3356 KDE_age, KDE = KDE_bw_selector(ages=ages, x1=x1, x2=x2, xdif=xdif, bw=bw, cumulative=cumulative)
3357 return KDE_age, KDE
3359 else:
File ~\anaconda3\lib\site-packages\detritalpy\detritalFuncs.py:3398, in KDE_bw_selector(ages, x1, x2, xdif, bw, cumulative)
3396 KDE_age, KDE = KDEcalcAgesLocalAdapt(ages=ages, x1=x1, x2=x2, xdif=xdif, cumulative=cumulative)
3397 if bw == 'optimizedFixed':
-> 3398 KDE_age, KDE = KDEcalcAgesGlobalAdapt(ages=ages, x1=x1, x2=x2, xdif=xdif, cumulative=cumulative)
3400 return KDE_age, KDE
File ~\anaconda3\lib\site-packages\detritalpy\detritalFuncs.py:3542, in KDEcalcAgesGlobalAdapt(ages, x1, x2, xdif, cumulative)
3540 KDE = np.zeros(shape=(len(ages),len(KDE_age)))
3541 for i in range(len(ages)):
-> 3542 kde = akde.ssvkernel(np.asarray(ages[i]), tin=KDE_age, nbs=100)[0]
3543 if cumulative:
3544 kde = np.cumsum(kde)
File ~\anaconda3\lib\site-packages\detritalpy\adaptiveKDE.py:411, in ssvkernel(x, tin, M, nbs, WinFunc)
409 y_hist = np.histogram(x_ab, thist-dt/2)[0] / dt
410 L = y_hist.size
--> 411 N = sum(y_hist * dt).astype(np.float)
413 # initialize window sizes
414 W = logexpSSV(np.linspace(ilogexpSSV(5 * dt), ilogexpSSV(T), np.int(M)))
File ~\anaconda3\lib\site-packages\numpy\__init__.py:305, in __getattr__(attr)
300 warnings.warn(
301 f"In the future `np.{attr}` will be defined as the "
302 "corresponding NumPy scalar.", FutureWarning, stacklevel=2)
304 if attr in __former_attrs__:
--> 305 raise AttributeError(__former_attrs__[attr])
307 # Importing Tester requires importing all of UnitTest which is not a
308 # cheap import Since it is mainly used in test suits, we lazy import it
309 # here to save on the order of 10 ms of import time for most users
310 #
311 # The previous way Tester was imported also had a side effect of adding
312 # the full `numpy.testing` namespace
313 if attr == 'testing':
AttributeError: module 'numpy' has no attribute 'float'.
`np.float` was a deprecated alias for the builtin `float`. To avoid this error in existing code, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.