Questions tagged [numpy]

NumPy is a Python module, adding support for large, multi-dimensional arrays and matrices, along with a large library of high-level mathematical functions to operate on these arrays.

Filter by
Sorted by
Tagged with
1 vote
2 answers
38 views

Raster to Numpy array for aspecified area, search maximum value using ArcPy and numpy

I want to filter the maximum value within a given area using the fastest method possible. I don't want to load the input files (several 100s of full size, classified Sentinel 2 images, integer) ...
user avatar
  • 79
1 vote
1 answer
42 views

Converting ee.Image to numpy array in Earth Engine Python API takes too much time

I am using Earth Engine's Python API to convert ee.Image() to Python plots. I am currently using the ee.sampleRectangle() function to convert ee.Image() to a NumPy array and then using matplotlib's ...
user avatar
1 vote
0 answers
16 views

Error Showing With Python-"ee.ee_exception.EEException: Image.select: Pattern 'B4' did not match any bands."

I'm working on estimation chlorophyll-a using a Landsat 8 image woth python code and then I’m trying to build an web-app which is using streamlit and geemap library. But my map doesn’t showing when I ...
user avatar
0 votes
0 answers
14 views

GDAL Runtime warnings for overflow when squaring directly but not when breaking down in two steps

Expected behaviour and actual behaviour. I expect this GDAL calc expression to work without warnings the same way it does when I break it down into two. This returns RuntimeWarning: overflow ...
user avatar
  • 1,385
0 votes
1 answer
14 views

Vegetative index calculation yields Inf instead of value

I am calculating a the Green Leaf Index (GLI) from an orthomosaic and am somehow getting inf values for certain pixels instead of actual values. When calculated manually, I am getting an expected ...
user avatar
  • 61
1 vote
1 answer
107 views

Turning TIFF numpy array into a .jpeg

I am trying to convert a numpy array - containing the Red, Green, and Blue band obtained from the .TIFF file of the satellite image - into a simple .jpeg. The issue at hand is that the colours on the ....
user avatar
  • 73
0 votes
1 answer
47 views

Opening Raster Stack without 'No Data Values' in GDAL with Python

When I open a raster stack with GDAL and call it as a numpy array, lines with 'no data values' also appear. Since I do not want to include these 'no data values' (mine is 128) in the calculations I ...
user avatar
  • 143
0 votes
0 answers
25 views

Why points created from polyline are not being placed on original polyline? [duplicate]

I have extracted coordinates of a polyline and created a list using FeatureClassToNumPyArray. Now i have written code to create points at those vertices. I have used the SR information of the polyline ...
user avatar
0 votes
0 answers
16 views

Writing HDF5 datasets using GDAL for compatibility with ArcGIS

I have a collection of 3D numpy array, each corresponding to a specific timestamp, and want to create an HDF5 datasets to display the temporally varied raster in ArcGIS Pro. My intention is to create ...
user avatar
0 votes
1 answer
16 views

How do you reclassify a single integer band raster to keep only the last digit for each cell value?

