EnMAP-Box / enmap-box

EnMAP-Box source code repository. See https://enmap-box.readthedocs.io for documentation
GNU General Public License v3.0
38 stars 16 forks source link

Exclude default values from asPythonCommand & asQgisProcessCommand #344

Open jakimowb opened 1 year ago

jakimowb commented 1 year ago

Some EnMAP-Box processing algorithms like enmapbox:SpectralResamplingToPrisma return complete but unnecessarily long python / CLI text when using the "Coppy as python / qgis_process command" options:

grafik

The enmapbox:SpectralResamplingToPrisma dialog just requires to define input and output files. Advanced parameters like the wavelength and fwhm have default values. grafik

Exporting this to a CLI command gives:

``` qgis_process run enmapbox:SpectralResamplingToPrisma --distance_units=meters --area_units=m2 --ellipsoid=EPSG:7030 --raster='path to EnMAP' --response='from collections import OrderedDict . . . ... too many many lines just to describe default parameters ... . . . --outputResampledRaster='resampledPRISMA.tif' ``` ``` qgis_process run enmapbox:SpectralResamplingToPrisma --distance_units=meters --area_units=m2 --ellipsoid=EPSG:7030 --raster='path to EnMAP' --response='from collections import OrderedDict responses = OrderedDict() wavelength = [402.4, 411.3, 419.4, 427.0, 434.3, 441.7, 449.0, 456.4, 463.7, 470.9, 478.2, 485.4, 492.7, 500.1, 507.7, 515.2, 522.9, 530.7, 538.5, 546.5, 554.6, 562.7, 571.0, 579.4, 587.8, 596.5, 605.4, 614.2, 623.2, 632.1, 641.3, 650.8, 660.3, 669.8, 679.5, 689.4, 699.1, 709.0, 719.2, 729.2, 739.4, 749.7, 760.1, 770.5, 780.9, 791.4, 801.9, 812.5, 823.1, 833.8, 844.4, 855.2, 865.9, 876.6, 887.3, 898.0, 908.6, 919.2, 929.4, 939.9, 951.4, 962.3, 972.6, 943.0, 951.0, 959.5, 969.4, 978.7, 988.4, 998.4, 1008.2, 1018.0, 1028.8, 1037.8, 1047.4, 1057.4, 1067.6, 1078.0, 1088.6, 1099.1, 1109.7, 1120.5, 1131.1, 1141.9, 1152.5, 1163.5, 1174.5, 1185.4, 1196.2, 1207.1, 1217.7, 1229.0, 1240.1, 1250.8, 1262.3, 1273.3, 1284.3, 1295.2, 1306.0, 1317.0, 1328.1, 1338.9, 1349.6, 1360.8, 1372.7, 1383.0, 1394.5, 1405.4, 1416.3, 1427.1, 1438.2, 1448.9, 1459.1, 1469.7, 1480.6, 1491.2, 1501.8, 1512.4, 1523.0, 1533.6, 1544.0, 1554.6, 1565.1, 1575.4, 1585.6, 1596.0, 1606.2, 1616.6, 1626.8, 1636.9, 1647.0, 1656.8, 1667.0, 1677.1, 1687.2, 1697.0, 1706.8, 1716.6, 1726.4, 1736.3, 1745.9, 1755.5, 1765.3, 1774.9, 1784.4, 1793.7, 1803.4, 1812.8, 1822.1, 1831.7, 1841.0, 1850.3, 1859.3, 1868.0, 1878.5, 1886.8, 1895.8, 1904.6, 1914.0, 1923.1, 1932.0, 1940.8, 1949.6, 1958.4, 1967.1, 1975.8, 1984.5, 1993.3, 2001.8, 2010.4, 2019.0, 2027.5, 2036.0, 2044.4, 2052.8, 2061.1, 2069.5, 2077.8, 2086.1, 2094.4, 2102.5, 2110.8, 2119.0, 2127.1, 2135.2, 2143.2, 2151.1, 2159.3, 2167.3, 2175.1, 2183.2, 2190.8, 2198.9, 2206.6, 2214.3, 2222.2, 2229.8, 2237.6, 2245.2, 2252.8, 2260.6, 2268.0, 2275.8, 2283.3, 2290.6, 2298.3, 2305.5, 2312.9, 2320.6, 2327.6, 2335.2, 2342.6, 2349.6, 2357.0, 2364.4, 2371.3, 2378.5, 2385.8, 2392.8, 2399.8, 2407.3, 2414.2, 2421.0, 2428.4, 2435.3, 2442.2, 2448.9, 2456.3, 2462.8, 2469.4, 2476.8, 2483.6, 2490.0, 2496.9] fwhm = [11.4, 10.6, 9.8, 9.4, 9.3, 9.2, 9.1, 9.1, 9.0, 9.0, 9.0, 9.0, 9.2, 9.3, 9.4, 9.5, 9.6, 9.7, 9.8, 10.0, 10.1, 10.2, 10.3, 10.4, 10.5, 10.8, 11.0, 11.0, 11.2, 11.2, 11.5, 11.6, 11.7, 11.8, 12.0, 12.1, 12.0, 12.4, 12.4, 12.4, 12.5, 12.6, 12.8, 12.7, 12.8, 12.8, 12.9, 12.9, 13.0, 13.0, 13.1, 13.1, 13.2, 13.1, 13.1, 13.1, 13.1, 12.9, 12.8, 13.2, 13.5, 13.0, 12.9, 10.9, 11.0, 12.0, 12.1, 12.2, 12.3, 12.7, 12.4, 13.0, 13.0, 13.3, 13.5, 13.7, 13.9, 14.0, 14.1, 14.1, 14.4, 14.0, 14.3, 14.1, 14.3, 14.7, 14.3, 14.4, 14.3, 14.6, 14.4, 14.7, 14.4, 14.7, 14.9, 14.6, 14.5, 14.4, 14.5, 14.6, 14.7, 14.4, 14.5, 15.1, 14.5, 14.8, 14.2, 14.4, 14.3, 14.1, 14.7, 13.9, 13.7, 14.2, 14.2, 14.0, 14.1, 14.0, 13.9, 13.9, 13.7, 13.9, 13.7, 13.6, 13.6, 13.6, 13.5, 13.7, 13.3, 13.2, 13.2, 12.6, 13.4, 12.9, 13.0, 13.1, 13.0, 12.7, 12.6, 12.7, 12.9, 12.9, 12.4, 12.3, 12.5, 12.5, 12.3, 12.2, 12.9, 12.2, 12.4, 12.4, 12.1, 11.1, 12.5, 11.6, 11.5, 12.5, 11.6, 12.0, 11.6, 11.8, 11.5, 11.4, 11.5, 11.4, 11.6, 11.2, 11.4, 11.2, 11.3, 11.0, 11.3, 10.9, 11.0, 10.9, 11.1, 10.9, 11.0, 10.8, 10.8, 10.8, 10.8, 10.6, 10.7, 10.5, 10.6, 10.8, 10.2, 10.7, 10.3, 10.3, 10.6, 10.1, 10.4, 10.1, 10.3, 10.3, 10.1, 10.2, 10.2, 9.9, 10.2, 9.8, 10.0, 10.0, 9.7, 10.1, 9.8, 9.7, 10.1, 9.6, 9.6, 10.0, 9.5, 9.5, 9.6, 9.7, 9.3, 9.6, 9.7, 9.0, 9.7, 9.5, 9.4, 8.8, 9.4, 9.5, 8.9, 9.1, 9.7, 9.0, 9.0, 9.5] for w, f in zip(wavelength, fwhm): responses[w] = f' --saveResponseFunction=false --outputResampledRaster='resampledPRISMA.tif' ```

