oasys-kit/shadow3

improve plot range (get_good_range)

Closed this issue · 1 comments

srio commented

On 8/23/22 10:47 AM, Yu Xiaojiang wrote:

Dear Manuel
I study a flat-field spectrometer, when CCD located at far from zero, the display not correct, please try with the attached workspace, and correct display on the CCD ('flat-field.png') also attached.

I correct it with a slight change to get_good_range function in shadow package:
C:\python38\Lib\site-packages\Shadow\ShadowLibExtensions.py

code attached in file 'get_good_range.txt'

Best regards
Xiaojiang

flat-field

#C:\python38\Lib\site-packages\Shadow\ShadowLibExtensions.py, L660 
def get_good_range(self,icol, nolost=0):
    """

    :param icol: the column number (SHADOW convention, starting from 1)
    :param nolost: lost rays flag (0=all, 1=good, 2=losses)
    :return: [rmin,rmax] the selected range
    """
    col = self.getshonecol(icol,nolost=nolost)
    if col.size == 0:
      return [-1,1]
    rmin0 = min(col)
    rmax0 = max(col)
    if rmin0>0.0:
        rmin = rmin0*0.95
    else:
        rmin = rmin0*1.05
    if rmax0<0.0:
        rmax = rmax0*0.95
    else:
        rmax = rmax0*1.05
    if rmin0==rmax0 and rmin0 !=0.0:
        rmin = rmin0*0.95
        rmax = rmax0*1.05
    if rmin0==0.0:
        rmin = -1.0
        rmax =  1.0
    if (rmax - rmin)/1.25 > (rmax0-rmin0) and rmin0!=rmax0:  #YXJ
        rmin = 0.5*(rmax0+rmin0) -  0.55*(rmax0-rmin0)
        rmax = 0.5*(rmax0+rmin0) +  0.55*(rmax0-rmin0)   
    return [rmin,rmax]

flat-field-spectometer.zip

srio commented

Done in shadow3 22.8.25 shadowOui 1.5.202