Specify csv output filename on command line

If I have this pipeline

input(relation: 'test.csv')
-> save(name: 'output')

and run

riskscape model run readCSV --output test2.csv

riskscape creates a folder called test2.csv and then saves output.csv into that folder.

file:/C:/.../readCSV/test2.csv/output.csv

How can I save to a new file called test2.csv using a command line argument?

You could make the output filename a model parameter, e.g.

input(relation: 'test.csv')
-> save(name: $output)

and then run it with something like:

riskscape model run readCSV -p "output='test2'"

For bonus points, you can use the ‘text’ parameter property, and then you don’t have to quote the value on the CLI, e.g. in your project.ini

[model readCSV]
framework = pipeline
pipeline = input(relation: 'test.csv') -> save(name: $output)
param.output = output
param.output.properties = text

Then you should be able to run it with:

riskscape model run readCSV -p output=test2
1 Like

Thanks Tim, I should have specified I am trying to save into the root folder of the project. Modifying your command slightly gives me what I want

riskscape model run readCSV -p "output='test2'" --output .

What confused me here is that the pipeline

input(relation: 'test.gpkg')
-> save(name: 'output')
riskscape model run readGPKG --output test2.gpkg

Does do what I expect

file:/C:/.../readGPKG/test2.gpkg?layer=output

Hi John,

The --output CLI option specifies the output location (typically the directory), whereas the name in the save() step specifies the layer name (typically the filename).

By default, each RiskScape output layer gets written as a separate file, and so to change the directory where the files get written you would use ‘--output OUTPUT_DIR

GeoPackage files are a bit special, in that RiskScape can either treat them as output layers (i.e. one .gpkg file per layer) or as output locations (i.e. one .gpkg file for all the output layers). So in your example ‘--output test2.gpkg’ is creating a test2.gpkg output location and saves an ‘output’ layer (based on the save() step) within that .gpkg file.

Whereas if you used save(name: 'output', format: 'geopackage') then you would be saving a single layer as a geopackage file. RiskScape would create a output.gpkg file in the given OUTPUT_DIR.

There’s a bit more info about RiskScape outputs here:
https://riskscape.org.nz/docs/reference/output.html#geopackage-output

Hope that somewhat makes sense.
Tim