I need to reclassify a raster with values in the form xxxxx1, xxxxx2, or xxxxx3. Each digit of cells values encodes a categorical information (e.g. first digit is the land cover, second digit the ...
user avatar
  • 303
0 votes
0 answers
102 views

How to determine the order of shapely's intersection function between two LineStrings

I want to find all the Point intersections between two shapely LineStrings. It is possible that there are multiple intersections and hence the output can be a MultiPoint. How do I know that the output ...
user avatar
  • 311
1 vote
0 answers
64 views

Compute the distance from a point to polygon given the point and direction

I want to compute the distance from a point to a polygon given the point and direction. Currently I am using shapely and defining a "somewhat" infinite line string. This is not ideal as I ...
user avatar
  • 311
1 vote
0 answers
23 views

Label coordinates that fall in a specific shapefile

I have a dataframe for individuals, each individual has X and Y coordinates, and I have a .shp file that has a number of polygons. individuals dataframe look like: ind_ID x_coordinates y_coordinates ...
user avatar
  • 11
1 vote
2 answers
103 views

GDAL geographic coordinate to pixel coordinate

I've got a function that converts x,y of raster to geographic coordinates in given transformation (where gt is GetGeoTransform() from GDAL): def p(col, row, gt): # p: pixel coords to map coords c, ...
user avatar
5 votes
2 answers
325 views

Converting multiple x,y coordinates to new coordinate system using GeoPandas

I have a Python script to convert the x, y coordinates in a csv file from EPSG:29902 to EPSG:2157 based on their naming Easting and Northing import geopandas as gpd import numpy as np EPSG_ITM = 2157 ...
user avatar
0 votes
0 answers
49 views

Sliding window std calculation

I got raster with float values (from Sentinel-1) data cut to lake shape. It has nodata value of 255. Importing it to numpy masked array. Now would like to create an array with STD value of ...
user avatar
0 votes
1 answer
149 views

Method to resample 2d numpy array to a coarser grid and weighted by pixel area in python (analogy to grass r.resmap.stats -w)

What is the optimal method in Python, when I need to resample 2d numpy array (grid) to coarser resolution (weighted by pixel area, the case when the new resolution is not the exact multiple of the ...
user avatar
  • 989
2 votes
1 answer
86 views

Performance problem with getting average pixel values within buffered circles

I have a EPSG:4326 raster file with pixel size of 15 arcseconds, and a list of longitudes and latitudes. For each pair of coordinate, I want to create a buffered circle of X kilometers surrounding ...
user avatar
1 vote
1 answer
41 views

Most efficient way to merge all .asc files to avoid memoryerror

Most efficient way to merge all .asc files to avoid memoryerror. gpw-v4-population-count-rev11_2020_30_sec_1.asc gpw-v4-population-count-rev11_2020_30_sec_2.asc gpw-v4-population-count-...
user avatar
0 votes
0 answers
26 views

Query ASCII Rastor format data data in gpw

I have downloaded this from website gpw-v4-population-count-rev11_2020_30_sec_1.asc gpw-v4-population-count-rev11_2020_30_sec_2.asc gpw-v4-population-count-rev11_2020_30_sec_3.asc gpw-v4-population-...
user avatar
0 votes
0 answers
54 views

Fourier Transform on Sediment Wave Data Python

I have cross profile data taken from sediment waves so the x axis in this instance would be distance in metres and the y axis of the profile would be height. Each profile is 60 m long. I have a sample ...
user avatar
0 votes
0 answers
13 views

Convert raster to numpy array from OpticalRS import *

I want to use the OpticalRS python library to convert images from google earth engine (ee) in Google Colab to numpy arrays so that I can plot x,y scatter plots, etc. But when I try to import the ...
user avatar
  • 47
3 votes
3 answers
2k views

Shapely deprecation warning message when plotting GeoPandas geodataframe

I am trying to plot a GeoPandas geodataframe as I always do. Now I am having a new pc when I try to plot my geodataframe using : gdf.plot() there is no plot displayed and I receive this message: C:\...
user avatar
0 votes
1 answer
46 views

Reclassifying raster using numpy

I have more than 300 NDVI, Soil Salinity and NDMI Calculated Rasters I want to reclassify into categories based on percentages of values like this function: def classify_salinity(ras): max_val = ...
user avatar
2 votes
0 answers
50 views

Sentinel 1 creating ratio from polarizations

I am trying to perform a simple raster operation (In python) on two different bands (polarization VV and polarization VH) of the same SAR GRD product so that I have a co/cross-polarized ratio: VV/VH ...
user avatar
  • 291
0 votes
1 answer
50 views

How to reclassify a raster into equal intervals in numpy?

I want to reclassify a raster based on equal intervals. For example, if the value is in the first interval, the raster cell should be ouput as 1; the second interval should be a 2, etc. So far I've ...
user avatar
  • 13
2 votes
1 answer
61 views

OGR create polygon giving four corners from raster pixel position

How do I create a geometry from pixels positions in GeoTiff? ds = gdal.Open("image.tif") myarray = np.array(ds.GetRasterBand(1).ReadAsArray()) shape = ogr.Geometry(ogr.wkbLinearRing) And ...
user avatar
3 votes
0 answers
43 views

Running vector percentile breaks is very slow QGIS

I solved my own question a couple weeks ago on how to create percentile breaks in QGIS. Creating percentile class breaks in vector data QGIS using numpy.percentile However, this code is unbelievably ...
user avatar
  • 257
2 votes
2 answers
231 views

Get dimensions of raster without reading it to memory

I have an URL to a TIFF file: url = "https://copernicus-dem-30m.s3.amazonaws.com/Copernicus_DSM_COG_10_N59_00_E010_00_DEM/Copernicus_DSM_COG_10_N59_00_E010_00_DEM.tif" I can get the ...
user avatar
  • 250
0 votes
0 answers
70 views

How to use affine matrix to calculate row-column pair on a raster corresponding to a lat-long pair using NumPy?

I have a pair of latitude-longitude coordinates: lat, lon = 59.87115844471202, 10.656472637769236 I have a URL for a TIFF (this - it's public). I open it with rasterio (install: pip install rasterio),...
user avatar
  • 250
0 votes
1 answer
38 views

Extracting a Particular Masked NetCD4 Datapoint in Python

Suppose in Python, I have read in a netCDF4 file, as follows: import netCDF4 ds = netCDF4.Dataset('fire_weather_index_2018.nc') The aspects of the netCDF4 is as follows: <class 'netCDF4._netCDF4....
user avatar
  • 1
2 votes
1 answer
82 views

Creating percentile class breaks in vector data QGIS using numpy.percentile

I am having trouble making percentile breaks in my point data for a numeric field. I have looked at these similar questions, most seem to relate to raster though: Exporting features when column value ...
user avatar
  • 257
2 votes
1 answer
239 views

How to change the dtype of a NetCDF variable and rewrite as a new NetCDF file

I was wondering how to change the dtype of precipitation from int16 to float64 in the following NetCDF file with these dimensions and variables, and rewrite it as new NetCDF file; <class 'netCDF4....
user avatar
1 vote
1 answer
54 views

Issue with normal score transformation of raster data in arcpy script

I am writing a script as part of a larger model builder workflow to perform a normal score transformation on an inputted raster that will be used for maximum likelihood classification. The normal ...
user avatar
  • 11
1 vote
2 answers
100 views

How to create a NetCDF file with Albers conical equal area projection in Python

I was wondering how to create a NetCDF file with the following dimensions and variables; <class 'netCDF4._netCDF4.Dataset'> root group (NETCDF4 data model, file format HDF5): Conventions: CF-...
user avatar
1 vote
0 answers
79 views

Calculating latitude-longitude of given pixel on TIFF using numpy only [closed]

I know how to calculate the latitude-longitude coordinates of a given pixel of a TIFF file using rasterio. Methods based on importing external functions (from within rasterio or GDAL for example) ...
user avatar
  • 250
2 votes
0 answers
121 views

Stacking multi-dimensional bands in rasterio

I'm trying to stack numpy arrays to write a TIFF file: stacked_bands = [] for i in range(1, 37): stacked_bands.append(np.stack(([get_window(t, x, y, i) for t in tif_files]))) ...
user avatar
1 vote
1 answer
54 views

Array is visualized differently in matplotlib than QGIS

I am getting different resutls when plotting a np.array with matplotlib than when doing it in an external software - QGIS. Here is what I have: print(wiw[0].shape) (1, 8433, 9254) print(wiw[0]...
user avatar
  • 1,058
0 votes
0 answers
136 views

Acquiring data point coordinates from Geotiff and converting to numpy array

I would like to use scipy.interpolate.griddata to interpolate my Sentinel-1 products (see two sample images below) taken from different orbits resulting in having the uniform datapoint coordinates. I ...
user avatar
0 votes
1 answer
36 views

Varying resolution (scale) when using Google Earth Engine sampleRectangle to convert to numpy array

I am trying to convert my google earth engine image to a numpy array. I have used sampleRectangle but the scale seems to be set to 1 degree, way too large, even though the native resolution of the ...
user avatar
0 votes
0 answers
95 views

Extracting lon lat data from .hgt file using Python

I have a .hgt file and I want to extract the lon and lat data from it. I separated the height values by using python==3.8 to work with the data in an numpy array-format. import rasterio raster1 = ...
user avatar
1 vote
0 answers
31 views

ArcPy: Populating array column with rank values

I am trying to get the rank values for some values in my fields. I have created an array from fields of an attribute table, sorted them in descending order, and I now want to populate the third column ...
user avatar
0 votes
1 answer
120 views

Reclassifying raster image in Google Colab with NumPy

In Google Earth Engine's Java API, I have the following code that works and am trying to use this in Google Colab with Python. How do you reclassify the pixels in a raster image in Python? var ...
user avatar
  • 3
0 votes
1 answer
101 views

Get Numpy array from SHAPE@WKB token

I am trying to get a numpy array from the SHAPE@WKB token that is obtained either using FeatureClassToNumpyArray or cursors, however what I get does not make much sense. Specifically I am interested ...
user avatar
3 votes
1 answer
173 views

Reproject NumPy ndarray without saving as TIFF

I have NumPy ndarray with shape (1063,2116,12) (has 12 bands). The ndarray has non geographical data, but I do have its' transform affine and the crs. I want to give this geographical data to the ...
user avatar
  • 1,797
0 votes
1 answer
65 views

Python array based alternative to GRASS r.cost

I am looking for a numpy array based alternative to the GRASS r.cost function. I have a friction surface raster where the value of each cell corresponds to travel time. I would like to find the cells ...
user avatar
  • 1
0 votes
2 answers
220 views

Type error for gdal- GDAL-style transforms have been deprecated

I'm trying to export numpy ndarray that I have to TIFF using rasterio. I have the transform of the image: print(transf) >>>(583932.1992386435, 10.0, 0, 2223772.1491772938, 0, -10.0) When I ...
user avatar
  • 1,797
5 votes
1 answer
2k views

Strange warning/error when working with polygons

Reading a polygon shapefile with geopandas I got a strange error. I found out it is a normally hidden warning about another error, which I saw only because I turned warnings to errors. It also appears ...
user avatar
  • 1,970
2 votes
0 answers
400 views

Reclassify raster MemoryError: Unable to allocate 97.5 GiB for an array with shape (6546455295, 2) and data type int64

I have tried to reclassify my global land use dataset downloaded from here. And I tried to reclassify this tiff file using the following code. driver = gdal.GetDriverByName('GTiff') file = gdal.Open('...
user avatar
  • 508
0 votes
1 answer
924 views

GeoPandas TypeError: geometries are not orderable (numpy: TypeError: '<' not supported between instances of 'Point' and 'Point')

I'm trying to group rows of a GeoDataFrame based on a common gid value and aggregating two columns for which the values differ but I am facing this error: TypeError ...
user avatar
  • 6,698

1
2 3 4 5
9