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
1answer
37 views

Creating a raster based on values of other rasters

I have three single band rasters, raster_a, raster_b and raster_c with pixel values 1 and 0. I am trying to burn the values of raster_a to raster_b and create a "new_raster_b" where if: raster_a == ...
1
vote
0answers
36 views

Python Classification of multiple NDVI images for difference

I have several months worth of NDVI images for an area. When I check the values, there seems to be some deviation. I am using python GDAL to attempt to calculate possible areas of concern for ...
0
votes
1answer
42 views

Extract/export Attribute Table of pixel information from Classified Raster in Python?

I am at beginner level in image processing with python. I have classified satellite image with python in 10 classes. I am able to write the image in geotiff format. However, I do not know how extract ...
1
vote
0answers
30 views

Extract point cloud data from shapefile with Python

I am trying to plot profiles from LAS data. So my first step is to extract the data using a shapefile. I found this piece of code on the laspy website and thought I could use it to do this : def ...
2
votes
2answers
75 views

Accelerating the code for random selection of polygons

I have a shapefile with thousands of features (polygons). I need to randomly sample one polygon at every 1 sq. km. area if at least one polygon is available. I wrote the following code which works. ...
1
vote
1answer
32 views

Raster is flipped when opened as numpy array

I have two rasters of the same dimensions. Opened in QGIS, they align perfectly. However when I open them via GDAL as a numpy array, one of them is flipped and I have to flip it back to make ...
0
votes
1answer
48 views

Open a GDAL dataset with rasterio.open()

I am processing geotiff files with GDAL and rasterio. Every process of my processing chain generates a file in output. What I want is saving every file in memory instead of creating files in the disk. ...
1
vote
1answer
31 views

NetCDF hourly data to year raster layers (using Python)

Having a NetCDF with a 'time', 'lat' and 'lon' dimension, where time is hourly during a year and the variable to extract is temperature, how do I calculate mean temperature throughout the year using ...
2
votes
1answer
25 views

Parsing text into a numpy ndarray

