Skip to content

Commit

Permalink
Add CRS argument
Browse files Browse the repository at this point in the history
Skip test for now as it is unclear how this can be tested
  • Loading branch information
peanutfun committed Aug 8, 2022
1 parent 1be9772 commit ccec87f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
13 changes: 8 additions & 5 deletions climada/hazard/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
from climada import CONFIG
import climada.util.hdf5_handler as u_hdf5
import climada.util.coordinates as u_coord
from climada.util.constants import ONE_LAT_KM
from climada.util.constants import ONE_LAT_KM, DEF_CRS
from climada.util.coordinates import NEAREST_NEIGHBOR_THRESHOLD

LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -387,6 +387,7 @@ def from_raster_xarray(
intensity: str = "intensity",
coordinate_vars: Optional[Dict[str, str]] = None,
data_vars: Optional[Dict[str, str]] = None,
crs: str = DEF_CRS,
):
"""Read raster-like data from an xarray Dataset or a raster data file
Expand Down Expand Up @@ -417,9 +418,8 @@ def from_raster_xarray(
arguments.
* The attributes ``Hazard.tag.haz_type`` and ``Hazard.unit`` currently cannot be
read from the Dataset. Use the method parameters to set these attributes.
* This method does not read coordinate system metadata and uses the default WGS
84 coordinate system exclusively. To set a custom coordinate system, modify
the ``Hazard.centroids.geometry`` attribute of the returned object.
* This method does not read coordinate system metadata. Use the ``crs`` parameter
to set a custom coordinate system identifier.
* This method **does not** read lazily. Single data arrays must fit into memory.
Parameters
Expand Down Expand Up @@ -454,6 +454,9 @@ def from_raster_xarray(
* ``frequency``: 1.0 for every event
* ``event_name``: String representation of the event time
* ``event_id``: Consecutive integers starting at 1 and increasing with time
crs : str, optional
Identifier for the coordinate reference system to use. Defaults to
``EPSG:4326`` (WGS 84), defined by ``climada.util.constants.DEF_CRS``.
Returns
-------
Expand Down Expand Up @@ -592,7 +595,7 @@ def from_raster_xarray(

# Transform coordinates into centroids
hazard.centroids = Centroids.from_lat_lon(
data[coords["latitude"]].values, data[coords["longitude"]].values
data[coords["latitude"]].values, data[coords["longitude"]].values, crs=crs,
)

def to_csr_matrix(array: np.ndarray) -> sparse.csr_matrix:
Expand Down
4 changes: 4 additions & 0 deletions climada/hazard/test/test_base_xarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,10 @@ def test_nan(self):
# NaNs are propagated in dense data
np.testing.assert_array_equal(hazard.frequency, frequency)

@unittest.skip("no test for CRS input implemented")
def test_crs(self):
"""Check if different CRS are handled correctly"""
self.fail("No test implemented")

class ReadDimsCoordsNetCDF(unittest.TestCase):
"""Checks for dimensions and coordinates with different names and shapes"""
Expand Down

0 comments on commit ccec87f

Please sign in to comment.