def sweep_r(phi, theta, points, max_field_strength=1.5): ''' Generate a pysweep.SweepObject to sweep field amplitude at fixed phi and theta. Here we use the ISO 80000-2:2009 physics convention for the (r, theta, phi) <--> (x, y, z) definition. Only values for the x, y, and z component are passed to the magnet. Inputs: phi (float): the azimuth (in plane) angle, unit: degrees, range: 0 <= phi <= 360 theta (float): inclination angle, unit: degrees, 0 <= theta <= 180 points (float): sweep values for r, i.e. the magentic field strength, unit: T, range: 0 <= r <= max_field_strength max_field_strength (float): maximum magnetic field strength, unit: T Output: pysweep.SweepObject ''' if max_field_strength > 1.5: showwarning( 'Be aware that mu-metal shields are saturated by too large magnetic fields and will not work afterwards.' 'Are you sure you want to go to more than 1.5 T?', ResourceWarning, 'cqed/cqed/custom_pysweep_functions/magnet', 162) @MakeMeasurementFunction([]) def point_function(d): return points, [] @MakeMeasurementFunction([]) def set_function(r, d): # Here we use the ISO 80000-2:2009 physics convention for the (r, theta, phi) <--> (x, y, z) definition. # Note that r is the radial distance, theta the inclination and phi the azimuth (in-plane) angle. # For uniqueness, we restrict the parameter choice to r>=0, 0<= theta <= pi and 0<= phi <= 2pi. # The units are: r in T, theta in degrees, phi in degrees. assert max_field_strength>r>0., 'The field amplitude must not exceed {} and be lager than 0.' \ ' Upper limit can be adjusted with kwarg: max_field_strength.' \ ' Proceed with caution (Mu-metal shields do not appreciate high fields!)'.format(max_field_strength) assert 0. <= theta <= 180., 'The inclination angle must be equal or lager than 0 and smaller or equal than 180. Change setting!' assert 0. <= phi <= 2 * 180., 'The azimuth angle must be equal or lager than 0 and smaller or equal than 360. Change setting!' station = d['STATION'] x = r * np.sin(np.radians(theta)) * np.cos(np.radians(phi)) y = r * np.sin(np.radians(theta)) * np.sin(np.radians(phi)) z = r * np.cos(np.radians(theta)) station.mgnt.x_target(x) station.mgnt.y_target(y) station.mgnt.z_target(z) station.mgnt.ramp(mode='safe') return [] return SweepObject(set_function=set_function, unit="T", label="r", point_function=point_function, dataparameter=None)
def sweep_z(self, points, max_field_strength=1.5): ''' Generate a pysweep.SweepObject to sweep field z amplitude at fixed x and y. Inputs: points (float): sweep values for z, i.e. the magentic field strength, unit: T, range: -max_field_strength <= z <= max_field_strength max_field_strength (float): maximum magnetic field strength, unit: T Output: pysweep.SweepObject ''' if max_field_strength > 1.5: showwarning( 'Be aware that mu-metal shields are saturated by too large magnetic fields and will not work afterwards.' 'Are you sure you want to go to more than 1.5 T?', ResourceWarning, 'cqed/cqed/custom_pysweep_functions/magnet', 162) @MakeMeasurementFunction([]) def point_function(d): return points, [] @MakeMeasurementFunction([]) def set_function(z, d): assert max_field_strength > np.abs(z) >= 0, 'The field amplitude must not exceed {} and be lager than 0.' \ ' Upper limit can be adjusted with kwarg: max_field_strength.' \ ' Proceed with caution (Mu-metal shields do not appreciate high fields!)'.format( max_field_strength) self.magnet.z_target(z) self.magnet.ramp(mode="safe") return [] return SweepObject(set_function=set_function, unit="T", label="z_field", point_function=point_function, dataparameter=None)
def sweep_r_with_alignment(theta, phi, points, FieldAligner, optimization_at=None, optimize_first=True, max_field_strength=1.5): if max_field_strength > 1.5: showwarning( 'Be aware that mu-metal shields are saturated by too large magnetic fields and will not work afterwards.' 'Are you sure you want to go to more than 1.5 T?', ResourceWarning, 'cqed/cqed/custom_pysweep_functions/magnet', 225) if optimize_first: FieldAligner.optimize_x() #ToDo: adjustment of theta and phi after field optimization if optimization_at is None: # default optimization of angle every 100 mT optimization_at = np.arange(points[0], points[-1], 100e-3) optimization_value_index = 1 @MakeMeasurementFunction([]) def point_function(d): return points, [] @MakeMeasurementFunction([]) def set_function(r, d): # Here we use the ISO 80000-2:2009 physics convention for the (r, theta, phi) <--> (x, y, z) definition. # Note that r is the radial distance, theta the inclination and phi the azimuth (in-plane) angle. # For uniqueness, we restrict the parameter choice to r>=0, 0<= theta <= pi and 0<= phi <= 2pi. # The units are: r in T, theta in degrees, phi in degrees. assert max_field_strength > r > 0., 'The field amplitude must not exceed {} and be lager than 0.' \ ' Upper limit can be adjusted with kwarg: max_field_strength.' \ ' Proceed with caution (Mu-metal shields do not appreciate high fields!)'.format( max_field_strength) assert 0. <= theta <= 180., 'The inclination angle must be equal or lager than 0 and smaller or equal than 180. Change setting!' assert 0. <= phi <= 2 * 180., 'The azimuth angle must be equal or lager than 0 and smaller or equal than 360. Change setting!' station = d['STATION'] x = r * np.sin(np.radians(theta)) * np.cos(np.radians(phi)) y = r * np.sin(np.radians(theta)) * np.sin(np.radians(phi)) z = r * np.cos(np.radians(theta)) station.mgnt.x_target(x) station.mgnt.y_target(y) station.mgnt.z_target(z) station.mgnt.ramp(mode='safe') if r >= optimization_at[optimization_value_index]: FieldAligner.optimize_x() optimization_value_index += 1 #TODO: update theta and phi after field optimization return [] return SweepObject(set_function=set_function, unit="T", label="r", point_function=point_function, dataparameter=None)
def sweep_phi(self, r, theta, points, max_field_strength=1.5, use_conventions=True): """ Generate a pysweep.SweepObject to sweep phi at fixed amplitude and theta. Here we use the ISO 80000-2:2009 physics convention for the (r, theta, phi) <--> (x, y, z) definition. Only values for the x, y, and z component are passed to the magnet. Inputs: r (float): magentic field strength, unit: T theta (float): inclination angle, unit: degrees, 0 <= theta <= 180 points (float): sweep values for phi, i.e. the azimuth (in plane) angle, unit: degrees, range: 0 <= phi <= 360 max_field_strength (float): maximum magnetic field strength, unit: T use_conventions (boolean): check if the values specified are consistent with conventions. Can be problematic when sweeping through 0 degrees. Output: pysweep.SweepObject """ if max_field_strength > 1.5: showwarning( "Be aware that mu-metal shields are saturated by too large magnetic fields and will not work afterwards." "Are you sure you want to go to more than 1.5 T?", ResourceWarning, "cqed/cqed/custom_pysweep_functions/magnet", 60, ) @MakeMeasurementFunction([]) def point_function(d): return points, [] @MakeMeasurementFunction([]) def set_function(phi, d): if use_conventions: assert max_field_strength > r >= 0, ( "The field amplitude must not exceed {} and be larger than 0." " Upper limit can be adjusted with kwarg: max_field_strength." " Proceed with caution (Mu-metal shields do not appreciate high fields!)" .format(max_field_strength)) assert ( 0.0 <= theta <= 180.0 ), "The inclination angle must be equal or lager than 0 and smaller or equal than 180. Change setting!" assert ( 0.0 <= phi <= 2 * 180.0 ), "The azimuth angle must be equal or larger than 0 and smaller or equal than 360. Change setting!" assert max_field_strength > np.abs(r) >= 0, ( "The field amplitude must not exceed {} and be larger than 0." " Upper limit can be adjusted with kwarg: max_field_strength." " Proceed with caution (Mu-metal shields do not appreciate high fields!)" .format(max_field_strength)) x = r * np.sin(np.radians(theta)) * np.cos(np.radians(phi)) y = r * np.sin(np.radians(theta)) * np.sin(np.radians(phi)) z = r * np.cos(np.radians(theta)) self.magnet.x_target(x) self.magnet.y_target(y) self.magnet.z_target(z) self.magnet.ramp(mode="safe") return [] return SweepObject( set_function=set_function, unit="degrees", label="phi", point_function=point_function, dataparameter=None, )