Skip to content

Plots of data with a CRS without EPSG code not possible #1074

@timschmi95

Description

@timschmi95

Calculating impacts with a CRS not corresponding to an EPSG code (e.g. a rotated lat/lon coordinate grid with a specified center point: ccrs.RotatedPole(pole_latitude=30, pole_longitude=-175)) works well, but none of the plotting functions (hazard, exposure, impact) work.
The issue is that u_plot.get_transformation() is called, which tries and fails to get an EPSG code from the CRS.
For most plots, simply directly passing the CRS directly instead of trying to get an EPSG code in the u_plot.get_transformation() function creates a correct plot.

Minimal Rep. Example for (failing) exposure plots:

import geopandas as gpd
from shapely.geometry import Point
from climada.entity import Exposures

#Define a rotated pole projection
prj = ccrs.RotatedPole(pole_latitude=30, pole_longitude=-175)

# Create grid points (2x4 grid for 8 points)
x_coords = [0, 1, 2, 3]
y_coords = [-2,-1,0, 1]
points_list = [Point(x, y) for y in y_coords for x in x_coords]

# Random values
values = np.random.rand(16)

# Create GeoDataFrame
gdf = gpd.GeoDataFrame({'value': values}, geometry=points_list, crs=prj)

# Create Exposures object and plot data
exp = Exposures(gdf)
ax=exp.plot_raster()

This example results in a rasterio.errors.CRSError from trying epsg = CRS.from_user_input(crs_in).to_epsg() in the get_transformation() function.

My suggestion would be to catch the CRSError if no EPSG code can be found, and in this case directly pass the input crs (while checking it's the correct object type and potentially other checks).
Is this suitable, or is there something speaking against allowing plots for data in a CRS without an EPSG code?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions