Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
thelightonmyway opened this issue Jul 27, 2024 · 1 comment
Open

Comments

@thelightonmyway
Copy link

thelightonmyway commented Jul 27, 2024

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
Copy link
Member

khider commented Jul 29, 2024

  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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants