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

192 q6 data selection based flagging #396

Merged
merged 15 commits into from
Oct 9, 2024

Conversation

mpound
Copy link
Collaborator

@mpound mpound commented Oct 2, 2024

This PR contains

  • Flag class
  • Refactoring of Selection/Flag into SelectionBase/Selection/Flag
  • Addition of Flag class attribute to GBTFITSLoad
  • GBTFITSLoad methods to flag data (flag, flag_range, flag_within, etc)
  • Test code for Flag class

What is not contained:

  • flagging channels. When reviewing this PR, ignore code having to do with managing channel flagging. It is not complete.
  • passing flags to calibration routines.
  • reading of GBTIDL flag files.

This PR should not be merged until after #395, #392, #388

@mpound mpound linked an issue Oct 2, 2024 that may be closed by this pull request
@mpound mpound requested a review from astrofle October 2, 2024 20:07
@mpound
Copy link
Collaborator Author

mpound commented Oct 2, 2024

oops looks like I broke something else. let me fix it before you review

@mpound
Copy link
Collaborator Author

mpound commented Oct 2, 2024

ok, it was skeleton code for channel flags that is not really formulated yet

@astrofle
Copy link
Collaborator

astrofle commented Oct 7, 2024

Flagging using all of the columns is not possible. For example:

sdfits.flag(subobsmode="TPWCAL")

results in

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
Cell In[7], line 1
----> 1 sdfits.flag(subobsmode="TPWCAL")

File [/home/sandboxes/psalas/Dysh/dysh-clean/src/dysh/log.py:360](http://thales.gb.nrao.edu:9035/home/sandboxes/psalas/Dysh/dysh-clean/src/dysh/log.py#line=359), in log_call_to_history.<locals>.wrapper(self, *args, **kwargs)
    358 else:  # it's a class instance
    359     try:
--> 360         result = func(self, *args, **kwargs)
    361     except:  # remove the wrapper from the stack trace
    362         tp, exc, tb = sys.exc_info()

File [/home/sandboxes/psalas/Dysh/dysh-clean/src/dysh/fits/gbtfitsload.py:650](http://thales.gb.nrao.edu:9035/home/sandboxes/psalas/Dysh/dysh-clean/src/dysh/fits/gbtfitsload.py#line=649), in GBTFITSLoad.flag(self, tag, **kwargs)
    631 @log_call_to_history
    632 def flag(self, tag=None, **kwargs):
    633     """Add one or more exact flag rules, e.g., `key1 = value1, key2 = value2, ...`
    634     If `value` is array-like then a match to any of the array members will be selected.
    635     For instance `flag(object=['3C273', 'NGC1234'])` will flag data for either of those
   (...)
    648 
    649     """
--> 650     self._flag.flag(tag=tag, **kwargs)

File [/home/sandboxes/psalas/Dysh/dysh-clean/src/dysh/util/selection.py:1005](http://thales.gb.nrao.edu:9035/home/sandboxes/psalas/Dysh/dysh-clean/src/dysh/util/selection.py#line=1004), in Flag.flag(self, tag, **kwargs)
   1003 chan = kwargs.pop("chan", None)
   1004 self._handle_channel(chan)
-> 1005 self._base_select(tag, **kwargs)

File [/home/sandboxes/psalas/Dysh/dysh-clean/src/dysh/util/selection.py:491](http://thales.gb.nrao.edu:9035/home/sandboxes/psalas/Dysh/dysh-clean/src/dysh/util/selection.py#line=490), in SelectionBase._base_select(self, tag, **kwargs)
    475 def _base_select(self, tag=None, **kwargs):
    476     """Add one or more exact selection[/flag](http://thales.gb.nrao.edu:9035/flag) rules, e.g., `key1 = value1, key2 = value2, ...`
    477     If `value` is array-like then a match to any of the array members will be selected[/flagged.](http://thales.gb.nrao.edu:9035/flagged.)
    478     Derived classes will call this method with their own specific name, i.e. `select` or `flag`.
   (...)
    489 
    490     """
--> 491     self._check_keys(kwargs.keys())
    492     row = {}
    493     # if called via _select_from_mixed_kwargs, then we want to merge all the
    494     # selections

File [/home/sandboxes/psalas/Dysh/dysh-clean/src/dysh/util/selection.py:319](http://thales.gb.nrao.edu:9035/home/sandboxes/psalas/Dysh/dysh-clean/src/dysh/util/selection.py#line=318), in SelectionBase._check_keys(self, keys)
    317         unrecognized.append(k)
    318 if len(unrecognized) > 0:
--> 319     raise KeyError(f"The following keywords were not recognized: {unrecognized}")

KeyError: "The following keywords were not recognized: ['SUBOBSMODE']"

Other than that it looks good.

@mpound
Copy link
Collaborator Author

mpound commented Oct 9, 2024

For future reference:
Explanation of the change in dtype to dtype("<U32") in SelectionBase. Originally, I had dtype=str for most columns in the SeleectionBase._table. However that failed when Flag was implemented to allow channels to be set per selection rule (rather than globally as for Selection). It turns out you can't assign an astropy Table cell and change its dtype. So the Table got instantiated with dtype=str1 (=='<U1') [why it defaulted to 1 character, I don't know] and if I tried to assign say, '[0,100]' to a row in the CHAN column, it would truncate it to 1 character. I tried changing the default object type to object and to None, both of which had other side effects. So I would up setting the default to a longish string ("32 chars should be enough for anyone"). We'll see if that breaks down at some point. But it fixes the issue and does not have the side effects that object and None have.

@mpound mpound merged commit 720d517 into main Oct 9, 2024
14 checks passed
@mpound mpound deleted the 192-q6-data-selection-based-flagging branch October 9, 2024 21:42
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.

Q6 - Data selection based flagging
2 participants