Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _tpcorr_init(v2_ref, v3_ref, roll_ref):
s2c = SphericalToCartesian(name='s2c', wrap_lon_at=180)
c2s = CartesianToSpherical(name='c2s', wrap_lon_at=180)
unit_conv = Scale(1.0 / 3600.0, name='arcsec_to_deg_1D')
unit_conv = unit_conv & unit_conv
unit_conv.name = 'arcsec_to_deg_2D'
unit_conv_inv = Scale(3600.0, name='deg_to_arcsec_1D')
unit_conv_inv = unit_conv_inv & unit_conv_inv
unit_conv_inv.name = 'deg_to_arcsec_2D'
affine = AffineTransformation2D(name='tp_affine')
affine_inv = AffineTransformation2D(name='tp_affine_inv')
rot = RotationSequence3D(
[v2_ref, -v3_ref, roll_ref],
'zyx',
name='det_to_optic_axis'
try:
import gwcs
if LooseVersion(gwcs.__version__) > '0.12.0':
from gwcs.geometry import CartesianToSpherical, SphericalToCartesian
_GWCS_VER_GT_0P12 = True
else:
_GWCS_VER_GT_0P12 = False
except ImportError:
_GWCS_VER_GT_0P12 = False
if _GWCS_VER_GT_0P12:
_S2C = SphericalToCartesian(name='s2c', wrap_lon_at=180)
_C2S = CartesianToSpherical(name='c2s', wrap_lon_at=180)
else:
def _S2C(phi, theta):
phi = np.deg2rad(phi)
theta = np.deg2rad(theta)
cs = np.cos(theta)
x = cs * np.cos(phi)
y = cs * np.sin(phi)
z = np.sin(theta)
return x, y, z
def _C2S(x, y, z):
h = np.hypot(x, y)
phi = np.rad2deg(np.arctan2(y, x))
theta = np.rad2deg(np.arctan2(z, h))
return phi, theta
def from_tree_transform(cls, node, ctx):
transform_type = node['transform_type']
wrap_lon_at = node['wrap_lon_at']
if transform_type == 'spherical_to_cartesian':
return SphericalToCartesian(wrap_lon_at=wrap_lon_at)
elif transform_type == 'cartesian_to_spherical':
return CartesianToSpherical(wrap_lon_at=wrap_lon_at)
else:
raise TypeError(f"Unknown model_type {transform_type}")
def to_tree_transform(cls, model, ctx):
if isinstance(model, SphericalToCartesian):
transform_type = 'spherical_to_cartesian'
elif isinstance(model, CartesianToSpherical):
transform_type = 'cartesian_to_spherical'
else:
raise TypeError(f"Model of type {model.__class__} is not supported.")
node = {
'transform_type': transform_type,
'wrap_lon_at': model.wrap_lon_at
}
return yamlutil.custom_tree_to_tagged_tree(node, ctx)