POST
|
You may have figured this out or moved on already, so I'll keep this reply short. Option 1: Use Python to read the netCDF file as a numpy array object. If your dataset isn't too large, you can average all 1,308 time steps with a single keystroke. Search Google for 'scipy.io.netcdf' and 'numpy.mean'. Option2: If your dataset is too large to read as a single three-dimensional array, you'll have to loop through each time step and use a simple formula: T avg = ((n*a avg ) + a) / n + 1 n = the # of timesteps you've already averaged a avg = your current average a = data for the current time step Obviously for the first time step, a avg == a. But, for example, at the the fourth time step the formula would be: ((3*a avg ) + a) / 4 Either way, you're going to need to use Python. I like to use a good scientific IDE like SPyDeR for this type of work.
... View more
01-11-2012
10:18 AM
|
0
|
0
|
573
|
POST
|
It's probably best if you do some research and figure out the details of your particular script. You know what you need better than anyone. Here's a couple of helpful starting points. # create a new csv file
myoutputfile = open("C:\\example.csv", "w")
import time
start = time.ctime()
# do a bunch of stuff...
stop = time.ctime()
myoutputfile.write("Started: {0}\n".format(start)
myoutputfile.write("Finished: {0}\n".format(stop)
myoutputfile.close()
... View more
01-05-2012
09:43 AM
|
0
|
0
|
260
|
POST
|
I'm trying to write a subroutine for the first time and I'm getting very confused. I'm trying to create a tool where users would interactively add a point to a feature class (using a feature set and appending it to the original feature class). The tool uses the interactive feature input control. So far I've gotten that part to work and to append the new feature to the original feature class. Now I'm trying to add in some functionality so that if the user forgets to enter a project id for the point, an error message will be printed and then a subroutine is called so they can then enter the project id. Here is my code: # Import arcpy module import arcpy from arcpy import env #Set workspace # env.workspace = "L:/Projects/HMAP/EnvironmentalReview.gdb" # Script arguments Feature_Set = arcpy.GetParameterAsText(0) if Feature_Set == '#' or not Feature_Set: Feature_Set = "in_memory\\{C6359898-F410-49FF-96DD-0EB59C98516A}" # provide a default value if unspecified # Local variables: ##ProjectPoints = Feature_Set ##ProjectPoints__2_ = "ProjectPoints" #define subroutine if user forgot to enter a project identifier # def subroutine1(): cur = arcpy.UpdateCursor(Feature_Set) for row in cur: newVal = arcpy.GetParameterAsText(1) idValue = row.setValue(newVal) row.updateRow(row) del cur, row return #Check to make sure user entered a project identifier for point # cur = arcpy.SearchCursor(Feature_Set) for row in cur: idValue = row.getValue("ProjectID") if idValue == None: arcpy.AddError("PLEASE ENTER A VALUE(S) FOR PROJECT ID") subroutine1 else: arcpy.Append_management(Feature_Set, "ProjectPoints", "TEST", "", "") # Process: Append I know I'm doing something wrong as far as the subroutine is concerned. When I run the tool, it allows me to click the mouse to add a point. Then I hit "o.k" on the interactive input window to simulate someone forgetting to input the project id. Then the rest of the script starts to run but I get an error stating that "the name Feature_Set is not defined". I've tried reading all kinds of documentation on defining functions but I apparently still don't quite get it. Can anyone help? Thanks much! Amy Meehan MDIFW Bangor, Maine Amy- The subroutine (Python folks would just call this a 'function', which you have named 'subroutine1') looks okay to me. Except when you call a function, you need to use parentheses after it like this: ...
arcpy.AddError("PLEASE ENTER A VALUE(S) FOR PROJECT ID")
subroutine1()
... To see what's happening, go into a Python shell and do this: def my_function():
print "yes"
# type this first and see what happens
my_function()
#type this next and see what happens
my_function
... View more
10-26-2011
09:31 AM
|
0
|
0
|
288
|
POST
|
Or this even: http://resources.esri.com/help/9.3/arcgisengine/java/gp_toolref/data_management_tools/flip_data_management_.htm 🙂
... View more
10-26-2011
07:40 AM
|
0
|
0
|
1039
|
POST
|
Thanks for the feedback, especially the point/corner idea. I eventually found lower left corner (print LONmin() LATmin() for netcdf file) and cell size (simply by printing all the lats and lons in python and then minusing one from the other, not the prettiest method but it gave me what I needed) but I seem to still be producing an upside down raster! I have tried numpy.flipud and from the documentation this appears to be the best method but the results are strange lines. Maybe to solve this problem I need to go back to the original array? Is there some way I should write my array to a file that will make it easier to import into arcmap as a raster? I am currently using savetxt("myfile.txt", myarray) any feedback will be greatly appreciated. Now that you mention it, I recall getting weird results with np.flipud as well. The solution I found was to re-declare my data as an array, like so: myArrayFlipped = np.array(np.flipud(myArray)) If worst comes to worse you could flip the array yourself with some slicing, but yuck. What a pain. Good luck!
... View more
10-26-2011
07:37 AM
|
0
|
0
|
1039
|
POST
|
I would like to use arcpy.NumPyArrayToRaster to import a numpy array and use in arcGIS10 as a raster. This function works fine except I did not enter the lower left corner (in map units) and the x and y cell size, therefore my image was upside down! Is there a simple command I can run in python on my numpy array to find out what the lower left corner is?? thanks If your numpy array was originially a raster, you can export that raster to an ASCII file and get the coordinates of the lower left corner from the output('xllcorner' and 'yllcorner'). Note that, based on my own experience, you have to input coordinates for the lower left corner as a Point object: corner = arcpy.Point(xllcorner, yllcorner)
myRaster = arcpy.NumpyArrayToRaster(myArray, corner, cellSizeX, cellSizeY) Also note that you can quite easily flip a numpy array: flipped_array = numpy.flip_ud(myArray).
... View more
10-07-2011
08:38 AM
|
0
|
0
|
1039
|
POST
|
I've been spending the better part of the weekend trying to figure out the best way to transfer data from an personal geodatabase feature class into an Excel sheet using Python. I've found a few modules that may help (execsql, python-excel), but I'm not sure what the best approach should be. All I need to do is copy 4 columns of data from access to excel and then format the excel. I have the formatting part solved. Should I: Iterate through the rows using a cursor and somehow load the rows into excel? Copy the columns from access to excel? Export the whole access table into a sheet in excel? Thanks for any suggestions. I won't pretend to tell you what the "best" approach for this is. But I can tell you how I've done it. I like to use the win32 library like so: # first build the Microsoft Office Object library using the PythonWin makepy utility
import win32com.client
xl = win32com.client.Dispatch("Excel.Application")
xl.Visible = 1 # good for testing things interactively
wb = xlWorkbooks.Add()
xl.ActiveSheet.Name = "Whatever"
datasheet = xl.Worksheets("Whatever")
# set format for text
xl.Columns("A:A").NumberFormat = "@"
# set format for lots of decimal places
xl.Range("B2:ZZ45").NumberFormat = "0.0000000000"
# setting a cell value
datasheet.Cells(1, "A").Value = "SampleText"
xl.ActiveWorkbook.SaveAs("C:\temp\Whatever.xlsx")
xl.ActiveWorkbook.Close(SaveChanges = 1)
xl.Quit() I've never used Access this way, but I'm sure you could pretty easily copy data from one to the other.
... View more
10-03-2011
12:12 PM
|
0
|
0
|
1471
|
POST
|
Hi there, The files within the Python Standard Library have some pretty good examples of how to lay out code (especially code metadata) in a module. If not, I've always enjoyed this page's take on structuring code. Python actually has an official style guide, called PEP8 for brevity: http://www.python.org/dev/peps/pep-0008/. You can use the PEP8 Python module to check your code for adherence to this standard: http://pypi.python.org/pypi/pep8#downloads. In my opinion, what is needed is an official ArcGIS Python style guide. Even among the ESRI produced script tools there is some variation and considerable deviation from PEP8. With Python becoming more and more integral to ArcGIS, I'd like to see promulgation of coding standards and best practices that fit within PEP8, to the extent possible. Just my two cents.
... View more
09-20-2011
11:59 AM
|
1
|
0
|
1030
|
POST
|
arcpy.GetMessages is specific to getting messages from a tool which has executed. http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/GetMessages/000v0000000p000000/ Well, this is a digression, but that link is a bit misleading. You can put whatever you want into a message. For example, if you put this code into a script tool: import arcpy
arcpy.AddMessage("This is just a message...")
arcpy.AddWarning("This text is green...")
arcpy.AddError("This text is red...")
arcpy.GetMessages()
# this will make the tool bomb out
foo = bar No tools have executed but you've still returned three messages.
... View more
09-12-2011
12:19 PM
|
0
|
0
|
394
|
POST
|
Code is absolutely fine. I suspect you dont have a title in your map document. If you dont have a title, mxd.title will equal ''. In this case the AddMessage doesn't return anything. The title it is returning is from: File > Map Document Properties > Title: ________ Can you be sure you got something in there? Also as a check, take your code into the Python window. mxd = arcpy.mapping.MapDocument("current")
mxd.title (the arcpy.AddMessage isn't going to do what you want in the Py Window Based on my reading of his description, it looks like he's trying to run this as a script tool, not from the Python window. Hence, he would need arcpy.GetMessages() to return the document title to the geoprocessing window.
... View more
09-08-2011
03:50 PM
|
0
|
0
|
394
|
POST
|
Okay most of that stuff in here before was redundant so it seems. New toolbox, new Script. No changes made to validation. No input at all. Just a straight run of the script does not work. import arcpy mxd = arcpy.mapping.MapDocument("current") arcpy.AddMessage(mxd.title) Hopefully that is a bit easier to answer cos I reckon I must be missing something really, really simple. Based on what I see here, you are missing something really simple: a single line of code. arcpy.GetMessages()
... View more
09-08-2011
10:22 AM
|
0
|
0
|
394
|
POST
|
There are two reasons why the netcdf4-python windows binaries from <http://code.google.com/p/netcdf4-python/> won't work from within ArcGIS10: 1) The hdf5dll.dll file used by ArcGIS is incompatible with the one required by netcdf4-python's netcdf.dll. Some functions are missing. Hence the error message when loading netcdf.dll. Copying all netCDF4-python provided DLLs from "C:\Python26\ArcGIS10.0\lib\site-packages" to "C:\Program Files\ArcGIS\Desktop10.0\Bin" worked but might interfere with ArcGIS functions (no tested). Also there should be no other netcdf.dll files in the Windows DLL search path. 2) ArcGIS-python ships with numpy-1.3, which is quite outdated and will not work with extensions compiled with the latest numpy. Importing netcdf4-python will crash. Upgrading to numpy-1.6.1 solved this but might influence the arcpy package (not tested). Embedded manifests are not the problem here. NetCDF4.pyd was compiled with the patch from <http://bugs.python.org/issue7833> and also netcdf.dll and all dependent DLLs are linked with the 'MANIFEST:NO' option. Thanks Christoph. I'd read that bug report and got even more confused since it looked like the manifest issue had been fixed. Long story short, I ended up building an installer for Konrad Hinsen's ScientificPython module which is available here: https://sourcesup.cru.fr/frs/download.php/3745/ScientificPython-2.9.1.win32-py2.6.msi It's 100% compatible with versions of Python/numpy shipped with ArcGIS 10.
... View more
08-25-2011
12:23 PM
|
0
|
0
|
1714
|
POST
|
There are two reasons why the netcdf4-python windows binaries from <http://code.google.com/p/netcdf4-python/> won't work from within ArcGIS10: 1) The hdf5dll.dll file used by ArcGIS is incompatible with the one required by netcdf4-python's netcdf.dll. Some functions are missing. Hence the error message when loading netcdf.dll. Copying all netCDF4-python provided DLLs from "C:\Python26\ArcGIS10.0\lib\site-packages" to "C:\Program Files\ArcGIS\Desktop10.0\Bin" worked but might interfere with ArcGIS functions (no tested). Also there should be no other netcdf.dll files in the Windows DLL search path. 2) ArcGIS-python ships with numpy-1.3, which is quite outdated and will not work with extensions compiled with the latest numpy. Importing netcdf4-python will crash. Upgrading to numpy-1.6.1 solved this but might influence the arcpy package (not tested). Embedded manifests are not the problem here. NetCDF4.pyd was compiled with the patch from <http://bugs.python.org/issue7833> and also netcdf.dll and all dependent DLLs are linked with the 'MANIFEST:NO' option. Thanks Christoph. I'd read that bug report and got even more confused since it looked like the manifest issue had been fixed. Long story short, I ended up building an installer for Konrad Hinsen's ScientificPython module which is available here: https://sourcesup.cru.fr/frs/download.php/3745/ScientificPython-2.9.1.win32-py2.6.msi It's 100% compatible with versions of Python/numpy shipped with ArcGIS 10.
... View more
08-25-2011
12:14 PM
|
0
|
0
|
1714
|
POST
|
This is due to the nature of the build of the ArcGIS desktop applications. It establishes its own process-level settings in Windows for various binary runtime settings, which in turn causes a failure in any compiled module which has an embedded manifest within it. The binary Python modules (.pyd) include such a manifest, and as noted on the Python.org web site's issue tracker, the issue was not fixed for Python 2.6/2.7 and may likely not be fixed in future versions as well. One possible workaround is to use the Microsoft utility editbin to strip the manifest from the .pyd files of interest using the /ALLOWISOLATION:NO option. Jason- So when I follow your instructions for the file in question ("netCDF4.pyd") the output I get is: netCDF4.pyd : warning LNK4228: '/ALLOWISOLATION' invalid for a DLL; ignored Any thoughts? Does this mean the file was compiled with the /GL option?
... View more
07-20-2011
01:48 PM
|
0
|
0
|
1714
|
POST
|
This is due to the nature of the build of the ArcGIS desktop applications. It establishes its own process-level settings in Windows for various binary runtime settings, which in turn causes a failure in any compiled module which has an embedded manifest within it. The binary Python modules (.pyd) include such a manifest, and as noted on the Python.org web site's issue tracker, the issue was not fixed for Python 2.6/2.7 and may likely not be fixed in future versions as well. One possible workaround is to use the Microsoft utility editbin to strip the manifest from the .pyd files of interest using the /ALLOWISOLATION:NO option. That's great information. Thanks Jason.
... View more
07-12-2011
10:37 AM
|
0
|
0
|
1714
|
Title | Kudos | Posted |
---|---|---|
1 | 05-25-2012 05:22 AM | |
1 | 02-09-2018 01:19 PM | |
1 | 09-20-2011 11:59 AM | |
1 | 03-27-2013 09:08 AM | |
3 | 02-09-2018 06:34 AM |
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|