Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement match stats at first wire #65

Open
github-actions bot opened this issue Nov 19, 2022 · 0 comments
Open

implement match stats at first wire #65

github-actions bot opened this issue Nov 19, 2022 · 0 comments
Labels
help wanted Extra attention is needed todo

Comments

@github-actions
Copy link

if 'bmag_x' in self.output and 'bmag_y' in self.output:

nbmag = np.sqrt( self.output['bmag_x'] * self.output['bmag_y'] )

bmag_emit_err = nemit*nbmag * (

(self.output['norm_emit_x_err']/self.output['norm_emit_x'])**2 +

(self.output['norm_emit_y_err']/self.output['norm_emit_y'])**2 +

(self.output['bmag_x_err']/self.output['bmag_x'])**2 +

(self.output['bmag_y_err']/self.output['bmag_y'])**2)**0.5

self.output['bmag_emit'] = nemit * nbmag

self.output['bmag_emit_err'] = bmag_emit_err

# TODO: implement match stats at first wire

            res = estimate_sigma_mat_multiwire(self.wire_rmat, bs, bs_err, weights, self.out_dict[f'locations'],
                                               dim=dim, plot=self.plot, verbose=self.verbose)

            # Add all results
            print(res)
            self.output.update(res)

            # Skip further calcs if there was an error
            if res[f'error_{dim}']:
                continue

            if self.calc_bmag:
                # TODO: implement match at first wire
                # if dim == 'x':
                #     sig_11 = res['screen_sigma_11']
                #     sig_12 = res['screen_sigma_12']
                #     sig_22 = res['screen_sigma_22']
                #
                # else:
                #     sig_11 = res['screen_sigma_33']
                #     sig_12 = res['screen_sigma_34']
                #     sig_22 = res['screen_sigma_44']
                # self.sig_mat_screen[dim] = [sig_11, sig_12, sig_22]
                #
                # beta_rel_err = res[f'beta_{dim}_rel_err']
                # alpha_rel_err = res[f'alpha_{dim}_rel_err']
                #
                # self.beta_err = beta_rel_err
                # self.alpha_err = alpha_rel_err
                #
                # bmag_calc_res = self.get_twiss_bmag(dim=dim)
                # # Get bmag and bmag_err
                # self.output[f'screen_bmag{dim}'] = bmag_calc_res[0]
                # self.output[f'screen_bmag{dim}_err'] = bmag_calc_res[1]
                print("Match not implemented for multiwire scan yet.")
                pass

        # get geometric mean if possible
        if (not self.output['error_x']) and (not self.output['error_y']) :
            self.get_gmean_emit()

        if self.save_runs:
            self.save_run()

        return self.out_dict

    def get_twiss_bmag(self, dim='x'):
        '''Not Implemented'''
        # TODO: implement match at first wire
        # sig_11 = self.sig_mat_screen[dim][0]
        # sig_12 = self.sig_mat_screen[dim][1]
        # sig_22 = self.sig_mat_screen[dim][2]
        #
        # # twiss0 in x or y AT THE SCREEN
        # beta0, alpha0 = self.twiss0[dim][1], self.twiss0[dim][2]
        #
        # # return dict of emit, beta, alpha, bmag
        # twiss = twiss_and_bmag(sig_11, sig_12, sig_22,
        #                        self.beta_err, self.alpha_err,
        #                        beta0=beta0, alpha0=alpha0)
        # # Save twiss at screen
        # self.twiss_screen[dim] = [twiss['emit'], twiss['beta'], twiss['alpha']]
        #
        # return twiss['bmag'], twiss['bmag_err'], twiss['min_idx']
        pass

    def get_gmean_emit(self):

        try:
            nemit = np.sqrt( self.output['norm_emit_x'] * self.output['norm_emit_y'] )
            nemit_err = nemit * ( (self.output['norm_emit_x_err']/self.output['norm_emit_x'])**2 +
                                  (self.output['norm_emit_y_err']/self.output['norm_emit_y'])**2 )**0.5

            self.output['sqrt_norm_emit_4d'] = nemit
            self.output['sqrt_norm_emit_4d_err'] = nemit_err

            # TODO: implement match stats at first wire
            # if 'bmag_x' in self.output and 'bmag_y' in self.output:
            #     nbmag = np.sqrt( self.output['bmag_x'] * self.output['bmag_y'] )
            #     bmag_emit_err = nemit*nbmag * (
            #         (self.output['norm_emit_x_err']/self.output['norm_emit_x'])**2 +
            #         (self.output['norm_emit_y_err']/self.output['norm_emit_y'])**2 +
            #         (self.output['bmag_x_err']/self.output['bmag_x'])**2 +
            #         (self.output['bmag_y_err']/self.output['bmag_y'])**2)**0.5
            #     self.output['bmag_emit'] = nemit * nbmag
            #     self.output['bmag_emit_err'] = bmag_emit_err

        except TypeError:
            self.output['sqrt_norm_emit_4d'] = np.nan
            self.output['sqrt_norm_emit_4d_err'] = np.nan
            self.output['bmag_emit'] = np.nan
            self.output['bmag_emit_err'] = np.nan

    def save_run(self):
        save_emit_run(self.out_dict, path=self.config_dict['savepaths']['fits'])
@github-actions github-actions bot added the todo label Nov 19, 2022
@pluflou pluflou added the help wanted Extra attention is needed label Nov 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed todo
Projects
None yet
Development

No branches or pull requests

1 participant