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',
@classmethod
def to_tree_transform(cls, model, ctx):
if isinstance(model, FromDirectionCosines):
transform_type = 'from_direction_cosines'
elif isinstance(model, ToDirectionCosines):
transform_type = 'to_direction_cosines'
else:
raise TypeError(f"Model of type {model.__class__} is not supported.")
node = {'transform_type': transform_type}
return yamlutil.custom_tree_to_tagged_tree(node, ctx)
class SphericalCartesianType(GWCSTransformType):
name = "spherical_cartesian"
types = [SphericalToCartesian, CartesianToSpherical]
version = "1.1.0"
@classmethod
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}")
@classmethod
def to_tree_transform(cls, model, ctx):
if isinstance(model, SphericalToCartesian):
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}")
from spherical_geometry.polygon import SphericalPolygon
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))