From f5fa336475419bc513c40cd76d2dba883b2fd2d8 Mon Sep 17 00:00:00 2001
From: "Alan D. Snow" Alan D. Snow (https://github.com/snowman2) Alfredo Delos Santos (https://github.com/alfredoahds) David Hoese (https://github.com/djhoese)Navigation
All modules for which code is available
@@ -70,13 +68,11 @@ Source code for rioxarray.crs
@@ -57,6 +55,14 @@ Source code for rioxarray.exceptions
Source code for rioxarray.exceptions
@@ -62,7 +60,12 @@ Source code for rioxarray.rioxarray
from rasterio.features import geometry_mask
from scipy.interpolate import griddata
-from rioxarray.exceptions import NoDataInBounds, OneDimensionalRaster
+from rioxarray.exceptions import (
+ InvalidDimensionOrder,
+ NoDataInBounds,
+ OneDimensionalRaster,
+ TooManyDimensions,
+)
from rioxarray.crs import crs_to_wkt
FILL_VALUE_NAMES = ("_FillValue", "missing_value", "fill_value")
@@ -366,6 +369,34 @@
Source code for rioxarray.rioxarray
bottom = float(self._obj[self.y_dim][-1])
return left, bottom, right, top
+ def _check_dimensions(self):
+ """
+ This function validates that the dimensions 2D/3D and
+ they are are in the proper order.
+
+ Returns:
+ --------
+ str or None: Name extra dimension.
+ """
+ extra_dims = list(set(list(self._obj.dims)) - set([self.x_dim, self.y_dim]))
+ if len(extra_dims) > 1:
+ raise TooManyDimensions("Only 2D and 3D data arrays supported.")
+ elif extra_dims and self._obj.dims != (extra_dims[0], self.y_dim, self.x_dim):
+ raise InvalidDimensionOrder(
+ "Invalid dimension order. Expected order: {0}. "
+ "You can use `DataArray.transpose{0}`"
+ " to reorder your dimensions.".format(
+ (extra_dims[0], self.y_dim, self.x_dim)
+ )
+ )
+ elif not extra_dims and self._obj.dims != (self.y_dim, self.x_dim):
+ raise InvalidDimensionOrder(
+ "Invalid dimension order. Expected order: {0}"
+ "You can use `DataArray.transpose{0}` "
+ "to reorder your dimensions.".format((self.y_dim, self.x_dim))
+ )
+ return extra_dims[0] if extra_dims else None
+
Source code for rioxarray.rioxarray
dst_affine, dst_width, dst_height = _make_dst_affine(
self._obj, self.crs, dst_crs, resolution
)
- extra_dims = list(set(list(self._obj.dims)) - set([self.x_dim, self.y_dim]))
- if len(extra_dims) > 1:
- raise RuntimeError("Reproject only supports 2D and 3D datasets.")
- if extra_dims:
- assert self._obj.dims == (extra_dims[0], self.y_dim, self.x_dim)
+ extra_dim = self._check_dimensions()
+ if extra_dim:
dst_data = np.zeros(
- (self._obj[extra_dims[0]].size, dst_height, dst_width),
+ (self._obj[extra_dim].size, dst_height, dst_width),
dtype=self._obj.dtype.type,
)
else:
- assert self._obj.dims == (self.y_dim, self.x_dim)
dst_data = np.zeros((dst_height, dst_width), dtype=self._obj.dtype.type)
try:
@@ -781,13 +808,10 @@
Source code for rioxarray.rioxarray
:class:`xarray.DataArray`: An interpolated :class:`xarray.DataArray` object.
"""
- extra_dims = list(set(list(self._obj.dims)) - set([self.x_dim, self.y_dim]))
- if len(extra_dims) > 1:
- raise RuntimeError("Interpolate only supports 2D and 3D datasets.")
- if extra_dims:
- assert self._obj.dims == (extra_dims[0], self.y_dim, self.x_dim)
+ extra_dim = self._check_dimensions()
+ if extra_dim:
interp_data = []
- for _, sub_xds in self._obj.groupby(extra_dims[0]):
+ for _, sub_xds in self._obj.groupby(extra_dim):
interp_data.append(
self._interpolate_na(sub_xds.load().data, method=method)
)
@@ -806,7 +830,57 @@
Source code for rioxarray.rioxarray
# make sure correct attributes preserved & projection added
_add_attrs_proj(interp_array, self._obj)
- return interp_array
Source code for rioxarray.rioxarray
\
-
');
- }
- // Prettify the comment rating.
- comment.pretty_rating = comment.rating + ' point' +
- (comment.rating == 1 ? '' : 's');
- // Make a class (for displaying not yet moderated comments differently)
- comment.css_class = comment.displayed ? '' : ' moderate';
- // Create a div for this comment.
- var context = $.extend({}, opts, comment);
- var div = $(renderTemplate(commentTemplate, context));
-
- // If the user has voted on this comment, highlight the correct arrow.
- if (comment.vote) {
- var direction = (comment.vote == 1) ? 'u' : 'd';
- div.find('#' + direction + 'v' + comment.id).hide();
- div.find('#' + direction + 'u' + comment.id).show();
- }
-
- if (opts.moderator || comment.text != '[deleted]') {
- div.find('a.reply').show();
- if (comment.proposal_diff)
- div.find('#sp' + comment.id).show();
- if (opts.moderator && !comment.displayed)
- div.find('#cm' + comment.id).show();
- if (opts.moderator || (opts.username == comment.username))
- div.find('#dc' + comment.id).show();
- }
- return div;
- }
-
- /**
- * A simple template renderer. Placeholders such as <%id%> are replaced
- * by context['id'] with items being escaped. Placeholders such as <#id#>
- * are not escaped.
- */
- function renderTemplate(template, context) {
- var esc = $(document.createElement('div'));
-
- function handle(ph, escape) {
- var cur = context;
- $.each(ph.split('.'), function() {
- cur = cur[this];
- });
- return escape ? esc.text(cur || "").html() : cur;
- }
-
- return template.replace(/<([%#])([\w\.]*)\1>/g, function() {
- return handle(arguments[2], arguments[1] == '%' ? true : false);
- });
- }
-
- /** Flash an error message briefly. */
- function showError(message) {
- $(document.createElement('div')).attr({'class': 'popup-error'})
- .append($(document.createElement('div'))
- .attr({'class': 'error-message'}).text(message))
- .appendTo('body')
- .fadeIn("slow")
- .delay(2000)
- .fadeOut("slow");
- }
-
- /** Add a link the user uses to open the comments popup. */
- $.fn.comment = function() {
- return this.each(function() {
- var id = $(this).attr('id').substring(1);
- var count = COMMENT_METADATA[id];
- var title = count + ' comment' + (count == 1 ? '' : 's');
- var image = count > 0 ? opts.commentBrightImage : opts.commentImage;
- var addcls = count == 0 ? ' nocomment' : '';
- $(this)
- .append(
- $(document.createElement('a')).attr({
- href: '#',
- 'class': 'sphinx-comment-open' + addcls,
- id: 'ao' + id
- })
- .append($(document.createElement('img')).attr({
- src: image,
- alt: 'comment',
- title: title
- }))
- .click(function(event) {
- event.preventDefault();
- show($(this).attr('id').substring(2));
- })
- )
- .append(
- $(document.createElement('a')).attr({
- href: '#',
- 'class': 'sphinx-comment-close hidden',
- id: 'ah' + id
- })
- .append($(document.createElement('img')).attr({
- src: opts.closeCommentImage,
- alt: 'close',
- title: 'close'
- }))
- .click(function(event) {
- event.preventDefault();
- hide($(this).attr('id').substring(2));
- })
- );
- });
- };
-
- var opts = {
- processVoteURL: '/_process_vote',
- addCommentURL: '/_add_comment',
- getCommentsURL: '/_get_comments',
- acceptCommentURL: '/_accept_comment',
- deleteCommentURL: '/_delete_comment',
- commentImage: '/static/_static/comment.png',
- closeCommentImage: '/static/_static/comment-close.png',
- loadingImage: '/static/_static/ajax-loader.gif',
- commentBrightImage: '/static/_static/comment-bright.png',
- upArrow: '/static/_static/up.png',
- downArrow: '/static/_static/down.png',
- upArrowPressed: '/static/_static/up-pressed.png',
- downArrowPressed: '/static/_static/down-pressed.png',
- voting: false,
- moderator: false
- };
-
- if (typeof COMMENT_OPTIONS != "undefined") {
- opts = jQuery.extend(opts, COMMENT_OPTIONS);
- }
-
- var popupTemplate = '\
- Navigation
Credits
Development Lead¶
-
Contributors¶
-
This Page
Navigation
Navigation
Report Bugshttps://github.com/corteva/rioxarray/issues.
If you are reporting a bug, please include:
Your operating system name and version.
Any details about your local setup that might be helpful in troubleshooting.
Detailed steps to reproduce the bug.
If you are proposing a feature:
Explain in detail how it would work.
Keep the scope as narrow as possible, to make it easier to implement.
Remember that this is a volunteer-driven project, and that contributions +are welcome :)
Ready to contribute? Here’s how to set up rioxarray for local development.
Fork the rioxarray repo on GitHub.
-Clone your fork locally:
+Fork the rioxarray repo on GitHub.
Clone your fork locally:
$ git clone git@github.com:your_name_here/rioxarray.git
Install your local copy into a virtualenv. Assuming you have virtualenvwrapper installed, this is how you set up your fork for local development:
+Install your local copy into a virtualenv. Assuming you have virtualenvwrapper installed, this is how you set up your fork for local development:
$ python -m venv rioxarray_env
$ cd rioxarray/
$ python setup.py develop
Create a branch for local development:
+Create a branch for local development:
$ git checkout -b name-of-your-bugfix-or-feature
Now you can make your changes locally.
When you’re done making changes, check that your changes pass flake8, are black formatter, +
When you’re done making changes, check that your changes pass flake8, are black formatter, and the tests pass:
$ flake8 rioxarray test
$ black --check .
@@ -121,26 +118,25 @@ Get Started!Commit your changes and push your branch to GitLab:
+Commit your changes and push your branch to GitLab:
$ git add .
$ git commit -m "Your detailed description of your changes."
$ git push origin name-of-your-bugfix-or-feature
-Submit a pull request through the GitHub website.
-
+Submit a pull request through the GitHub website.
Before you submit a pull request, check that it meets these guidelines:
The pull request should include tests.
If the pull request adds functionality, the docs should be updated. Put your new functionality into a function with a docstring, and add the -feature to the list in README.rst.
The pull request should work for Python 3.5, 3.6, and 3.7.
\ - Sort by:\ - best rated\ - newest\ - oldest\ -
\ -\ -
Add a comment\ - (markup):
\ -``code``
, \ - code blocks:::
and an indented block after blank line