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

Refactor and organize dispersed Python Imports across readers #787

Open
2 tasks
srikanth-kumar opened this issue Sep 24, 2024 · 0 comments · May be fixed by #788
Open
2 tasks

Refactor and organize dispersed Python Imports across readers #787

srikanth-kumar opened this issue Sep 24, 2024 · 0 comments · May be fixed by #788
Assignees
Labels
refactor Code refactoring updates

Comments

@srikanth-kumar
Copy link
Collaborator

Description

  • The import statements are scattered across most of the readers, lacking a clear organization.
  • There are redundant, inconsistent, and unoptimized imports of same module in some readers.

Changes

  • Grouping the imports into one of the following:
    • Standard Library imports
    • Third-Party Library imports
    • GeoIPS-based imports
  • Move the import statements to the top of the file if they are inside a method that is definitely called each time.
  • Move the import statement to the top of the file if they are located in the call() function, the primary function in each reader.
  • Sorts the imports alphabetically within each group, adhering to PEP 8 standards
  • Remove redundant import statements such as :
    • amsr2_netcdf.py had three instances of import xarray including in the primary function call()
    • amsr2_netcdf.py has two functions read_amsr_winds() and read_amsr_mbt(). One of the two is called and each one has same imports listed in their definition
  • Some readers had numpy listed under standard libraries import which should be moved to Third-Party Library imports
  • Fix inconsistent imports of the same module in a given reader
    import numpy 
    import numpy as np 
    
    import os 
    from os.path import basename
    
    from numpy import datetime64
    import numpy 
    

Does Not Change

This issue does not intend to change the following

  • The imports handled through optional dependency checks have not been changed.
         with import_optional_dependencies(loglevel="info"):
              """Attempt to import a package and print to LOG.info if the import fails."""
              # If this reader is not installed on the system, don't fail alltogether, just skip
              # this import.  This reader will not work if the import fails and the package will
              # have to be installed to process data of this type.
              import netCDF4 as ncdf
              import numexpr as ne

  • The GeoIPS-based imports, which are local and used for a specific function within the method, have not been modified to maintain the relevant context.

Background and Motivation

  • Adhere to PEP 8 standards of imports organization to improve code readability and standardize imports.

Checklist for Completion

  • make the changes across all the readers
  • perform a full test to ensure successful validation
@srikanth-kumar srikanth-kumar added the refactor Code refactoring updates label Sep 24, 2024
@srikanth-kumar srikanth-kumar self-assigned this Sep 24, 2024
@srikanth-kumar srikanth-kumar linked a pull request Oct 24, 2024 that will close this issue
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor Code refactoring updates
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant