Skip to content

Commit

Permalink
Merge pull request #113 from dvm-shlee/main
Browse files Browse the repository at this point in the history
remove shleeh dependency v0.3.8
  • Loading branch information
dvm-shlee authored Jul 1, 2023
2 parents 75cda67 + 76f9554 commit ee3f658
Show file tree
Hide file tree
Showing 8 changed files with 155 additions and 17 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ build
test
test/*
*.egg-info
*.egg-info/*
*.egg-info/*
.DS_Store
2 changes: 1 addition & 1 deletion brkraw/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from .lib import *

__version__ = '0.3.8-rc1'
__version__ = '0.3.8'
__all__ = ['BrukerLoader', '__version__']


Expand Down
6 changes: 2 additions & 4 deletions brkraw/lib/backup.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from shleeh import *
from shleeh.utils import *
from shleeh.errors import *
from .errors import *
from .loader import BrukerLoader
from .utils import get_dirsize, get_filesize, yes_or_no
from .utils import get_dirsize, get_filesize, yes_or_no, TimeCounter
import os
import sys
import tqdm
Expand Down
125 changes: 125 additions & 0 deletions brkraw/lib/errors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import os


def print_internal_error(io_handler=None):
import traceback
import sys
if io_handler is None:
io_handler = sys.stderr
traceback.print_exception(*sys.exc_info(),
file=io_handler)


class Error(Exception):
""" Base class for other custom exceptions """
message = None


class FileNotValidError(Error):
""" Raised when the file is not valid format """

def __init__(self, file_name=None, data_type=None):
self.file_name = None
self.data_type = None

if file_name is not None:
self.file_name = os.path.basename(file_name)
if os.path.isdir(file_name):
object_type = 'directory'
else:
object_type = 'file'
if data_type is not None:
self.data_type = data_type
self.message = "The {} '{}' is not valid {}".format(object_type,
self.file_name,
self.data_type)
else:
self.message = "The {} '{}' is not valid".format(object_type,
self.file_name)
else:
self.message = "The file is not valid"


class ArchiveFailedError(Error):
""" Raised when the archive process is failed [designed for brkraw module] """
file_name = None

def __init__(self, file_name=None):
if file_name is not None:
self.file_name = os.path.basename(file_name)
self.message = "The data '{}' is not archived".format(
self.file_name)
else:
self.message = "Archive failed to execute"


class RemoveFailedError(Error):
""" Raise when the os.remove process is failed """
file_name = None

def __init__(self, file_name=None):
if file_name is not None:
self.file_name = os.path.basename(file_name)
self.message = "The file '{}' is not removed".format(
self.file_name)
else:
self.message = "Remove failed to execute"


class RenameFailedError(Error):
""" Raised when the os.rename process is failed (OSError)"""
file1_name = None
file2_name = None

def __init__(self, file1_name=None, file2_name=None):
if file1_name is not None:
self.file1_name = os.path.basename(file1_name)
if file2_name is not None:
self.file2_name = os.path.basename(file2_name)
if (self.file1_name is not None) and (self.file2_name is not None):
self.message = "Rename failed to execute from:'{}' to:'{}'".format(self.file1_name,
self.file2_name)
else:
self.message = "Rename failed to execute"


class UnexpectedError(Error):
""" Raised when unexpected error occurred """

def __init__(self, message=None):
print_internal_error()
if message is None:
self.message = "Unexpected error"
else:
self.message = message


class ValueConflictInField(Error):
""" Raised when input value was conflicted with other """

def __init__(self, message=None):
if message is None:
self.message = "The value is conflicted"
else:
self.message = message


class InvalidValueInField(Error):
""" Raise when the invalid value is detected in field """

def __init__(self, message=None):
if message is None:
self.message = "Invalid value is detected"
else:
self.message = message


class InvalidApproach(Error):
""" Raise when the user try invalid approach """

def __init__(self, message=None):
print_internal_error()
if message is None:
self.message = "Invalid approach!"
else:
self.message = message
11 changes: 8 additions & 3 deletions brkraw/lib/loader.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from shleeh import *
from shleeh.errors import *

from .errors import *
from .orient import build_affine_from_orient_info, reversed_pose_correction, get_origin
from .pvobj import PvDatasetDir, PvDatasetZip
from .utils import *
Expand All @@ -13,6 +11,13 @@
import re
import warnings
np.set_printoptions(formatter={'float_kind':'{:f}'.format})
import enum


@enum.unique
class DataType(enum.Enum):
PVDATASET = 1
NIFTI1 = 2


def load(path):
Expand Down
17 changes: 15 additions & 2 deletions brkraw/lib/utils.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
from shleeh.errors import UnexpectedError

from .errors import UnexpectedError
from .reference import *
import re
import os
import numpy as np
from collections import OrderedDict
from functools import partial, reduce
from copy import copy as cp
import time


class TimeCounter:
_start = None

def __init__(self):
self.reset()

def reset(self):
self._start = time.time()

def time(self):
return time.time() - self._start


def load_param(stringlist):
Expand Down
4 changes: 1 addition & 3 deletions brkraw/scripts/brkraw.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# -*- coding: utf-8 -*-
from operator import index
from shleeh import *
from shleeh.errors import *

from ..lib.errors import *
from .. import BrukerLoader, __version__
from ..lib.utils import set_rescale, save_meta_files, mkdir
import argparse
Expand Down
4 changes: 1 addition & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
url=__url__,
license='GNLv3',
packages=find_packages(),
install_requires=['shleeh>=0.1.0',
'nibabel>=3.0.2',
install_requires=['nibabel>=3.0.2',
'numpy>=1.18.0',
'pandas>=1.0.0',
'pillow>=7.1.1',
Expand All @@ -47,7 +46,6 @@
'Intended Audience :: Science/Research',
'Topic :: Scientific/Engineering :: Medical Science Apps.',
'Natural Language :: English',
'Programming Language :: Python :: >3.5'
],
keywords = 'bruker data_handler converter administrator_tool'
)

0 comments on commit ee3f658

Please sign in to comment.