Commit 430584ea authored by BO ZHANG's avatar BO ZHANG 🏀
Browse files

tweaks

parent 9fea0933
Pipeline #1424 failed with stage
in 0 seconds
from .flip_image import flip_image, read_default_image
from .demo import demo_function, DemoClass from .demo import demo_function, DemoClass
from .flip_image import flip_image, read_default_image
from .flip_image_in_parallel import flip_multiple_images_jl, flip_multiple_images_mp
from .config import read_config
__version__ = "0.0.1" __version__ = "0.0.1"
__all__ = [ __all__ = [
"flip_image",
"read_default_image",
"demo_function", "demo_function",
"DemoClass", "DemoClass",
"flip_image",
"read_default_image",
"flip_multiple_images_jl",
"flip_multiple_images_mp",
"read_config",
] ]
from .flip_image import flip_image, read_test_image
from .demo import a_demo_function, ADemoClass
__all__ = ["flip_image", "read_test_image", "a_demo_function", "ADemoClass"]
import joblib
from astropy.io import fits
from csst.core.processor import CsstProcessor
from csst.msc.data_manager import CsstMscDataManager
from csst_proto.api import flip_image
class CsstProcFlipImage(CsstProcessor):
""" This processor flips images """
def __init__(self, dm: CsstMscDataManager, n_jobs: int = 1):
"""
Parameters
----------
dm:
csst data manager, used to manage the input/output file paths
n_jobs:
number of jobs launched
"""
super(CsstProcFlipImage, self).__init__()
self.dm = dm
self.n_jobs = n_jobs
def run(self, debug: bool = False):
""" flip images for all detectors
Parameters
----------
debug:
if True, use debug mode
Returns
-------
a list of flipped images
"""
img_flipped_list = joblib.Parallel(n_jobs=self.n_jobs)(
joblib.delayed(CsstProcFlipImage.run_one_detector)(this_ccd_id)
for this_ccd_id in self.dm.target_ccd_ids)
return img_flipped_list
def prepare(self, **kwargs):
""" prepare the environment """
return
def cleanup(self):
""" clean up the environment """
return
@staticmethod
def run_one_detector(dm: CsstMscDataManager, ccd_id: int = 6):
""" run for one detector
Parameters
----------
dm:
csst data manager, used to manage the input/output file paths
ccd_id:
detector id
Returns
-------
the flipped image
"""
# input file path
fp_input = dm.l1_ccd(ccd_id, post="img.fits")
img_input = fits.getdata(fp_input)
# flip image
img_flipped = flip_image(img_input)
return img_flipped
import numpy as np
# a function to be finished
def cos_to_be_finished(x):
# TODO: to be finished
return
# a function with a simple docstring
def _cos(x):
""" this is a cosine function """
return np.cos(x)
# a function with a complete docstring
def cos(x: float = 0.) -> float:
""" cosine function
Parameters
----------
x : float
x values
Returns
-------
cos(x) : float
Examples
--------
>>> import numpy as np
>>> cos(np.pi)
Notes
-----
this function is a warpper of `numpy.cos()`
Conf
----
https://numpydoc.readthedocs.io/en/latest/example.html#example
"""
return np.cos(x)
import unittest
from csst_proto.api import a_demo_function
class TestCaseDemoFunction(unittest.TestCase):
""" test demo function """
def test_demo_function(self):
# flip test image
self.assertTrue(
a_demo_function(None) == 1
)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment