Я хотел бы обработать несколько изображений в Python с помощью для l oop.
Когда я пытаюсь сделать это для одного файла, это работает, например:
!gpt "Method/gpt_scripts/s1_cal_deb.xml" -t "result_step1/S1A_IW_SLC__1SDV_20190928T003154_20190928T003221_029214_035175_65FA.zip/s1_cal_deb/S1A_IW_SLC__1SDV_20190928T003154_20190928T003221_029214_035175_65FA.zip_Cal_deb_script.dim" "./Rader Images/S1A_IW_SLC__1SDV_20190928T003154_20190928T003221_029214_035175_65FA.zip"
Однако я хочу сделать это для многих файлов, поэтому я проверил это в Python 3.
deb = (f'"{"Method/gpt_scripts/s1_cal_deb.xml"}"')
deb = deb + " -t "
url = (f'"{"result_step1/S1A_IW_SLC__1SDV_20190928T003154_20190928T003221_029214_035175_65FA.zip"}')
url5 = (f'{"S1A_IW_SLC__1SDV_20190928T003154_20190928T003221_029214_035175_65FA.zip"}')
url2 = (f'{"/s1_cal_deb/"}')
url3 = (f'{url5}')
url4 = (f'{"_Cal_deb_script.dim"}"')
source = (f'"{"./Rader Images/S1A_IW_SLC__1SDV_20190928T003154_20190928T003221_029214_035175_65FA.zip"}"')
output = url + url2 + url3 + url4
final = deb + output + " " + source
final
Вывод:
'"Method/gpt_scripts/s1_cal_deb.xml" -t "result_step1/S1A_IW_SLC__1SDV_20190928T003154_20190928T003221_029214_035175_65FA.zip/s1_cal_deb/S1A_IW_SLC__1SDV_20190928T003154_20190928T003221_029214_035175_65FA.zip_Cal_deb_script.dim" "./Rader Images/S1A_IW_SLC__1SDV_20190928T003154_20190928T003221_029214_035175_65FA.zip"'
Окончательная строка точно такая же, как первый. Но я получаю следующую ошибку:
INFO: org.esa.snap.core.gpf.operators.tooladapter.ToolAdapterIO: Initializing external tool adapters
INFO: org.esa.snap.core.util.EngineVersionCheckActivator: Please check regularly for new updates for the best SNAP experience.
java.lang.IllegalStateException: Operator SPI not found for operator [final]
at org.esa.snap.core.gpf.annotations.ParameterDescriptorFactory.getOpSpi(ParameterDescriptorFactory.java:262)
at org.esa.snap.core.gpf.annotations.ParameterDescriptorFactory.createMapBackedOperatorPropertyContainer(ParameterDescriptorFactory.java:67)
at org.esa.snap.core.gpf.main.CommandLineTool.convertParameterMap(CommandLineTool.java:400)
at org.esa.snap.core.gpf.main.CommandLineTool.runOperator(CommandLineTool.java:296)
at org.esa.snap.core.gpf.main.CommandLineTool.runGraphOrOperator(CommandLineTool.java:284)
at org.esa.snap.core.gpf.main.CommandLineTool.run(CommandLineTool.java:188)
at org.esa.snap.core.gpf.main.CommandLineTool.run(CommandLineTool.java:121)
at org.esa.snap.core.gpf.main.GPT.run(GPT.java:54)
at org.esa.snap.core.gpf.main.GPT.main(GPT.java:34)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.esa.snap.runtime.Launcher.lambda$run$0(Launcher.java:55)
at org.esa.snap.runtime.Engine.runClientCode(Engine.java:189)
at org.esa.snap.runtime.Launcher.run(Launcher.java:51)
at org.esa.snap.runtime.Launcher.main(Launcher.java:31)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.exe4j.runtime.LauncherEngine.launch(LauncherEngine.java:65)
at com.exe4j.runtime.WinLauncher.main(WinLauncher.java:101)
at com.install4j.runtime.launcher.WinLauncher.main(WinLauncher.java:26)
Error: Operator SPI not found for operator [final]
Мне не хватает чего-то очень очевидного здесь? Я новичок в строках F в Python, поэтому буду очень признателен за любую помощь.
Некоторые примеры:
deb = (f'"{"Method/gpt_scripts/s1_cal_deb.xml"}"') # This is the script to run
deb = deb + " -t "
url = (f'"{"result_step1/S1A_IW_SLC__1SDV_20190928T003154_20190928T003221_029214_035175_65FA.zip"}') # output folder
url5 = (f'{"S1A_IW_SLC__1SDV_20190928T003154_20190928T003221_029214_035175_65FA.zip"}') # input file
url2 = (f'{"/s1_cal_deb/"}') # output folder
url3 = (f'{url5}') # filename
url4 = (f'{"_Cal_deb_script.dim"}"') # output file extention
source = (f'"{"./Rader Images/S1A_IW_SLC__1SDV_20190928T003154_20190928T003221_029214_035175_65FA.zip"}"') # input file
output = url + url2 + url3 + url4
final = deb + output + " " + source
final
Это создает следующую строку:
Вывод:
'"Method/gpt_scripts/s1_cal_deb.xml" -t "result_step1/S1A_IW_SLC__1SDV_20190928T003154_20190928T003221_029214_035175_65FA.zip/s1_cal_deb/S1A_IW_SLC__1SDV_20190928T003154_20190928T003221_029214_035175_65FA.zip_Cal_deb_script.dim" "./Rader Images/S1A_IW_SLC__1SDV_20190928T003154_20190928T003221_029214_035175_65FA.zip"'
Но я хочу следующую строку:
"Method/gpt_scripts/s1_cal_deb.xml" -t "result_step1/S1A_IW_SLC__1SDV_20190928T003154_20190928T003221_029214_035175_65FA.zip/s1_cal_deb/S1A_IW_SLC__1SDV_20190928T003154_20190928T003221_029214_035175_65FA.zip_Cal_deb_script.dim" "./Rader Images/S1A_IW_SLC__1SDV_20190928T003154_20190928T003221_029214_035175_65FA.zip"
Я хочу преобразовать:
'"Method / gpt ... to" Method / gpt ... на обоих концах строки
Тогда я мог бы выполнить команду! gpt следующим образом:
!gpt final
Надеюсь, это понятнее.
Большое спасибо,
Ишак