I'm trying to parse this string into a numpy ndarray 'POLYHEDRALSURFACE(((0 1 0,0 0 0,1 0 0,1 1 0,0 1 0)),((1 -0 1,0 0 1,0 1 1,1 1 1,1 -0 1)),((1 0 0,1 -0 1,1 1 1,1 1 0,1 0 0)),((0 0 0,0 0 1,1 -0 1,1 ...
1
vote
0answers
24 views

GDAL couldn't create raster with equal shape

I am trying to carry out pixel by pixel correlation for each image in a time series vs another 1d array of data. To do that, the arrays coming out of the raster files must be identical in shape. ...
1
vote
0answers
39 views

DSM - DTM = -ve value

I want to calculate the elevation of a particular feature. I have both DSM and DTM as input data, both with the same cell size and same number of columns and rows (same resolution). For the DSM, min = ...
0
votes
0answers
17 views

Masked array fill value getting changed

I am using the following code to mask the clouds from Landsat image using QA band. I am facing the strange issue as you can see I have 2 print statements in my code which prints the fill_value of ...
1
vote
2answers
111 views

When calcuating distance between points on Earth why are my Haversine vs. Geodesic calculations wildy diverging?

I am getting wildly diverging distances using two approximations to calculate distance between points on Earth's surface. I am using the Haversine (vectorized) approximation (spherical earth) and the ...
0
votes
0answers
37 views

Calculating the mean value of a raster stack using numpy

I am calculating the mean value of a stack of images. I created a virtual raster which is the stack of 68 sentinel-1 images. I want to calculate the mean value for every pixel. Here is my code: ...
1
vote
1answer
30 views

Applying equation to a Numpy array while preserving TIFF metadata (coordinates)

I wish to load a .tif image into a numpy array, apply a formula and then spit the image back out with the same geo/nodata metadata information. So far I have created this, which does the processing ...
1
vote
0answers
1k views

“TypeError: list indices must be integers or slices, not tuple” - the code works in one case but not in another? [closed]

The following code executes smoothly: for i in range (1, 10): for j in range (1, 10): if a1[i][j] == 100: if np.count_nonzero(a1[i-1:i+2,j-1:j+2]) > 8: a1[i]...
0
votes
1answer
75 views

I am unable to combine Numpy arrays in ArcMap when using FeatureClassToNumPyArray

I am using FeatureClasstoNumPyArray to get information from two features classes import arcpy import numpy sspipe_fcs = 'ssGravityMain' sspipe_fl = ('ORIGINAL_COST', 'FEATURE', 'DEVELOPMENT','...
3
votes
1answer
240 views

Counting number of points in each grid?

I would like to count the number of points in each cell. I have tried https://docs.scipy.org/doc/numpy/reference/generated/numpy.histogram2d.html but the out isn't appropriate. Does anybody know how I ...
1
vote
0answers
44 views

Getting inconsistent raster output from gdal_calc.py raster calculation

I'm attempting to do what is generally a straightforward raster calculation when I do this in QGIS, but am trying to do this with gdal_calc.py in terminal. The output is close, but produces banding ...
0
votes
1answer
41 views

Accessing Numpy Array found within an XArray from Satpy

dask.array<shape=(76, 76), dtype=float32, chunksize=(76, 76)> Coordinates: crs object +proj=utm +datum=WGS84 +ellps=WGS84 +no_defs +units=m +zone=33.0 +type=crs * y (y) float64 ...
3
votes
1answer
135 views

How to change a numpy array's dimensions [closed]

I'm using GDAL Python API to read a raster into a NumPy array, it will return a array's shape like [bands, rows, cols], if we want to use OpencCV to deal with this array, it will cause some problem, ...
0
votes
0answers
32 views

GDAL calc difference between two NDVI rasters

I get a series of NDVI rasters every 2 weeks and need to calculate changes. The rasters overlap, but are different in area. The resolution is also a little different in each raster, raster 1: -0....
0
votes
0answers
112 views

From SQL database to pandas dataframe to numpy array to ESRI Table

End goal: Join data pulled from a SQL database to three different feature classes in a ESRI geodatabase. Efforts: Using PYODBC, I've connected to the database and dumped the data into a Pandas ...
2
votes
1answer
74 views

Georeferencing a numpy tensor (spatio-temporal data)

I have a CSV file in which each row represents a record of an event with the following columns: latitude, longitude, time I want to build a numpy tensor with n x m x 8760 (hours in a year) ...
0
votes
2answers
106 views

Converting GeoTIFF to np array?

I am fairly new to GIS in general. I am having some issues converting a GeoTIFF into an numpy array. There are multiple questions online about how to do it, I've tried, many, with the same result ...
4
votes
1answer
565 views

Creating an in memory rasterio Dataset from numpy array

I am reading in a raster using rasterio, and then upsampling the raster as per the example in the documentation: def upsample_raster(raster): return raster.read( out_shape=(raster.height *...
2
votes
1answer
68 views

arcpy.da.NumPyArrayToTable() RuntimeError: Unspecified error

Using arcpy for ArcGIS Desktop 10.7.1... In order to append data from a Pandas data frame to an ArcGIS table, I am attempting to create a temporary in-memory table from the Pandas data frame as ...
1
vote
1answer
36 views

Setting default value for date columns with FeatureClassToNumPyArray in ArcGIS Pro?

I am reading a feature class into a pandas dataframe using: df = DataFrame( arcpy.da.FeatureClassToNumPyArray( in_table=feature_class, field_names=field_list, skip_nulls=...
1
vote
1answer
163 views

Get non-masked values of multiband numpy masked array

I am working on a multiband image with python. I imported my image as a masked numpy array of shape (bands, rows, cols) using rasterio. The mask is the same for all bands. I would like to get the ...
0
votes
1answer
255 views

GDAL polygonize only particular values

I want to polygonize .tiff raster file for specific values. For example, using one method I firstly reclassified the raster by gdal_calc.py --calc="A*logical_and(A>0,A<1)" then used gdal....
0
votes
0answers
499 views

TypeError: 'int' object does not support item assignment

I am trying python for the first time. I have a raster layer of Type Float32, and another raster output of Type Integer created from this raster layer outside the python code. I want to scan every ...
1
vote
1answer
346 views

How to downsample raster image for nightlights data in Python?

I'm working with the nightlights data - 30 arc second grids, spanning -180 to 180 degrees longitude and -65 to 75 degrees latitude. I want to downsample it to 5 arc-min resolution. Now my question is ...
1
vote
3answers
294 views

Numpy masked array to raster

I am trying to transform a masked array, result of a NETCFD4 file, to a raster. The array is saved as a masked array, with shape (500,805), and the mask is the value 32768.0. The array looks like: ...
0
votes
1answer
69 views

Count number of pixels from .msk in Python to derive study area size

Apologies I am totally new to GIS in Python. I am trying to find out the total area of the Barents Sea mask the NSIDC use to calculate their products and therefore I need to know how many pixels the ...
0
votes
0answers
29 views

ArcGIS is importing orginal numpy while VirtualEnv is activated

I could activate ArcGIS's python command windows to use VirtualEnv by "execute execfile(r'C:\Users\jason\myenv\Scripts\activate_this.py', {'file': r'C:\Users\jason\myenv\Scripts\activate_this.py'})" ...
1
vote
0answers
72 views

PyQGIS Creating Numpy Array from QByteArray (QgsRasterBlock.data()) and vice versa (QGIS3) [closed]

I am looking for a way to convert the values contained in a QgsRasterLayer object to a numpy array and vice versa without using any GDAL methods. To obtain the numpy array I go through ...
0
votes
0answers
47 views

Compare Specific Points of Line Features in two Feature Classes using FeatureClassToNumPyArray

I am looking to compare the first and last point between features in two different feature classes. The features share a common ID. My thought was to create two arrays via FeatureClassToNumPyArray. ...
1
vote
1answer
161 views

Writing numpy arrays to irregularly shaped, multiband raster

I have the following numpy arrays: predictions; type is float32; shape: (94, 1461) lats; float32; shape: (94,); centroid of cell in vector layer, decimal degs. lons; float32; shape: (94,); centroid ...
0
votes
0answers
68 views

pyinstaller stops in the middle of process

I try to create a .exe from a .py script. I use Pyinstaller. The script runs fine with no errors in Pycharm. If I open the .exe my Tkinter opens I can choose the files etc.. And then in the middle of ...
1
vote
0answers
15 views

GDAL rastercalc giving unexpected results

I have a raster file containing the following values: data values from 0 to 8488 nodata values values equalling -3.40282347e+38 The values equalling -3.40282347e+38 are presumably supposed to be ...
0
votes
1answer
297 views

Open 4d NetCDF subdatasets with GDAL in Python

I have NetCDF files containing subdatasets with 4 dimensions: time, height, latitude, longitude. Here is an example of the output of GDAL GetSubDatasets(): ('NETCDF:"Martinique_ALT22.nc":height', '[...
0
votes
1answer
290 views

“No module named numpy” Python Error in ArcGIS Label Expression?

I have developed code to label points that pull formatting from a dictionary. I developed this code and it was working fine two weeks ago, today I try to open my map and I am now met with an error ...
0
votes
1answer
344 views

Broadcast Shapely Point on numpy array

I have some code that looks something like this: def get_objs(all_objs, line, my_distance): """ Gets all objs within my_distance of line. all_objs is a numpy array of shape (x, 4) ...
0
votes
0answers
58 views

Calculating Raster Percentile Values in ModelBuilder

I want to calculate the 75th percentile value of a raster dataset (floating, 32Bit) and use this value as an input to a set null expression. I have multiple rasters to perform this on so I need to ...
2
votes
1answer
213 views

NumPyArrayToFeatureClass gives RuntimeError: create table

I've tried to change polygon feautre to point by using tools: FeatureClassToNumPyArray NumPyArrayToFeatureClass. My code as below: import arcpy import numpy as np in_file='C:/ios/...
1
vote
1answer
137 views

Extracting values from array created with FeatureClassToNumPyArray and converted to DataFrame?

I cannot understand how to use the values in the arrays created with arcpy.FeaturesToNumPyArray. I want to create an array and then convert them to a pandas DataFrame. So I created an array from ...
1
vote
1answer
111 views

Array in python just full of zeros when opened using GDAL

I'm working on the below script. What I'm trying to do is create a stats.txt file output which has the Land Cover Class ID, Fractional Coverage (of that class) and the number of pixels (of that class) ...
1
vote
1answer
146 views

Classifying quantiles in raster dataset with ArcPy?

I am trying to write a Python script which uses the reclassify function in ArcPy to create 9 classes in a raster file. I want to use the quantile method to create the breaks, but so far, I can't seem ...
0
votes
0answers
335 views

Binary Raster (numpy array) to shapefile

i did a classification with a min/max threshold for stormdamaged areas. For that i calculated two indices (NSDVI) and (SAVI). I intersected two numpy arrays from those results. I recieve a binary ...
2
votes
0answers
229 views

Fill masked array values with reflect padding

I have a square matrix (image) with masked values in an area. The mask corresponds to missing values in areas close to the border (always). I want to create a new image where the masked values are ...