Skip to Content.

mget-help - RE: [mget-help] using MGET in arcgis python with ImportToolbox

Please Wait...

Subject: Marine Geospatial Ecology Tools (MGET) help

Text archives


RE: [mget-help] using MGET in arcgis python with ImportToolbox


Chronological Thread 
  • From: Joseph McGlinchy <>
  • To: Jason Roberts <>
  • Cc: "" <>
  • Subject: RE: [mget-help] using MGET in arcgis python with ImportToolbox
  • Date: Mon, 7 Nov 2016 22:20:18 +0000
  • Accept-language: en-US

As a follow up, I’ve gotten the GAM tool to work in my script by stripping out the keyword definitions and placing the parameters in order in the function call.

 

From: Joseph McGlinchy
Sent: Monday, November 07, 2016 2:21 PM
To: 'Jason Roberts' <>
Cc:
Subject: RE: using MGET in arcgis python with ImportToolbox

 

Hey Jason,

 

thanks for the quick reply. Using arcgisscripting does seem to help, although it seems the call to the tool is a bit different? I thought that simply replacing arcpy. with gp. would allow me to call the tool, but are the parameters structured differently? I ran this tool in ArcMap and the python snippet looks like below. However, replacing the arcpy with gp gives me an error like the one below, as if it cannot parse the input parameters.

 

Failed to execute. Parameters are not valid.

ERROR 000735: Input table: Value is required

ERROR 000735: Output model file: Value is required

ERROR 000735: Response variable: Value is required

ERROR 000735: Response variable distribution: Value is required

Failed to execute (GAMFitToArcGISTable).

 

Executing: GAMFitToArcGISTable # # # # mgcv # # # # # # # # # GCV.Cp outer newton false 1 # true true true true false true true png 1000 3000 3000 10 white

Start Time: Mon Nov 07 14:17:47 2016

Failed to execute. Parameters are not valid.

ERROR 000735: Input table: Value is required

ERROR 000735: Output model file: Value is required

ERROR 000735: Response variable: Value is required

ERROR 000735: Response variable distribution: Value is required

Failed to execute (GAMFitToArcGISTable).

Failed at Mon Nov 07 14:17:47 2016 (Elapsed Time: 0.00 seconds)

PYTHON ERRORS:

Traceback info:

  File "<string>", line 536, in execute

 

Error Info:

Failed to execute. Parameters are not valid.

ERROR 000735: Input table: Value is required

ERROR 000735: Output model file: Value is required

ERROR 000735: Response variable: Value is required

ERROR 000735: Response variable distribution: Value is required

Failed to execute (GAMFitToArcGISTable).

 

 

  arcpy.GAMFitToArcGISTable_GeoEco(inputTable=templyr,

                            outputModelFile="V:/DBS_ChangeDetection/MGET_models/test/GAM_fit_test.RData",

                            responseVariable="TEST",

                            family="binomial",

                            rPackage="mgcv",

                            continuousPredictors="grayStats_corr # # #;grayStats_energy # # #;grayStats_entropy # # #;grayStats_kurtosis # # #;grayStats_skewness # # #;grayStats_mean # # #;grayStats_variance # # #",

                            categoricalPredictors="",

                            offsetVariable="",

                            offsetTransform="",

                            bivariateInteractions="",

                            where="",

                            link="",

                            variance="",

                            theta="",

                            method="GCV.Cp",

                            optimizer="outer",

                            alternativeOptimizer="newton",

                            select="false",

                            gamma="1",

                            selectionMethod="",

                            logSelectionDetails="true",

                            writeSummaryFile="true",

                            writeDiagnosticPlots="true",

                            writeTermPlots="true",

                            residuals="false",

                            xAxis="true",

                            commonScale="true",

                            plotFileFormat="png",

                            res="1000",

                            width="3000",

                            height="3000",

                            pointSize="10",

                            bg="white")

 

 

Hi Joe,

 

I’m glad you’re excited about the toolbox..

 

