diff --git a/README.md b/README.md index 9d9afb8..4a716cf 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/metis_simulations/runSimulationBlock.py b/metis_simulations/runSimulationBlock.py index b63e91b..d83254f 100644 --- a/metis_simulations/runSimulationBlock.py +++ b/metis_simulations/runSimulationBlock.py @@ -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() @@ -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)) @@ -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 diff --git a/metis_simulations/setupSimulations.py b/metis_simulations/setupSimulations.py index 6adbca9..18385aa 100644 --- a/metis_simulations/setupSimulations.py +++ b/metis_simulations/setupSimulations.py @@ -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) @@ -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")