Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,20 @@ so the same command also works with a YAML file. All other flags from
`setupSimulations.parseCommandLine` apply (`-o`, `-s`, `-d`, `-q`, `-t`,
`-f`, `-n`) regardless of input format.

### Inspecting the CSV → YAML mapping

To review what the CSV parser produced without running any simulations,
combine `--testRun` with `--writeYaml`:

```
python -m metis_simulations.runSimulationBlock -i path/to/test_sequence.csv -o out/ -t -w
```

This writes a `.yaml` file next to the input CSV containing the parsed
recipes and exits before any ScopeSim call. `-w` on its own also writes
the YAML but then continues into the normal simulation run; `-w` is
ignored for YAML input.

## Programmatic usage

The CSV parser can also be used directly:
Expand Down
11 changes: 9 additions & 2 deletions metis_simulations/runSimulationBlock.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@ def runSimulationBlock(yamlFiles, params, args):
simulationSet.params['nCores'] = int(simulationSet.params['nCores'])

# load the YAML file

simulationSet.loadYAML()

if simulationSet.params.get('testRun') and simulationSet.params.get('writeYaml'):
continue

# get the start date
simulationSet.getStartDate()

Expand All @@ -50,6 +53,9 @@ def runSimulationBlock(yamlFiles, params, args):
allDarks = allDarks + simulationSet.darkParms
allFlats = allFlats + simulationSet.flatParms

if params.get('testRun') and params.get('writeYaml'):
return

# now do all the calibrations

allDarks = list(set(allDarks))
Expand Down Expand Up @@ -80,7 +86,8 @@ def runSimulationBlock(yamlFiles, params, args):
sys.exit("error: -o/--outputDir is required")

for key, default in (('small', False), ('doStatic', False),
('doCalib', 0), ('testRun', False), ('nCores', 1)):
('doCalib', 0), ('testRun', False), ('nCores', 1),
('writeYaml', False)):
if params[key] is None:
params[key] = default

Expand Down
5 changes: 4 additions & 1 deletion metis_simulations/setupSimulations.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ def parseCommandLine(self,args):
parser.add_argument('-n', '--nCores', type=int, default=None,
help='number of cores for parallel processing')

parser.add_argument('-w', '--writeYaml', action="store_true", default=None,
help='write a YAML file with the parsed recipes next to the input CSV (only meaningful with .csv input). Combine with --testRun to skip simulation entirely.')

inArgs = parser.parse_args(args)
params = vars(inArgs)

Expand Down Expand Up @@ -126,7 +129,7 @@ def loadInput(self):
self.allrcps = yaml.safe_load(file)
print(f"Recipes loaded from {input_path}")
elif ext == '.csv':
self.allrcps = loadCSV(input_path)
self.allrcps = loadCSV(input_path, write_yaml=bool(self.params.get('writeYaml')))
else:
raise ValueError(f"Unsupported input format: {ext}. Use .yaml, .yml, or .csv")

Expand Down