9
9
# See the License for the specific language governing permissions and
10
10
# limitations under the License.
11
11
12
- from os import path , makedirs
12
+ import shutil
13
+ from os import makedirs , path
13
14
from pathlib import Path
14
15
from shutil import copy
15
- import shutil
16
+
16
17
import monai .deploy .core as md
17
18
from monai .deploy .core import DataPath , ExecutionContext , Image , InputContext , IOType , Operator , OutputContext
18
19
@@ -34,10 +35,7 @@ def compute(self, op_input: InputContext, op_output: OutputContext, context: Exe
34
35
raise ValueError ("Expected a folder path for saved_image_folder input" )
35
36
36
37
density_path , mask_path = self ._find_density_and_mask_files (saved_images_folder )
37
- subs = {
38
- "DENSITY_FILE" : path .basename (density_path ),
39
- "MASK_FILE" : path .basename (mask_path )
40
- }
38
+ subs = {"DENSITY_FILE" : path .basename (density_path ), "MASK_FILE" : path .basename (mask_path )}
41
39
42
40
app_output_folder = op_output .get ().path
43
41
publish_folder_name = "publish"
@@ -54,15 +52,17 @@ def compute(self, op_input: InputContext, op_output: OutputContext, context: Exe
54
52
config_render_file .write (CONFIG_RENDER_TXT )
55
53
56
54
# Replace the file name in the CONFIG_META_TXT and save as config.meta
57
- config_meta_txt = CONFIG_META_TXT .replace ("DENSITY_FILE" , subs ["DENSITY_FILE" ]).replace ("MASK_FILE" , subs ["MASK_FILE" ])
55
+ config_meta_txt = CONFIG_META_TXT .replace ("DENSITY_FILE" , subs ["DENSITY_FILE" ]).replace (
56
+ "MASK_FILE" , subs ["MASK_FILE" ]
57
+ )
58
58
with open (path .join (publish_folder_path , "config.meta" ), "w" ) as config_meta_file :
59
59
config_meta_file .write (config_meta_txt )
60
60
61
61
def _find_density_and_mask_files (self , folder_path ):
62
62
density_path = None
63
63
mask_path = None
64
64
65
- for matched_file in Path (folder_path ).rglob ('*' ):
65
+ for matched_file in Path (folder_path ).rglob ("*" ):
66
66
# Need to get the file name in str
67
67
f_name = str (matched_file )
68
68
if path .isfile (f_name ):
@@ -77,6 +77,7 @@ def _find_density_and_mask_files(self, folder_path):
77
77
78
78
raise ValueError ("Cannot find both density and mask nii.gz files." )
79
79
80
+
80
81
CONFIG_META_TXT = """
81
82
{
82
83
"data": [
@@ -937,4 +938,4 @@ def _find_density_and_mask_files(self, folder_path):
937
938
"mode": "CINEMATIC"
938
939
}
939
940
}
940
- """
941
+ """
0 commit comments