The root problem here is that there is a bug in how arcpy constructs Python docstrings for imported toolboxes. The MGET tool called “Copy CoastWatch Navigation Offsets” has four parameters. The last parameter of this tool contains documentation that ends with a double quote character. When arcpy constructs the CoastWatchAVHRRCopyNavigationOffsets_GeoEco method for that tool, it does not anticipate that the documentation for the last parameter could end with a double quote, and creates Python code that is four double quote characters in a row:

 

          ...

          said:"I've thought about it for a while and my inclination is to say don't

          correct

          the angle data. It's not a perfect solution -- ie: if we knew the satellite's

          position and orientation perfectly and recomputed the angle data, we would find

          very small discrepancies compared with the navigation-corrected version.""""

 

The first three of these are interpreted by Python as the end of the multi-line docstring, and the fourth is the beginning of a new single line string. It then encounters the end of the line without a terminating double quote and raises SyntaxError: EOL while scanning string literal.

 

I’m sorry about this problem. Although I have known about it for quite a while, I don’t think I have raised it with anyone at ESRI (e.g. Shaun Walbridge), nor have I changed MGET to work around the bug (e.g. by inserting something after that final double quote).

 

You can still import MGET via the old method that existed before arcpy. Here is an example of trying to call the problematic tool. The example fails because I did not give it any parameters; if I had, it would have worked. But you can see that gp.AddToolbox is successful. I should also note that because AddToolbox does not try to construct docstrings, etc., for all of the 300+ tools in the MGET toolbox, it is much faster than arcpy.ImportToolbox.

 

>>> import arcgisscripting

>>> gp = arcgisscripting.create()

>>> gp.AddToolbox('C:\\Program Files\\GeoEco\\ArcGISToolbox\\Marine Geospatial Ecology Tools.tbx', 'GeoEco')

>>> gp.CoastWatchAVHRRCopyNavigationOffsets_GeoEco()

Traceback (most recent call last):

  File "<interactive input>", line 1, in <module>

ExecuteError: Failed to execute. Parameters are not valid.

ERROR 000735: Source CoastWatch file: Value is required

ERROR 000735: Source variable for navigation: Value is required

ERROR 000735: Destination CoastWatch file: Value is required

Failed to execute (CoastWatchAVHRRCopyNavigationOffsets).

 

>>> 

 

Let me know if that helps..

 

Best,

Jason

 

From: Joseph McGlinchy [mailto:]
Sent: Monday, November 7, 2016 3:35 PM
To:
Subject: using MGET in arcgis python with ImportToolbox

 

Hello,

 

First, I’d like to thank you for providing this toolbox. I’m excited to use it!

 

I am trying to run a series of calls to the model fitting tools, and as such would like to import the toolbox within the arcpy environment. I’m trying to import the toolbox with arcpy.ImportToolbox(<path to MGET toolbox .tbx file>) and I get the following error. Is it possible to import this toolbox within the context of a python script using other arcpy functionality?

 

Thanks!

Joe

 

 

arcpy.ImportToolbox(mget_path)

Runtime error

Traceback (most recent call last):

  File "<string>", line 1, in <module>

  File "c:\program files (x86)\arcgis\desktop10.4\arcpy\arcpy\__init__.py", line 125, in ImportToolbox

    return import_toolbox(input_file, module_name)

  File "c:\program files (x86)\arcgis\desktop10.4\arcpy\arcpy\toolbox_code.py", line 440, in import_toolbox

    mymodule = generate_toolbox_module(toolbox, None, False, False, False, module_name, use_alt_alias)

  File "c:\program files (x86)\arcgis\desktop10.4\arcpy\arcpy\toolbox_code.py", line 414, in generate_toolbox_module

    'exec')

  File "C:\Program Files\GeoEco\ArcGISToolbox\Marine Geospatial Ecology Tools.tbx", line 41319

    """CoastWatchAVHRRCopyNavigationOffsets_GeoEco(sourceFile, sourceVariable, destFile, {destVariables;destVariables...})

 

        Copies the navigation offsets from one variable in a CoastWatch POES AVHRR CWF

        or HDF file to one or more variables in another file.The navigation offsets are

        the e and f coefficients of the navigation affine

        attribute of each variable (the HDF nav_affine attribute). Prior to setting the

        navigation offsets in the destination file, the entire navigation affine is

        reset by invoking the cwnavigate utility with the -R option.

 

     INPUTS:

      sourceFile (File):

          CoastWatch POES AVHRR CWF or HDF file containing the variable from which the

          navigation offsets should be copied.Only CoastWatch POES AVHRR files are

          supported. An error will be raised for

          other CoastWatch files, such as those for the GOES satellite series.

      sourceVariable (String):

          CoastWatch variable in the source file from which navigation offsets should be

          copied.

      destFile (File):

          CoastWatch POES AVHRR CWF or HDF file containing the variables to which the

          navigation offsets should be applied. This file can be the same as the source

          file.Only CoastWatch POES AVHRR files are supported. An error will be raised for

          other CoastWatch files, such as those for the GOES satellite series.

      destVariables {String}:

          CoastWatch variables in the destination file to which the navigation offsets

          should be applied. In general, navigation offsets should only be applied to

          variables that are derived from sensor data. At the time of this writing, the

          variables derived from sensor data included:avhrr_ch1 avhrr_ch2 avhrr_ch3

          avhrr_ch3a avhrr_ch4 avhrr_ch5 cloud cloudx sstPeter Hollemans, one of the lead

          CoastWatch researchers at NOAA, suggested that

          navigation offsets should not be applied to the graphics, rel_azimuth,

          sat_zenith, and sun_zenith variables. With respect to the last three, he

          said:"I've thought about it for a while and my inclination is to say don't

          correct

          the angle data. It's not a perfect solution -- ie: if we knew the satellite's

          position and orientation perfectly and recomputed the angle data, we would find

          very small discrepancies compared with the navigation-corrected version.""""

                                                                                                                          

 

                                                                                     

                                                                                       

                                                         

                                                                                       

                                                                                   

                                                                    

 

           

                        

                                                                                      

                                                                                  

                                                

                                                                              

                              

                                                                                        

                 

                      

                                                                                     

                                                                                       

                                                                                          

                                                                              

                             

                                                                                      

                                                                                     

                                                                                       

                                                                                   

                                                                                         

                                                        

                                                                                

                                                                                  

                                                                                    

                 

                                                                                       

                                                                                         

                                                                                     ^

SyntaxError: EOL while scanning string literal

----------------------------------------------------------------------

Joe McGlinchy | Imagery Scientist

Esri Professional Services

ESRI || 1 International Court || Broomfield, CO 80021 || USA

T 909-793-2853, ext. 4783 LinkedIn

 




Archive powered by MHonArc 2.6.19.

Top of Page