Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
iamap
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
AMAP
iamap
Commits
c92b5146
Commit
c92b5146
authored
6 months ago
by
paul.tresson_ird.fr
Browse files
Options
Downloads
Patches
Plain Diff
load parameters from json file for encoder.
parent
e5e80c36
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
encoder.py
+28
-0
28 additions, 0 deletions
encoder.py
tests/test_encoder.py
+2
-1
2 additions, 1 deletion
tests/test_encoder.py
utils/misc.py
+0
-1
0 additions, 1 deletion
utils/misc.py
with
30 additions
and
2 deletions
encoder.py
+
28
−
0
View file @
c92b5146
...
@@ -86,6 +86,7 @@ class EncoderAlgorithm(QgsProcessingAlgorithm):
...
@@ -86,6 +86,7 @@ class EncoderAlgorithm(QgsProcessingAlgorithm):
PAUSES
=
'
PAUSES
'
PAUSES
=
'
PAUSES
'
REMOVE_TEMP_FILES
=
'
REMOVE_TEMP_FILES
'
REMOVE_TEMP_FILES
=
'
REMOVE_TEMP_FILES
'
TEMP_FILES_CLEANUP_FREQ
=
'
TEMP_FILES_CLEANUP_FREQ
'
TEMP_FILES_CLEANUP_FREQ
=
'
TEMP_FILES_CLEANUP_FREQ
'
JSON_PARAM
=
'
JSON_PARAM
'
def
initAlgorithm
(
self
,
config
=
None
):
def
initAlgorithm
(
self
,
config
=
None
):
...
@@ -311,6 +312,16 @@ class EncoderAlgorithm(QgsProcessingAlgorithm):
...
@@ -311,6 +312,16 @@ class EncoderAlgorithm(QgsProcessingAlgorithm):
defaultValue
=
0
,
defaultValue
=
0
,
)
)
json_param
=
QgsProcessingParameterFile
(
name
=
self
.
JSON_PARAM
,
description
=
self
.
tr
(
'
Pass parameters as json file
'
),
# extension='pth',
fileFilter
=
'
JSON Files (*.json)
'
,
optional
=
True
,
defaultValue
=
None
)
for
param
in
(
for
param
in
(
crs_param
,
crs_param
,
res_param
,
res_param
,
...
@@ -321,6 +332,7 @@ class EncoderAlgorithm(QgsProcessingAlgorithm):
...
@@ -321,6 +332,7 @@ class EncoderAlgorithm(QgsProcessingAlgorithm):
pauses_param
,
pauses_param
,
remove_tmp_files
,
remove_tmp_files
,
tmp_files_cleanup_frq
,
tmp_files_cleanup_frq
,
json_param
,
):
):
param
.
setFlags
(
param
.
setFlags
(
param
.
flags
()
|
QgsProcessingParameterDefinition
.
FlagAdvanced
)
param
.
flags
()
|
QgsProcessingParameterDefinition
.
FlagAdvanced
)
...
@@ -333,6 +345,8 @@ class EncoderAlgorithm(QgsProcessingAlgorithm):
...
@@ -333,6 +345,8 @@ class EncoderAlgorithm(QgsProcessingAlgorithm):
"""
"""
Here is where the processing itself takes place.
Here is where the processing itself takes place.
"""
"""
parameters
=
self
.
load_parameters_as_json
(
feedback
,
parameters
)
self
.
process_options
(
parameters
,
context
,
feedback
)
self
.
process_options
(
parameters
,
context
,
feedback
)
## compute parameters hash to have a unique identifier for the run
## compute parameters hash to have a unique identifier for the run
...
@@ -638,6 +652,20 @@ class EncoderAlgorithm(QgsProcessingAlgorithm):
...
@@ -638,6 +652,20 @@ class EncoderAlgorithm(QgsProcessingAlgorithm):
return
{
"
Output feature path
"
:
self
.
output_subdir
,
'
Patch samples saved
'
:
self
.
iPatch
,
'
OUTPUT_RASTER
'
:
dst_path
,
'
OUTPUT_LAYER_NAME
'
:
layer_name
}
return
{
"
Output feature path
"
:
self
.
output_subdir
,
'
Patch samples saved
'
:
self
.
iPatch
,
'
OUTPUT_RASTER
'
:
dst_path
,
'
OUTPUT_LAYER_NAME
'
:
layer_name
}
def
load_parameters_as_json
(
self
,
feedback
,
parameters
):
parameters
[
'
JSON_PARAM
'
]
=
str
(
parameters
[
'
JSON_PARAM
'
])
json_param
=
parameters
[
'
JSON_PARAM
'
]
print
(
json_param
)
if
json_param
!=
'
NULL
'
:
with
open
(
json_param
)
as
json_file
:
parameters
=
json
.
load
(
json_file
)
feedback
.
pushInfo
(
f
'
Loading previous parameters from
{
json_param
}
'
)
parameters
.
pop
(
'
JSON_PARAM
'
,
None
)
else
:
parameters
.
pop
(
'
JSON_PARAM
'
,
None
)
return
parameters
def
remove_temp_files
(
self
):
def
remove_temp_files
(
self
):
"""
"""
...
...
This diff is collapsed.
Click to expand it.
tests/test_encoder.py
+
2
−
1
View file @
c92b5146
...
@@ -46,7 +46,8 @@ class TestEncoderAlgorithm(unittest.TestCase):
...
@@ -46,7 +46,8 @@ class TestEncoderAlgorithm(unittest.TestCase):
'
SIZE
'
:
224
,
'
SIZE
'
:
224
,
'
STRIDE
'
:
224
,
'
STRIDE
'
:
224
,
'
TEMP_FILES_CLEANUP_FREQ
'
:
1000
,
'
TEMP_FILES_CLEANUP_FREQ
'
:
1000
,
'
WORKERS
'
:
0
'
WORKERS
'
:
0
,
'
JSON_PARAM
'
:
'
NULL
'
,
}
}
result
=
self
.
algorithm
.
processAlgorithm
(
parameters
,
self
.
context
,
self
.
feedback
)
result
=
self
.
algorithm
.
processAlgorithm
(
parameters
,
self
.
context
,
self
.
feedback
)
expected_result_path
=
os
.
path
.
join
(
self
.
algorithm
.
output_subdir
,
'
merged.tif
'
)
expected_result_path
=
os
.
path
.
join
(
self
.
algorithm
.
output_subdir
,
'
merged.tif
'
)
...
...
This diff is collapsed.
Click to expand it.
utils/misc.py
+
0
−
1
View file @
c92b5146
...
@@ -103,7 +103,6 @@ def save_parameters_to_json(parameters, output_dir):
...
@@ -103,7 +103,6 @@ def save_parameters_to_json(parameters, output_dir):
converted_parameters
=
convert_qvariant
(
parameters
)
converted_parameters
=
convert_qvariant
(
parameters
)
converted_parameters
[
'
CKPT
'
]
=
str
(
converted_parameters
[
'
CKPT
'
])
converted_parameters
[
'
CKPT
'
]
=
str
(
converted_parameters
[
'
CKPT
'
])
for
key
,
item
in
converted_parameters
.
items
():
with
open
(
dst_path
,
"
w
"
)
as
json_file
:
with
open
(
dst_path
,
"
w
"
)
as
json_file
:
json
.
dump
(
converted_parameters
,
json_file
,
indent
=
4
)
json
.
dump
(
converted_parameters
,
json_file
,
indent
=
4
)
...
...
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