Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
instance_segmentation_classic
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Maciej Wielgosz
instance_segmentation_classic
Commits
4ec7b9c6
Commit
4ec7b9c6
authored
2 years ago
by
Maciej Wielgosz
Browse files
Options
Downloads
Patches
Plain Diff
inplace option is provided
parent
3f8ebc4e
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
nibio_preprocessing/convert_files_in_folder.py
+20
-2
20 additions, 2 deletions
nibio_preprocessing/convert_files_in_folder.py
with
20 additions
and
2 deletions
nibio_preprocessing/convert_files_in_folder.py
+
20
−
2
View file @
4ec7b9c6
...
@@ -9,7 +9,7 @@ logging.basicConfig(level=logging.INFO)
...
@@ -9,7 +9,7 @@ logging.basicConfig(level=logging.INFO)
class
ConvertFilesInFolder
(
object
):
class
ConvertFilesInFolder
(
object
):
def
__init__
(
self
,
input_folder
,
output_folder
,
out_file_type
,
verbose
=
False
):
def
__init__
(
self
,
input_folder
,
output_folder
,
out_file_type
,
in_place
=
False
,
verbose
=
False
):
"""
"""
There are following available file types:
There are following available file types:
- las
- las
...
@@ -19,6 +19,7 @@ class ConvertFilesInFolder(object):
...
@@ -19,6 +19,7 @@ class ConvertFilesInFolder(object):
self
.
input_folder
=
input_folder
self
.
input_folder
=
input_folder
self
.
output_folder
=
output_folder
self
.
output_folder
=
output_folder
self
.
out_file_type
=
out_file_type
self
.
out_file_type
=
out_file_type
self
.
in_place
=
in_place
self
.
verbose
=
verbose
self
.
verbose
=
verbose
def
convert_file
(
self
,
file_path
):
def
convert_file
(
self
,
file_path
):
...
@@ -41,13 +42,19 @@ class ConvertFilesInFolder(object):
...
@@ -41,13 +42,19 @@ class ConvertFilesInFolder(object):
os
.
system
(
command
)
os
.
system
(
command
)
# use logging to print out the progress
# use logging to print out the progress
logging
.
info
(
"
Converted file {} to {}.
"
.
format
(
file_name
,
self
.
out_file_type
))
if
self
.
verbose
:
logging
.
info
(
"
Converted {} to {}
"
.
format
(
file_path
,
output_file_path
))
# convert all files in the input folder
# convert all files in the input folder
def
convert_files
(
self
):
def
convert_files
(
self
):
"""
"""
Convert all files in the input folder to the specified output file type.
Convert all files in the input folder to the specified output file type.
"""
"""
# print if in_place is True
if
self
.
in_place
:
logging
.
info
(
"
Converting files in place.
"
)
# get paths to all files in the input folder and subfolders
# get paths to all files in the input folder and subfolders
if
self
.
verbose
:
if
self
.
verbose
:
print
(
"
Searching for files in the input folder...
"
)
print
(
"
Searching for files in the input folder...
"
)
...
@@ -79,6 +86,15 @@ class ConvertFilesInFolder(object):
...
@@ -79,6 +86,15 @@ class ConvertFilesInFolder(object):
# use logging to print out the progress
# use logging to print out the progress
logging
.
info
(
"
Converted all files in the input folder to {}.
"
.
format
(
self
.
out_file_type
))
logging
.
info
(
"
Converted all files in the input folder to {}.
"
.
format
(
self
.
out_file_type
))
# if in_place is True, delete all the original files
if
self
.
in_place
:
for
file_path
in
tqdm
(
file_paths
):
os
.
remove
(
file_path
)
if
self
.
verbose
:
# use logging to print out the progress
logging
.
info
(
"
Deleted all the original files.
"
)
if
__name__
==
"
__main__
"
:
if
__name__
==
"
__main__
"
:
parser
=
argparse
.
ArgumentParser
()
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
"
--input_folder
"
,
help
=
"
Path to the folder with the files to convert.
"
)
parser
.
add_argument
(
"
--input_folder
"
,
help
=
"
Path to the folder with the files to convert.
"
)
...
@@ -88,6 +104,7 @@ if __name__ == "__main__":
...
@@ -88,6 +104,7 @@ if __name__ == "__main__":
default
=
'
ply
'
,
default
=
'
ply
'
,
help
=
"
The file type of the output files.There are following available file types: las, laz, ply
"
help
=
"
The file type of the output files.There are following available file types: las, laz, ply
"
)
)
parser
.
add_argument
(
"
--in_place
"
,
action
=
"
store_true
"
,
help
=
"
If set, the original files will be deleted.
"
)
parser
.
add_argument
(
"
--verbose
"
,
help
=
"
Print more information.
"
,
action
=
"
store_true
"
)
parser
.
add_argument
(
"
--verbose
"
,
help
=
"
Print more information.
"
,
action
=
"
store_true
"
)
args
=
parser
.
parse_args
()
args
=
parser
.
parse_args
()
# create an instance of the class
# create an instance of the class
...
@@ -95,6 +112,7 @@ if __name__ == "__main__":
...
@@ -95,6 +112,7 @@ if __name__ == "__main__":
args
.
input_folder
,
args
.
input_folder
,
args
.
output_folder
,
args
.
output_folder
,
args
.
out_file_type
,
args
.
out_file_type
,
args
.
in_place
,
args
.
verbose
args
.
verbose
)
)
# convert all files in the input folder
# convert all files in the input folder
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment