Skip to content

Conversation

@woutdenolf
Copy link
Collaborator

@woutdenolf woutdenolf commented Jun 20, 2025

Closes #1128

@woutdenolf woutdenolf linked an issue Jun 20, 2025 that may be closed by this pull request
@woutdenolf woutdenolf force-pushed the 1128-fastxrflinearfit-ignores-use_limit branch from 35ddd86 to f7ad9b6 Compare June 20, 2025 19:39
Comment on lines -133 to -136
if xmin is None:
xmin = config['fit']['xmin']
if xmax is None:
xmax = config['fit']['xmax']
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This essential forced use_limits=True regardless of where it is true or false in the config file.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it is the desired behavior in the fast linear fit to prevent user mistakes.

If xmin and xmax are passed, then they are used. If not the fit configuration is used. It has been always the case.

Copy link
Member

@vasole vasole Jun 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would revert that modification. It can only be harmful. because many users do not set use_limits=True

You can see in the McaAdvancedFit that it is done internally by setting xmax and xmin to the fit configuration values.

Comment on lines -1117 to +1141
xmin = self.config['fit']['xmin']
if not self.config['fit']['use_limit']:
if 'xmin' in kw:
xmin=kw['xmin']
if xmin is not None:
self.config['fit']['xmin'] = xmin
else:
xmin=min(self.xdata)
if self.config['fit']['use_limit']:
xmin = self.config['fit']['xmin']
else:
xmin = kw.get('xmin')
if xmin is not None:
self.config['fit']['xmin'] = xmin
elif len(self.xdata):
xmin=min(self.xdata)
xmax = self.config['fit']['xmax']
if not self.config['fit']['use_limit']:
if 'xmax' in kw:
xmax=kw['xmax']
if xmax is not None:
self.config['fit']['xmax'] = xmax
else:
xmax=max(self.xdata)
xmin = min(self.xdata)
else:
xmin = 0

if self.config['fit']['use_limit']:
xmax = self.config['fit']['xmax']
else:
xmax = kw.get('xmax')
if xmax is not None:
self.config['fit']['xmax'] = xmax
elif len(self.xdata):
xmax=max(self.xdata)
xmax = max(self.xdata)
else:
xmax = 0
Copy link
Collaborator Author

@woutdenolf woutdenolf Jun 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code was very hard to understand so I modified it to make it more clear (at least imo).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • use_limit=True -> use the config
  • use_limit=False:
    • function argument not None -> use function arguments
    • function argument None :
      - xdata not empty -> use first/last value
      - xdata empty -> 0

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct.

Copy link
Member

@vasole vasole Jun 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However, the fit configuration limits should not be changed. xmin and xmax is what is going to be used at the end.

Well, it seems it was the previous behavior when explicit values were passed.

@woutdenolf woutdenolf marked this pull request as ready for review June 20, 2025 20:19
@woutdenolf woutdenolf requested a review from vasole June 20, 2025 20:19
@woutdenolf woutdenolf marked this pull request as draft June 20, 2025 21:00
@woutdenolf
Copy link
Collaborator Author

I see a regression in fit quality due to this commit. Need to investigate what's going on ...

@woutdenolf woutdenolf marked this pull request as ready for review June 20, 2025 21:13
@woutdenolf
Copy link
Collaborator Author

woutdenolf commented Jun 20, 2025

Ok no, my mistake I was calculating a theoretical spectrum with use_limit=1 and then fitting it with use_limit=1 while I wanted to calculate with use_limit=0 and fit with use_limit=1.

@vasole
Copy link
Member

vasole commented Jun 23, 2025

Passing xmin and xmax to the setData should change the fit limits but not the configuration.

It seems it was the case before when explicit limits were passed.

@woutdenolf
Copy link
Collaborator Author

Then how about this

# Force fit limits to be used, whether the user enabled it or not.
config['fit']['use_limit'] = 1

instead of this

if xmin is None:
    xmin = config['fit']['xmin']
if xmax is None:
    xmax = config['fit']['xmax']

@vasole
Copy link
Member

vasole commented Jun 23, 2025

If the user explicitly ask you to use different limits, then you have to use them. I cannot afford that by performing a fit, a parameter that only has sense in interactive mode gets changed. If you set it like that, the user will never be able to select the fitting region because the limits will always be hard-coded after selecting the first fitting region.

The use_limit flag only has sense within the interactive use and it was explicitly requested to achieve that behavior: to give the user the possibility to fix or not the zoomed region to be fitted.

It is the same as with the parameter to ignore calibration from input data:

image

@woutdenolf woutdenolf closed this Jun 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FastXRFLinearFit ignores "use_limit"

3 participants