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

Example for constructing SpecArray from scratch #107

Open
ryancoe opened this issue Jan 19, 2024 · 2 comments
Open

Example for constructing SpecArray from scratch #107

ryancoe opened this issue Jan 19, 2024 · 2 comments

Comments

@ryancoe
Copy link
Contributor

ryancoe commented Jan 19, 2024

It'd be great to add a brief example in the documentation on creating a SpecArray object from scratch (i.e., using the __init__ method). I think it would be as simple as this:

efth = np.array([0.00000000e+00, 0.00000000e+00, 1.09429785e-03, 5.89094920e-02,
                 2.07249055e-01, 2.02675843e-01, 1.68867998e-01, 1.19803351e-01,
                 7.78674098e-02, 4.96642804e-02, 3.23615943e-02, 2.09029418e-02,
                 1.36226413e-02, 8.86459619e-03, 5.62541522e-03, 3.37224324e-03,
                 2.02762403e-03, 1.13507449e-03, 4.59939791e-04, 2.04417576e-04,
                 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
                 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
                 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
                 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
                 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
                 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
                 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
                 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
                 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
                 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
                 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
                 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
                 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
                 0.00000000e+00, 0.00000000e+00, 0.00000000e+00])
freq = np.array([0.025, 0.05, 0.075, 0.1, 0.125, 0.15, 0.175, 0.2, 0.225,
                 0.25, 0.275, 0.3, 0.325, 0.35, 0.375, 0.4, 0.425, 0.45,
                 0.475, 0.5, 0.525, 0.55, 0.575, 0.6, 0.625, 0.65, 0.675,
                 0.7, 0.725, 0.75, 0.775, 0.8, 0.825, 0.85, 0.875, 0.9,
                 0.925, 0.95, 0.975, 1., 1.025, 1.05, 1.075, 1.1, 1.125,
                 1.15, 1.175, 1.2, 1.225, 1.25, 1.275, 1.3, 1.325, 1.35,
                 1.375, 1.4, 1.425, 1.45, 1.475, 1.5, 1.525, 1.55, 1.575,
                 1.6, 1.625, 1.65, 1.675, 1.7, 1.725, 1.75, 1.775, 1.8,
                 1.825, 1.85, 1.875])
da = xr.DataArray(data=np.transpose(np.atleast_2d(efth)),
             dims=[
                 "freq",
                 "dir"
                 ],
             coords=dict(
                 freq=freq,
                 dir=[0],
                 ),
             )
ws = wavespectra.SpecArray(da)
@rafa-guedes
Copy link
Collaborator

rafa-guedes commented Jan 21, 2024

@ryancoe that is a good idea. We are currently working on a major version upgrade #106 that will add several features including spectra reconstruction and a new partitioning api and the documentation will be also upgraded as a result. Will try to put an example perhaps in the "Quick start" section.

One comment though is that the last line in your snippet ws = wavespectra.SpecArray(da) isn't really needed - the spec accessor will already by available to da as long as wavespectra has been imported and da conforms to wavespectra conventions (freq cood in Hz, dir coord in degrees, efth values in m2/Hz/deg)

@ryancoe
Copy link
Contributor Author

ryancoe commented Jan 22, 2024

Very slick, thanks!

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