Skip to content

Add gallery examples for cropping and extracting profiles - #263

Open
Amityush-lgtm wants to merge 7 commits into
sunpy:ndcube-refactorfrom
Amityush-lgtm:slicing-examples
Open

Add gallery examples for cropping and extracting profiles#263
Amityush-lgtm wants to merge 7 commits into
sunpy:ndcube-refactorfrom
Amityush-lgtm:slicing-examples

Conversation

@Amityush-lgtm

@Amityush-lgtm Amityush-lgtm commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

PR Description

This PR adds a new gallery examples demonstrating slicing and cropping using the ndcube API as discussed in #262.

Changes:

  • Added plot_cropping.py to demonstrate cropping spectrograms and extracting time profiles and line profiles using NDCube's crop() and crop_by_values().

AI Assistance Disclosure

AI tools were used for:

  • Code generation (e.g., when writing an implementation or fixing a bug)
  • Test/benchmark generation
  • Documentation (including examples)
  • Research and understanding
  • No AI tools were used

Regardless of AI use, the human contributor remains fully responsible for correctness, design choices, licensing compatibility, and long-term maintainability.

Comment thread examples/plot_cropping.py Outdated
@@ -0,0 +1,89 @@
"""
Cropping a WIND/WAVES spectrogram

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Cropping a WIND/WAVES spectrogram
Cropping a Spectrogram

as it not specifically to WIND/WAVES that just the data being used for the example

Comment thread examples/plot_cropping.py Outdated
# Two key methods are available:
#
# * `~ndcube.NDCube.crop` — accepts high-level coordinate objects
# (e.g. `~astropy.time.Time`).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add SpectralCoord too

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, i'll add SpectralCoord :)

Comment thread examples/plot_cropping.py
spec = waves_specs[0]

###############################################################################
# Cropping by time

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hum maybe just Crop and show how to crop using only one axes e.g. Time then the other e.g. SpectralCoord and the using both?

Comment thread examples/plot_cropping.py
time_cropped = spec.crop((start_time, None), (end_time, None))

###############################################################################
# Cropping by frequency

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again maybe keep same as above for by time using u.s then frequency as a quantity an then both?

Comment thread examples/plot_profiles.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure but could maybe fold this into the other example as its an extreme version of cropping to a single axis

@Amityush-lgtm

Copy link
Copy Markdown
Contributor Author

Ive pushed the suggested changes and updated the examples. While testing locally, the NASA SPDF server is having some issues so fido.search() was getting stuck query, i tried with some other instruments and they are working

@samaloney

Copy link
Copy Markdown
Member

Need to megre / rebase main into here or at least update the miniforge3-latest change on the RTD config so the docs build.

@Amityush-lgtm

Copy link
Copy Markdown
Contributor Author

I have updated the RTD config

@Amityush-lgtm

Copy link
Copy Markdown
Contributor Author

@samaloney i have brought all the requirements that were added in the Waves Example gallery setup here to check the example here, let me know if this looks right

@samaloney

Copy link
Copy Markdown
Member

Yea I guess we should keep the ndcube branch up today with main to avoid having to make the same changes manually

@Amityush-lgtm

Amityush-lgtm commented Aug 12, 2026

Copy link
Copy Markdown
Contributor Author

That sounds good, but since @hayesla created the ndcube-refactor branch, i dont believe i have permissions to merge main into it,
Would you like me to open a PR from main into ndcube-refactor instead???

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

Successfully merging this pull request may close these issues.

2 participants