def __init__(self, camTBinDegC=6.5650, camRotInRad=0): """Initialization of camera simulator class. This class is used to correct the camera distortion. Parameters ---------- camTBinDegC : float, optional Camera body temperature in degree C. (the default is 6.5650.) camRotInRad : float, optional Camera rotation angle in radian. (the default is 0.) """ # Configuration directory self.configDir = os.path.join(getConfigDir(), "camera") # Camera setting file settingFilePath = os.path.join(self.configDir, "camSetting.yaml") self._camSettingFile = ParamReader(filePath=settingFilePath) # Camera body temperature in degree C self.camTBinDegC = self.setBodyTempInDegC(camTBinDegC) # Camera rotation angle in radian self.camRotInRad = self.setRotAngInRad(camRotInRad)
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 setUpClass(cls): """Only do the instantiation for one time for the slow speed.""" cls.innerRinM = 0.9 cls.outerRinM = 1.710 configDir = os.path.join(getConfigDir(), "M2") cls.mirror = MirrorSim(cls.innerRinM, cls.outerRinM, configDir) cls.mirror.config(numTerms=28, actForceFileName="M2_1um_force.yaml", lutFileName="")
def testGetLUTforce(self): m1m3DataDir = os.path.join(getConfigDir(), "M1M3") mirror = MirrorSim(self.innerRinM, self.outerRinM, m1m3DataDir) mirror.config(numTerms=28, lutFileName="M1M3_LUT.yaml") zangleInDeg = 1.5 lutForce = mirror.getLUTforce(zangleInDeg) # Skip the row 1 as the ruler oriLutForce = mirror._lutFile.getMatContent()[1:, :] ansLutForce = (oriLutForce[:, 1] + oriLutForce[:, 2]) / 2 self.assertLess(np.sum(np.abs(lutForce - ansLutForce)), 1e-10)
def __init__(self): """Initiate the M1M3 simulator class.""" # M2 setting file configDir = os.path.join(getConfigDir(), "M1M3") settingFilePath = os.path.join(configDir, "m1m3Setting.yaml") self._m1m3SettingFile = ParamReader(filePath=settingFilePath) # Inner and outer radius of M1 mirror in m radiusM1Inner = self._m1m3SettingFile.getSetting("radiusM1Inner") radiusM1Outer = self._m1m3SettingFile.getSetting("radiusM1Outer") # Inner and outer radius of M3 mirror in m radiusM3Inner = self._m1m3SettingFile.getSetting("radiusM3Inner") radiusM3Outer = self._m1m3SettingFile.getSetting("radiusM3Outer") super(M1M3Sim, self).__init__((radiusM1Inner, radiusM3Inner), (radiusM1Outer, radiusM3Outer), configDir) # Mirror surface bending mode grid file self._gridFile = ParamReader() # FEA model file self._feaFile = ParamReader() # FEA model data in zenith angle self._feaZenFile = ParamReader() # FEA model data in horizontal angle self._feaHorFile = ParamReader() # Actuator forces along zenith direction self._forceZenFile = ParamReader() # Actuator forces along horizon direction self._forceHorFile = ParamReader() # Influence matrix of actuator forces self._forceInflFile = ParamReader() self._config("M1M3_1um_156_force.yaml", "M1M3_LUT.yaml", "M1M3_1um_156_grid.yaml", "M1M3_thermal_FEA.yaml", "M1M3_dxdydz_zenith.yaml", "M1M3_dxdydz_horizon.yaml", "M1M3_force_zenith.yaml", "M1M3_force_horizon.yaml", "M1M3_influence_256.yaml")
def __init__(self): """Initialization of telescope facade class. This class uses the facade pattern that the high level class telescope helps to write the perturbations of camera, M1M3, and M2 into the PhoSim by the interface to PhoSim. """ # Telescope setting file settingFilePath = os.path.join(getConfigDir(), "teleSetting.yaml") self._teleSettingFile = ParamReader(filePath=settingFilePath) # Camera subsystem self.cam = None # M1M3 subsystem self.m1m3 = None # M2 subsystem self.m2 = None # PhoSim communication self.phoSimCommu = PhosimCommu() # Telescope aggregated DOF in um # This value will be put back to PhoSim to do the perturbation numOfDof = self.getNumOfDof() self.dofInUm = np.zeros(numOfDof) # Telescopt survery parameters defocalDist = self.getDefaultDefocalDist() self.surveyParam = {"instName": "lsst", "defocalDistInMm": defocalDist, "obsId": 9999, "filterType": FilterType.REF, "boresight": (0, 0), "zAngleInDeg": 0, "rotAngInDeg": 0} # Sensors on the telescope self.sensorOn = {"sciSensorOn": True, "wfSensorOn": True, "guidSensorOn": False}
def __init__(self): """Initiate the M2 simulator class.""" # M2 setting file configDir = os.path.join(getConfigDir(), "M2") settingFilePath = os.path.join(configDir, "m2Setting.yaml") self._m2SettingFile = ParamReader(filePath=settingFilePath) # Inner and outer radius of M2 mirror in m radiusInner = self._m2SettingFile.getSetting("radiusInner") radiusOuter = self._m2SettingFile.getSetting("radiusOuter") super(M2Sim, self).__init__(radiusInner, radiusOuter, configDir) # Mirror surface bending mode grid file self._gridFile = ParamReader() # Mirror FEA model with gradient temperature data self._feaFile = ParamReader() self._config("M2_1um_force.yaml", "", "M2_1um_grid.yaml", "M2_GT_FEA.yaml")
def __init__(self, tele): """Initialization of PhoSim component class. WEP: wavefront estimation pipeline. Parameters ---------- tele : TeleFacade Telescope instance. """ # Configuration directory self.configDir = getConfigDir() # Telescope setting file settingFilePath = os.path.join(self.configDir, "phosimCmptSetting.yaml") self._phosimCmptSettingFile = ParamReader(filePath=settingFilePath) # OPD metrology self.metr = OpdMetrology() # TeleFacade instance self.tele = tele # Output directory of data self.outputDir = "" # Output directory of image self.outputImgDir = "" # Seed number self.seedNum = 0 # M1M3 force error self.m1m3ForceError = 0.05
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)
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])