Commit 3ca6e260 authored by BO ZHANG's avatar BO ZHANG 🏀
Browse files

update example API

parent 37b1bc15
Loading
Loading
Loading
Loading
Loading
+41 −6
Original line number Diff line number Diff line
@@ -28,19 +28,54 @@ Change list

        .. code-block:: python

            import os.path

            import numpy as np
            from astropy.io import fits
            from astropy import table
            from csst_common.status import CsstStatus, CsstResult

            def base_distortion(input_file, output_file, rc="/path/to/gaia_dr3.fits", **kwargs): -> CsstResult:

            def read_data(file_path: str = "/path/to/data") -> np.ndarray:
                return fits.getdata(file_path)


            def _do_step_one(data: np.ndarray) -> np.ndarray:
                reduced_data = np.fliplr(data)
                return reduced_data


            def _do_step_two(data: np.ndarray) -> np.ndarray:
                reduced_data = np.flipud(data)
                return reduced_data


            def _do_step_three(data: np.ndarray, rc="/path/to/catalog") -> np.ndarray:
                trc = table.Table.read(rc)
                return data + np.mean(trc["ra"]) + np.mean(trc["dec"])


            def base_distortion(
                input_file, output_file, rc: str = "/path/to/gaia_dr3.fits", **kwargs
            ) -> CsstResult:
                """your docstring here"""
                # do your calculation
                process(input_file, output_fle)
                # read data
                data = read_data(input_file)
                # do your algorithm
                data = _do_step_one(data)
                data = _do_step_two(data)
                data = _do_step_three(data, rc=rc)
                # write results
                hl = fits.HDUList(fits.PrimaryHDU(data=data))
                hl.writeto(output_file, overwrite=True)
                assert os.path.exists(output_file)
                # construct CsstResult
                result = CsstResult(
                    status=CsstStatus.PERFECT,
                    file_list=[output_file, "an additional output file"]
                    status=CsstStatus.PERFECT, file_list=[output_file, "an additional output file"]
                )
                return result


导入模块
---------