-
Notifications
You must be signed in to change notification settings - Fork 1
Rewrote parts of the codebase to support python function arguments #107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,9 @@ | ||
| #!/usr/bin/env python | ||
|
|
||
| import scopesim as sim | ||
| from pathlib import Path | ||
|
|
||
| sim.download_packages("METIS",release="github:dev_master") | ||
| sim.download_packages("Armazones", release="2023-07-11") | ||
| sim.download_packages("ELT", release="2024-02-29") | ||
| pkgs = ["METIS", "Armazones", "ELT"] | ||
|
|
||
| for pkg in pkgs: | ||
| sim.download_packages(pkg,release="stable", save_dir=str(Path.home()) + '/.inst_pkgs' ) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it is better to just leave the directory the default.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean the current working directory? As that is the default in ScopeSim.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that all our projects use the same default setting, unless there is a strong reason to deviate from that, which I don't think applies here. (Not that the current default is particularly good, but that is another thing.) |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,9 +15,7 @@ | |
| from datetime import datetime | ||
| import numpy as np | ||
| from astropy.io import fits | ||
| import astropy | ||
| import copy | ||
| from multiprocessing import Pool,Process,Manager | ||
| from multiprocessing import Pool | ||
|
|
||
| class runRecipes(): | ||
|
|
||
|
|
@@ -29,7 +27,8 @@ def __init__(self): | |
| self.tDelt = TimeDelta(0, format='sec') | ||
| self.allFileNames = [] | ||
| self.allmjd = [] | ||
|
|
||
| self.params = {} | ||
|
|
||
| def parseCommandLine(self,args): | ||
|
|
||
| """ | ||
|
|
@@ -73,6 +72,9 @@ def parseCommandLine(self,args): | |
| parser.add_argument('-n', '--nCores', type=int, | ||
| default = 1, | ||
| help='number of cores for parallel processing') | ||
| parser.add_argument('-p', '--scopesim_path', type=str, | ||
| default = str(Path.home()) + '/.inst_pkgs', | ||
|
||
| help='Path to the IRDB instrument packages') | ||
|
|
||
|
|
||
| args = parser.parse_args() | ||
|
|
@@ -120,6 +122,9 @@ def parseCommandLine(self,args): | |
| else: | ||
| params['nCores'] = 1 | ||
|
|
||
| if args.scopesim_path: | ||
| params['scopesim_path'] = args.scopesim_path | ||
|
|
||
| print(f"Starting Simulations") | ||
| print(f" input YAML = {params['inputYAML']}, output directory = {params['outputDir']}") | ||
| if(params['startMJD'] is not None): | ||
|
|
@@ -133,6 +138,28 @@ def parseCommandLine(self,args): | |
| print(f" Generate External Calibs {params['doCalib']}") | ||
|
|
||
| self.params = params | ||
|
|
||
| def setParms(self, **params): | ||
| """ | ||
| Set parameters directly from keyword arguments or a dictionary. | ||
| """ | ||
| self.params = params | ||
|
|
||
| print(f"Starting Simulations") | ||
| print(f" input YAML = {params['inputYAML']}, output directory = {params['outputDir']}") | ||
| if(params['sequence'] == "1"): | ||
| params['startMJD'] = None | ||
| params['sequence'] = True | ||
| else: | ||
| params['startMJD'] = params['sequence'] | ||
| params['sequence'] = True | ||
| if(params['sequence']): | ||
| print(f" Observation sequence will start from first date in YAML file") | ||
| else: | ||
| print(f" Observation dates will be taken from YAML file if given") | ||
| print(f" Automatically generated darks and flats {params['doCalib']}") | ||
| print(f" Small output option {params['small']}") | ||
| print(f" Generate External Calibs {params['doCalib']}") | ||
|
|
||
| def loadYAML(self): | ||
|
|
||
|
|
@@ -157,16 +184,8 @@ def _filter_yaml(self,allrcps): | |
|
|
||
| """filter a dictionary of recipes""" | ||
|
|
||
| if self.params['catglist'] is None: | ||
|
|
||
| dorcps = allrcps | ||
| else: | ||
| dorcps = {} | ||
| for catg in self.params['catglist']: | ||
| if catg in allrcps.keys(): | ||
| dorcps[catg] = allrcps[catg] | ||
| else: | ||
| raise ValueError(f"ERROR: {catg} is not a supported product category") | ||
| dorcps = allrcps | ||
|
|
||
|
||
| return dorcps | ||
|
|
||
| def validateYAML(self): | ||
|
|
@@ -739,7 +758,7 @@ def _run(self,dorcps): | |
| recipe["wcu"] = None | ||
| #simulate(fname, mode, kwargs,recipe["wcu"], source=recipe["source"], small=self.params['small']) | ||
|
|
||
| allArgs.append((fname,mode,kwargs,recipe["wcu"],recipe["source"],self.params["small"])) | ||
| allArgs.append((self.params["scopesim_path"],fname,mode,kwargs,recipe["wcu"],recipe["source"],self.params["small"])) | ||
|
|
||
| if(not self.params['testRun']): | ||
| nCores = self.params['nCores'] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,42 +8,71 @@ | |
| import runRecipes as rr | ||
| import sys | ||
| import makeCalibPrototypes | ||
|
|
||
|
|
||
| def runRecipes(argv): | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| def runRecipes(inputYAML=Path.joinpath(Path(__file__).parent.parent, | ||
| "YAML/allRecipes.yaml"), | ||
|
||
| outputDir="output/", | ||
| small=False, | ||
| doStatic=False, | ||
| doCalib=0, | ||
| sequence="1", | ||
| testRun=False, | ||
| calibFile=None, | ||
| nCores=8, | ||
| scopesim_path=Path.home() / ".sigmas_pkg", | ||
|
||
| **kwargs): | ||
| """ | ||
| Run a set of recipes with explicit arguments instead of command line. | ||
| Arguments: | ||
| inputYAML: Path to the input YAML file. | ||
| doCalib: Integer flag for calibration. | ||
| calibFile: Path to calibration file. | ||
| testRun: Boolean flag for test run. | ||
| doStatic: Boolean flag for static calibration. | ||
| outputDir: Output directory. | ||
| kwargs: Any additional parameters. | ||
| """ | ||
| simulationSet = rr.runRecipes() | ||
|
|
||
| #simulationSet.setParms(inputYAML = None) \TODO - set parameters directly rather than commandline | ||
|
|
||
| # get the command line arguments | ||
|
|
||
| simulationSet.parseCommandLine(argv[1:]) | ||
| # Set parameters directly | ||
| simulationSet.setParms( | ||
| scopesim_path=scopesim_path, | ||
| inputYAML=inputYAML, | ||
| outputDir=outputDir, | ||
| small=small, | ||
| doStatic=doStatic, | ||
| doCalib=doCalib, | ||
| sequence=sequence, | ||
| testRun=testRun, | ||
| calibFile=calibFile, | ||
| nCores=nCores, | ||
| **kwargs | ||
| ) | ||
|
|
||
| # read in the YAML | ||
| simulationSet.loadYAML() | ||
|
|
||
| # validate the YAML | ||
|
|
||
| goodInput = simulationSet.validateYAML() | ||
|
|
||
| # exit if the YAML entries are not valid | ||
| if (not goodInput): | ||
| exit | ||
| if not goodInput: | ||
| return | ||
|
|
||
| # if requested, get the list of flats and darks | ||
| if(simulationSet.params['doCalib'] > 0): | ||
| if simulationSet.params['doCalib'] > 0: | ||
| simulationSet.calculateCalibs() | ||
|
|
||
| # run the simulations | ||
| simulationSet.runSimulations() | ||
|
|
||
| # run the calibrations if requested | ||
| if(simulationSet.params['doCalib'] > 0): | ||
| if simulationSet.params['doCalib'] > 0: | ||
| simulationSet.runCalibrations() | ||
|
|
||
| # if requested, dump the calibration dictionary to a YAML file in the same format as the input YAML | ||
| if(simulationSet.params['calibFile'] is not None): | ||
| if simulationSet.params['calibFile'] is not None: | ||
| simulationSet.dumpCalibsToFile() | ||
|
|
||
| simulationSet.allFileNames.sort() | ||
|
|
@@ -52,12 +81,40 @@ def runRecipes(argv): | |
|
|
||
|
|
||
| # if simulations were done, update the headers | ||
| if(not simulationSet.params['testRun']): | ||
| if not simulationSet.params['testRun']: | ||
| simulationSet.updateHeaders() | ||
|
|
||
| if(simulationSet.params['doStatic']): | ||
| if simulationSet.params['doStatic']: | ||
| makeCalibPrototypes.generateStaticCalibs(simulationSet.params['outputDir']) | ||
|
|
||
| if __name__ == "__main__": | ||
| simulationSet = rr.runRecipes() | ||
| simulationSet.parseCommandLine(sys.argv[1:]) | ||
|
||
|
|
||
| simulationSet.loadYAML() | ||
|
|
||
| runRecipes(sys.argv) | ||
| goodInput = simulationSet.validateYAML() | ||
|
|
||
| if (not goodInput): | ||
| exit | ||
|
|
||
| if(simulationSet.params['doCalib'] > 0): | ||
| simulationSet.calculateCalibs() | ||
|
|
||
| simulationSet.runSimulations() | ||
|
|
||
| if(simulationSet.params['doCalib'] > 0): | ||
| simulationSet.runCalibrations() | ||
|
|
||
| if(simulationSet.params['calibFile'] is not None): | ||
| simulationSet.dumpCalibsToFile() | ||
|
|
||
| simulationSet.allFileNames.sort() | ||
| for elem in simulationSet.allFileNames: | ||
| print(elem) | ||
|
|
||
| if(not simulationSet.params['testRun']): | ||
| simulationSet.updateHeaders() | ||
|
|
||
| if(simulationSet.params['doStatic']): | ||
| makeCalibPrototypes.generateStaticCalibs(simulationSet.params['outputDir']) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are not the same, because the release is not mentioned anymore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed them because the
dev_masterrelease doesn't work with the current ScopeSim version. Stable works with the current one, but I can of course change them to specific versions that work, although I don't know which release that would be.