From 7e147103c5605364130711f13a8bdee94aa3c632 Mon Sep 17 00:00:00 2001 From: Wenqi Li Date: Thu, 31 Aug 2023 15:02:35 +0100 Subject: [PATCH 1/3] update properties Signed-off-by: Wenqi Li --- .gitignore | 1 + docs/Makefile | 2 ++ docs/requirements.txt | 2 +- docs/source/bundle_intro.rst | 1 + docs/source/mb_properties.rst | 30 ++++++++++++++++++++++++++++++ monai/bundle/properties.py | 16 ++++++++++++++++ 6 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 docs/source/mb_properties.rst diff --git a/.gitignore b/.gitignore index c6aea2258b..7c81bfaf87 100644 --- a/.gitignore +++ b/.gitignore @@ -70,6 +70,7 @@ instance/ # Sphinx documentation docs/build/ docs/source/_gen +docs/source/*_properties.csv _build/ # PyBuilder diff --git a/docs/Makefile b/docs/Makefile index 5dcb45d6df..ee0516a371 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -21,8 +21,10 @@ help: # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). %: Makefile PIP_ROOT_USER_ACTION=ignore pip install -r requirements.txt + python -m monai.bundle.properties # generate bundle properties markdown @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) clean: rm -rf build/ rm -rf source/_gen + rm -rf source/*_properties.csv diff --git a/docs/requirements.txt b/docs/requirements.txt index 701b7998a9..c4bd50ec2b 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -33,7 +33,7 @@ jsonschema pynrrd pydicom h5py -nni +nni; platform_system == "Linux" optuna opencv-python-headless onnx>=1.13.0 diff --git a/docs/source/bundle_intro.rst b/docs/source/bundle_intro.rst index c43093db96..b4a185ba25 100644 --- a/docs/source/bundle_intro.rst +++ b/docs/source/bundle_intro.rst @@ -8,6 +8,7 @@ Bundle mb_specification config_syntax.md + mb_properties Detailed bundle examples and get started tutorial: https://github.com/Project-MONAI/tutorials/tree/main/bundle diff --git a/docs/source/mb_properties.rst b/docs/source/mb_properties.rst new file mode 100644 index 0000000000..f261480f55 --- /dev/null +++ b/docs/source/mb_properties.rst @@ -0,0 +1,30 @@ +MONAI Bundle Properties +======================= + + +Train properties +---------------- + +.. csv-table:: + :header-rows: 1 + :file: train_properties.csv + :class: longtable + :widths: 10, 55, 5, 30 + +Infer properties +---------------- + +.. csv-table:: + :header-rows: 1 + :file: infer_properties.csv + :class: longtable + :widths: 10, 55, 5, 30 + +Meta properties +--------------- + +.. csv-table:: + :header-rows: 1 + :file: meta_properties.csv + :class: longtable + :widths: 10, 55, 5, 30 diff --git a/monai/bundle/properties.py b/monai/bundle/properties.py index a75e862a84..428370b500 100644 --- a/monai/bundle/properties.py +++ b/monai/bundle/properties.py @@ -260,3 +260,19 @@ BundlePropertyConfig.ID: f"_meta_{ID_SEP_KEY}network_data_format{ID_SEP_KEY}outputs{ID_SEP_KEY}pred{ID_SEP_KEY}channel_def", }, } + + +if __name__ == "__main__": + import os + + import pandas as pd + + html_path = os.path.join("docs", "source") + csv_file = os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, html_path, "train_properties.csv") + pd.DataFrame.from_dict(TrainProperties, orient="index").iloc[:, :3].to_csv(csv_file) + + csv_file = os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, html_path, "infer_properties.csv") + pd.DataFrame.from_dict(InferProperties, orient="index").iloc[:, :3].to_csv(csv_file) + + csv_file = os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, html_path, "meta_properties.csv") + pd.DataFrame.from_dict(MetaProperties, orient="index").iloc[:, :3].to_csv(csv_file) From bfeb61e30614ea87aedf43c2727098b094564d02 Mon Sep 17 00:00:00 2001 From: Wenqi Li Date: Thu, 31 Aug 2023 15:14:51 +0100 Subject: [PATCH 2/3] update Signed-off-by: Wenqi Li --- docs/Makefile | 1 - docs/source/conf.py | 14 +++++++++++++- monai/bundle/properties.py | 16 ---------------- 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/docs/Makefile b/docs/Makefile index ee0516a371..57b69ce273 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -21,7 +21,6 @@ help: # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). %: Makefile PIP_ROOT_USER_ACTION=ignore pip install -r requirements.txt - python -m monai.bundle.properties # generate bundle properties markdown @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) clean: diff --git a/docs/source/conf.py b/docs/source/conf.py index d04ff6acac..b0087a954c 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -55,7 +55,19 @@ def generate_apidocs(*args): """Generate API docs automatically by trawling the available modules""" - module_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", "monai")) + + import pandas as pd + from monai.bundle.properties import TrainProperties, InferProperties, MetaProperties + + csv_file = os.path.join(os.path.dirname(__file__), "train_properties.csv") # used in mb_properties.rst + pd.DataFrame.from_dict(TrainProperties, orient="index").iloc[:, :3].to_csv(csv_file) + csv_file = os.path.join(os.path.dirname(__file__), "infer_properties.csv") + pd.DataFrame.from_dict(InferProperties, orient="index").iloc[:, :3].to_csv(csv_file) + csv_file = os.path.join(os.path.dirname(__file__), "meta_properties.csv") + pd.DataFrame.from_dict(MetaProperties, orient="index").iloc[:, :3].to_csv(csv_file) + + + module_path = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, "monai")) output_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "apidocs")) apidoc_command_path = "sphinx-apidoc" if hasattr(sys, "real_prefix"): # called from a virtualenv diff --git a/monai/bundle/properties.py b/monai/bundle/properties.py index 428370b500..a75e862a84 100644 --- a/monai/bundle/properties.py +++ b/monai/bundle/properties.py @@ -260,19 +260,3 @@ BundlePropertyConfig.ID: f"_meta_{ID_SEP_KEY}network_data_format{ID_SEP_KEY}outputs{ID_SEP_KEY}pred{ID_SEP_KEY}channel_def", }, } - - -if __name__ == "__main__": - import os - - import pandas as pd - - html_path = os.path.join("docs", "source") - csv_file = os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, html_path, "train_properties.csv") - pd.DataFrame.from_dict(TrainProperties, orient="index").iloc[:, :3].to_csv(csv_file) - - csv_file = os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, html_path, "infer_properties.csv") - pd.DataFrame.from_dict(InferProperties, orient="index").iloc[:, :3].to_csv(csv_file) - - csv_file = os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, html_path, "meta_properties.csv") - pd.DataFrame.from_dict(MetaProperties, orient="index").iloc[:, :3].to_csv(csv_file) From 126dd9e7abd4ef40cd7a1e0f0b90bfddf8c4d507 Mon Sep 17 00:00:00 2001 From: Wenqi Li Date: Thu, 31 Aug 2023 15:20:12 +0100 Subject: [PATCH 3/3] style fix Signed-off-by: Wenqi Li --- docs/source/conf.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index b0087a954c..86131c565c 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -59,14 +59,13 @@ def generate_apidocs(*args): import pandas as pd from monai.bundle.properties import TrainProperties, InferProperties, MetaProperties - csv_file = os.path.join(os.path.dirname(__file__), "train_properties.csv") # used in mb_properties.rst + csv_file = os.path.join(os.path.dirname(__file__), "train_properties.csv") # used in mb_properties.rst pd.DataFrame.from_dict(TrainProperties, orient="index").iloc[:, :3].to_csv(csv_file) csv_file = os.path.join(os.path.dirname(__file__), "infer_properties.csv") pd.DataFrame.from_dict(InferProperties, orient="index").iloc[:, :3].to_csv(csv_file) csv_file = os.path.join(os.path.dirname(__file__), "meta_properties.csv") pd.DataFrame.from_dict(MetaProperties, orient="index").iloc[:, :3].to_csv(csv_file) - module_path = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, "monai")) output_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "apidocs")) apidoc_command_path = "sphinx-apidoc"