LinkedEarth / Pyleoclim_util

Python Package for the Analysis of Paleoclimate Data. Documentation at
https://pyleoclim-util.readthedocs.io
GNU General Public License v3.0
88 stars 33 forks source link

Significant values return from signif_test(qs=[0.95],number=5) #609

Open thelightonmyway opened 4 months ago

thelightonmyway commented 4 months ago

I have finished an power spectrum density analysis recently by using .spectral(), and making significant analysis by using .signif_test(). However, I'm facing a problem about how I could plot optionally. Particularly, I want to adjust the 95% threshold curve's characters, such as linewidth, colors, and so on. But, through my search, neither could I print the 95% threshold data to make a plot, nor could I change the parameters to adjust it. I‘d greatly appreciate if you could answer my question on how I could print the 95% threshold data or change the parameters to adjust the 95% threshold curve. My code is as follows: def Z_Score(data): mean = np.mean(data) # 均值 std_dev = np.std(data) # 标准差 norm_data = (data - mean) / std_dev return norm_data fg=xr.open_dataset("/mnt/e/wind_global/obs/masked/E-OBS_wind_monthly_mean_1×1_masked.nc").fg[:-6,:,:] fg_spatial=np.nanmean(fg,(1,2)) fg_de_spatial=signal.detrend(fg_spatial,axis=0,type="linear",bp=0,overwrite_data=False) fg_de_std_spatial=Z_Score(fg_de_spatial) time=np.arange(516) wind_speed=pyleo.Series(time=time,value=fg_de_std_spatial,time_name="cycles per year",time_unit="month") psd=wind_speed.spectral(method="mtm") psd_signif=psd.signif_test(qs=[0.95],number=5) fig, ax = psd_signif.plot(label="original",lgd_kwargs={"ncol":1},color="k",linewidth=2)) This is my plot: issue Thanks, sincerely!

khider commented 4 months ago
  1. To adjust the plot, you can use some of the arguments of the plot function directly to do what you need: plot(in_loglog=True, in_period=True, label=None, xlabel=None, ylabel='PSD', title=None, marker=None, markersize=None, color=None, linestyle=None, linewidth=None, transpose=False, xlim=None, ylim=None, figsize=[10, 4], savefig_settings=None, ax=None, legend=True, lgd_kwargs=None, xticks=None, yticks=None, alpha=None, zorder=None, plot_kwargs=None, signif_clr='red', signif_linestyles=['--', '-.', ':'], signif_linewidth=1, plot_beta=True, beta_kwargs=None)

Have a look at the doc: https://pyleoclim-util.readthedocs.io/en/latest/core/api.html#pyleoclim.core.psds.PSD.plot

In particular, look at signif_clr, signif_linestyles, and signif_linewidth. If you need something more granular and specific to your use case, make sure you return fig and ax:

fig, ax = psd_signif.plot()

They are Matplotlib objects that you can use.

  1. To get the data:

You can do: psd_signif.signif_qs to get the information. Have a look at the object itself in the doc: https://pyleoclim-util.readthedocs.io/en/latest/core/api.html#pyleoclim.core.psds.PSD

CommonClimate commented 2 weeks ago

@thelightonmyway does this answer your question? If so, we'll close the issue. If not, please tell us what else you need.

thelightonmyway commented 1 week ago

@thelightonmyway does this answer your question? If so, we'll close the issue. If not, please tell us what else you need.

Yes, it's undoubtedly useful for me! Thank you all for your kindness contribution!