-
-
Notifications
You must be signed in to change notification settings - Fork 41
Initial draft of SpectrogramMeta classes #245
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
Open
Amityush-lgtm
wants to merge
9
commits into
sunpy:ndcube-refactor
Choose a base branch
from
Amityush-lgtm:metadata-classes
base: ndcube-refactor
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+426
−35
Open
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
23be630
Initial draft of SpectrogramMeta classes
Amityush-lgtm 0d3fb5e
Adding changelog
Amityush-lgtm 132e1a1
cleaning up comments and callisto location logic
Amityush-lgtm b519dc8
adding type info and docstrings
Amityush-lgtm 104f8d2
adding type info and docstrings in some more places
Amityush-lgtm 6672094
Removinh data_units and rename observer_location to observer_coordinate
Amityush-lgtm 357ff3c
add meta tests for CALISTO and WAVES
Amityush-lgtm 0ce6a01
add meta-classes for remaining instruments
Amityush-lgtm b9ea4d8
Updating changelog
Amityush-lgtm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Add ``SpectrogramMetaABC`` and ``SpectrogramMeta`` metadata classes backed by ``ndcube.meta.NDMeta`` with instrument specific subclasses ``WAVESMeta`` and ``CALISTOMeta`` providing typed property access to spectrogram metadata. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,182 @@ | ||
| import abc | ||
|
|
||
| from ndcube.meta import NDMeta, NDMetaABC | ||
|
|
||
| __all__ = ["SpectrogramMetaABC", "SpectrogramMeta"] | ||
|
|
||
|
|
||
| class SpectrogramMetaABC(NDMetaABC): | ||
| """ | ||
| Abstract base class for all spectrogram metadata. | ||
| """ | ||
|
|
||
| # Identification | ||
| @property | ||
| @abc.abstractmethod | ||
| def instrument(self): | ||
| pass | ||
|
|
||
| @property | ||
| @abc.abstractmethod | ||
| def observatory(self): | ||
| pass | ||
|
|
||
| @property | ||
| @abc.abstractmethod | ||
| def detector(self): | ||
| pass | ||
|
|
||
| @property | ||
| @abc.abstractmethod | ||
| def processing_level(self): | ||
| """The level to which the data has been processed.""" | ||
| pass | ||
|
|
||
| @property | ||
| @abc.abstractmethod | ||
| def version(self): | ||
| """The data version.""" | ||
| pass | ||
|
|
||
| @property | ||
| @abc.abstractmethod | ||
| def source_filename(self): | ||
| """The source filename.""" | ||
| pass | ||
|
|
||
| # Time | ||
| @property | ||
| @abc.abstractmethod | ||
| def date_start(self): | ||
| """The start time of the observation.""" | ||
| pass | ||
|
|
||
| @property | ||
| @abc.abstractmethod | ||
| def date_end(self): | ||
| """The end time of the observation.""" | ||
| pass | ||
|
|
||
| @property | ||
| @abc.abstractmethod | ||
| def temporal_resolution(self): | ||
| """Temporal resolution, both raw and current.""" | ||
| pass | ||
|
|
||
| # Frequency | ||
| @property | ||
| @abc.abstractmethod | ||
| def frequency_range(self): | ||
| """Start and end frequencies of the observation.""" | ||
| pass | ||
|
|
||
| @property | ||
| @abc.abstractmethod | ||
| def frequency_resolution(self): | ||
| """Frequency resolution, both raw and current.""" | ||
| pass | ||
|
|
||
| # Calibration and signal | ||
| @property | ||
| @abc.abstractmethod | ||
| def data_units(self): | ||
| """Units of the data (e.g. arbitrary, V^2/Hz, sfu, dB).""" | ||
| pass | ||
|
|
||
| @property | ||
| @abc.abstractmethod | ||
| def calibration_state(self): | ||
| """Calibration state.""" | ||
| pass | ||
|
|
||
| @property | ||
| @abc.abstractmethod | ||
| def polarisation(self): | ||
| """Stokes parameter convention or polarization.""" | ||
| pass | ||
|
|
||
| # Quality | ||
| @property | ||
| @abc.abstractmethod | ||
| def data_mask(self): | ||
| """Data mask.""" | ||
| pass | ||
|
|
||
| # Position | ||
| @property | ||
| @abc.abstractmethod | ||
| def observer_location(self): | ||
| """Observer location.""" | ||
| pass | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it, I'm working on it |
||
|
|
||
|
|
||
| class SpectrogramMeta(NDMeta, SpectrogramMetaABC): | ||
| """ | ||
| Base class for radio spectrogram metadata. | ||
|
|
||
| Backed by `ndcube.meta.NDMeta` (a `dict` subclass). | ||
| """ | ||
|
|
||
| @property | ||
| def instrument(self): | ||
| return self["instrument"] | ||
|
|
||
| @property | ||
| def observatory(self): | ||
| return self["observatory"] | ||
|
|
||
| @property | ||
| def detector(self): | ||
| return self["detector"] | ||
|
|
||
| @property | ||
| def date_start(self): | ||
| return self["start_time"] | ||
|
|
||
| @property | ||
| def date_end(self): | ||
| return self["end_time"] | ||
|
|
||
| @property | ||
| def processing_level(self): | ||
| return self.get("processing_level") | ||
|
|
||
| @property | ||
| def version(self): | ||
| return self.get("version") | ||
|
|
||
| @property | ||
| def source_filename(self): | ||
| return self.get("source_filename") | ||
|
|
||
| @property | ||
| def temporal_resolution(self): | ||
| return self.get("temporal_resolution") | ||
|
|
||
| @property | ||
| def frequency_range(self): | ||
| return self.get("wavelength") | ||
|
|
||
| @property | ||
| def frequency_resolution(self): | ||
| return self.get("frequency_resolution") | ||
|
|
||
| @property | ||
| def data_units(self): | ||
| return self.get("data_units") | ||
|
|
||
| @property | ||
| def calibration_state(self): | ||
| return self.get("calibration_state") | ||
|
|
||
| @property | ||
| def polarisation(self): | ||
| return self.get("polarisation") | ||
|
|
||
| @property | ||
| def data_mask(self): | ||
| return self.get("data_mask") | ||
|
|
||
| @property | ||
| def observer_location(self): | ||
| return self.get("observer_location") | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import pytest | ||
|
|
||
| from radiospectra.spectrogram.meta import SpectrogramMeta | ||
|
|
||
|
|
||
| def test_spectrogram_meta_required_keys(): | ||
| meta = SpectrogramMeta( | ||
| { | ||
| "instrument": "test_inst", | ||
| "observatory": "test_obs", | ||
| "detector": "test_det", | ||
| "start_time": "2020-01-01", | ||
| "end_time": "2020-01-02", | ||
| } | ||
| ) | ||
|
|
||
| assert meta.instrument == "test_inst" | ||
| assert meta.observatory == "test_obs" | ||
| assert meta.detector == "test_det" | ||
| assert meta.date_start == "2020-01-01" | ||
| assert meta.date_end == "2020-01-02" | ||
|
|
||
|
|
||
| def test_spectrogram_meta_missing_required(): | ||
| meta = SpectrogramMeta({}) | ||
| with pytest.raises(KeyError): | ||
| _ = meta.instrument | ||
|
|
||
|
|
||
| def test_spectrogram_meta_optional_keys(): | ||
| meta = SpectrogramMeta( | ||
| { | ||
| "processing_level": "L2", | ||
| "version": "1.0", | ||
| "wavelength": "radio", | ||
| } | ||
| ) | ||
|
|
||
| assert meta.processing_level == "L2" | ||
| assert meta.version == "1.0" | ||
| assert meta.frequency_range == "radio" | ||
| assert meta.temporal_resolution is None |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a short description and the type info should be encode here for each property e.g.
and then here if we only return str then the default south be
""if that better or worse then returning a str or none e.g.-> str|NoneThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for properties like
date_start,frequency_rangeordata_units, what should i write for them??There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Start of the observation"
Time"Frequency range of observation"
Quantity"Unit for the data"
UnitMaybe we don't need the docstrings for them all but they types would be good
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more doubt, what would you prefer for
observer_locationanddata_mask?