|
10 | 10 |
|
11 | 11 | from abc import ABCMeta, abstractmethod
|
12 | 12 | from functools import cached_property
|
| 13 | +import re |
13 | 14 | import warnings
|
14 | 15 |
|
15 | 16 | import cartopy.crs as ccrs
|
16 | 17 | import numpy as np
|
17 | 18 |
|
| 19 | +from iris._deprecation import warn_deprecated |
18 | 20 | import iris.exceptions
|
19 | 21 |
|
20 | 22 |
|
@@ -1634,3 +1636,197 @@ def as_cartopy_crs(self):
|
1634 | 1636 |
|
1635 | 1637 | def as_cartopy_projection(self):
|
1636 | 1638 | return self.as_cartopy_crs()
|
| 1639 | + |
| 1640 | + |
| 1641 | +class ObliqueMercator(CoordSystem): |
| 1642 | + """ |
| 1643 | + A cylindrical map projection, with XY coordinates measured in metres. |
| 1644 | +
|
| 1645 | + Designed for regions not well suited to :class:`Mercator` or |
| 1646 | + :class:`TransverseMercator`, as the positioning of the cylinder is more |
| 1647 | + customisable. |
| 1648 | +
|
| 1649 | + See Also |
| 1650 | + -------- |
| 1651 | + :class:`RotatedMercator` |
| 1652 | +
|
| 1653 | + """ |
| 1654 | + |
| 1655 | + grid_mapping_name = "oblique_mercator" |
| 1656 | + |
| 1657 | + def __init__( |
| 1658 | + self, |
| 1659 | + azimuth_of_central_line, |
| 1660 | + latitude_of_projection_origin, |
| 1661 | + longitude_of_projection_origin, |
| 1662 | + false_easting=None, |
| 1663 | + false_northing=None, |
| 1664 | + scale_factor_at_projection_origin=None, |
| 1665 | + ellipsoid=None, |
| 1666 | + ): |
| 1667 | + """ |
| 1668 | + Constructs an ObliqueMercator object. |
| 1669 | +
|
| 1670 | + Parameters |
| 1671 | + ---------- |
| 1672 | + azimuth_of_central_line : float |
| 1673 | + Azimuth of centerline clockwise from north at the center point of |
| 1674 | + the centre line. |
| 1675 | + latitude_of_projection_origin : float |
| 1676 | + The true longitude of the central meridian in degrees. |
| 1677 | + longitude_of_projection_origin: float |
| 1678 | + The true latitude of the planar origin in degrees. |
| 1679 | + false_easting: float, optional |
| 1680 | + X offset from the planar origin in metres. |
| 1681 | + Defaults to 0.0 . |
| 1682 | + false_northing: float, optional |
| 1683 | + Y offset from the planar origin in metres. |
| 1684 | + Defaults to 0.0 . |
| 1685 | + scale_factor_at_projection_origin: float, optional |
| 1686 | + Scale factor at the central meridian. |
| 1687 | + Defaults to 1.0 . |
| 1688 | + ellipsoid: :class:`GeogCS`, optional |
| 1689 | + If given, defines the ellipsoid. |
| 1690 | +
|
| 1691 | + Examples |
| 1692 | + -------- |
| 1693 | + >>> from iris.coord_systems import GeogCS, ObliqueMercator |
| 1694 | + >>> my_ellipsoid = GeogCS(6371229.0, None, 0.0) |
| 1695 | + >>> ObliqueMercator(90.0, -22.0, -59.0, -25000.0, -25000.0, 1., my_ellipsoid) |
| 1696 | + ObliqueMercator(azimuth_of_central_line=90.0, latitude_of_projection_origin=-22.0, longitude_of_projection_origin=-59.0, false_easting=-25000.0, false_northing=-25000.0, scale_factor_at_projection_origin=1.0, ellipsoid=GeogCS(6371229.0)) |
| 1697 | +
|
| 1698 | + """ |
| 1699 | + #: Azimuth of centerline clockwise from north. |
| 1700 | + self.azimuth_of_central_line = float(azimuth_of_central_line) |
| 1701 | + |
| 1702 | + #: True latitude of planar origin in degrees. |
| 1703 | + self.latitude_of_projection_origin = float( |
| 1704 | + latitude_of_projection_origin |
| 1705 | + ) |
| 1706 | + |
| 1707 | + #: True longitude of planar origin in degrees. |
| 1708 | + self.longitude_of_projection_origin = float( |
| 1709 | + longitude_of_projection_origin |
| 1710 | + ) |
| 1711 | + |
| 1712 | + #: X offset from planar origin in metres. |
| 1713 | + self.false_easting = _arg_default(false_easting, 0) |
| 1714 | + |
| 1715 | + #: Y offset from planar origin in metres. |
| 1716 | + self.false_northing = _arg_default(false_northing, 0) |
| 1717 | + |
| 1718 | + #: Scale factor at the central meridian. |
| 1719 | + self.scale_factor_at_projection_origin = _arg_default( |
| 1720 | + scale_factor_at_projection_origin, 1.0 |
| 1721 | + ) |
| 1722 | + |
| 1723 | + #: Ellipsoid definition (:class:`GeogCS` or None). |
| 1724 | + self.ellipsoid = ellipsoid |
| 1725 | + |
| 1726 | + def __repr__(self): |
| 1727 | + return ( |
| 1728 | + "{!s}(azimuth_of_central_line={!r}, " |
| 1729 | + "latitude_of_projection_origin={!r}, " |
| 1730 | + "longitude_of_projection_origin={!r}, false_easting={!r}, " |
| 1731 | + "false_northing={!r}, scale_factor_at_projection_origin={!r}, " |
| 1732 | + "ellipsoid={!r})".format( |
| 1733 | + self.__class__.__name__, |
| 1734 | + self.azimuth_of_central_line, |
| 1735 | + self.latitude_of_projection_origin, |
| 1736 | + self.longitude_of_projection_origin, |
| 1737 | + self.false_easting, |
| 1738 | + self.false_northing, |
| 1739 | + self.scale_factor_at_projection_origin, |
| 1740 | + self.ellipsoid, |
| 1741 | + ) |
| 1742 | + ) |
| 1743 | + |
| 1744 | + def as_cartopy_crs(self): |
| 1745 | + globe = self._ellipsoid_to_globe(self.ellipsoid, None) |
| 1746 | + |
| 1747 | + return ccrs.ObliqueMercator( |
| 1748 | + central_longitude=self.longitude_of_projection_origin, |
| 1749 | + central_latitude=self.latitude_of_projection_origin, |
| 1750 | + false_easting=self.false_easting, |
| 1751 | + false_northing=self.false_northing, |
| 1752 | + scale_factor=self.scale_factor_at_projection_origin, |
| 1753 | + azimuth=self.azimuth_of_central_line, |
| 1754 | + globe=globe, |
| 1755 | + ) |
| 1756 | + |
| 1757 | + def as_cartopy_projection(self): |
| 1758 | + return self.as_cartopy_crs() |
| 1759 | + |
| 1760 | + |
| 1761 | +class RotatedMercator(ObliqueMercator): |
| 1762 | + """ |
| 1763 | + :class:`ObliqueMercator` with ``azimuth_of_central_line=90``. |
| 1764 | +
|
| 1765 | + As noted in CF versions 1.10 and earlier: |
| 1766 | +
|
| 1767 | + The Rotated Mercator projection is an Oblique Mercator projection |
| 1768 | + with azimuth = +90. |
| 1769 | +
|
| 1770 | + .. deprecated:: 3.8.0 |
| 1771 | + This coordinate system was introduced as already scheduled for removal |
| 1772 | + in a future release, since CF version 1.11 onwards now requires use of |
| 1773 | + :class:`ObliqueMercator` with ``azimuth_of_central_line=90.`` . |
| 1774 | + Any :class:`RotatedMercator` instances will always be saved to NetCDF |
| 1775 | + as the ``oblique_mercator`` grid mapping. |
| 1776 | +
|
| 1777 | + """ |
| 1778 | + |
| 1779 | + def __init__( |
| 1780 | + self, |
| 1781 | + latitude_of_projection_origin, |
| 1782 | + longitude_of_projection_origin, |
| 1783 | + false_easting=None, |
| 1784 | + false_northing=None, |
| 1785 | + scale_factor_at_projection_origin=None, |
| 1786 | + ellipsoid=None, |
| 1787 | + ): |
| 1788 | + """ |
| 1789 | + Constructs a RotatedMercator object. |
| 1790 | +
|
| 1791 | + Parameters |
| 1792 | + ---------- |
| 1793 | + latitude_of_projection_origin : float |
| 1794 | + The true longitude of the central meridian in degrees. |
| 1795 | + longitude_of_projection_origin: float |
| 1796 | + The true latitude of the planar origin in degrees. |
| 1797 | + false_easting: float, optional |
| 1798 | + X offset from the planar origin in metres. |
| 1799 | + Defaults to 0.0 . |
| 1800 | + false_northing: float, optional |
| 1801 | + Y offset from the planar origin in metres. |
| 1802 | + Defaults to 0.0 . |
| 1803 | + scale_factor_at_projection_origin: float, optional |
| 1804 | + Scale factor at the central meridian. |
| 1805 | + Defaults to 1.0 . |
| 1806 | + ellipsoid: :class:`GeogCS`, optional |
| 1807 | + If given, defines the ellipsoid. |
| 1808 | +
|
| 1809 | + """ |
| 1810 | + message = ( |
| 1811 | + "iris.coord_systems.RotatedMercator is deprecated, and will be " |
| 1812 | + "removed in a future release. Instead please use " |
| 1813 | + "iris.coord_systems.ObliqueMercator with " |
| 1814 | + "azimuth_of_central_line=90 ." |
| 1815 | + ) |
| 1816 | + warn_deprecated(message) |
| 1817 | + |
| 1818 | + super().__init__( |
| 1819 | + 90.0, |
| 1820 | + latitude_of_projection_origin, |
| 1821 | + longitude_of_projection_origin, |
| 1822 | + false_easting, |
| 1823 | + false_northing, |
| 1824 | + scale_factor_at_projection_origin, |
| 1825 | + ellipsoid, |
| 1826 | + ) |
| 1827 | + |
| 1828 | + def __repr__(self): |
| 1829 | + # Remove the azimuth argument from the parent repr. |
| 1830 | + result = super().__repr__() |
| 1831 | + result = re.sub(r"azimuth_of_central_line=\d*\.?\d*, ", "", result) |
| 1832 | + return result |
0 commit comments