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:

>> (700, 299, 217)

As a working example I have selected only the first array of the first dimension, such as:

data = my_array[0][0]
print (data.shape())
>> (299,217)

This is stored as a masked array by default, this means that some of the values are empty. I am trying to export this to a raster file, so it looks like the image below 1. The array looks likes 2:

I want this array

However, with the following code (see below) the raster is saved as the second picture 3. The empty values in my array are stored as 2.147483648000000000e+09. See attached filed.

np.savetxt('raster.txt', data)


data_1 = np.ma.masked_array(data, fill_value=None)
np.savetxt('raster.txt', data_1)

What I do next is with arcpy

import os
import sys
import numpy as np
import arcpy

arcpy.env.overwriteOutput = True
arcpy.env.outputCoordinateSystem = arcpy.SpatialReference('WGS 1984')
nraster = np.genfromtxt('raster.txt', missing_values='Null')
cell_size = 0.041666667
lat = 18.020833333333343
lon = -104.97916666666666
corner = arcpy.Point(lat, lon)

# Convert array to a geodatabase raster
my_raster = arcpy.NumPyArrayToRaster(nraster, corner, x_cell_size=cell_size, y_cell_size=cell_size)    

It looks like this

So my question is, how can I save this array to a .txt file (in Python) so I can read it back with arcpy.NumPyArrayToRaster and continue my process in ArcMap?

closed as off-topic by BERA, Kadir Şahbaz, nmtoken, Evil Genius, csk Aug 14 '18 at 20:09

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions relating to general IT or with no clear GIS component, are off-topic here but can be researched/asked at Stack Overflow (software development), Super User (computing hardware and software), Database Administrators (relational databases) and other SE sites" – BERA, Kadir Şahbaz, nmtoken, Evil Genius, csk
If this question can be reworded to fit the rules in the help center, please edit the question.

  • I added my question at the bottom. – Daniel Aug 13 '18 at 13:04
  • Does this answer your question? – Hornbydd Aug 13 '18 at 13:27
  • 1
    Your problem is not GIS related since you get strange values in the textfile and is probably more likely to get answered on stackoverflow.com – BERA Aug 13 '18 at 15:31

Your data is weird:


So you have many values around 22 which the very large mean/max "hides". If you do:

nraster = np.where(nraster>100,100,nraster)

And apply a stretch you get something: enter image description here

What mean/max/median do you get on the original numpy array?

  • I have max = 155.9 median = 22.6 mean = 31.443140428976122 You get different results because, as max you are considering what I wrote is set as default 2.147483648000000000e+09 – Daniel Aug 13 '18 at 13:37
  • Then something goes wrong when you create the txt file. Why do you need this step? Use the correct numpy array as input to NumpyArrayToRaster – BERA Aug 13 '18 at 13:39
  • Yes, I know something is going wrong. But when I use np.savetxt the txt contain a large number for empty rows. – Daniel Aug 13 '18 at 13:41
  • As the question is on hold by some weird reason. I will post the answer to this in my github. It is a problem related to GIS/Python/ArcMap. – Daniel Aug 16 '18 at 10:29

Not the answer you're looking for? Browse other questions tagged or ask your own question.