I assume that in most cases users want to use the default parameters anyway. Therefore it would be nice, if only parameter are returned that differ from default values.

For better readibility, the CLI output could be multilined and should show the most important arguments like input and output datasets first. For example, instead:

qgis_process run enmapbox:SpectralResamplingToPrisma --distance_units=meters --area_units=m2 --ellipsoid=EPSG:7030 ...

return something like:

qgis_process run enmapbox:SpectralResamplingToPrisma \ 
  --raster='path to EnMAP' \
  --outputResampledRaster='resampledPRISMA.tif' \
  ... other arguments, if different to default values
janzandr commented 1 year ago

Do you mean those button here? image

Those are specified by the QGIS processing framework. Has nothing to do with EnMAP-Box algorithms in particular. Try any QGIS algorithm and you will get default values inside the generated code snippet.

jakimowb commented 1 year ago

According to the API docs, the responsible methods can be overwritten:

QgsProcessingAlgorithm::asPythonCommand(...) QgsProcessingAlgorithm::asQgisProcessCommand(...)

janzandr commented 1 year ago

As discussed, this is QGIS default behaviour. If that should change, please open an issue inside the QGIS issue tracker.

jakimowb commented 1 year ago

This entire behaviour is really anoying. I will fix it exemplary for the enmapbox:SpectralResamplingToPrisam and may use this at a later time as example for an QGIS issue. I need a CLI ouput that make more sense and does not include default values for the EnMAP-Box publication. A command line command that contains lines of unnecessary Python code cannot be expected to be liked by any reviewer that likes to test the EnMAP-Box.