- 
                Notifications
    
You must be signed in to change notification settings  - Fork 11
 
          [Best Practices] Add check for TimeSeries unit follows CMIXF-12 convention
          #281
        
          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
          
     Draft
      
      
            weiglszonja
  wants to merge
  15
  commits into
  NeurodataWithoutBorders:dev
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
catalystneuro:add_check_for_unit_follows_CMIXF-12
  
      
      
   
  
    
  
  
  
 
  
      
    base: dev
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.
          
          
  
     Draft
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            15 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      0ab683b
              
                add check for unit formatting complies with CMIXF-12
              
              
                weiglszonja 257e292
              
                add cmixf to requirements.txt
              
              
                weiglszonja ac22c09
              
                add unittests for check_unit_formatting
              
              
                weiglszonja a9f5e90
              
                add units formatting as new section with examples
              
              
                weiglszonja 5641e1a
              
                extend best practice for TimeSeries with unit formatting
              
              
                weiglszonja 842e0f1
              
                add unit formatting to appear at the end of best practices
              
              
                weiglszonja 82329ac
              
                Merge branch 'dev' into add_check_for_unit_follows_CMIXF-12
              
              
                weiglszonja 2dfb82b
              
                fix derived unit test
              
              
                weiglszonja ac5888c
              
                Merge remote-tracking branch 'origin/add_check_for_unit_follows_CMIXF…
              
              
                weiglszonja bba0820
              
                Apply suggestions from code review
              
              
                weiglszonja f4aad15
              
                fix unittest
              
              
                weiglszonja 1d1e0c8
              
                use CMIXFLexer instead of parser
              
              
                weiglszonja 8964521
              
                move CMIXF-12 into Units of Measurement
              
              
                weiglszonja f2f7017
              
                fix reference for best_practice_unit_of_measurement
              
              
                weiglszonja 655a97f
              
                extend examples
              
              
                weiglszonja 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
    
  
  
    
              
  
    
      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 | 
|---|---|---|
| 
          
            
          
           | 
    @@ -2,6 +2,7 @@ | |
| import numpy as np | ||
| 
     | 
||
| from pynwb import TimeSeries | ||
| from cmixf.parser import CMIXFLexer | ||
| 
     | 
||
| # from ..tools import all_of_type | ||
| from ..register_checks import register_check, Importance, Severity, InspectorMessage | ||
| 
          
            
          
           | 
    @@ -92,3 +93,23 @@ def check_resolution(time_series: TimeSeries): | |
| return InspectorMessage( | ||
| message=f"'resolution' should use -1.0 or NaN for unknown instead of {time_series.resolution}." | ||
| ) | ||
| 
     | 
||
| 
     | 
||
| @register_check(importance=Importance.BEST_PRACTICE_VIOLATION, neurodata_type=TimeSeries) | ||
| def check_unit_formatting(time_series: TimeSeries): | ||
| """ | ||
| Check the unit value of a TimeSeries that it complies with CMIXF-12 convention for formatting the units. | ||
| 
     | 
||
| Best Practice: :ref:`best_practice_unit_of_measurement` | ||
| """ | ||
| 
     | 
||
| # Early return for arbitrary units that are unknown or unavailable. | ||
| if time_series.unit == "a.u.": | ||
| return | ||
| 
     | 
||
| lexer = CMIXFLexer() | ||
| tokens = lexer.tokenize(time_series.unit) | ||
| 
         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. 
 would return the recognized token value for unit t next(tokens)  | 
||
| try: | ||
| list(tokens) | ||
| except ValueError: | ||
| return InspectorMessage(message=f"The 'unit' should adhere to CMIXF-12 format instead of '{time_series.unit}'.") | ||
  
    
      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
    
  
  
    
              
  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.
This is not
TimeSeriesbut I thought could be good to include for example for representing degrees?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.
CompassDirection is more typical for that as an example (be sure to include radians as well)