From 550a9ab5a9e5ea37f60a268186f9fa16ad24dd66 Mon Sep 17 00:00:00 2001 From: Phillip Chlap Date: Tue, 22 Sep 2020 05:29:41 +0000 Subject: [PATCH] Add Apache licence and setup.py --- .gitignore | 2 +- .vscode/settings.json | 1 + LICENCE.md | 201 ++++++++++++++++++ README.md | 4 +- platipy/__init__.py | 0 platipy/backend/__init__.py | 14 ++ platipy/backend/api.py | 36 +++- platipy/backend/application.py | 14 ++ platipy/backend/client.py | 17 +- platipy/backend/manage.py | 14 ++ platipy/backend/models.py | 14 ++ platipy/backend/sample/sample.py | 21 +- platipy/backend/tasks.py | 18 +- platipy/backend/tests/test_framework.py | 14 ++ platipy/backend/views.py | 20 +- platipy/cli/__init__.py | 0 platipy/cli/run.py | 18 +- platipy/dicom/communication/connector.py | 15 +- platipy/dicom/nifti_to_rtstruct/convert.py | 14 ++ .../nifti_to_rtstruct/export_to_rtstruct.py | 15 ++ .../dicom/nifti_to_rtstruct/gen_contours.py | 14 ++ platipy/dicom/rtstruct_to_nifti/convert.py | 23 +- platipy/dicom/tests/test_convert_nifti.py | 14 ++ platipy/dicom/tests/test_convert_rtstruct.py | 14 ++ platipy/imaging/.vscode/settings.json | 3 - platipy/imaging/__init__.py | 0 platipy/imaging/atlas/__init__.py | 0 .../imaging/atlas/iterative_atlas_removal.py | 18 +- platipy/imaging/atlas/label_fusion.py | 14 ++ platipy/imaging/label/__init__.py | 0 platipy/imaging/label/label_comparison.py | 14 +- platipy/imaging/label/label_operations.py | 13 ++ platipy/imaging/projects/__init__.py | 0 platipy/imaging/projects/bronchus/bronchus.py | 17 +- platipy/imaging/projects/bronchus/run.py | 17 +- platipy/imaging/projects/bronchus/service.py | 18 +- platipy/imaging/projects/cardiac/run.py | 18 +- platipy/imaging/projects/cardiac/service.py | 18 +- platipy/imaging/projects/cardiac/utils.py | 19 +- platipy/imaging/registration/__init__.py | 0 platipy/imaging/registration/registration.py | 17 +- platipy/imaging/tests/__init__.py | 0 platipy/imaging/tests/pull_data.py | 188 ++++++++-------- platipy/imaging/tests/test_bronchus.py | 21 +- platipy/imaging/tests/test_cardiac.py | 30 ++- platipy/imaging/utils/__init__.py | 0 platipy/imaging/utils/tools.py | 15 ++ platipy/imaging/visualisation/Python3DMesh.py | 14 ++ .../visualisation/VesselSurfaces-Auto.py | 14 ++ platipy/imaging/visualisation/__init__.py | 0 .../visualisation/surface_operations.py | 15 +- platipy/imaging/visualisation/tools.py | 18 +- platipy/imaging/visualisation/vis_tools.py | 15 +- platipy/services/dirqa/service.py | 17 +- platipy/services/pinnacle/service.py | 17 +- requirements.txt | 1 - setup.py | 30 +++ 57 files changed, 903 insertions(+), 195 deletions(-) create mode 100644 LICENCE.md create mode 100644 platipy/__init__.py create mode 100644 platipy/cli/__init__.py delete mode 100644 platipy/imaging/.vscode/settings.json create mode 100644 platipy/imaging/__init__.py create mode 100644 platipy/imaging/atlas/__init__.py create mode 100644 platipy/imaging/label/__init__.py create mode 100644 platipy/imaging/projects/__init__.py create mode 100644 platipy/imaging/registration/__init__.py create mode 100644 platipy/imaging/tests/__init__.py create mode 100644 platipy/imaging/utils/__init__.py create mode 100644 platipy/imaging/visualisation/__init__.py create mode 100644 setup.py diff --git a/.gitignore b/.gitignore index 6a7e0379..9634a5f1 100644 --- a/.gitignore +++ b/.gitignore @@ -134,4 +134,4 @@ dicom_data/ .DS_Store # Exclude data files which are dynamically downloaded for tests -platipy/*/tests/data/dynamic +platipy/*/tests/data diff --git a/.vscode/settings.json b/.vscode/settings.json index 8b7a30a4..697119ae 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -6,6 +6,7 @@ "--load-plugins=pylint_flask_sqlalchemy", "--max-line-length=99", "--disable=C0330", + "--disable=C0111", "--disable=W0102", "--disable=W0105", "--init-hook", diff --git a/LICENCE.md b/LICENCE.md new file mode 100644 index 00000000..48fafdf4 --- /dev/null +++ b/LICENCE.md @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2020 University of New South Wales, University of Sydney, Ingham Institute + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/README.md b/README.md index 243ba929..7e1e9470 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,6 @@ applications. The following structure should be observed: - **README.md**: Contains description of tool, authors, etc... - **Sample.ipynb**: Jupyter notebook demonstrating the basics of using the tool - tests/: Directory containing test scripts to be run by pytest - - data/: Directory containing test data. Used by tests but also Jupyter notebooks for demonstration. ### Providing command line functionality with *click* @@ -67,5 +66,4 @@ from the root directory of the toolbox. ## Authors * **Phillip Chlap** - [phillip.chlap@unsw.edu.au](phillip.chlap@unsw.edu.au) - -* **Robert Finnegan** - [rfin5459@uni.sydney.edu.au](rfin5459@uni.sydney.edu.au) \ No newline at end of file +* **Robert Finnegan** - [rfin5459@uni.sydney.edu.au](rfin5459@uni.sydney.edu.au) diff --git a/platipy/__init__.py b/platipy/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/platipy/backend/__init__.py b/platipy/backend/__init__.py index 2bd80227..16a250a2 100644 --- a/platipy/backend/__init__.py +++ b/platipy/backend/__init__.py @@ -1,3 +1,17 @@ +# Copyright 2020 University of New South Wales, University of Sydney, Ingham Institute + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + import os import uuid diff --git a/platipy/backend/api.py b/platipy/backend/api.py index bcd40954..cd4ee2c7 100644 --- a/platipy/backend/api.py +++ b/platipy/backend/api.py @@ -1,20 +1,38 @@ -from platipy.backend import app, api -from loguru import logger +# Copyright 2020 University of New South Wales, University of Sydney, Ingham Institute + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. -import flask_restful -from flask_restful import Api, reqparse -from flask import request, send_from_directory -import werkzeug -import uuid import datetime import json import os import tempfile import time +import uuid +import werkzeug + +from loguru import logger + +import flask_restful +from flask_restful import Api, reqparse +from flask import request, send_from_directory + from functools import wraps -from ..dicom.communication import DicomConnector + +from platipy.backend import app, api +from platipy.dicom.communication import DicomConnector + from .models import db, AlchemyEncoder, APIKey, Dataset, DataObject, DicomLocation -from .tasks import run_task, retrieve_task, listen_task +from .tasks import run_task, retrieve_task class CustomConfig(object): diff --git a/platipy/backend/application.py b/platipy/backend/application.py index 30d44239..36ee72a8 100644 --- a/platipy/backend/application.py +++ b/platipy/backend/application.py @@ -1,3 +1,17 @@ +# Copyright 2020 University of New South Wales, University of Sydney, Ingham Institute + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + from flask import Flask from celery import current_app from celery.bin import worker diff --git a/platipy/backend/client.py b/platipy/backend/client.py index 9033366c..f621df03 100644 --- a/platipy/backend/client.py +++ b/platipy/backend/client.py @@ -1,6 +1,17 @@ -""" -Provides a client to interact with PlatiPy's framework -""" +# Copyright 2020 University of New South Wales, University of Sydney, Ingham Institute + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + import time import os import json diff --git a/platipy/backend/manage.py b/platipy/backend/manage.py index 49a59658..85ec2dd2 100644 --- a/platipy/backend/manage.py +++ b/platipy/backend/manage.py @@ -1,3 +1,17 @@ +# Copyright 2020 University of New South Wales, University of Sydney, Ingham Institute + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + from . import app from .models import db, APIKey diff --git a/platipy/backend/models.py b/platipy/backend/models.py index a2f2a212..43cebfd9 100644 --- a/platipy/backend/models.py +++ b/platipy/backend/models.py @@ -1,3 +1,17 @@ +# Copyright 2020 University of New South Wales, University of Sydney, Ingham Institute + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + from platipy.backend import db import datetime import json diff --git a/platipy/backend/sample/sample.py b/platipy/backend/sample/sample.py index c9e08779..0d529dee 100644 --- a/platipy/backend/sample/sample.py +++ b/platipy/backend/sample/sample.py @@ -1,15 +1,26 @@ -import sys +# Copyright 2020 University of New South Wales, University of Sydney, Ingham Institute + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 -sys.path.append("../../../") +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import sys +import os +import pydicom +import SimpleITK as sitk from loguru import logger from platipy.backend import app, DataObject from platipy.dicom.nifti_to_rtstruct.convert import convert_nifti -import SimpleITK as sitk -import pydicom -import os body_settings_defaults = { "outputContourName": "primitive_body_contour", diff --git a/platipy/backend/tasks.py b/platipy/backend/tasks.py index e6a90c1d..137ee3c3 100644 --- a/platipy/backend/tasks.py +++ b/platipy/backend/tasks.py @@ -1,4 +1,17 @@ -from platipy.backend import celery, db, app +# Copyright 2020 University of New South Wales, University of Sydney, Ingham Institute + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + from celery.schedules import crontab from loguru import logger @@ -9,7 +22,8 @@ import shutil import time -from ..dicom.communication import DicomConnector +from platipy.backend import celery, db, app +from platipy.dicom.communication import DicomConnector from .models import Dataset, DataObject diff --git a/platipy/backend/tests/test_framework.py b/platipy/backend/tests/test_framework.py index 225c1f47..ee339814 100644 --- a/platipy/backend/tests/test_framework.py +++ b/platipy/backend/tests/test_framework.py @@ -1,3 +1,17 @@ +# Copyright 2020 University of New South Wales, University of Sydney, Ingham Institute + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + import pytest import os import json diff --git a/platipy/backend/views.py b/platipy/backend/views.py index c408cad6..235b2942 100644 --- a/platipy/backend/views.py +++ b/platipy/backend/views.py @@ -1,12 +1,26 @@ -from platipy.backend import app, celery, log_file_path -from ..dicom.communication import DicomConnector -from .models import db, APIKey +# Copyright 2020 University of New South Wales, University of Sydney, Ingham Institute + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. from loguru import logger import psutil from flask import Flask, request, render_template, jsonify +from platipy.backend import app, celery, log_file_path +from platipy.dicom.communication import DicomConnector +from .models import db, APIKey + @app.route("/endpoint/add", methods=["GET"]) def add_endpoint(): diff --git a/platipy/cli/__init__.py b/platipy/cli/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/platipy/cli/run.py b/platipy/cli/run.py index 4b6cc463..74e7f897 100644 --- a/platipy/cli/run.py +++ b/platipy/cli/run.py @@ -1,5 +1,16 @@ -"""Provides a command line interface to use the auto-segmentation tools from the command line -""" +# Copyright 2020 University of New South Wales, University of Sydney, Ingham Institute + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. import os import sys @@ -101,6 +112,9 @@ def click_command(algorithm, input_path, config, default, output): for result in results: sitk.WriteImage(results[result], os.path.join(output, f"{result}.nii.gz")) +def platipy_cli(): + click_command() + if __name__ == "__main__": click_command() # pylint: disable=no-value-for-parameter diff --git a/platipy/dicom/communication/connector.py b/platipy/dicom/communication/connector.py index c7a67d7a..d21a9f0f 100644 --- a/platipy/dicom/communication/connector.py +++ b/platipy/dicom/communication/connector.py @@ -1,3 +1,17 @@ +# Copyright 2020 University of New South Wales, University of Sydney, Ingham Institute + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + import os import pydicom import tempfile @@ -11,7 +25,6 @@ ImplicitVRLittleEndian, ExplicitVRBigEndian, ) - from pynetdicom import ( AE, evt, diff --git a/platipy/dicom/nifti_to_rtstruct/convert.py b/platipy/dicom/nifti_to_rtstruct/convert.py index c5a97b61..72b95a51 100644 --- a/platipy/dicom/nifti_to_rtstruct/convert.py +++ b/platipy/dicom/nifti_to_rtstruct/convert.py @@ -1,3 +1,17 @@ +# Copyright 2020 University of New South Wales, University of Sydney, Ingham Institute + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + import click import yaml import sys diff --git a/platipy/dicom/nifti_to_rtstruct/export_to_rtstruct.py b/platipy/dicom/nifti_to_rtstruct/export_to_rtstruct.py index fb671064..b752390a 100644 --- a/platipy/dicom/nifti_to_rtstruct/export_to_rtstruct.py +++ b/platipy/dicom/nifti_to_rtstruct/export_to_rtstruct.py @@ -1,3 +1,18 @@ +# Copyright 2020 University of New South Wales, University of Sydney, Ingham Institute + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + import sys import pydicom import datetime diff --git a/platipy/dicom/nifti_to_rtstruct/gen_contours.py b/platipy/dicom/nifti_to_rtstruct/gen_contours.py index 51fe1a96..fd2846a8 100644 --- a/platipy/dicom/nifti_to_rtstruct/gen_contours.py +++ b/platipy/dicom/nifti_to_rtstruct/gen_contours.py @@ -1,3 +1,17 @@ +# Copyright 2020 University of New South Wales, University of Sydney, Ingham Institute + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + import itk import sys import yaml diff --git a/platipy/dicom/rtstruct_to_nifti/convert.py b/platipy/dicom/rtstruct_to_nifti/convert.py index 5754acdf..e9ebc371 100644 --- a/platipy/dicom/rtstruct_to_nifti/convert.py +++ b/platipy/dicom/rtstruct_to_nifti/convert.py @@ -1,17 +1,24 @@ -#!/usr/bin/env python +# Copyright 2020 University of New South Wales, University of Sydney, Ingham Institute -# -# rtstruct_to_nifti -# Written by Rob Finnegan -# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +import os import click import pydicom +import numpy as np import SimpleITK as sitk from skimage.draw import polygon -import numpy as np -import os -import sys def readDICOMImage(filename): diff --git a/platipy/dicom/tests/test_convert_nifti.py b/platipy/dicom/tests/test_convert_nifti.py index 630193c9..a968877f 100644 --- a/platipy/dicom/tests/test_convert_nifti.py +++ b/platipy/dicom/tests/test_convert_nifti.py @@ -1,3 +1,17 @@ +# Copyright 2020 University of New South Wales, University of Sydney, Ingham Institute + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + import os import pydicom import numpy as np diff --git a/platipy/dicom/tests/test_convert_rtstruct.py b/platipy/dicom/tests/test_convert_rtstruct.py index 76aeaf0f..5f39a9cd 100644 --- a/platipy/dicom/tests/test_convert_rtstruct.py +++ b/platipy/dicom/tests/test_convert_rtstruct.py @@ -1,3 +1,17 @@ +# Copyright 2020 University of New South Wales, University of Sydney, Ingham Institute + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + import os import SimpleITK as sitk diff --git a/platipy/imaging/.vscode/settings.json b/platipy/imaging/.vscode/settings.json deleted file mode 100644 index de288e1e..00000000 --- a/platipy/imaging/.vscode/settings.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "python.formatting.provider": "black" -} \ No newline at end of file diff --git a/platipy/imaging/__init__.py b/platipy/imaging/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/platipy/imaging/atlas/__init__.py b/platipy/imaging/atlas/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/platipy/imaging/atlas/iterative_atlas_removal.py b/platipy/imaging/atlas/iterative_atlas_removal.py index e6ed05b4..f3b3540f 100644 --- a/platipy/imaging/atlas/iterative_atlas_removal.py +++ b/platipy/imaging/atlas/iterative_atlas_removal.py @@ -1,7 +1,17 @@ -""" -Provides tools to perform iterative atlas removal for use within -atlas based segmentation algorithms. -""" +# Copyright 2020 University of New South Wales, University of Sydney, Ingham Institute + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + import sys diff --git a/platipy/imaging/atlas/label_fusion.py b/platipy/imaging/atlas/label_fusion.py index 1a4437ed..4940356c 100644 --- a/platipy/imaging/atlas/label_fusion.py +++ b/platipy/imaging/atlas/label_fusion.py @@ -1,3 +1,17 @@ +# Copyright 2020 University of New South Wales, University of Sydney, Ingham Institute + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + from functools import reduce diff --git a/platipy/imaging/label/__init__.py b/platipy/imaging/label/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/platipy/imaging/label/label_comparison.py b/platipy/imaging/label/label_comparison.py index 30073e3b..ed562cd1 100644 --- a/platipy/imaging/label/label_comparison.py +++ b/platipy/imaging/label/label_comparison.py @@ -1,4 +1,16 @@ -#!/usr/bin/python +# Copyright 2020 University of New South Wales, University of Sydney, Ingham Institute + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. """ Module name: LabelComparison diff --git a/platipy/imaging/label/label_operations.py b/platipy/imaging/label/label_operations.py index 0630d6ca..c4b5588c 100644 --- a/platipy/imaging/label/label_operations.py +++ b/platipy/imaging/label/label_operations.py @@ -1,3 +1,16 @@ +# Copyright 2020 University of New South Wales, University of Sydney, Ingham Institute + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. import itk import numpy as np diff --git a/platipy/imaging/projects/__init__.py b/platipy/imaging/projects/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/platipy/imaging/projects/bronchus/bronchus.py b/platipy/imaging/projects/bronchus/bronchus.py index 5af773e7..c70d2dec 100644 --- a/platipy/imaging/projects/bronchus/bronchus.py +++ b/platipy/imaging/projects/bronchus/bronchus.py @@ -1,5 +1,18 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- +# Copyright 2020 University of New South Wales, University of Sydney, Ingham Institute + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + """ Created on Wed Feb 21 16:39:27 2018 diff --git a/platipy/imaging/projects/bronchus/run.py b/platipy/imaging/projects/bronchus/run.py index bdf72265..d370bf02 100644 --- a/platipy/imaging/projects/bronchus/run.py +++ b/platipy/imaging/projects/bronchus/run.py @@ -1,6 +1,17 @@ -""" -Service to run bronchus segmentation. -""" +# Copyright 2020 University of New South Wales, University of Sydney, Ingham Institute + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + import tempfile from loguru import logger diff --git a/platipy/imaging/projects/bronchus/service.py b/platipy/imaging/projects/bronchus/service.py index 3aac09c0..249136d6 100644 --- a/platipy/imaging/projects/bronchus/service.py +++ b/platipy/imaging/projects/bronchus/service.py @@ -1,6 +1,18 @@ -""" -Service to run bronchus segmentation. -""" +# Copyright 2020 University of New South Wales, University of Sydney, Ingham Institute + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + import os # import pydicom diff --git a/platipy/imaging/projects/cardiac/run.py b/platipy/imaging/projects/cardiac/run.py index fd78de92..6ae2f7fb 100644 --- a/platipy/imaging/projects/cardiac/run.py +++ b/platipy/imaging/projects/cardiac/run.py @@ -1,6 +1,18 @@ -""" -Service to run cardiac segmentation. -""" +# Copyright 2020 University of New South Wales, University of Sydney, Ingham Institute + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + import tempfile import SimpleITK as sitk diff --git a/platipy/imaging/projects/cardiac/service.py b/platipy/imaging/projects/cardiac/service.py index 2dd12f63..9c229054 100644 --- a/platipy/imaging/projects/cardiac/service.py +++ b/platipy/imaging/projects/cardiac/service.py @@ -1,8 +1,18 @@ -""" -Service to run multi-atlas based cardiac segmentation. +# Copyright 2020 University of New South Wales, University of Sydney, Ingham Institute + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + -Rob Finnegan -""" import os import SimpleITK as sitk diff --git a/platipy/imaging/projects/cardiac/utils.py b/platipy/imaging/projects/cardiac/utils.py index 4c0c73d0..475c696b 100644 --- a/platipy/imaging/projects/cardiac/utils.py +++ b/platipy/imaging/projects/cardiac/utils.py @@ -1,9 +1,18 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -""" -Created on Tues Aug 13 +# Copyright 2020 University of New South Wales, University of Sydney, Ingham Institute + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + -""" import os import re import sys diff --git a/platipy/imaging/registration/__init__.py b/platipy/imaging/registration/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/platipy/imaging/registration/registration.py b/platipy/imaging/registration/registration.py index 3d2ddb6d..5b68847c 100644 --- a/platipy/imaging/registration/registration.py +++ b/platipy/imaging/registration/registration.py @@ -1,6 +1,17 @@ -""" -Provides tools to perform registration for use within atlas based segmentation algorithms. -""" +# Copyright 2020 University of New South Wales, University of Sydney, Ingham Institute + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + import sys import numpy as np diff --git a/platipy/imaging/tests/__init__.py b/platipy/imaging/tests/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/platipy/imaging/tests/pull_data.py b/platipy/imaging/tests/pull_data.py index ff633331..585a9478 100644 --- a/platipy/imaging/tests/pull_data.py +++ b/platipy/imaging/tests/pull_data.py @@ -1,6 +1,17 @@ -""" -Functions to pull data for tests -""" +# Copyright 2020 University of New South Wales, University of Sydney, Ingham Institute + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + import os import json @@ -21,78 +32,9 @@ series_endpoint = f"{API_URL}/query/getSeries" download_series = f"{API_URL}/query/getImage" -datasets = { - "lung": { - "collection": "LCTSC", - "modalities": ["CT", "RTSTRUCT"], - "patient_ids": [ - "LCTSC-Train-S1-001", - "LCTSC-Train-S1-002", - "LCTSC-Train-S1-003", - "LCTSC-Train-S1-004", - "LCTSC-Train-S1-005", - "LCTSC-Train-S1-006", - "LCTSC-Train-S1-007", - "LCTSC-Train-S1-008", - "LCTSC-Train-S1-009", - "LCTSC-Train-S1-010", - "LCTSC-Train-S1-011", - "LCTSC-Train-S1-012", - "LCTSC-Train-S2-001", - "LCTSC-Train-S2-002", - "LCTSC-Train-S2-003", - "LCTSC-Train-S2-004", - "LCTSC-Train-S2-005", - "LCTSC-Train-S2-006", - "LCTSC-Train-S2-007", - "LCTSC-Train-S2-008", - "LCTSC-Train-S2-009", - "LCTSC-Train-S2-010", - "LCTSC-Train-S2-011", - "LCTSC-Train-S2-012", - "LCTSC-Train-S3-001", - "LCTSC-Train-S3-002", - "LCTSC-Train-S3-003", - "LCTSC-Train-S3-004", - "LCTSC-Train-S3-005", - "LCTSC-Train-S3-006", - "LCTSC-Train-S3-007", - "LCTSC-Train-S3-008", - "LCTSC-Train-S3-009", - "LCTSC-Train-S3-010", - "LCTSC-Train-S3-011", - "LCTSC-Train-S3-012", - "LCTSC-Test-S1-101", - "LCTSC-Test-S1-102", - "LCTSC-Test-S1-103", - "LCTSC-Test-S1-104", - "LCTSC-Test-S1-201", - "LCTSC-Test-S1-202", - "LCTSC-Test-S1-203", - "LCTSC-Test-S1-204", - "LCTSC-Test-S2-101", - "LCTSC-Test-S2-102", - "LCTSC-Test-S2-103", - "LCTSC-Test-S2-104", - "LCTSC-Test-S2-201", - "LCTSC-Test-S2-202", - "LCTSC-Test-S2-203", - "LCTSC-Test-S2-204", - "LCTSC-Test-S3-101", - "LCTSC-Test-S3-102", - "LCTSC-Test-S3-103", - "LCTSC-Test-S3-104", - "LCTSC-Test-S3-201", - "LCTSC-Test-S3-202", - "LCTSC-Test-S3-203", - "LCTSC-Test-S3-204", - ], - } -} - def get_lung_data(number_of_patients=3): - """Gets some images and structures from the LCTSC (Lung) dataset in TCIA. + """Gets some images and structures from the Head-Neck-Radiomics-HN1 (HN) dataset in TCIA. Keyword Arguments: number_of_patients {int} -- The number of patients to fetch (default: {3}) @@ -101,45 +43,83 @@ def get_lung_data(number_of_patients=3): dict -- dictionary of patient ids as key and path to data as value """ - return fetch_data("lung", datasets["lung"]["patient_ids"][0:number_of_patients]) + collection = "LCTSC" + patient_ids = get_patients_in_collection(collection) + return fetch_data(collection, patient_ids=patient_ids[0:number_of_patients]) + + +def get_hn_data(number_of_patients=3): + """Gets some images and structures from the HN (Lung) dataset in TCIA. + + Keyword Arguments: + number_of_patients {int} -- The number of patients to fetch (default: {3}) + + Returns: + dict -- dictionary of patient ids as key and path to data as value + """ + collection = "HEAD-NECK-RADIOMICS-HN1" + patient_ids = get_patients_in_collection(collection) + return fetch_data(collection, patient_ids=patient_ids[0:number_of_patients]) -def fetch_data(dataset, patient_ids=None): + +def get_patients_in_collection(collection): + """Get a list of sorted patient IDs in a TCIA collection + + Args: + collection (str): TCIA collection + + Returns: + list: List of sorted Patient IDs in the collection + """ + + res = requests.get(patient_endpoint, params={"Collection": collection}) + patient_ids = [pat["PatientID"] for pat in res.json()] + patient_ids.sort() + + return patient_ids + + +def fetch_data( + collection, patient_ids=None, output_directory=None, save_nifti=True, save_dicom=False +): """Fetches data from TCIA from the dataset specified Args: - dataset (str): The platipy id of the dataset to fetch from (see datasets) + collection (str): The TCIA collection to fetch from patient_ids (list, optional): The patient IDs to fetch. If not set all patients are fetched. + output_directory (str): The directory in which to place fetched data + save_nifti (bool): Whether or not to save the data as Nifti in the output directory + save_dicom (bool): Whether or not to save the data as Dicom in the output directory Returns: - dict: The patients and directories where their data was fetched to + dict: The patients and directories where their data was fetched """ result = {} - data_directory = os.path.join(os.path.dirname(__file__), "data", "dynamic", dataset) + if not output_directory: + output_directory = os.path.join(os.path.dirname(__file__), "data", collection) - os.makedirs(data_directory, exist_ok=True) + os.makedirs(output_directory, exist_ok=True) - collection = datasets[dataset]["collection"] - modalities = datasets[dataset]["modalities"] + modalities = ["CT", "RTSTRUCT"] if not patient_ids: - patient_ids = datasets[dataset]["patient_ids"] + patient_ids = get_patients_in_collection(collection) for pid in patient_ids: - output_directory = os.path.join(data_directory, pid) - result[pid] = output_directory - if os.path.exists(output_directory): - logger.debug(f"Path exists: {output_directory}, won't fetch data") + patient_directory = os.path.join(output_directory, pid) + result[pid] = patient_directory + if os.path.exists(patient_directory): + logger.debug(f"Path exists: {patient_directory}, won't fetch data") continue logger.debug(f"Fetching data for Patient: {pid}") res = requests.get( - series_endpoint, - params={"Collection": collection, "PatientID": pid, "Modality": "CT"}, + series_endpoint, params={"Collection": collection, "PatientID": pid, "Modality": "CT"}, ) series = json.loads(res.text) series_fetched = {} @@ -160,25 +140,29 @@ def fetch_data(dataset, patient_ids=None): for chunk in response.iter_content(): file_obj.write(chunk) - directory_to_extract_to = os.path.join( - working_dir, pid, obj["Modality"] - ) + directory_to_extract_to = os.path.join(working_dir, pid, obj["Modality"]) with zipfile.ZipFile(save_path, "r") as zip_ref: zip_ref.extractall(directory_to_extract_to) series_fetched[obj["Modality"]] = directory_to_extract_to - ct_dir = series_fetched["CT"] - rts_file = os.path.join( - series_fetched["RTSTRUCT"], os.listdir(series_fetched["RTSTRUCT"])[0] - ) - convert_rtstruct( - ct_dir, - rts_file, - prefix="Struct_", - output_dir=output_directory, - output_img="CT.nii.gz", - ) + if save_dicom: + shutil.copytree( + directory_to_extract_to, os.path.join(patient_directory, "dicom") + ) + + if save_nifti: + ct_dir = series_fetched["CT"] + rts_file = os.path.join( + series_fetched["RTSTRUCT"], os.listdir(series_fetched["RTSTRUCT"])[0] + ) + convert_rtstruct( + ct_dir, + rts_file, + prefix="Struct_", + output_dir=patient_directory, + output_img="CT.nii.gz", + ) # Remove the working files shutil.rmtree(working_dir) diff --git a/platipy/imaging/tests/test_bronchus.py b/platipy/imaging/tests/test_bronchus.py index 6cd21f09..fd8dec73 100644 --- a/platipy/imaging/tests/test_bronchus.py +++ b/platipy/imaging/tests/test_bronchus.py @@ -1,6 +1,17 @@ -""" -Tests for bronchus segmentation -""" +# Copyright 2020 University of New South Wales, University of Sydney, Ingham Institute + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + # pylint: disable=redefined-outer-name import tempfile @@ -12,7 +23,7 @@ import SimpleITK as sitk import numpy as np -from platipy.imaging.tests.pull_data import get_lung_data +from platipy.imaging.tests.pull_data import fetch_data from platipy.imaging.projects.bronchus.bronchus import ( generate_lung_mask, @@ -33,7 +44,7 @@ def bronchus_data(): Returns: dict -- Data for broncus test """ - return get_lung_data(number_of_patients=1) + return fetch_data("LCTSC", patient_ids=["LCTSC-Train-S1-001"]) def assert_lung_mask(lung_mask): diff --git a/platipy/imaging/tests/test_cardiac.py b/platipy/imaging/tests/test_cardiac.py index f8ff0cfa..643698e1 100644 --- a/platipy/imaging/tests/test_cardiac.py +++ b/platipy/imaging/tests/test_cardiac.py @@ -1,6 +1,17 @@ -""" -Tests for cardiac atlas -""" +# Copyright 2020 University of New South Wales, University of Sydney, Ingham Institute + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + # pylint: disable=redefined-outer-name import os @@ -10,7 +21,7 @@ import SimpleITK as sitk -from platipy.imaging.tests.pull_data import get_lung_data +from platipy.imaging.tests.pull_data import fetch_data # os.environ["ATLAS_PATH"] = os.path.join(os.path.dirname(__file__), "data", "lung") @@ -28,7 +39,16 @@ def cardiac_data(): Returns: dict -- Data for cardiac test """ - return get_lung_data(number_of_patients=5) + return fetch_data( + "LCTSC", + patient_ids=[ + "LCTSC-Train-S1-001", + "LCTSC-Train-S1-002", + "LCTSC-Train-S1-003", + "LCTSC-Train-S1-004", + "LCTSC-Train-S1-005", + ], + ) def test_cardiac_service(cardiac_data): diff --git a/platipy/imaging/utils/__init__.py b/platipy/imaging/utils/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/platipy/imaging/utils/tools.py b/platipy/imaging/utils/tools.py index 562e79eb..e28795b5 100644 --- a/platipy/imaging/utils/tools.py +++ b/platipy/imaging/utils/tools.py @@ -1,3 +1,18 @@ +# Copyright 2020 University of New South Wales, University of Sydney, Ingham Institute + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + """ Various useful utility functions for atlas based segmentation algorithms. """ diff --git a/platipy/imaging/visualisation/Python3DMesh.py b/platipy/imaging/visualisation/Python3DMesh.py index 9ce2d5b7..64b34f30 100644 --- a/platipy/imaging/visualisation/Python3DMesh.py +++ b/platipy/imaging/visualisation/Python3DMesh.py @@ -1,3 +1,17 @@ +# Copyright 2020 University of New South Wales, University of Sydney, Ingham Institute + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + import numpy as np import SimpleITK as sitk import os diff --git a/platipy/imaging/visualisation/VesselSurfaces-Auto.py b/platipy/imaging/visualisation/VesselSurfaces-Auto.py index f03d1265..f62ab551 100644 --- a/platipy/imaging/visualisation/VesselSurfaces-Auto.py +++ b/platipy/imaging/visualisation/VesselSurfaces-Auto.py @@ -1,3 +1,17 @@ +# Copyright 2020 University of New South Wales, University of Sydney, Ingham Institute + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + import numpy as np import SimpleITK as sitk import os diff --git a/platipy/imaging/visualisation/__init__.py b/platipy/imaging/visualisation/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/platipy/imaging/visualisation/surface_operations.py b/platipy/imaging/visualisation/surface_operations.py index a470f9ef..4b8a1e81 100644 --- a/platipy/imaging/visualisation/surface_operations.py +++ b/platipy/imaging/visualisation/surface_operations.py @@ -1,4 +1,17 @@ -#!/usr/bin/python +# Copyright 2020 University of New South Wales, University of Sydney, Ingham Institute + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + """ Script name: Surface Operations diff --git a/platipy/imaging/visualisation/tools.py b/platipy/imaging/visualisation/tools.py index 4f7a68a9..59c1ee59 100644 --- a/platipy/imaging/visualisation/tools.py +++ b/platipy/imaging/visualisation/tools.py @@ -1,10 +1,16 @@ -""" +# Copyright 2020 University of New South Wales, University of Sydney, Ingham Institute +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at -Author: Rob Finnegan & Phillip Chlap +# http://www.apache.org/licenses/LICENSE-2.0 - -""" +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. import SimpleITK as sitk @@ -52,7 +58,7 @@ class ImageVisualiser: """Class to assist with visualising images and overlaying contours, scalars and bounding boxes. """ - def __init__(self, image, cut=None): + def __init__(self, image, cut=None, window=[-250, 500]): self.__set_image(image) self.__contours = [] self.__bounding_boxes = [] @@ -62,7 +68,7 @@ def __init__(self, image, cut=None): self.__show_colorbar = False self.__figure = None self.__figure_size = 6 - self.__window = [-250, 500] + self.__window = window self.__axis = "ortho" self.__cut = cut diff --git a/platipy/imaging/visualisation/vis_tools.py b/platipy/imaging/visualisation/vis_tools.py index 9bdb9cef..761fad1f 100644 --- a/platipy/imaging/visualisation/vis_tools.py +++ b/platipy/imaging/visualisation/vis_tools.py @@ -1,4 +1,17 @@ -#!/usr/bin/python +# Copyright 2020 University of New South Wales, University of Sydney, Ingham Institute + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + """ Module name: Visualisation diff --git a/platipy/services/dirqa/service.py b/platipy/services/dirqa/service.py index f01f98ff..b69a6d52 100644 --- a/platipy/services/dirqa/service.py +++ b/platipy/services/dirqa/service.py @@ -1,6 +1,17 @@ -""" -Service to run DIRQA tool. -""" +# Copyright 2020 University of New South Wales, University of Sydney, Ingham Institute + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + import os import subprocess diff --git a/platipy/services/pinnacle/service.py b/platipy/services/pinnacle/service.py index 9b22963c..4c4997e5 100644 --- a/platipy/services/pinnacle/service.py +++ b/platipy/services/pinnacle/service.py @@ -1,6 +1,17 @@ -""" -Service to run Pinnacle Export. -""" +# Copyright 2020 University of New South Wales, University of Sydney, Ingham Institute + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + import os import tarfile import tempfile diff --git a/requirements.txt b/requirements.txt index a9394ed7..7c821d49 100644 --- a/requirements.txt +++ b/requirements.txt @@ -15,7 +15,6 @@ celery redis loguru psutil -pyradiomics gunicorn requests pandas diff --git a/setup.py b/setup.py new file mode 100644 index 00000000..51b47c0b --- /dev/null +++ b/setup.py @@ -0,0 +1,30 @@ +import setuptools + +with open("README.md", "r") as fh: + long_description = fh.read() + +with open('requirements.txt', 'r') as fp: + requirements = list(filter(bool, (line.strip() for line in fp))) + +setuptools.setup( + name="platipy", + version="2020.1", + author="Phillip Chlap & Robert Finnegan", + author_email="", + description="Processing Library and Analysis Toolkit for Medical Imaging in Python", + long_description=long_description, + long_description_content_type="text/markdown", + url="https://github.com/pyplati/platipy", + packages=setuptools.find_packages(), + classifiers=[ + "Programming Language :: Python :: 3", + "License :: OSI Approved :: Apache 2.0 License", + "Operating System :: OS Independent", + ], + entry_points={ + 'console_scripts': [ + 'platipy=platipy.cli.run:platipy_cli', + ]}, + license='Apache 2.0 License', + install_requires=requirements, +)