Skip to content

Fix all style/type errors in existing code #111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion monai/deploy/cli/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# limitations under the License.


from main import main
from main import main # type: ignore # for pytype

if __name__ == "__main__":
main()
138 changes: 65 additions & 73 deletions monai/deploy/core/domain/dicom_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,25 @@ def __init__(self, series_instance_uid):
self._series_instance_uid = series_instance_uid
self._sop_instances = []

# Do not set attributes in advance to save memory

# self._series_date: Any = None
# self._series_time: Any = None
# self._modality: Any = None
# self._series_description: Any = None
# self._body_part_examined: Any = None
# self._patient_position: Any = None
# self._series_number: Any = None
# self._laterality: Any = None
# self._row_pixel_spacing: Any = None
# self._col_pixel_spacing: Any = None
# self._depth_pixel_spacing: Any = None
# self._row_direction_cosine: Any = None
# self._col_direction_cosine: Any = None
# self._depth_direction_cosine: Any = None
# self._dicom_affine_transform: Any = None
# self._nifti_affine_transform: Any = None

def get_series_instance_uid(self):
return self._series_instance_uid

Expand All @@ -33,215 +52,188 @@ def get_sop_instances(self):

@property
def series_date(self):
return self.__series_date
return getattr(self, "_series_date", None)

@series_date.setter
def series_date(self, val):
self.__series_date = val
self._series_date = val

@property
def series_time(self):
return self.__series_time
return getattr(self, "_series_time", None)

@series_time.setter
def series_time(self, val):
self.__series_time = val
self._series_time = val

@property
def modality(self):
return self.__modality
return getattr(self, "_modality", None)

@modality.setter
def modality(self, val):
self.__modality = val
self._modality = val

@property
def series_description(self):
return self.__series_description
return getattr(self, "_series_description", None)

@series_description.setter
def series_description(self, val):
self.__series_description = val
self._series_description = val

@property
def body_part_examined(self):
return self.__body_part_examined
return getattr(self, "_body_part_examined", None)

@body_part_examined.setter
def body_part_examined(self, val):
self.__body_part_examined = val
self._body_part_examined = val

@property
def patient_position(self):
return self.__patient_position
return getattr(self, "_patient_position", None)

@patient_position.setter
def patient_position(self, val):
self.__patient_position = val
self._patient_position = val

@property
def series_number(self):
return self.__series_number
return getattr(self, "_series_number", None)

@series_number.setter
def series_number(self, val):
self.__series_number = val
self._series_number = val

@property
def laterality(self):
return self.__laterality
return getattr(self, "_laterality", None)

@laterality.setter
def laterality(self, val):
self.__laterality = val
self._laterality = val

@property
def row_pixel_spacing(self):
return self.__row_pixel_spacing
return getattr(self, "_row_pixel_spacing", None)

@row_pixel_spacing.setter
def row_pixel_spacing(self, val):
self.__row_pixel_spacing = val
self._row_pixel_spacing = val

@property
def col_pixel_spacing(self):
return self.__col_pixel_spacing
return getattr(self, "_col_pixel_spacing", None)

@col_pixel_spacing.setter
def col_pixel_spacing(self, val):
self.__col_pixel_spacing = val
self._col_pixel_spacing = val

@property
def depth_pixel_spacing(self):
return self.__depth_pixel_spacing
return getattr(self, "_depth_pixel_spacing", None)

@depth_pixel_spacing.setter
def depth_pixel_spacing(self, val):
self.__depth_pixel_spacing = val
self._depth_pixel_spacing = val

@property
def row_direction_cosine(self):
return self.__row_direction_cosine
return getattr(self, "_row_direction_cosine", None)

@row_direction_cosine.setter
def row_direction_cosine(self, val):
self.__row_direction_cosine = val
self._row_direction_cosine = val

@property
def col_direction_cosine(self):
return self.__col_direction_cosine
return getattr(self, "_col_direction_cosine", None)

@col_direction_cosine.setter
def col_direction_cosine(self, val):
self.__col_direction_cosine = val
self._col_direction_cosine = val

@property
def depth_direction_cosine(self):
return self.__depth_direction_cosine
return getattr(self, "_depth_direction_cosine", None)

@depth_direction_cosine.setter
def depth_direction_cosine(self, val):
self.__depth_direction_cosine = val
self._depth_direction_cosine = val

@property
def dicom_affine_transform(self):
return self.__dicom_affine_transform
return getattr(self, "_dicom_affine_transform", None)

@dicom_affine_transform.setter
def dicom_affine_transform(self, val):
self.__dicom_affine_transform = val
self._dicom_affine_transform = val

@property
def nifti_affine_transform(self):
return self.__nifti_affine_transform
return getattr(self, "_nifti_affine_transform", None)

@nifti_affine_transform.setter
def nifti_affine_transform(self, val):
self.__nifti_affine_transform = val
self._nifti_affine_transform = val

