Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revise SpatialReference properties, add geotransform #367

Closed
wants to merge 6 commits into from
Closed

Revise SpatialReference properties, add geotransform #367

wants to merge 6 commits into from

Conversation

mwtoews
Copy link
Contributor

@mwtoews mwtoews commented Jul 25, 2018

The commit messages have more details, but the aim of this PR is to revise a few properties in the SpatialReference class. Here are the main changes:

  • Add dx, dy, xlength, ylength and geotransform properties to SpatialReference, which are used for array exports.
  • Remove set_origin and theta, as they don't appear to be needed (anymore?) and have no tests. They can be re-added, but some of the trigonometry will need to be revised, and tests added. theta was removed as it was using -ve angles for clockwise rotations. The correct rotation direction is counter clockwise (i.e. positive angles).
  • Exporting rasters with different resolutions in x- and y-directions should be supported by export_array, as it is supported by Surfer and GDAL (and hence QGIS). However, not all software support dx/dy in Arc Ascii grid formats. A warning is added if either delr and/or delc are not uniform.
  • Currently, rotated grids exported to Arc Ascii grids with export_array will do a spline interpolation. This modifies the grid dimensions and values, which are often extrapolated beyond the grid's min/max values. I've added a warning to be shown, as it's not typical that an export method would do this processing. Consider removing this feature, and moving the recipe to the Notes section or other place.

In case anyone is wondering where this is all going, I'd like to eventually revise export_netcdf to write netCDF files that are more compliant with the GDAL family of GIS software, which is best done with a geotransform.

Happy to discuss any of the changes, as there is a lot going on.

mwtoews added 5 commits July 12, 2018 21:28
add missing autotests for get_extent
 - remove unused set_origin (assumed to not be needed?)
 - remove theta property, which was used in equations that assumed CW
   rotations (we use CCW elsewhere)
 - reverse sign in xll and xul to use CCW rotation convention
 - add generic cos_sin(deg), which snaps to right angles
 - use shorthand logic "x or y" instead of "x if x is not None else y"
Use this for export_array with .tif, since it is more robust with
older versions of affine (before v.2, rotation was clock-wise, and after
it is counter clock-wise. E.g. the added autotest previously failed with
affine 1.2.0 packaged with Ubuntu).
 - Remove restriction that a uniform grid is needed; use dx and dy
   fields, as is supported by GDAL and Surfer, but perhaps not others.
 - Raise a warning when rotation is used, as it currently modifies
   grid values via spline interpolation. Add TODO to consider removing
   this feature, perhaps making an example in the notes or elsewhere.

Rewrite test_export_array:
 - First do some simpler tests on unrotated exports.
 - More compact reading/testing of .asc
 - Use np.testing.assert_almost_equal list/tuple/array checks
   that are not 100% identical.

Other changes:
 - Move dx/dy to properties, which raise warnings if not constant.
 - Rewrite part of 'Notes' section for export_array
 - Raise ValueError if filename extension not supported
 - Add some other tests for dx/dy in test_dynamic_xll_yll
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.1%) to 68.699% when pulling 51f05b8 on mwtoews:export into be3281f on modflowpy:develop.

@coveralls
Copy link

coveralls commented Jul 25, 2018

Coverage Status

Coverage decreased (-1.7%) to 68.846% when pulling 3f434b3 on mwtoews:export into 1bfa795 on modflowpy:develop.

@spaulins-usgs
Copy link
Contributor

Mike, a few of us are currently working on refactoring some of the SpatialReference code. We are generalizing the code so that the existing SpatialReference, exporting, and plotting code can be used with MODFLOW6. Specifically, we are adding a ModelGrid class with StructuredModelGrid and VertexModelGrid subclasses that handle model grid specific behavior. SpatialReference will work with the different types of model grids to perform model grid specific operations, like get_xcenter_array.

That said, I briefly looked at your changes and I believe they can all be incorporated into what we are doing. Andy Leaf may also have comments on this since he is the one currently working on the SpatialReference class. Given your interest and knowledge of the SpatialReference code I think it would be valuable if you reviewed our changes once we have completed them. Your input would be greatly appreciated.

@mwtoews
Copy link
Contributor Author

mwtoews commented Jul 25, 2018

@spaulins-usgs happy to review the mf6 spatial reference code, as these are critical components for exporting a variety of formats (rasters, netcdf, vtk, etc.). And yes, it does make sense to have subclasses, such as StructuredModelGrid, to handle mesh-specific properties such as the ones that I've touched in this PR.

@aleaf
Copy link
Contributor

aleaf commented Jul 26, 2018

@mwtoews, I think this looks reasonable. I agree with @spaulins-usgs that all of these changes can be integrated into the upcoming revisions (see also #368 and let us know what you think).

My only concerns are potentially adding to an already somewhat cluttered list of public attributes (but maybe this isn't that big of a deal) and also dx/dy when delr/delc have variable spacings. Instead of using median values, I think they should just be None or inactivated in some other way, to make it clear that they don't apply to that case.

@mwtoews
Copy link
Contributor Author

mwtoews commented Aug 8, 2018

As for dx/dy/geotransform returning None for non-uniform grids, I see the merit in this and I can change this behavior later today.

Also, considering #368, should the names dx/dy be renamed? In most other contexts, it seems that (e.g.) "x"/"y" means a projected coordinate, while here it means local Cartesian in model units. I can alternatively "hide" these properties as _const_delr, as they may not be helpful in too many other places.

 - replace dx/dy with resolution with length multiplier applied
 - return None rather than median of delr/delc
 - geotransform raises ValueError for non-uniform grids
 - check full bounds for recent rasterio only
@mwtoews
Copy link
Contributor Author

mwtoews commented Aug 21, 2018

I removed dx and dy to avoid the number of properties with "x" and "y", and replaced it with a single resolution property that returns a tuple of the model grid resolution with length multiplier applied.

Any other comments?

@mwtoews
Copy link
Contributor Author

mwtoews commented Apr 30, 2019

Closing this PR for now as it's based on deprecated methods. It may re-appear in a different form, as it would be useful to have an Affine GeoTransform property for exporting regular grids to custom raster formats.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants