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
2
votes
1answer
37 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 ...
0
votes
1answer
21 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
37 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
0answers
50 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
60 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 ...
0
votes
0answers
41 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
68 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
31 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
23 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
34 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
23 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
46 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
45 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
13 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
109 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
158 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
95 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
31 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
97 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
68 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
69 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
75 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
168 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
71 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 ...
0
votes
1answer
247 views

How to create a GeoDataFrame points grid from a numpy.mgrid?

I'm trying to create a GeoDataFrame points grid from a numpy.mgrid. I already have created the numpy.mgrid with coordinates of future points. >>>arr = np.mgrid[-1827342.1753285176:-1827523....
0
votes
2answers
42 views

If field 1 > field 2 update field 3 in loop

I am trying to update the table above. What I want to do is if the values in the PMP fields are less than the Max fields update the check fields with PASS, if not FAIL. I started doing this trying ...
1
vote
1answer
291 views

NumPy array to Raster file (GeoTIFF)

I converted a raster file (one band grey scale) to an numpy array and set a range to it. I Did like that: import gdal import numpy ds = gdal.Open('H:/GDAL_docs/a.tif') myarray = numpy.array(ds....
2
votes
1answer
101 views

Get data from a raster using two coordinate arrays with Python

I'm trying to find a function in Python, that given two arrays with geographic coordinates, returns a list or array of raster values in those positions. that is to say: import numpy as np """geog ...
0
votes
1answer
72 views

Loading all rasters in a directory and naming the variables iteratively

Hi I'm working with prism data and I already have clipped (masked) rasters (*.bil files) of a specific area for each day of a year. I'd like to open all these rasters with rasterio, convert them into ...
1
vote
1answer
230 views

Comparing pixel values at a given point in two rasters

I have two raster images, one for land use and one for NDVI, i would like to calculate LAI based on land use. So i need to compare the pixel value in the NDVI raster and Land use raster then select ...
1
vote
0answers
83 views

Numpy import error in OSGeo4W Shell

I and my colleagues are running into a very frustrating Python import error while using the OSGeo4W Shell. Any time we attempt to use gdal_calc in a Python script, we get the following error message: ...
1
vote
1answer
226 views

Using rasterio and matplotlib how can I create a window for an NDVI image to fit into?

I am using Rasterio, Numpy, and Matplotlib. I created a window with the dimensions of 800x600 and plotted the band 5 for a Landsat 8 image, that worked just fine. I also have the nir image so then I ...
0
votes
1answer
251 views

Using Rasterio, Matplotlib, and Numpy trying to calculate and plot NDVI of a raster image getting error: IndexError: list index out of range?

First I create two variables and store my raster images in them and I use MatPlotLib to plot a subset of the original "nirband" raster image. That works fine. I am getting an IndexError: list index ...
1
vote
0answers
56 views

Using Null Values in Raster To NumPy?

I am trying a convert a raster dataset [a simple 4 x 4] into a numpy array using RasterToNumPyArray. Here is my sample raster dataset: RasterToNumPyArray however, returns zero for Null values: ...
3
votes
0answers
93 views

QGIS 3 - Save processing output to memory and turn into numpy array?

I'm currently developing a python plugin for QGIS 3. In short, the code conducts among others a viewshed algorithm, turns the output in a numpy array and calculates some spatial metrics the user can ...
0
votes
1answer
148 views

How to convert masks generated by rasterio to channel last mask

The problem is about using rasterio to generate mask from GeoJSON file which contains geographic coordinates. The function that I used is from: from rasterio.tools.mask import mask with rasterio....
1
vote
0answers
425 views

Writing numpy array to rasterio raster file generates empty file

I'm using Rasterio to read GeoTIFF from Sentinel 2 and calculating NDVI, but when I try to save as a new TIF file, the file turns to transparent and empty file. What am I missing? That's the code: ...
0
votes
0answers
123 views

numpy array coordinates to polyline in shapefile Python

I am calculating the shortest path in a numpy array which was converted from a raster (.tif). I have a list representing a path like [(1,3),(2,3)(3,3)]. How can I transform this into a polyline in ...
1
vote
1answer
126 views

Write array to CSV inside arc script tool (works in pycharm, doesn't work in arc)

I have an arcpy script in which I am writing an array to a CSV (for later use in the script to make a routeing layer). I've tried a couple iterations, and all work like a charm in PyCharm (can't ...
2
votes
0answers
276 views

Networkx shortest paths for two point layers

I have a task to know the best way from houses to subway station. There are three types of data on a picture below: orange dots are the entrances to subway stations violet dots are centerspoints of ...
1
vote
0answers
90 views

Point displacement between map (Cesium 3D) and raster (numpy array)

It is better to show than tell: On this image, the layer below the colorful shape is a trivial heat map in raster format. The colorful shape is the product of the skimage.graph.MCP_Geometric method. ...
1
vote
1answer
282 views

Writing a raster file from multi-dimension array using Python

I've been attempting to create a raster file that has multiple bands (10 or more) from a numpy array with multiple dimension(i.e. 10 or more). The script I'm currently using exports the TIFF file I ...
3
votes
1answer
248 views

Determine size of GeoTIFF header

Is there a way to find the size (in bytes) of the header information in a GeoTIFF file using Python? I am not trying to read the header (I know I can use gdalinfo for this) but rather to figure out ...
3
votes
1answer
754 views

Efficiently read large tif raster to a numpy array with GDAL?

I have been using the Python GDAL API to read tif raster files as NumPy arrays. Previously, I simply read the raster into an array directly with GDAL: ds = gdal.Open('example.tif') fullarray = np....
1
vote
1answer
270 views

Numpy array to raster with ArcPy [closed]

I have a Python script to download data in netCFD format. I have managed to extract the information I need in a masked array. This looks like: print(my_array.shape()) >> (700, 299, 217) As a ...
0
votes
0answers
441 views

Opening numpy array to rasterio?

I have numpy array that I know bbox for and can transform like this: import rasterio.plot from rasterio.transform import from_bounds t = from_bounds(minx, miny, maxx, maxy, sorted_np[3,:,:,7].shape[...
0
votes
0answers
29 views

Google Earth Engine Output - Returns Unexpected Values with np.sum()

I am exporting a CHIRPS precipitation raster from Google Earth Engine. This is part of a larger collection of data that I'll be exporting, but I'm just inspecting one image at the moment. I've ...
1
vote
2answers
699 views

NumPy memory error on large rasters

I have multiple large rasters. Their 5 percentile and 95 percentile are needed to be calculated. After loading the rasters to the ArcMap, I am using the following codes - import numpy import arcpy ...
3
votes
1answer
59 views

Raster representation in arcpy/numpy

I have a .tif raster file which contains integer values at 1, 2, 3, 4 and 5. Importing this file into ArcMap also shows a number of cells with Nodata value where the above classes are not present. I ...
2
votes
2answers
883 views

How to create a TIFF file using GDAL from a numpy array and specifying NoData value

I have some tiff files I obtained from splitting a bigger tiff file using gdal translate. The border tiff files have some nodata values, which I can see in numpy as number 15. I want to manipulate ...