Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/history.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Latest
- ENH: Generate 2D coordinates for non-rectilinear sources (issue #290)
- BUG: Return correct transform in `rio.transform` with non-rectilinear transform (discussions #280)
- BUG: Update to handle WindowError in rasterio 1.2.2 (issue #286)
- BUG: Don't generate x,y coords in `rio` methods if not previously there (pull #294)

0.3.2
-----
Expand Down
1 change: 1 addition & 0 deletions rioxarray/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ def merge_datasets(
merged_data[data_var].rio.transform(),
merged_data[data_var].shape[-1],
merged_data[data_var].shape[-2],
force_generate=True,
),
attrs=representative_ds.attrs,
)
Expand Down
15 changes: 11 additions & 4 deletions rioxarray/rioxarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,19 @@ def _get_nonspatial_coords(src_data_array):
return coords


def _make_coords(src_data_array, dst_affine, dst_width, dst_height):
def _make_coords(
src_data_array, dst_affine, dst_width, dst_height, force_generate=False
):
"""Generate the coordinates of the new projected `xarray.DataArray`"""
coords = _get_nonspatial_coords(src_data_array)
new_coords = _generate_spatial_coords(dst_affine, dst_width, dst_height)
new_coords.update(coords)
return new_coords
if force_generate or (
src_data_array.rio.x_dim in src_data_array.coords
and src_data_array.rio.y_dim in src_data_array.coords
):
new_coords = _generate_spatial_coords(dst_affine, dst_width, dst_height)
new_coords.update(coords)
return new_coords
return coords


def _get_data_var_message(obj):
Expand Down
52 changes: 27 additions & 25 deletions test/integration/test_integration_rioxarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ def test_reproject(modis_reproject):
"open_func",
[
rioxarray.open_rasterio,
# partial(rioxarray.open_rasterio, parse_coordinates=False), TODO: Fix
partial(rioxarray.open_rasterio, parse_coordinates=False),
],
)
def test_reproject_3d(open_func, modis_reproject_3d):
Expand All @@ -586,18 +586,19 @@ def test_reproject_3d(open_func, modis_reproject_3d):
mds_repr = mda.rio.reproject(modis_reproject_3d["to_proj"])
# test
_assert_xarrays_equal(mds_repr, mdc)
assert mds_repr.coords[mds_repr.rio.x_dim].attrs == {
"long_name": "longitude",
"standard_name": "longitude",
"units": "degrees_east",
"axis": "X",
}
assert mds_repr.coords[mds_repr.rio.y_dim].attrs == {
"long_name": "latitude",
"standard_name": "latitude",
"units": "degrees_north",
"axis": "Y",
}
if mdc.rio.x_dim in mdc.coords:
assert mds_repr.coords[mds_repr.rio.x_dim].attrs == {
"long_name": "longitude",
"standard_name": "longitude",
"units": "degrees_east",
"axis": "X",
}
assert mds_repr.coords[mds_repr.rio.y_dim].attrs == {
"long_name": "latitude",
"standard_name": "latitude",
"units": "degrees_north",
"axis": "Y",
}


def test_reproject__grid_mapping(modis_reproject):
Expand Down Expand Up @@ -725,18 +726,19 @@ def test_reproject_match(modis_reproject_match):
mds_repr = mda.rio.reproject_match(mdm)
# test
_assert_xarrays_equal(mds_repr, mdc)
assert mds_repr.coords[mds_repr.rio.x_dim].attrs == {
"axis": "X",
"long_name": "x coordinate of projection",
"standard_name": "projection_x_coordinate",
"units": "metre",
}
assert mds_repr.coords[mds_repr.rio.y_dim].attrs == {
"axis": "Y",
"long_name": "y coordinate of projection",
"standard_name": "projection_y_coordinate",
"units": "metre",
}
if mdc.rio.x_dim in mdc.coords:
assert mds_repr.coords[mds_repr.rio.x_dim].attrs == {
"axis": "X",
"long_name": "x coordinate of projection",
"standard_name": "projection_x_coordinate",
"units": "metre",
}
assert mds_repr.coords[mds_repr.rio.y_dim].attrs == {
"axis": "Y",
"long_name": "y coordinate of projection",
"standard_name": "projection_y_coordinate",
"units": "metre",
}


def test_reproject_match__masked(modis_reproject_match):
Expand Down