Commit b2232b2d authored by Fang Yuedong's avatar Fang Yuedong
Browse files

1. Hotfix: make the importlib.resources usages compatible with python3.9

2. Hotfix: fixed a bug when get the bandpasses for spectroscopic chips in Filter.py
parent be11dd52
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -88,8 +88,12 @@ def on_orbit_obs_position(input_ra_list, input_dec_list, input_pmra_list, input_
                raise TypeError("Parameter 16 minute range error [0 ~ 59]!", input_minute)
            if not (input_second>=0 and input_second<60.0):
                raise TypeError("Parameter 16 second range error [0 ~ 60)!", input_second)
    
    #Inital dynamic lib
    # shao = cdll.LoadLibrary(lib_path)
    try:
        with pkg_resources.files('ObservationSim.Astrometry.lib').joinpath("libshao.so") as lib_path:
            shao = cdll.LoadLibrary(lib_path)
    except AttributeError:
        with pkg_resources.path('ObservationSim.Astrometry.lib', "libshao.so") as lib_path:
            shao = cdll.LoadLibrary(lib_path)
    shao.onOrbitObs.restype = c_int
+30 −13
Original line number Diff line number Diff line
@@ -49,18 +49,27 @@ class Chip(FocalPlane):
        self.bound = self.getChipLim()
        self.ccdEffCurve_dir = ccdEffCurve_dir
        self.CRdata_dir = CRdata_dir
        # self.sls_dir=sls_dir
        # self.sls_conf = os.path.join(self.sls_dir, self.getChipSLSConf())
        slsconfs = self.getChipSLSConf()
        if np.size(slsconfs) == 1:
            # self.sls_conf = [os.path.join(self.sls_dir, slsconfs)]
            try:
                with pkg_resources.files('ObservationSim.Instrument.data.sls_conf').joinpath(slsconfs) as conf_path:
                    self.sls_conf = str(conf_path)
            except AttributeError:
                with pkg_resources.path('ObservationSim.Instrument.data.sls_conf', slsconfs) as conf_path:
                    self.sls_conf = str(conf_path)
        else:
            # self.sls_conf = [os.path.join(self.sls_dir, slsconfs[0]), os.path.join(self.sls_dir, slsconfs[1])]
            self.sls_conf = []
            try:
                with pkg_resources.files('ObservationSim.Instrument.data.sls_conf').joinpath(slsconfs[0]) as conf_path:
                    self.sls_conf.append(str(conf_path))
            except AttributeError:
                with pkg_resources.path('ObservationSim.Instrument.data.sls_conf', slsconfs[0]) as conf_path:
                    self.sls_conf.append(str(conf_path))
            try:
                with pkg_resources.files('ObservationSim.Instrument.data.sls_conf').joinpath(slsconfs[1]) as conf_path:
                    self.sls_conf.append(str(conf_path))
            except AttributeError:
                with pkg_resources.path('ObservationSim.Instrument.data.sls_conf', slsconfs[1]) as conf_path:
                    self.sls_conf.append(str(conf_path))
        
@@ -103,6 +112,10 @@ class Chip(FocalPlane):
        
        # path = os.path.join(self.ccdEffCurve_dir, filename)
        # table = Table.read(path, format='ascii')
        try:
            with pkg_resources.files('ObservationSim.Instrument.data.ccd').joinpath(filename) as ccd_path:
                table = Table.read(ccd_path, format='ascii')
        except AttributeError:
            with pkg_resources.path('ObservationSim.Instrument.data.ccd', filename) as ccd_path:
                table = Table.read(ccd_path, format='ascii')
        # throughput = galsim.LookupTable(x=table['col1'], f=table['col2']*mirror_eff, interpolant='linear')
@@ -113,6 +126,10 @@ class Chip(FocalPlane):
    def _getCRdata(self):
        # path = os.path.join(self.CRdata_dir, 'wfc-cr-attachpixel.dat')
        # self.attachedSizes = np.loadtxt(path)
        try:
            with pkg_resources.files('ObservationSim.Instrument.data').joinpath("wfc-cr-attachpixel.dat") as cr_path:
                self.attachedSizes = np.loadtxt(cr_path)
        except AttributeError:
            with pkg_resources.path('ObservationSim.Instrument.data', "wfc-cr-attachpixel.dat") as cr_path:
                self.attachedSizes = np.loadtxt(cr_path)

+25 −13
Original line number Diff line number Diff line
@@ -51,16 +51,26 @@ class Filter(object):
            # Get full-bandpass
            # filter_file = os.path.join(filter_dir, self.filter_type+".dat")
            # bandpass_full = galsim.Bandpass(filter_file, wave_type=unit)
            try:
                with pkg_resources.files('ObservationSim.Instrument.data.filters').joinpath(self.filter_type.lower() + '.txt') as filter_file:
                    self.filter_bandpass = galsim.Bandpass(str(filter_file), wave_type=unit)
            except AttributeError:
                with pkg_resources.path('ObservationSim.Instrument.data.filters', self.filter_type.lower() + '.txt') as filter_file:
                    self.filter_bandpass = galsim.Bandpass(str(filter_file), wave_type=unit)
            try:
                with pkg_resources.files('ObservationSim.Instrument.data.throughputs').joinpath(self.filter_type.lower() + '_throughput.txt') as filter_file:
                    bandpass_full = galsim.Bandpass(str(filter_file), wave_type=unit)
            except AttributeError:
                with pkg_resources.path('ObservationSim.Instrument.data.throughputs', self.filter_type.lower() + '_throughput.txt') as filter_file:
                    bandpass_full = galsim.Bandpass(str(filter_file), wave_type=unit)
            # bandpass_full = bandpass_full * self.ccd_bandpass

            # Get sub-bandpasses
            bandpass_sub_list = []
            # wave_bin_file = os.path.join(filter_dir, self.filter_type.lower() + "_sub.list")
            # wave_points = open(wave_bin_file).read().splitlines()
            try:
                with pkg_resources.files('ObservationSim.Instrument.data.filters').joinpath(self.filter_type.lower() + "_sub.list") as wave_bin_file:
                    wave_points = open(wave_bin_file).read().splitlines()
            except AttributeError:
                with pkg_resources.path('ObservationSim.Instrument.data.filters', self.filter_type.lower() + "_sub.list") as wave_bin_file:
                    wave_points = open(wave_bin_file).read().splitlines()

@@ -75,11 +85,13 @@ class Filter(object):
        else:   # Spectroscopic
            sls_lamb = np.linspace(self.blue_limit, self.red_limit, 100)
            sls_flux = np.ones_like(sls_lamb)
            con_spec = galsim.LookupTable(sls_lamb, sls_lamb, interpolant='nearest')
            con_spec = galsim.LookupTable(sls_lamb, sls_flux, interpolant='nearest')
            bandpass_full = galsim.Bandpass(con_spec, wave_type=unit)
            bandpass_sub_list = []
            # wave_bin_file = os.path.join(filter_dir, self.filter_type.lower() + "_sub.list")
            # wave_points = open(wave_bin_file).read().splitlines()
            try:
                with pkg_resources.files('ObservationSim.Instrument.data.filters').joinpath(self.filter_type.lower() + "_sub.list") as wave_bin_file:
                    wave_points = open(wave_bin_file).read().splitlines()
            except AttributeError:
                with pkg_resources.path('ObservationSim.Instrument.data.filters', self.filter_type.lower() + "_sub.list") as wave_bin_file:
                    wave_points = open(wave_bin_file).read().splitlines()
            for i in range(2, len(wave_points), 2):
+6 −2
Original line number Diff line number Diff line
@@ -15,6 +15,10 @@ class Telescope(object):
		if optEffCurve_path is not None:
			self.efficiency = self._get_efficiency(optEffCurve_path)
		else:
			try:
				with pkg_resources.files('ObservationSim.Instrument.data').joinpath('mirror_ccdnote.txt') as optEffCurve_path:
					self.efficiency = self._get_efficiency(optEffCurve_path)
			except AttributeError:
				with pkg_resources.path('ObservationSim.Instrument.data', 'mirror_ccdnote.txt') as optEffCurve_path:
					self.efficiency = self._get_efficiency(optEffCurve_path)

+12 −4
Original line number Diff line number Diff line
@@ -43,6 +43,10 @@ return {*} limit mag and saturation mag
'''

def calculateLimitMag(aperture = 2.0, psf_fwhm = 0.1969,pixelSize = 0.074, pmRation = 0.8, throughputFn = 'i_throughput.txt', readout = 5.0, skyFn= 'sky_emiss_hubble_50_50_A.dat', darknoise = 0.02,exTime = 150, exNum = 1, fw = 90000):
	try:
		with pkg_resources.files('ObservationSim.Instrument.data.throughputs').joinpath(throughputFn) as data_file:
			throughput_f = np.loadtxt(data_file)
	except AttributeError:
		with pkg_resources.path('ObservationSim.Instrument.data.throughputs', throughputFn) as data_file:
			throughput_f = np.loadtxt(data_file)
	thr_i = interpolate.interp1d(throughput_f[:,0]/10, throughput_f[:,1]); # wavelength in anstrom
@@ -59,6 +63,10 @@ def calculateLimitMag(aperture = 2.0, psf_fwhm = 0.1969,pixelSize = 0.074, pmRat
	wave = np.arange(f_s,f_e+delt_f,delt_f)
	wavey = np.ones(wave.shape[0])

	try:
		with pkg_resources.files('ObservationSim.Instrument.data.throughputs').joinpath(skyFn) as data_file:
			skydata = np.loadtxt(data_file)
	except AttributeError:
		with pkg_resources.path('ObservationSim.Instrument.data.throughputs', skyFn) as data_file:
			skydata = np.loadtxt(data_file)
	skydatai = interpolate.interp1d(skydata[:,0]/10, skydata[:,1]*10)
Loading