rioxarray | geospatial xarray extension powered by rasterio | Dataset library

 by   corteva Python Version: 0.15.6 License: Non-SPDX

kandi X-RAY | rioxarray Summary

kandi X-RAY | rioxarray Summary

rioxarray is a Python library typically used in Artificial Intelligence, Dataset applications. rioxarray has no vulnerabilities, it has build file available and it has low support. However rioxarray has 2 bugs and it has a Non-SPDX License. You can install using 'pip install rioxarray' or download it from GitHub, PyPI.

geospatial xarray extension powered by rasterio
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              rioxarray has a low active ecosystem.
              It has 392 star(s) with 62 fork(s). There are 14 watchers for this library.
              There were 1 major release(s) in the last 6 months.
              There are 40 open issues and 205 have been closed. On average issues are closed in 144 days. There are 1 open pull requests and 0 closed requests.
              It has a neutral sentiment in the developer community.
              The latest version of rioxarray is 0.15.6

            kandi-Quality Quality

              rioxarray has 2 bugs (0 blocker, 0 critical, 2 major, 0 minor) and 48 code smells.

            kandi-Security Security

              rioxarray has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              rioxarray code analysis shows 0 unresolved vulnerabilities.
              There are 1 security hotspots that need review.

            kandi-License License

              rioxarray has a Non-SPDX License.
              Non-SPDX licenses can be open source with a non SPDX compliant license, or non open source licenses, and you need to review them closely before use.

            kandi-Reuse Reuse

              rioxarray releases are available to install and integrate.
              Deployable package is available in PyPI.
              Build file is available. You can build the component from source.
              rioxarray saves you 2179 person hours of effort in developing the same functionality from scratch.
              It has 6769 lines of code, 363 functions and 26 files.
              It has high code complexity. Code complexity directly impacts maintainability of the code.

            Top functions reviewed by kandi - BETA

            kandi has reviewed rioxarray and discovered the below as its top functions. This is intended to give you an instant insight into rioxarray implemented functionality, and help decide if they suit your requirements.
            • Compute raster
            • Return the numpy dtype for the given dtype
            • Ensures that the nodata s dtype is correct
            • Get numpy dtype dtype dtype and numpy dtype dtype dtype
            • Get an item from a window
            • Return a file handle
            • Read data from a window
            • Return indexer for rasterio dataset
            • Coordinate of the rasterio object
            • Set the crs attribute
            • Create a raster from a user input
            • The grid mapping
            • Check if object has spatial dimensions
            • Return the number of items in this array
            • Check the dimensions of the data arrays
            • X dimension
            • The y dimension
            Get all kandi verified functions for this library.

            rioxarray Key Features

            No Key Features are available at this moment for rioxarray.

            rioxarray Examples and Code Snippets

            xarray - MissingSpatialDimensionError (assign coordinates as dimensions)
            Pythondot img1Lines of Code : 60dot img1License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            In [7]: countries = gpd.read_file('https://naturalearth.s3.amazonaws.com/110m_cultural/ne_110m_admin_0_countries.zip')
            
            In [13]: sample = np.arange(100)
                ...: ddm = np.arange(4)
                ...: timestep = pd.date_range(
            Python: Masking ERA5 data (NetCDF) from shapefile (polygon/multipolygon)
            Pythondot img2Lines of Code : 17dot img2License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            import geopandas as gpd
            import xarray as xr
            import rioxarray
            from shapely.geometry import mapping
            
            # load shapefile with geopandas
            radar_north = gpd.read_file('radar_north140.shp')
            
            # load ERA5 netcdf with xarray
            era = xr.open_dataset('ERA
            Generate Streamplot With 2D Raster Arrays
            Pythondot img3Lines of Code : 10dot img3License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            ds = xr.Dataset({'u': ucomp, 'v': 'vcomp'})
            ds.plot.streamplot(x="x", y="y", u="u", v="v")
            
            plt.streamplot(
                ux.ravel(),
                uy.ravel(),
                ucomp.values.ravel(),
                vcomp.values.ravel(),
            )
            
            combine multiple xarray accessors into single one
            Pythondot img4Lines of Code : 44dot img4License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            class Printable:
                def __init__(self, obj):
                    self._obj = obj
            
                def print_me(self):
                    print(
                      type(self).__name__.lower()
                      + '\n'
                       + str(self._obj)
                    )
            
            class A(Printable):
                pass
            
            class
            How to resolve : "IndexError: band index 1 out of range (not in ())". Raster. Rasterio
            Pythondot img5Lines of Code : 9dot img5License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            import rioxarray as rxr
            
            modis = rxr.open_rasterio('/Users/sayantanmandal/Projects/MODIS/MOD09GQ. 
                    A2010200.h26v06.061.2021166023144.hdf', masked = True)
            
            type(modis)
            
            xarray.core.dataset.Dataset
            
            How to add a band to xarray dataset using rioxarray
            Pythondot img6Lines of Code : 7dot img6License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            xr.concat(
                [
                    raster_1,
                    raster_2.reset_coords('band', drop=True).expand_dims(band=[232]),
                ], dim='band',
            )
            
            Copernicus Dem xarray select nearest lat/lon with multi-dimension coordinates
            Pythondot img7Lines of Code : 16dot img7License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            xds.x.values
            array([-113.        , -112.99972222, -112.99944444, ..., -112.00083333,
                   -112.00055556, -112.00027778])
            
            (xds.x.values + 113)*3600
            array([0.000e+00, 1.000e+00, 2.000e+00, ..., 3.597e+03, 3.598e+03,
               3.599e+03])
            
            Exporting netcdf file in MODIS sinusoidal grid with xarray
            Pythondot img8Lines of Code : 6dot img8License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            import rioxarray
            
            crs = "+proj=sinu +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs"
            
            stacked = stacked.rio.set_spatial_dims(x_dim="x", y_dim="y").rio.write_grid_mapping().rio.write_crs(crs).rio.write_coordinate_system()
            copy iconCopy
            file_to_reproject = xr.open_dataarray("myfile.nc",decode_coords="all") 
            
            Geotiff overlay position is slightly off on Holoviews/Bokeh tilemap
            Pythondot img10Lines of Code : 7dot img10License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            tiff_rio_500 = rioxarray.open_rasterio('/content/mw/mw_dist_to_light_at_all_from_light_mask_mw_cut_s3_500.tif').rio.reproject('EPSG:3857')
            hv_dataset_500_meters = hv.Dataset(tiff_rio_500[0], name='nightlights', vdims='cumulative_cost')
            hv_

            Community Discussions

            QUESTION

            xarray - MissingSpatialDimensionError (assign coordinates as dimensions)
            Asked 2022-Apr-15 at 17:02

            A have a netCDF file that I opened with xarray. I want to clip the xarray data set using a shapefile; however, I cannot figure out how to properly set my spatial dimensions.

            I have the following data set:

            print(ds.keys())

            ...

            ANSWER

            Answered 2022-Apr-15 at 17:02

            rioxarray expects your data to be on a regular grid. Your data appears to be observational data, with a lat, lon value given for the position (of a given spacecraft maybe?) at that time step. You will not be able to expand the dimensions of your array to include (lat, lon).

            Instead, you can build an array indicating whether a given (sample, ddm) point is contained in a shapefile using the arrays sp_lat, sp_lon directly.

            Example assignment to countries

            For example, if you have a shapefile of countries:

            Source https://stackoverflow.com/questions/71880746

            QUESTION

            Generate Streamplot With 2D Raster Arrays
            Asked 2022-Mar-13 at 19:37

            I am attempting to generate a streamplot in Matplotlib using u-component & v-component winds from a gridded analysis, and am unsure how to compile these arrays into the Streamplot function. These data are two-dimensional, in GeoTIFF format, and is read into Python using xarray/rioxarray as follows:

            ...

            ANSWER

            Answered 2022-Mar-13 at 19:37

            The simplest way to do this is definitely to use xarray.Dataset.plot.streamplot:

            Source https://stackoverflow.com/questions/71453495

            QUESTION

            Drop dimension for exporting dataarray to geotiff not working
            Asked 2022-Feb-14 at 18:35

            I want to export a single date and variable fwi of a xarray dataset ds to a tif file. However, my dataarray has too many dimensions and I cannot figure out how to effectively remove the dimension lsm_time.

            ...

            ANSWER

            Answered 2022-Feb-14 at 18:35

            Dimensions with size 1 can be removed using the .squeeze method.

            Conversely, you can add a dimension of size 1 using .expand_dims

            Source https://stackoverflow.com/questions/71078885

            QUESTION

            Python Zonal statistics script: Problem after trying to install rioxarray
            Asked 2022-Jan-13 at 21:13

            I have a script that used to work for calculating zonal statistics (median), but now I get the AttributeError: 'DatasetReader' object has no attribute 'affine'. Here is my code:

            ...

            ANSWER

            Answered 2022-Jan-13 at 21:13

            affine has been deprecated. transform now accepts GDAL and Affine style transforms.

            From Migrating to Rasterio 1.0 affine.Affine() vs. GDAL-style geotransforms:

            https://rasterio.readthedocs.io/en/latest/topics/migrating-to-v1.html

            Since the above changes, several functions have been added to Rasterio that accept a transform argument. Rather than add an affine argument to each, the transform argument could be either an Affine() object or a GDAL geotransform, the latter issuing the same deprecation warning.

            The original plan was to remove the affine argument + property, and assume that the object passed to transform is an Affine(). However, after further discussion it was determined that since Affine() and GDAL geotransforms are both 6 element tuples users may experience unexplained errors and outputs, so an exception is raised instead to better highlight the error.

            Source https://stackoverflow.com/questions/70092328

            QUESTION

            Copernicus Dem xarray select nearest lat/lon with multi-dimension coordinates
            Asked 2021-Dec-28 at 17:45

            This question is related, but somehow I still need some help to get this to work. xarray select nearest lat/lon with multi-dimension coordinates

            ...

            ANSWER

            Answered 2021-Dec-28 at 17:45

            Actually the longitude and latitude are evenly space at 1/3600 degrees. We can see that with:

            Source https://stackoverflow.com/questions/70508260

            QUESTION

            Lookup table in xarray?
            Asked 2021-Dec-14 at 02:22

            So I want to merge 2 datasets, 1 is a single band raster dataset that came from rioxarray.open_rasterio(), the other a lookup table, with an index dim 'mukey'. The coords along 'mukey' correspond to 'mukey' index values in the lookup table. The desired result is a dataset with identical x and y coords to the Raster dataset, with variables 'n' and 'K' whose values are populated by merging on the 'mukey'. If you are familiar with ArcGIS, this is the analogous operation.

            xr.merge() and assign() don't quite seem to perform this operation, and cheating by converting into pandas or numpy hits memory issues on my 32GB machine. Does xarray provide any support for this simple use case? Thanks,

            ...

            ANSWER

            Answered 2021-Dec-14 at 02:22

            You're looking for the advanced indexing with DataArrays feature of xarray.

            You can provide a DataArray as a keyword argument to DataArray.sel or Dataset.sel - this will reshape the indexed array along the dimensions of the indexing array, based on the values of the indexing array. I think this is exactly what you're looking for in a "lookup table".

            In your case:

            Source https://stackoverflow.com/questions/70342632

            QUESTION

            Compute polygon mean from raster: rasterstats.zonal_stats versus rio.clip
            Asked 2021-Aug-17 at 14:56

            I have a raster file and a shapefile containing polygons. For each polygon, I want to compute the mean value of all raster cells within that polygon.

            I had been doing this with rasterstats.zonal_stats, which works perfectly but is very slow for large rasters. Recently I came across rioxarray's example of instead clipping the raster to the polygon and then computing the mean. From my experiments, the clipping approach is a lot faster than zonal_stats and the results are the same.

            I am therefore wondering if there is anything else except for the time difference that would lead to a preference of one over the other method? And why it is that the clipping is so much faster than the zonal_stats?

            Below the output and timing of the two methods, and a snippet of the code. The full code can be found here.

            It would be great to get insights on this :)

            ...

            ANSWER

            Answered 2021-Aug-17 at 14:56

            In the view of self-learning, I realized I made a mistake here and I think it is beneficial to report.

            It all depends on the order you run the functions in. As I loaded the raster data with rioxarray.open_rasterio, this data is not loaded into memory. Thereafter both the clip and zonal_stats still have to load this into memory. When one of the two is called before the other, the latter makes use of the fact that the data is already loaded.

            You can also choose to instead call ds.load() before calling the fuctions. In my tests this didn't change the total computation time.

            Source https://stackoverflow.com/questions/68726522

            QUESTION

            rioxarray (or xarray) converts spatial_ref coordinate to variable after reprojecting and saving with to_netcdf?
            Asked 2021-Jun-13 at 15:12

            I have a "dataarray" which I am trying to reproject it using rioxarray. However after reprojection when I use xarray.to_netcdf, the saved file is a dataset where the "spatial_ref" coordinate converted to a variable. I am not sure if that is xarray or rioxarray.reprojection causes this behavior. Here are some codes that show the issue:

            ...

            ANSWER

            Answered 2021-Apr-29 at 17:43

            The issue was I did not set decode_coords="all" when I used xarray.open_dataarray. With the following everything looks ok:

            Source https://stackoverflow.com/questions/67306598

            QUESTION

            Databricks - export dataset to a raster file in DBFS using rioxarray
            Asked 2021-May-31 at 12:25

            I am trying to follow simple example in rioxarray documentation to export a dataset to a raster file in DBFS.

            Install the library:

            ...

            ANSWER

            Answered 2021-May-31 at 12:25

            I suspect that this is caused by the limitations of the DBFS local file API, although the library doesn't throw the exception - just simply don't create a file.

            The solution would be to output raster to the local disk, and copy file into the DBFS using dbutils.fs.cp:

            Source https://stackoverflow.com/questions/67763373

            QUESTION

            Geotiff overlay position is slightly off on Holoviews/Bokeh tilemap
            Asked 2021-Apr-16 at 00:32

            I have a Geotiff that I display on a tile map, but it's slightly off to the south. For example, on this screenshot the edge of the image should be where the country border is, but it's a bit to the south:

            Here's the relevant part of the code:

            ...

            ANSWER

            Answered 2021-Apr-16 at 00:32

            I've got the answer on the Holoviz Discourse from one of the developers. Seeing how the recommended function is practically undocumented, I copy it here in case somebody looks for an easy way to load a geotiff and add to a tilemap in Holoviews/Geoviews:

            https://discourse.holoviz.org/t/geotiff-overlay-position-is-slightly-off-on-holoviews-bokeh-tilemap/2071

            philippjfr
            I wouldn’t expect manually transforming the coordinates to work particularly well. While it’s a much heavier weight dependency for accurate coordinate transforms I’d recommend using GeoViews.

            img = gv.util.load_tiff( '/content/mw/mw_dist_to_light_at_all_from_light_mask_mw_cut_s3_500.tif' ) gv.tile_sources.OSM() * img.opts(cmap='inferno_r')

            Edit: Now it is possible one doesn't want to use Geoviews as it has a pretty heavy dependency chain that requires a lot of patience and luck to set it up right. Fortunately rioxarray (through rasterio) has a tool to reproject, just append ".rio.reproject('EPSG:3857')" to the first line and then you don't have to use the lnglat_to_meters which is not intended for this purpose.

            So the corrected code becomes:

            Source https://stackoverflow.com/questions/66978228

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install rioxarray

            You can install using 'pip install rioxarray' or download it from GitHub, PyPI.
            You can use rioxarray like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.

            Support

            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            Install
          • PyPI

            pip install rioxarray

          • CLONE
          • HTTPS

            https://github.com/corteva/rioxarray.git

          • CLI

            gh repo clone corteva/rioxarray

          • sshUrl

            git@github.com:corteva/rioxarray.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link