diff --git a/csst_proto/__init__.py b/csst_proto/__init__.py index f102a9cadfa89ce554b3b26d2b90bfba2e05273c..ba61cccaa91c40203ec13164c69e8442e1cf681a 100644 --- a/csst_proto/__init__.py +++ b/csst_proto/__init__.py @@ -1 +1,6 @@ +import os +from .top_level_interface import * + __version__ = "0.0.1" + +PACKAGE_PATH = os.path.dirname(__file__) diff --git a/csst_proto/data/data.csv b/csst_proto/data/data.csv new file mode 100644 index 0000000000000000000000000000000000000000..cd92b6f2dc785d991a8126557807371575922210 --- /dev/null +++ b/csst_proto/data/data.csv @@ -0,0 +1,3 @@ +a, b, c +1,2,3 +4,5,6 \ No newline at end of file diff --git a/csst_proto/flip_image.py b/csst_proto/flip_image.py index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..109e7a16339aa0fc78be98ae225b306e2d72f9eb 100644 --- a/csst_proto/flip_image.py +++ b/csst_proto/flip_image.py @@ -0,0 +1,35 @@ +import numpy as np +from astropy import table +from . import PACKAGE_PATH + + +# the main algorithm +def flip_image(img: np.ndarray): + """ flip an input image + + This function uses an awesome algorithm to flip an input image. + + Parameters + ---------- + img: + the input image + + Returns + ------- + the flipped image + + """ + try: + assert img.ndim == 2 + except AssertionError: + raise AssertionError("The input image is {}D not 2D!".format(img.ndim)) + return img[::-1, ::-1] + + +# a demo on how to package data +def print_data(): + """ print out data """ + fp_data = PACKAGE_PATH + "/data/data.csv" + data = table.Table.read(fp_data) + print(data) + return diff --git a/csst_proto/data/your_data.txt b/csst_proto/some_other_modules.py similarity index 100% rename from csst_proto/data/your_data.txt rename to csst_proto/some_other_modules.py diff --git a/csst_proto/top_level_interface.py b/csst_proto/top_level_interface.py new file mode 100644 index 0000000000000000000000000000000000000000..aa96701c1ea1dacc21279e484059177099d17cec --- /dev/null +++ b/csst_proto/top_level_interface.py @@ -0,0 +1,4 @@ +from .flip_image import flip_image, print_data + + +__all__ = ["flip_image", "print_data"] diff --git a/demo/__init__.py b/demo/__init__.py deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/demo/demo_processor.py b/demo/demo_processor.py deleted file mode 100644 index be22f22c40a1e38d514d3a489d8353e1f7f64802..0000000000000000000000000000000000000000 --- a/demo/demo_processor.py +++ /dev/null @@ -1,43 +0,0 @@ -import joblib - -from csst.core.processor import CsstProcessor -from csst.msc.data_manager import CsstMscDataManager - - -class CsstProcPhotonAbsorption(CsstProcessor): - """ This processor absorbs photons """ - - def __init__(self, dm: CsstMscDataManager, n_jobs: int = 1): - super(CsstProcPhotonAbsorption, self).__init__() - self.dm = dm - self.n_jobs = n_jobs - - def run(self, debug=False): - """ run this processor - - Parameters - ---------- - debug - if True, use debug mode - - Returns - ------- - - """ - joblib.Parallel(n_jobs=self.n_jobs)( - joblib.delayed(CsstProcPhotonAbsorption.run_one_chip)(this_ccd_id) - for this_ccd_id in self.dm.target_ccd_ids) - return - - def prepare(self, **kwargs): - """ prepare the environment """ - return - - def cleanup(self): - """ clean up the environment """ - return - - @staticmethod - def run_one_chip(ccd_id): - """ run for one chip """ - return diff --git a/examples/how_this_code_will_be_used.py b/examples/how_this_code_will_be_used.py new file mode 100644 index 0000000000000000000000000000000000000000..a1071e6759770b4dbd9b2fd5a6773ca57ce17694 --- /dev/null +++ b/examples/how_this_code_will_be_used.py @@ -0,0 +1,53 @@ +import joblib +from astropy.io import fits +from csst.core.processor import CsstProcessor +from csst.msc.data_manager import CsstMscDataManager + +from csst_proto import flip_image + + +class CsstProcFlipImage(CsstProcessor): + """ This processor absorbs photons """ + + def __init__(self, dm: CsstMscDataManager, n_jobs: int = 1): + super(CsstProcFlipImage, self).__init__() + self.dm = dm + self.n_jobs = n_jobs + + def run(self, debug: bool = False): + """ run this processor + + Parameters + ---------- + debug: + if True, use debug mode + + Returns + ------- + + """ + img_flipped_list = joblib.Parallel(n_jobs=self.n_jobs)( + joblib.delayed(CsstProcFlipImage.run_one_chip)(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_chip(dm, ccd_id): + """ run for one chip + + this function + """ + # 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 diff --git a/demo/demo_docstring.py b/examples/how_to_write_docstring.py similarity index 91% rename from demo/demo_docstring.py rename to examples/how_to_write_docstring.py index 34a8430cb57269ccd0652fde6200c14bb07c2061..037c3680bf66660e3300d8862a23bceacd7f6244 100644 --- a/demo/demo_docstring.py +++ b/examples/how_to_write_docstring.py @@ -1,7 +1,7 @@ import numpy as np -# this function need to be finished +# a function to be finished def cos_to_be_finished(x): # TODO: to be finished return @@ -28,5 +28,3 @@ def cos(x: float = 0.): """ return np.cos(x) - -