diff --git a/src/toolbox_scs/detectors/hrixs.py b/src/toolbox_scs/detectors/hrixs.py index 24f87bc7aad902187693b27e73a9971a8957f6f0..6e505f29ab9d68fe505cbce53a1219934134cdef 100644 --- a/src/toolbox_scs/detectors/hrixs.py +++ b/src/toolbox_scs/detectors/hrixs.py @@ -185,33 +185,34 @@ class hRIXS: Attributes ---------- - PROPOSAL: int + PROPOSAL : int the number of the proposal - X_RANGE: slice + X_RANGE : slice the slice to take in the dispersive direction, in pixels. Defaults to the entire width. - Y_RANGE: slice + Y_RANGE : slice the slice to take in the energy direction - THRESHOLD: float + THRESHOLD : float pixel counts above which a hit candidate is assumed, for centroiding. use None if you want to give it in standard deviations instead. - STD_THRESHOLD: + STD_THRESHOLD : same as THRESHOLD, in standard deviations. - BINS: int + BINS : int the number of bins used in centroiding - CURVE_A, CURVE_B: float + CURVE_A, CURVE_B : float the coefficients of the parabola for the curvature correction - USE_DARK: bool + USE_DARK : bool whether to do dark subtraction. Is initially `False`, magically switches to `True` if a dark has been loaded, but may be reset. - ENERGY_INTERCEPT, ENERGY_SLOPE: + ENERGY_INTERCEPT, ENERGY_SLOPE : The calibration from pixel to energy - FIELDS: + FIELDS : the fields to be loaded from the data. Add additional fields if so desired. Example ------- + A usual setup for the hRIXS class looks like this:: h = hRIXS() h.PROPOSAL = 3145 @@ -264,12 +265,15 @@ class hRIXS: Example ------- + Load data from a run:: data = h.from_run(145) # load run 145 + Combine data from two runs:: + data1 = h.from_run(145) # load run 145 data2 = h.from_run(155) # load run 155 - data = xarray.concat([data1, data2], 'trainId') # combine both + data = xarray.concat([data1, data2], 'trainId') """ if proposal is None: proposal = self.PROPOSAL @@ -287,8 +291,9 @@ class hRIXS: Example ------- + Load a dark run into the hRIXS object:: - h.load_dark(166) # load dark run 166 + h.load_dark(166) """ data = self.from_run(runNB, proposal) self.dark_image = data['hRIXS_det'].mean(dim='trainId') @@ -308,19 +313,21 @@ class hRIXS: Parameters ---------- - runNB: int + runNB : int the run number to use - proposal: int + proposal : int the proposal to use, default to the current proposal - plot: bool + plot : bool whether to plot the found curvature onto the data - args: pair of float, optional + args : pair of float, optional a starting value to prime the fitting routine Example ------- - h.find_curvature(155) # use run 155 to fit the curvature + Use run 155 to fit the curvature:: + + h.find_curvature(155) """ data = self.from_run(runNB, proposal) @@ -380,9 +387,11 @@ class hRIXS: Example ------- + Find photons in all images of run `data`, then plot the spectrum of + the first image:: - h.centroid(data) # find photons in all images of the run - data.spectrum[0, :].plot() # plot the spectrum of the first image + h.centroid(data) + data.spectrum[0, :].plot() """ if bins is None: bins = self.BINS @@ -424,9 +433,11 @@ class hRIXS: Example ------- + Create a spectrum by summing pixels with same energy in each image of + a run, then plot the spectrum of the first image:: - h.integrate(data) # create spectrum by summing pixels - data.spectrum[0, :].plot() # plot the spectrum of the first image + h.integrate(data) + data.spectrum[0, :].plot() """ bins = self.Y_RANGE.stop - self.Y_RANGE.start margin = 10 @@ -479,14 +490,19 @@ class hRIXS: Example ------- + Create spectra by finding photons, then sum all spectra, and + plot the result:: + + h.centroid(data) + agg = h.aggregate(data) + agg.spectrum.plot() - h.centroid(data) # create spectra from finding photons - agg = h.aggregate(data) # sum all spectra - agg.spectrum.plot() # plot the resulting spectrum + Group data by a variable, sum the corresponding spectra, and + plot the spectrum for the first value of the variable:: - groups = data.groupby('hRIXS_index') # group data by a variable - agg = groups.map(h.aggregate) # sum corresponding spectra - agg.spectrum[0, :].plot() # plot the spectrum for first value + groups = data.groupby('hRIXS_index') + agg = groups.map(h.aggregate) + agg.spectrum[0, :].plot() """ ret = ds.map(self.aggregator, dim=dim) ret = ret.drop_vars([n for n in ret if n not in self.aggregators])