From 5254ae8010937e5400900afe53f9ed01e7f9f487 Mon Sep 17 00:00:00 2001 From: Chengliang Date: Sat, 26 Oct 2024 09:57:54 +0800 Subject: [PATCH] update codestyle-PEP8 --- observation_sim/instruments/chip/effects.py | 108 ++++++++++---------- 1 file changed, 53 insertions(+), 55 deletions(-) diff --git a/observation_sim/instruments/chip/effects.py b/observation_sim/instruments/chip/effects.py index f215a21..9e80182 100644 --- a/observation_sim/instruments/chip/effects.py +++ b/observation_sim/instruments/chip/effects.py @@ -534,7 +534,7 @@ def CTEModelColRow(img, trail_direction='up', direction='column', threshold=27): trail_pix_eff = trail_f/all_trail_pix all_trail = trail_pix_eff*all_trail all_trail[0] = f - trail_f - + for m in np.arange(0, xy_num, 1): if direction == 'column': if trail_direction == 'down': @@ -559,22 +559,22 @@ def CTEModelColRow(img, trail_direction='up', direction='column', threshold=27): # ---------- For Cosmic-Ray Simulation ------------ # ---------- Zhang Xin ---------------------------- def getYValue(collection, x): - index = 0; + index = 0 if (collection.shape[1] == 2): - while(x>collection[index, 0] and index < collection.shape[0]): - index= index + 1; + while(x > collection[index, 0] and index < collection.shape[0]): + index = index + 1 if (index == collection.shape[0] or index == 0): - return 0; + return 0 - deltX = collection[index, 0] - collection[index-1, 0]; - deltY = collection[index, 1] - collection[index-1, 1]; + deltX = collection[index, 0] - collection[index-1, 0] + deltY = collection[index, 1] - collection[index-1, 1] if deltX == 0: return (collection[index, 1] + collection[index-1, 1])/2.0 else: - a = deltY/deltX; - return a * (x - collection[index-1, 0]) + collection[index-1, 1]; - return 0; + a = deltY/deltX + return a * (x - collection[index-1, 0]) + collection[index-1, 1] + return 0 def selectCosmicRayCollection(attachedSizes, xLen, yLen, cr_pixelRatio, CR_max_size): @@ -582,45 +582,45 @@ def selectCosmicRayCollection(attachedSizes, xLen, yLen, cr_pixelRatio, CR_max_s normalRay = 0.90 nnormalRay = 1-normalRay max_nrayLen = 100 - pixelNum = int(xLen * yLen * cr_pixelRatio * normalRay ); - pixelNum_n = int(xLen * yLen * cr_pixelRatio * nnormalRay ) - CRPixelNum = 0; - + pixelNum = int(xLen * yLen * cr_pixelRatio * normalRay) + pixelNum_n = int(xLen * yLen * cr_pixelRatio * nnormalRay) + CRPixelNum = 0 + maxValue = max(attachedSizes[:, 1]) - maxValue += 0.1; + maxValue += 0.1 - cr_event_num = 0; - CRs = np.zeros(pixelNum); + cr_event_num = 0 + CRs = np.zeros(pixelNum) while (CRPixelNum < pixelNum): - x = CR_max_size * np.random.random(); - y = maxValue * np.random.random(); + x = CR_max_size * np.random.random() + y = maxValue * np.random.random() if (y <= getYValue(attachedSizes, x)): - CRs[cr_event_num] = np.ceil(x); - cr_event_num = cr_event_num + 1; - CRPixelNum = CRPixelNum + round(x); + CRs[cr_event_num] = np.ceil(x) + cr_event_num = cr_event_num + 1 + CRPixelNum = CRPixelNum + round(x) while (CRPixelNum < pixelNum + pixelNum_n): nx = np.random.random()*(max_nrayLen-CR_max_size)+CR_max_size - CRs[cr_event_num] = np.ceil(nx); - cr_event_num = cr_event_num + 1; - CRPixelNum = CRPixelNum + np.ceil(nx); + CRs[cr_event_num] = np.ceil(nx) + cr_event_num = cr_event_num + 1 + CRPixelNum = CRPixelNum + np.ceil(nx) - return CRs[0:cr_event_num]; + return CRs[0:cr_event_num] -def defineEnergyForCR(cr_event_size, seed = 12345): +def defineEnergyForCR(cr_event_size, seed=12345): import random - sigma = 0.6 / 2.355; - mean = 3.3; + sigma = 0.6 / 2.355 + mean = 3.3 random.seed(seed) - energys = np.zeros(cr_event_size); + energys = np.zeros(cr_event_size) for i in np.arange(cr_event_size): - energy_index = random.normalvariate(mean,sigma); - energys[i] = pow(10, energy_index); + energy_index = random.normalvariate(mean, sigma); + energys[i] = pow(10, energy_index) - return energys; + return energys -def convCR(CRmap=None, addPSF=None, sp_n = 4): +def convCR(CRmap=None, addPSF=None, sp_n=4): sh = CRmap.shape # sp_n = 4 @@ -629,7 +629,7 @@ def convCR(CRmap=None, addPSF=None, sp_n = 4): for i in np.arange(sh[0]): i_st = sp_n*i for j in np.arange(sh[1]): - if CRmap[i,j] ==0: + if CRmap[i, j] == 0: continue j_st = sp_n*j pix_v1 = CRmap[i, j]*pix_v0 @@ -639,11 +639,11 @@ def convCR(CRmap=None, addPSF=None, sp_n = 4): m_size = addPSF.shape[0] - subCRmap_n = np.zeros(np.array(subCRmap.shape) + m_size -1) + subCRmap_n = np.zeros(np.array(subCRmap.shape) + m_size - 1) for i in np.arange(subCRmap.shape[0]): for j in np.arange(subCRmap.shape[1]): - if subCRmap[i, j]>0: + if subCRmap[i, j] > 0: convPix = addPSF*subCRmap[i, j] subCRmap_n[i:i+m_size, j:j+m_size] += convPix @@ -654,7 +654,7 @@ def convCR(CRmap=None, addPSF=None, sp_n = 4): i_st = sp_n*i for j in np.arange(sh_n[1]): p_v = 0 - j_st=sp_n*j + j_st = sp_n*j for m in np.arange(sp_n): for n in np.arange(sp_n): p_v += subCRmap_n[i_st+m, j_st + n] @@ -668,13 +668,13 @@ def produceCR_Map(xLen, yLen, exTime, cr_pixelRatio, gain, attachedSizes, seed=2 # Return: an 2-D numpy array # attachedSizes = np.loadtxt('./wfc-cr-attachpixel.dat'); np.random.seed(seed) - CR_max_size = 20.0; - cr_size = selectCosmicRayCollection(attachedSizes, xLen, yLen, cr_pixelRatio, CR_max_size); + CR_max_size = 20.0 + cr_size = selectCosmicRayCollection(attachedSizes, xLen, yLen, cr_pixelRatio, CR_max_size) - cr_event_size = cr_size.shape[0]; - cr_energys = defineEnergyForCR(cr_event_size,seed = seed); + cr_event_size = cr_size.shape[0] + cr_energys = defineEnergyForCR(cr_event_size, seed=seed) - CRmap = np.zeros([yLen, xLen]); + CRmap = np.zeros([yLen, xLen]) # produce conv kernel from astropy.modeling.models import Gaussian2D @@ -689,28 +689,26 @@ def produceCR_Map(xLen, yLen, exTime, cr_pixelRatio, gain, attachedSizes, seed=2 addPSF = addPSF_(xp, yp) convKernel = addPSF/addPSF.sum() - #--------------------------------- - - + # --------------------------------- for i in np.arange(cr_event_size): xPos = round((xLen - 1)* np.random.random()); yPos = round((yLen - 1)* np.random.random()); cr_lens = int(cr_size[i]); - if cr_lens ==0: - continue; - pix_energy = cr_energys[i]/gain/cr_lens; - pos_angle = 1/2*math.pi*np.random.random(); + if cr_lens == 0: + continue + pix_energy = cr_energys[i]/gain/cr_lens + pos_angle = 1/2*math.pi*np.random.random() crMatrix = np.zeros([cr_lens+1, cr_lens + 1]) for j in np.arange(cr_lens): - x_n = int(np.cos(pos_angle)*j - np.sin(pos_angle)*0); + x_n = int(np.cos(pos_angle)*j - np.sin(pos_angle)*0) if x_n < 0: x_n = x_n + cr_lens+1 - y_n = int(np.sin(pos_angle)*j + np.cos(pos_angle)*0); + y_n = int(np.sin(pos_angle)*j + np.cos(pos_angle)*0) if x_n < 0 or x_n > cr_lens or y_n < 0 or y_n > cr_lens: - continue; - crMatrix[y_n, x_n] = pix_energy; + continue + crMatrix[y_n, x_n] = pix_energy crMatrix_n = convCR(crMatrix, convKernel, sp_n) # crMatrix_n = crMatrix @@ -747,7 +745,7 @@ def ShutterEffectArr(GSImage, t_exp=150, t_shutter=1.3, dist_bearing=735, dt=1E- s = np.zeros(SampleNumb) s1 = np.zeros(SampleNumb) s2 = np.zeros(SampleNumb) - brt = np.zeros(SampleNumb) + brt = np.zeros(SampleNumb) idx = np.arange(SampleNumb) sidx = np.zeros(SampleNumb) s1idx = np.zeros(SampleNumb) -- GitLab