Skip to content
Snippets Groups Projects

P2866 updates

Merged Hampus Wikmark Kreuger requested to merge p2866_updates into p2866
3 unresolved threads

We will add some quick fixes:

  • Allow loading a list of dark images
  • Allow centroid to return the raw hits (instead of spectrum)
Edited by Benjamin van Kuiken

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • added 1 commit

    • bd45362a - Centroiding algorithm can return individual hits

    Compare with previous version

  • You can now get x- and y-arrays of the individual hits sorted by train number by specifying return_hits=True when calling the centroiding function. A known bug is that this now crashes any print call referring to your data (because that assumes the values can be flattened to scalars).

    h = hRIXS()
    h.PROPOSAL = 2866
    pixel0    = 1080
    h.FIELDS  = ['hRIXS_det','hRIXS_index','hRIXS_norm','hRIXS_delay']
    h.Y_RANGE = slice(pixel0,2000)
    h.STD_THRESHOLD = 3.5 # default 3.5
    h.CURVE_B  = -3.695346575286939e-07
    h.CURVE_A  = 0.024084479232443695
    # Ranges for centroiding
    h.RANGE = 0,1100
    h.BINS  = 968
    
    data = h.from_run(467,2866)
    
    tot = h.centroid(data, return_hits=True)
    
    x, y = np.concatenate([tot.xhits.values[i] for i in range(len(tot))]),\
           np.concatenate([tot.yhits.values[i] for i in range(len(tot))])
    
    plt.plot(x, y, alpha = 0.1, marker = '.', linestyle='none')
    plt.xlim([0,1000])
    plt.ylim([0,2048])

    Screenshot_2022-05-16_at_16.12.07

    Edited by Hampus Wikmark Kreuger
  • added 1 commit

    • 92cb6a1f - Allow load_dark to load an array of dark images

    Compare with previous version

  • load_dark can now load and average over an array of dark images. It seems we're still not using the dark images, but at least this seems to work now...

    • I think the part

      x, y = np.concatenate([tot.xhits.values[i] for i in range(len(tot))]),
      np.concatenate([tot.yhits.values[i] for i in range(len(tot))])

      is unnecessarily complicated. Could one simply have an attribute tot.hits for as a 2D array or is there some other stuff with xhits and yhits?

      Edited by Johannes Niskanen
    • I agree that we could have a "hits" 2D array instead. The concatenation, however, is bringing together the xhits/yhits for all the different trains in the run. I think if we had a "hits" array we would still be left with something like:

      x, y = np.concatenate([tot.hits.values[i, 0] for i in range(len(tot))]),  
      np.concatenate([tot.hits.values[i, 1] for i in range(len(tot))])

      or saving everything as a hit-array and plotting hit_array[:,0] for x, etc.

      This is of course only in the context of plotting. If you have a use-case where a 2D array would be more useful, by all means we can change it, this is how I started doing it until I started trying to plot them. It would be a (tiny) bit of data overhead but we could also add both separate x- and y-arrays and a 2D one :smiley:

      Edit: Sorry @niskanen I thought I posted this comment last week but it was apparently "in review" the whole time...

      Edited by Hampus Wikmark Kreuger
    • Please register or sign in to reply
  • added 2 commits

    • 7134dd95 - Centroid subtracts dark image if there is one
    • 239dd0e3 - Merge branch 'p2866_updates_darksubtraction' into 'p2866_updates'

    Compare with previous version

  • added 4 commits

    • f68b7f75 - Load_dark optionally generates a mask to filter bad pixels
    • 8e8e7e9f - Return_hits returns a "hits" array with both x and y of hits
    • a2ffa1b9 - Merge branch 'p2866_updates' of https://git.xfel.eu/gitlab/SCS/ToolBox into...
    • bd425898 - Merge branch 'p2866_updates_darksubtraction' into 'p2866_updates'

    Compare with previous version

  • I have added dark subtraction and also the mask for hot pixels (that we also find using the dark images).

    The way the hot pixel detection works at the moment is that each pixel is compared to an "average" (of a region we set using ´MASK_AVG_X´ and ´MASK_AVG_Y´). If the difference is higher than ´DARK_MASK_THRESHOLD´ we will replace it by the average. This applies to both the dark image and the sample image.

    mask_thresholds

    The above image shows a few different thresholds. I have set the default to 100 now but this can of course be changed. Above 150 this seems more or less useless (corrected and uncorrected are the same), however as seen below higher thresholds may still remove some hot pixels in other places. I think another takeaway is that subtracting by the dark image (especially with hot pixel correction) mostly adds noise to the spectrum.

    Screenshot_2022-05-30_at_17.13.00

    Screenshot_2022-05-30_at_17.12.45

    Screenshot_2022-05-31_at_11.19.51

    In the above "vertical squashes" of dark images, with and without hot pixel correction, we see that thresholds of 50 and below cause some artifacts. This is because we (as of now) the average is taken at the far "right" of the detector screen (close to our data) and the average is slightly different on the other side of the bright line in the middle.

    Edited by Hampus Wikmark Kreuger
    • I checked the hot pixel code, and there we now have dead/cold pixels removed too:

      self.dark_mask = np.abs(self.dark_im_array - dark_avg) > mask_threshold

      should this be simply

      self.dark_mask = self.dark_im_array > dark_avg + mask_threshold

    • I think this is a good idea. I forgot about the abs but added this to avoid some strange effects of (what later turned out to be) an incorrect calculation of the average.

      Edited by Hampus Wikmark Kreuger
    • Please register or sign in to reply
  • added 4 commits

    • c0259d32 - Modified and commented dark_load
    • 96e004b0 - Remove print call
    • 2a045d6e - Merge branch 'p2866_updates_darksubtraction_jhns' into 'p2866_updates_darksubtraction'
    • 53f1f4f8 - Merge branch 'p2866_updates_darksubtraction' into 'p2866_updates'

    Compare with previous version

  • Added Johannes' corrections to the load_dark and centroid functions.

  • added 3 commits

    • 4fed0c4a - Commented and changed centroid function. Now the BG subtraction makes
    • 919a4e77 - jhns_centroid'.
    • 4f96b0f8 - Merge branch 'p2866_updates_jhns_centroid' into 'p2866_updates'

    Compare with previous version

  • added 7 commits

    • 71e16cc5 - Initial commit with alignment function draft
    • 35e26f66 - A few comments clarified
    • e5d7a675 - Alignment routine runs, but needs a careful validation & debugging.
    • 36ac54ed - align_readouts() now runs, but has some bugs still. It can group
    • a5388fee - Some nasty bugs fixed.
    • 8f178956 - Align_readouts() should work now.
    • 1898f7ac - Merge branch 'p2866_updates_jhns_alignment' into 'p2866_updates'

    Compare with previous version

  • added 4 commits

    • d38c138a - Add energy calibration and associated helper functions to hrixs class
    • 81a0e24a - Expand comments
    • 16bbd8d2 - Add (optional) elastic peak finding to centroid function
    • ed027f70 - Merge branch 'p2866_updates_elasticfit' into 'p2866_updates'

    Compare with previous version

  • Benjamin van Kuiken approved this merge request

    approved this merge request

  • Benjamin van Kuiken marked this merge request as ready

    marked this merge request as ready

  • mentioned in commit 563fcc83

Please register or sign in to reply
Loading