def __str__(self):
result = "---------------" + "\n"

series_instance_uid_attr = "Series Instance UID: " + self._series_instance_uid + "\n"
result += series_instance_uid_attr

try:
num_sop_instances = "Num SOP Instances: " + str(len(self._sop_instances)) + "\n"
result += num_sop_instances
except AttributeError:
pass
num_sop_instances = "Num SOP Instances: " + str(len(self._sop_instances)) + "\n"
result += num_sop_instances

try:
if self.series_date is not None:
series_date_attr = "Series Date: " + self.series_date + "\n"
result += series_date_attr
except AttributeError:
pass

try:
if self.series_time is not None:
series_time_attr = "Series Time: " + self.series_time + "\n"
result += series_time_attr
except AttributeError:
pass

try:
if self.modality is not None:
modality_attr = "Modality: " + self.modality + "\n"
result += modality_attr
except AttributeError:
pass

try:
if self.series_description is not None:
series_desc_attr = "Series Description: " + self.series_description + "\n"
result += series_desc_attr
except AttributeError:
pass

try:
if self.row_pixel_spacing is not None:
row_pixel_spacing_attr = "Row Pixel Spacing: " + str(self.row_pixel_spacing) + "\n"
result += row_pixel_spacing_attr
except AttributeError:
pass

try:
if self.col_pixel_spacing is not None:
col_pixel_spacing_attr = "Column Pixel Spacing: " + str(self.col_pixel_spacing) + "\n"
result += col_pixel_spacing_attr
except AttributeError:
pass

try:
if self.depth_pixel_spacing is not None:
depth_pixel_spacing_attr = "Depth Pixel Spacing: " + str(self.depth_pixel_spacing) + "\n"
result += depth_pixel_spacing_attr
except AttributeError:
pass

try:
if self.row_direction_cosine is not None:
row_direction_cosine_attr = "Row Direction Cosine: " + str(self.row_direction_cosine) + "\n"
result += row_direction_cosine_attr
except AttributeError:
pass

try:
if self.col_direction_cosine is not None:
col_direction_cosine_attr = "Column Direction Cosine: " + str(self.col_direction_cosine) + "\n"
result += col_direction_cosine_attr
except AttributeError:
pass

try:
if self.depth_direction_cosine is not None:
depth_direction_cosine_attr = "Depth Direction Cosine: " + str(self.depth_direction_cosine) + "\n"
result += depth_direction_cosine_attr
except AttributeError:
pass

try:
if self.dicom_affine_transform is not None:
dicom_affine_transform_attr = "DICOM affine transform: " + "\n" + str(self.dicom_affine_transform) + "\n"
result += dicom_affine_transform_attr
except AttributeError:
pass

try:
if self.nifti_affine_transform is not None:
nifti_affine_transform_attr = "NIFTI affine transform: " + "\n" + str(self.nifti_affine_transform) + "\n"
result += nifti_affine_transform_attr
except AttributeError:
pass

result += "---------------" + "\n"

Expand Down
21 changes: 12 additions & 9 deletions monai/deploy/core/domain/dicom_sop_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,21 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import Union
from typing import Any, Union

from monai.deploy.utils.importutil import optional_import

from .domain import Domain

DataElement, _ = optional_import("pydicom", name="DataElement")
Dataset, _ = optional_import("pydicom", name="Dataset")
Tag, _ = optional_import("pydicom.tag", name="Tag")
BaseTag, _ = optional_import("pydicom.tag", name="BaseTag")
tag_in_exception, _ = optional_import("pydicom.tag", name="tag_in_exception")
TagType, _ = optional_import("pydicom.tag", name="TagType")
DataElement_, _ = optional_import("pydicom", name="DataElement")
# Dynamic class is not handled so make it Any for now: https://github.com/python/mypy/issues/2477
DataElement: Any = DataElement_
Dataset_, _ = optional_import("pydicom", name="Dataset")
# Dynamic class is not handled so make it Any for now: https://github.com/python/mypy/issues/2477
Dataset: Any = Dataset_
TagType_, _ = optional_import("pydicom.tag", name="TagType")
# Dynamic class is not handled so make it Any for now: https://github.com/python/mypy/issues/2477
TagType: Any = TagType_


class DICOMSOPInstance(Domain):
Expand All @@ -31,12 +34,12 @@ class DICOMSOPInstance(Domain):

def __init__(self, native_sop):
super().__init__(None)
self._sop = native_sop
self._sop: Any = native_sop

def get_native_sop_instance(self):
return self._sop

def __getitem__(self, key: Union[int, slice, "TagType"]) -> Union["Dataset", "DataElement"]:
def __getitem__(self, key: Union[int, slice, TagType]) -> Union[Dataset, DataElement]:
return self._sop.__getitem__(key)

def get_pixel_array(self):
Expand Down
Loading