Skip to content

Commit

Permalink
Merge pull request #119 from pysat/sty/gen_meth
Browse files Browse the repository at this point in the history
STY: reduce duplication for init and clean
  • Loading branch information
jklenzing committed May 26, 2022
2 parents 9b9b4fd + c209c54 commit fb2e29f
Show file tree
Hide file tree
Showing 19 changed files with 123 additions and 297 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](https://semver.org/).

## [0.0.4] - 2022-XX-XX
* Maintenance
* Reduce duplication of code in instrument modules

## [0.0.3] - 2022-05-18
* Include flake8 linting of docstrings and style in Github Actions
* Include Windows tests in Github Actions
Expand Down
14 changes: 13 additions & 1 deletion pysatNASA/constellations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,23 @@
package.
"""

import logging

import pysat

__all__ = ['de2', 'icon']

# TODO(#89): reevaluate logger suppression if fixes implemented in pysat
# Save current level and turn off before constellation import
user_level = pysat.logger.level
pysat.logger.setLevel(logging.WARNING)

# Import constellation objects
for const in __all__:
exec("from pysatNASA.constellations import {:}".format(const))

# Restore user level
pysat.logger.setLevel(user_level)

# Remove dummy variable
del const
del const, user_level
16 changes: 3 additions & 13 deletions pysatNASA/instruments/cnofs_ivm.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@
import numpy as np

from pysat.instruments.methods import general as mm_gen
from pysat import logger

from pysatNASA.instruments.methods import cdaweb as cdw
from pysatNASA.instruments.methods import cnofs as mm_cnofs
from pysatNASA.instruments.methods import general as mm_nasa

# ----------------------------------------------------------------------------
# Instrument attributes
Expand All @@ -82,18 +82,8 @@
# Instrument methods


def init(self):
"""Initialize the Instrument object with instrument specific values.
Runs once upon instantiation.
"""
logger.info(mm_cnofs.ackn_str)
self.acknowledgements = mm_cnofs.ackn_str
self.references = '\n'.join((mm_cnofs.refs['mission'],
mm_cnofs.refs['ivm']))

return
# Use standard init routine
init = functools.partial(mm_nasa.init, module=mm_cnofs, name=name)


def preprocess(self):
Expand Down
17 changes: 3 additions & 14 deletions pysatNASA/instruments/cnofs_plp.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@
import numpy as np

from pysat.instruments.methods import general as mm_gen
from pysat import logger

from pysatNASA.instruments.methods import cdaweb as cdw
from pysatNASA.instruments.methods import cnofs as mm_cnofs
from pysatNASA.instruments.methods import general as mm_nasa

# ----------------------------------------------------------------------------
# Instrument attributes
Expand All @@ -82,19 +82,8 @@
# ----------------------------------------------------------------------------
# Instrument methods


def init(self):
"""Initialize the Instrument object with instrument specific values.
Runs once upon instantiation.
"""
logger.info(mm_cnofs.ackn_str)
self.acknowledgements = mm_cnofs.ackn_str
self.references = '\n'.join((mm_cnofs.refs['mission'],
mm_cnofs.refs['plp']))

return
# Use standard init routine
init = functools.partial(mm_nasa.init, module=mm_cnofs, name=name)


def clean(self):
Expand Down
16 changes: 3 additions & 13 deletions pysatNASA/instruments/cnofs_vefi.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@
import numpy as np

from pysat.instruments.methods import general as mm_gen
from pysat import logger

from pysatNASA.instruments.methods import cdaweb as cdw
from pysatNASA.instruments.methods import cnofs as mm_cnofs
from pysatNASA.instruments.methods import general as mm_nasa

# ----------------------------------------------------------------------------
# Instrument attributes
Expand All @@ -85,18 +85,8 @@
# Instrument methods


def init(self):
"""Initialize the Instrument object with instrument specific values.
Runs once upon instantiation.
"""
logger.info(mm_cnofs.ackn_str)
self.acknowledgements = mm_cnofs.ackn_str
self.references = '\n'.join((mm_cnofs.refs['mission'],
mm_cnofs.refs['vefi']))

return
# Use standard init routine
init = functools.partial(mm_nasa.init, module=mm_cnofs, name=name)


def clean(self):
Expand Down
34 changes: 5 additions & 29 deletions pysatNASA/instruments/de2_lang.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,12 @@

import datetime as dt
import functools
import warnings

from pysat.instruments.methods import general as mm_gen
from pysat import logger

from pysatNASA.instruments.methods import cdaweb as cdw
from pysatNASA.instruments.methods import de2 as mm_de2
from pysatNASA.instruments.methods import general as mm_nasa

# ----------------------------------------------------------------------------
# Instrument attributes
Expand All @@ -77,34 +76,11 @@
# Instrument methods


def init(self):
"""Initialize the Instrument object with instrument specific values.
Runs once upon instantiation.
"""

logger.info(mm_de2.ackn_str)
self.acknowledgements = mm_de2.ackn_str
self.references = mm_de2.refs['lang']
return


def clean(self):
"""Clean DE2 LANG data to the specified level.
Note
----
'clean' - Not specified
'dusty' - Not specified
'dirty' - Not specified
'none' No cleaning applied, routine not called in this case.
"""
warnings.warn('No cleaning routines available for DE2 LANG')

return
# Use standard init routine
init = functools.partial(mm_nasa.init, module=mm_de2, name=name)

# No cleaning, use standard warning function instead
clean = mm_nasa.clean_warn

# ----------------------------------------------------------------------------
# Instrument functions
Expand Down
34 changes: 5 additions & 29 deletions pysatNASA/instruments/de2_nacs.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,12 @@

import datetime as dt
import functools
import warnings

from pysat.instruments.methods import general as mm_gen
from pysat import logger

from pysatNASA.instruments.methods import cdaweb as cdw
from pysatNASA.instruments.methods import de2 as mm_de2
from pysatNASA.instruments.methods import general as mm_nasa

# ----------------------------------------------------------------------------
# Instrument attributes
Expand All @@ -100,34 +99,11 @@
# Instrument methods


def init(self):
"""Initialize the Instrument object with instrument specific values.
Runs once upon instantiation.
"""

logger.info(mm_de2.ackn_str)
self.acknowledgements = mm_de2.ackn_str
self.references = mm_de2.refs['lang']
return


def clean(self):
"""Clean DE2 NACS data to the specified level.
Note
----
'clean' - Not specified
'dusty' - Not specified
'dirty' - Not specified
'none' No cleaning applied, routine not called in this case.
"""
warnings.warn('No cleaning routines available for DE2 NACS')

return
# Use standard init routine
init = functools.partial(mm_nasa.init, module=mm_de2, name=name)

# No cleaning, use standard warning function instead
clean = mm_nasa.clean_warn

# ----------------------------------------------------------------------------
# Instrument functions
Expand Down
34 changes: 5 additions & 29 deletions pysatNASA/instruments/de2_rpa.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,12 @@

import datetime as dt
import functools
import warnings

from pysat.instruments.methods import general as mm_gen
from pysat import logger

from pysatNASA.instruments.methods import cdaweb as cdw
from pysatNASA.instruments.methods import de2 as mm_de2
from pysatNASA.instruments.methods import general as mm_nasa

# ----------------------------------------------------------------------------
# Instrument attributes
Expand All @@ -86,34 +85,11 @@
# Instrument methods


def init(self):
"""Initialize the Instrument object with instrument specific values.
Runs once upon instantiation.
"""

logger.info(mm_de2.ackn_str)
self.acknowledgements = mm_de2.ackn_str
self.references = mm_de2.refs['lang']
return


def clean(self):
"""Clean DE2 RPA data to the specified level.
Note
----
'clean' - Not specified
'dusty' - Not specified
'dirty' - Not specified
'none' No cleaning applied, routine not called in this case.
"""
warnings.warn('No cleaning routines available for DE2 RPA')

return
# Use standard init routine
init = functools.partial(mm_nasa.init, module=mm_de2, name=name)

# No cleaning, use standard warning function instead
clean = mm_nasa.clean_warn

# ----------------------------------------------------------------------------
# Instrument functions
Expand Down
34 changes: 5 additions & 29 deletions pysatNASA/instruments/de2_wats.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,12 @@

import datetime as dt
import functools
import warnings

from pysat.instruments.methods import general as mm_gen
from pysat import logger

from pysatNASA.instruments.methods import cdaweb as cdw
from pysatNASA.instruments.methods import de2 as mm_de2
from pysatNASA.instruments.methods import general as mm_nasa

# ----------------------------------------------------------------------------
# Instrument attributes
Expand All @@ -97,34 +96,11 @@
# Instrument methods


def init(self):
"""Initialize the Instrument object with instrument specific values.
Runs once upon instantiation.
"""

logger.info(mm_de2.ackn_str)
self.acknowledgements = mm_de2.ackn_str
self.references = mm_de2.refs['lang']
return


def clean(self):
"""Clean DE2 LANG data to the specified level.
Note
----
'clean' - Not specified
'dusty' - Not specified
'dirty' - Not specified
'none' No cleaning applied, routine not called in this case.
"""
warnings.warn('No cleaning routines available for DE2 WATS')

return
# Use standard init routine
init = functools.partial(mm_nasa.init, module=mm_de2, name=name)

# No cleaning, use standard warning function instead
clean = mm_nasa.clean_warn

# ----------------------------------------------------------------------------
# Instrument functions
Expand Down
17 changes: 3 additions & 14 deletions pysatNASA/instruments/formosat1_ivm.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@

import datetime as dt
import functools
import warnings

from pysat.instruments.methods import general as mm_gen
from pysat import logger

from pysatNASA.instruments.methods import cdaweb as cdw
from pysatNASA.instruments.methods import general as mm_nasa

# ----------------------------------------------------------------------------
# Instrument attributes
Expand Down Expand Up @@ -74,19 +74,8 @@ def init(self):
return


def clean(self):
"""Clean FORMOSAT-1 IVM data to the specified level.
Note
----
No cleaning currently available for FORMOSAT-1 IVM.
"""

warnings.warn("No cleaning currently available for FORMOSAT-1")

return

# No cleaning, use standard warning function instead
clean = mm_nasa.clean_warn

# ----------------------------------------------------------------------------
# Instrument functions
Expand Down

0 comments on commit fb2e29f

Please sign in to comment.