Skip to content

Commit

Permalink
add option to not initiate the calibration fit with a simple fit of t…
Browse files Browse the repository at this point in the history
…heta circles
  • Loading branch information
julienguy committed Jun 10, 2020
1 parent a05cd59 commit b7e67ad
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
4 changes: 3 additions & 1 deletion bin/fit_posparams
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ parser.add_argument('-v', '--verbose', action='store_true',
help='extra verbosity of print outs at terminal')
parser.add_argument('--log-note-selection', type=str, default=None, required=False,
help="required keywords in LOG_NOTE selection, seperated by '&', like ''arc calibration & use_desimeter=True'")
parser.add_argument('--no-circle-fit', action='store_true', help="do not initiate the fit with a fit of theta circles")

args = parser.parse_args()

Expand Down Expand Up @@ -108,7 +109,8 @@ if __name__ == '__main__':
'savedir': args.outdir,
'static_quantile': args.static_quantile,
'printf': printf,
'log_note_selection': args.log_note_selection
'log_note_selection': args.log_note_selection,
'no_circle_fit': args.no_circle_fit
}
if args.n_processes_max == 1:
logstr = fithandler.run_best_fits(**kwargs)
Expand Down
27 changes: 15 additions & 12 deletions py/desimeter/posparams/fithandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
output_keys.update({key:True for key in fitter.all_keys})

def run_best_fits(posid, path, period_days, data_window, savedir,
static_quantile, printf=print, min_window=10, log_note_selection=None):
static_quantile, printf=print, min_window=10, log_note_selection=None, no_circle_fit = False):
'''Define best-fit analysis cases for one positioner.
INPUTS:
Expand All @@ -44,6 +44,7 @@ def run_best_fits(posid, path, period_days, data_window, savedir,
printf ... print function (so you can control how this module spits any messages)
min_window ... (optional) minimum number of data points to attempt a fit
log_note_selection ... (optional) required keywords in LOG_NOTE selection, seperated by '&', like ''arc calibration & use_desimeter=True'
no_circle_fit ... (bool, optional) if true, do not initiate the fit with a fit of theta circles
OUTPUTS:
logstr ... string describing (very briefly) what was done. suitable for
Expand All @@ -65,7 +66,7 @@ def run_best_fits(posid, path, period_days, data_window, savedir,
# FIRST-PASS: STATIC PARAMETERS
static_out = _process_cases(table, cases, printf=printf, mode='static',
param_nominals=fitter.default_values.copy(),
)
no_circle_fit=no_circle_fit)

# DECIDE ON BEST STATIC PARAMS
best_static = fitter.default_values.copy()
Expand Down Expand Up @@ -247,7 +248,7 @@ def _define_cases(table, datum_dates, data_window, printf=print):
printf(f'{posid}: {len(cases):5d} analysis cases defined')
return cases

def _process_cases(table, cases, mode, param_nominals, printf=print):
def _process_cases(table, cases, mode, param_nominals, printf=print, no_circle_fit = False):
'''Feed analysis cases for a positioner through the best-fit function.
INPUTS:
Expand All @@ -256,6 +257,7 @@ def _process_cases(table, cases, mode, param_nominals, printf=print):
mode ... 'static' or 'dynamic'
param_nominals ... Dict of nominal parameter values, structured like fitter.default_values
printf ... print function
no_circle_fit ... (bool, optional) if true, do not initiate the fit with a fit of theta circles
OUTPUT:
output ... Astropy table of results, headers given by output_keys.
Expand All @@ -281,15 +283,16 @@ def _process_cases(table, cases, mode, param_nominals, printf=print):
printf(f' final idx = {n:5d}, date = {subtable["DATE"][-1]}')
printf(f' num points = {n-m+1:5d}')
params, covariance_dict, rms_of_residuals = fitter.fit_params(posintT=xytp_data['posintT'],
posintP=xytp_data['posintP'],
ptlX=xytp_data['ptlX'],
ptlY=xytp_data['ptlY'],
gearT=xytp_data['gearT'],
gearP=xytp_data['gearP'],
mode=mode,
nominals=param_nominals,
bounds=fitter.default_bounds,
keep_fixed=[])
posintP=xytp_data['posintP'],
ptlX=xytp_data['ptlX'],
ptlY=xytp_data['ptlY'],
gearT=xytp_data['gearT'],
gearP=xytp_data['gearP'],
mode=mode,
nominals=param_nominals,
bounds=fitter.default_bounds,
keep_fixed=[],
no_circle_fit=no_circle_fit)
output['ANALYSIS_DATE'].append(Time.now().iso)
output['POS_ID'].append(posid)
for suffix in {'', '_SEC'}:
Expand Down
3 changes: 2 additions & 1 deletion py/desimeter/posparams/fitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def fit_params(posintT, posintP, ptlX, ptlY, gearT, gearP,
keep_fixed=None,
ptlXerr=None,
ptlYerr=None,
no_circle_fit=False
):
'''Best-fit function for parameters used in the transformation between
internally-tracked (theta,phi) and externally measured (x,y).
Expand Down Expand Up @@ -238,7 +239,7 @@ def compute_chi2(params):
x_exp, y_exp = expected_xy(params)
return np.sum(((x_exp - x_flat)/xerr_flat)**2 + ((y_exp - y_flat)/yerr_flat)**2)

if mode=='static' :
if (not no_circle_fit) and (mode=='static') :
# we initialize OFFSET_X and OFFSET_Y by fitting circles
# for all unique values of p_int
unique_p_int = np.unique(p_int)
Expand Down

0 comments on commit b7e67ad

Please sign in to comment.