def main(phosimDir): # Settings outputDir = getAoclcOutputPath() outputImgDir = os.path.join(outputDir, "img") os.makedirs(outputImgDir, exist_ok=True) configDir = getConfigDir() cmdSettingFile = os.path.join(configDir, "cmdFile", "opdDefault.cmd") instSettingFile = os.path.join(configDir, "instFile", "opdDefault.inst") # Declare the opd metrology and add the interested field points metr = OpdMetrology() metr.addFieldXYbyDeg(0, 0) metr.addFieldXYbyDeg(0.2, 0.3) # Set the Telescope facade class tele = TeleFacade() tele.setPhoSimDir(phosimDir) obsId = 9006050 filterType = FilterType.REF tele.setSurveyParam(obsId=obsId, filterType=filterType) # Update the telescope degree of freedom with sepecific camera dx dofInUm = np.zeros(50) dofInUm[6] = 1000 tele.accDofInUm(dofInUm) # Write the physical command file cmdFilePath = tele.writeCmdFile(outputDir, cmdSettingFile=cmdSettingFile, cmdFileName="opd.cmd") # Write the instance file instFilePath = tele.writeOpdInstFile(outputDir, metr, instSettingFile=instSettingFile, instFileName="opd.inst") # Get the argument to run the PhoSim logFilePath = os.path.join(outputImgDir, "opdPhoSim.log") argString = tele.getPhoSimArgs(instFilePath, extraCommandFile=cmdFilePath, numPro=2, outputDir=outputImgDir, e2ADC=0, logFilePath=logFilePath) # Run the PhoSim tele.runPhoSim(argString) # Analyze the OPD fits images opdFitsFile = os.path.join(outputImgDir, "opd_%d_0.fits.gz" % obsId) zk = metr.getZkFromOpd(opdFitsFile=opdFitsFile)[0] print("Zk of OPD_0 is %s." % zk) wavelengthInUm = tele.getRefWaveLength() * 1e-3 pssn = metr.calcPSSN(wavelengthInUm, opdFitsFile=opdFitsFile) print("Calculated PSSN is %.4f." % pssn)
def testGetAoclcOutputPathNotAssigned(self): with self.assertWarns(UserWarning): aoclcOutputPath = getAoclcOutputPath() self.assertEqual(aoclcOutputPath, os.path.join(getModulePath(), "output"))
def testGetAoclcOutputPath(self): AOCLCOUTPUTPATH = "/path/to/aoclc/output" os.environ["AOCLCOUTPUTPATH"] = AOCLCOUTPUTPATH aoclcOutputPath = getAoclcOutputPath() self.assertEqual(aoclcOutputPath, AOCLCOUTPUTPATH) os.environ.pop("AOCLCOUTPUTPATH")
def _prepareTeleAndSky(phosimDir): # Survey information filterType = FilterType.REF ra = 20 decl = 30 rotSkyPos = 10 # Set the Telescope facade class tele = TeleFacade() tele.setPhoSimDir(phosimDir) tele.setSurveyParam(filterType=filterType, boresight=(ra, decl), rotAngInDeg=rotSkyPos) tele.setInstName(CamType.LsstFamCam) # Declare the SkySim() skySim = SkySim() # Set the observation information mjd = tele.getCamMjd() skySim.setObservationMetaData(ra, decl, rotSkyPos, mjd) # Add the interested stars sensorName = "R22_S11" starId = [0, 1] xInpixelInCam = [3200, 400] yInPixelInCam = [3800, 700] starMag = [15, 16] for ii in range(len(starId)): skySim.addStarByChipPos(sensorName, starId[ii], xInpixelInCam[ii], yInPixelInCam[ii], starMag[ii]) # Output the sky information outputFilePath = os.path.join(getAoclcOutputPath(), "skyLsstFamInfo.txt") skySim.exportSkyToFile(outputFilePath) return tele, skySim
def main(phosimDir, numPro): # Settings outputDir = getAoclcOutputPath() outputImgDir = os.path.join(outputDir, "img") os.makedirs(outputImgDir, exist_ok=True) configDir = getConfigDir() cmdSettingFile = os.path.join(configDir, "cmdFile", "starDefault.cmd") instSettingFile = os.path.join(configDir, "instFile", "starSingleExp.inst") # Survey information obsId = 9006000 filterType = FilterType.REF ra = 20 decl = 30 rotSkyPos = 10 # Set the Telescope facade class tele = TeleFacade() tele.setPhoSimDir(phosimDir) tele.setSurveyParam(obsId=obsId, filterType=filterType, boresight=(ra, decl), rotAngInDeg=rotSkyPos) tele.setInstName(CamType.LsstCam) # Write the accumulated DOF file tele.writeAccDofFile(outputDir) # Declare the SkySim() skySim = SkySim() # Set the observation information mjd = tele.getCamMjd() skySim.setObservationMetaData(ra, decl, rotSkyPos, mjd) # Add the interested stars sensorName = [ "R44_S00_C0", "R00_S22_C1", "R44_S00_C1", "R00_S22_C0", "R04_S20_C1", "R40_S02_C0", "R04_S20_C0", "R40_S02_C1" ] xInpixelInCam = [500, 800] yInPixelInCam = [1000, 1300] starMag = [15, 15] starId = 0 for sensor in sensorName: for ii in range(len(starMag)): skySim.addStarByChipPos(sensor, starId, xInpixelInCam[ii], yInPixelInCam[ii], starMag[ii]) starId += 1 # Export sky information outputSkyFilePath = os.path.join(outputDir, "skyWfsInfo.txt") skySim.exportSkyToFile(outputSkyFilePath) # Write the star physical command file cmdFilePath = tele.writeCmdFile(outputDir, cmdSettingFile=cmdSettingFile, cmdFileName="star.cmd") # Write the instance file instFilePath = tele.writeStarInstFile(outputDir, skySim, instSettingFile=instSettingFile, instFileName="star.inst") # Get the argument to run the PhoSim logFilePath = os.path.join(outputImgDir, "phosimStar.log") argString = tele.getPhoSimArgs(instFilePath, extraCommandFile=cmdFilePath, numPro=numPro, outputDir=outputImgDir, e2ADC=0, logFilePath=logFilePath) # Run the PhoSim tele.runPhoSim(argString)
) parser.add_argument("--skyFile", type=str, default="", help="Star Id, ra, dec, and magnitude") parser.add_argument( "--m1m3FErr", type=float, default=0.05, help= "Ratio of M1M3 actuator force error between 0 and 1 (default: 0.05)") args = parser.parse_args() # Run the simulation phosimDir = getPhoSimPath() if (args.output == ""): outputDir = getAoclcOutputPath() else: outputDir = args.output os.makedirs(outputDir, exist_ok=True) main(phosimDir, args.numOfProc, args.iterNum, outputDir, isEimg=args.eimage, useMinDofIdx=args.minDof, inputSkyFilePath=args.skyFile, m1m3ForceError=args.m1m3FErr)
def main(phosimDir): # Settings outputDir = getAoclcOutputPath() outputImgDir = os.path.join(outputDir, "img") os.makedirs(outputImgDir, exist_ok=True) configDir = getConfigDir() cmdSettingFile = os.path.join(configDir, "cmdFile", "starDefault.cmd") instSettingFile = os.path.join(configDir, "instFile", "starSingleExp.inst") # Survey information obsId = 9006000 filterType = FilterType.REF ra = 20 decl = 30 zAngleInDeg = 27.0912 rotSkyPos = np.rad2deg(-1.2323) # Set the Telescope facade class tele = TeleFacade() tele.addSubSys(addCam=True, addM1M3=True, addM2=True) tele.setPhoSimDir(phosimDir) tele.setSurveyParam(obsId=obsId, filterType=filterType, boresight=(ra, decl), zAngleInDeg=zAngleInDeg, rotAngInDeg=rotSkyPos) tele.setInstName(CamType.LsstFamCam) # Declare the SkySim() skySim = SkySim() # Set the observation information mjd = tele.getCamMjd() skySim.setObservationMetaData(ra, decl, rotSkyPos, mjd) # Add the interested stars sensorName = "R22_S11" starId = [0, 1] xInpixelInCam = [3200, 300] yInPixelInCam = [3800, 1000] starMag = [15, 12] for ii in range(len(starId)): skySim.addStarByChipPos(sensorName, starId[ii], xInpixelInCam[ii], yInPixelInCam[ii], starMag[ii]) # Generate the perturbation iSim = 6 pertCmdFilePath = tele.writePertBaseOnConfigFile(outputDir, seedNum=iSim, saveResMapFig=True) # Update the telescope degree of freedom with camera piston in um dofInUm = np.zeros(50) dofInUm[5] = 1000 tele.accDofInUm(dofInUm) # Write the accumulated DOF file tele.writeAccDofFile(outputDir) # Write the star physical command file cmdFilePath = tele.writeCmdFile(outputDir, cmdSettingFile=cmdSettingFile, pertFilePath=pertCmdFilePath, cmdFileName="star.cmd") # Write the instance file instFilePath = tele.writeStarInstFile(outputDir, skySim, instSettingFile=instSettingFile, instFileName="star.inst") # Get the argument to run the PhoSim logFilePath = os.path.join(outputImgDir, "phosimStar.log") argString = tele.getPhoSimArgs(instFilePath, extraCommandFile=cmdFilePath, numPro=1, outputDir=outputImgDir, e2ADC=0, logFilePath=logFilePath) # Run the PhoSim tele.runPhoSim(argString)
def main(phosimDir): # Set the output directory outputDir = getAoclcOutputPath() outputImgDir = os.path.join(outputDir, "img") os.makedirs(outputImgDir, exist_ok=True) configDir = getConfigDir() cmdSettingFile = os.path.join(configDir, "cmdFile", "starDefault.cmd") instSettingFile = os.path.join(configDir, "instFile", "starSingleExp.inst") # Get the objects of TeleFacade and SkySim classes tele, skySim = _prepareTeleAndSky(phosimDir) # Write the star physical command file cmdFilePath = tele.writeCmdFile(outputDir, cmdSettingFile=cmdSettingFile, cmdFileName="star.cmd") # Set the intra- and extra-focal related information obsIdList = {"-1": 9005000, "1": 9005001} instFileNameList = {"-1": "starExtra.inst", "1": "starIntra.inst"} logFileNameList = {"-1": "starExtraPhoSim.log", "1": "starIntraPhoSim.log"} outputImgDirIntra = os.path.join(outputImgDir, "intra") outputImgDirExtra = os.path.join(outputImgDir, "extra") outputImgDirList = {"-1": outputImgDirExtra, "1": outputImgDirIntra} os.makedirs(outputImgDirIntra, exist_ok=True) os.makedirs(outputImgDirExtra, exist_ok=True) argStringList = [] for ii in (-1, 1): tele.setSurveyParam(obsId=obsIdList[str(ii)]) # Update the telescope degree of freedom dofInUm = np.zeros(50) # Camera piston (Change the unit from mm to um) dofInUm[5] = ii * tele.getDefocalDistInMm() * 1e3 # Set the degree fo freedom on telescope tele.setDofInUm(dofInUm) # Write the star instance file instFilePath = tele.writeStarInstFile( outputDir, skySim, instSettingFile=instSettingFile, instFileName=instFileNameList[str(ii)]) # Get the argument to run the phosim logFilePath = os.path.join(outputImgDirList[str(ii)], logFileNameList[str(ii)]) argString = tele.getPhoSimArgs(instFilePath, extraCommandFile=cmdFilePath, numPro=1, outputDir=outputImgDirList[str(ii)], e2ADC=0, logFilePath=logFilePath) argStringList.append(argString) for ii in range(2): tele.runPhoSim(argStringList[ii])