Skip to content

Commit

Permalink
improve python code
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosuc3m committed Dec 14, 2023
1 parent 6d9d6a9 commit 70d4e74
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
31 changes: 27 additions & 4 deletions python/ops/stardist_postprocessing/stardist_postprocessing.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
###
# #%L
# Use deep learning frameworks from Java in an agnostic and isolated way.
# %%
# Copyright (C) 2022 - 2023 Institut Pasteur and BioImage.IO developers.
# %%
# 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.
# #L%
###
from time import time
t = time()
import numpy as np
Expand All @@ -11,14 +30,18 @@
t = time()
import sys
import re
import os
ENV_DIR = os.path.dirname(sys.executable if os.name == 'nt' else os.path.dirname(sys.executable))
SITE_PACKAGES_DIR = os.path.join(ENV_DIR, "lib")
if os.name != 'nt':
PATTERN = r"python3\.\d{1,2}$"
matching_files = [file for file in file_list if re.match(pattern, file)]
SITE_PACKAGES_DIR = os.path.join(SITE_PACKAGES_DIR, matching_files[0])
if os.path.isdir(SITE_PACKAGES_DIR + "/python" + sys.version_info[0] + "." + sys.version_info[1]):
SITE_PACKAGES_DIR = os.path.join(SITE_PACKAGES_DIR, "python" + sys.version_info[0] + "." + sys.version_info[1])
else:
PATTERN = r"python3\.\d{1,2}$"
matching_files = [file for file in os.listdir(SITE_PACKAGES_DIR) if re.match(PATTERN, file)]
SITE_PACKAGES_DIR = os.path.join(SITE_PACKAGES_DIR, matching_files[0])
STARDIST_DIR = os.path.join(SITE_PACKAGES_DIR, "site-packages", "stardist", "lib")
sys.path.append(os.path.join(STARDIST_DIR)
sys.path.append(os.path.join(STARDIST_DIR))
from stardist2d import c_non_max_suppression_inds
print("impot nms star " + str(time() - t))
t = time()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@
ENV_DIR = os.path.dirname(sys.executable if os.name == 'nt' else os.path.dirname(sys.executable))
SITE_PACKAGES_DIR = os.path.join(ENV_DIR, "lib")
if os.name != 'nt':
PATTERN = r"python3\.\d{1,2}$"
matching_files = [file for file in os.listdir(SITE_PACKAGES_DIR) if re.match(PATTERN, file)]
SITE_PACKAGES_DIR = os.path.join(SITE_PACKAGES_DIR, matching_files[0])
if os.path.isdir(SITE_PACKAGES_DIR + "/python" + sys.version_info[0] + "." + sys.version_info[1]):
SITE_PACKAGES_DIR = os.path.join(SITE_PACKAGES_DIR, "python" + sys.version_info[0] + "." + sys.version_info[1])
else:
PATTERN = r"python3\.\d{1,2}$"
matching_files = [file for file in os.listdir(SITE_PACKAGES_DIR) if re.match(PATTERN, file)]
SITE_PACKAGES_DIR = os.path.join(SITE_PACKAGES_DIR, matching_files[0])
STARDIST_DIR = os.path.join(SITE_PACKAGES_DIR, "site-packages", "stardist", "lib")
sys.path.append(os.path.join(STARDIST_DIR))
from stardist2d import c_non_max_suppression_inds
Expand Down

0 comments on commit 70d4e74

Please sign in to comment.