A Maxent Script Tool for ArcGIS

As part of my PhD research at the University of Arizona where I study biogeography, biodiversity and macroecology, I have been part of a group looking at large-scale biodiversity questions for New World plants. In this role, I have been responsible for generating many species distribution models using Stephen Phillip’s Maxent software (and R with the Dismo package). I also use ArcGIS quite often to prepare environmental data for Maxent modeling, and wanted a way to perform and integrate Maxent modeling into my ArcGIS workflows.

Maxent Tool User InterfaceWhen working with data and analysis, my rule is that if I have to do something complicated more than twice, it’s generally worth it to develop an automated workflow. So for my species distribution modeling needs, I wanted a Maxent script tool that I could use as a standalone geoprocessing tool or embed within a ModelBuilder model for use more complicated workflows. For example, one of my most common workflow is iterating through a list of species and running a species distribution model for each one.

To accomplish this, I wrote an ArcGIS script tool in Python that collects a variety of common Maxent parameters in a typical ArcGIS geoprocessing user interface and populates a command string to execute Stephen Phillip’s maxent.jar Java application via a Python call to execute a system command. The resulting script tool uses the arcpy model, so it works like any other ArcGIS geoprocessing script tool. It can operate as a standalone tool to generate a species distribution model for a single species, or can be placed into a ModelBuilder workflow and linked to input parameters as shown in the example below.

Maxent Tool in a ModelBuilder Model

In this example, the script tool is parameterized with a species occurrence dataset obtained from the iterator object in which each dataset is named genus_species.csv. The tool then generates a species distribution model for each species and saves the model to a separate directory within a designated output directory, naming each directory by the genus and species name specified in the name of the input occurrence dataset.

A partial example of the Python script that obtains the parameters from the input datasets is shown below.

Maxent Tool Python Script

These parameters are then appended to a string object that is a system command call:

myCommand = "java -mx512m -jar \"" + maxent + "\" -e \"" + climatedataFolder + "\""
myCommand += " -s \"" + csvFile + "\" -o \"" + newOutputFolder + "\""
myCommand += " outputformat=" + optOutputFormat.lower() + " outputfiletype=" + optOutputFileType.lower()

Finally the command is executed via a call to the os.system Python interface that executes the maxent.jar Javascript application with the appropriate options:

result = os.system(myCommand)

When the maxent.jar Java application launches, you’ll see the typical Maxent GUI that you would see if you launched maxent.jar directly and ran a model manually. Except in this case the maxent.jar application launches and starts the model automatically, as shown below.:
Maxent Running

Of course there are some additional script lines that are not shown in the examples above add other maxent parameters to the command string and evaluate the result of the os.system call to determine whether the command executed correctly or not.

However, I have placed a copy of a simple ArcGIS Toolbox and the associated Python script in a zipfile that you can download for your own modeling uses at the link below. There are different versions for each version of ArcGIS you may be using. While newer versions of ArcGIS can read older toolboxes, older versions of ArcGIS cannot read newer toolboxes. So be sure to download the file below that is most appropriate for your ArcGIS version.

Maxent Tool in ArcCatalogIf you like the tool, please let me know if you have any questions or comments/ideas. This is a fairly simple first implementation that I built to get through a lot of modeling quickly. However, I have a few ideas for additions to the tool that would enable it to handle species occurrence point data directly (instead of using saved CSVs) and perhaps leverage Maxent cache (.mxe) files instead of using the environmental data ASC files for each model iteration. At the moment, I’m too busy to add these, but it may be something I add in the future to round out the tool better.

17 thoughts on “A Maxent Script Tool for ArcGIS

Add yours

    1. Dear John,
      I am Vy Nguyen, an Ornithologist in Viet nam. I am a PhD candidate in Thaiand. My study will focus on Germain’;s Peacock Pheasant, an endemic species to mainly South Viet Nam and small part in East of Cambodia. I intend to predict distribution range of this species in whole its distribution range in the future. By the way I have almost 300 present locations of another endemic species – Orange-necked Partridge to South Viet Nam. I try to look for a method helping to make a prediction Map for this species in Viet Nam. So far, I have had a training course of GIS 10.1 in Thailand and now I want to use this tools to combine with maxent program in order to make the distribution map. This morning, I found your blog and wanted to write to you so that I can have your help. I have not used maxent before. If you do not mind, could you help me to have a guildline step by step how to use Maxent in ArcGIS 10.1?

  1. First of all I want to say superb blog! I had a quick question that I’d like to ask if you do not mind. I was curious to find out how you center yourself and clear your thoughts before writing. I’ve had a tough
    time clearing my mind in getting my ideas out there.
    I truly do enjoy writing however it just seems like the first 10 to 15 minutes
    are generally lost just trying to figure out how to begin.
    Any ideas or hints? Appreciate it!

  2. when I extracted your toolbox and added it to my tool box set, I had a (x) mark on the tool titled Run Maxent Model. I guess that I didn’t put the script included in the zip file in the right place. Where should I place the python scrip file to be found by the tool

    1. Sorry about that. Apparently I didn’t have relative path names checked when I saved the models for sharing. To fix the problem:

      Right-click on the model in ArcCatalog and select “Properties”.
      On the Properties dialog check the box that is labled “Store relative path names (instead of absolute paths)”. Then click the Ok button.
      Next right-click on the model again and select “Edit” to open Model Builder.
      In Model Builder, double-click on the object named “Run Maxent Model”.
      A dialog will open asking you to select the tool. Browse to the location of the Maxent_Toolbox in your folder connections and select the “Run Maxent Model” script tool.
      Then save the Model, and close Model Builder.

      The red “X” should be gone and the model should now work as expected.

      1. Yes the (X) disappeared but when running the model I was returned with the following error message

        ERROR 000576: Script associated with this tool does not exist.
        Failed to execute (RunMaxentModel).
        Failed at Wed Jan 22 11:35:05 2014 (Elapsed Time: 0.00 seconds)

        Then I had to manually specify the path for the RunMaxentModel script in the properties dialogue box manually. Following that it worked. Thanks for your efforts. I don’t have to jump between ArcMap and Maxent anymore.
        Regards

  3. Just an idea for further development, the current script doesn’t allow selection of environmental variables in Maxent modeling it takes all the ASCII rasters in the input folder. It would be very much handy if such capability exists

    1. Hi Husam. I have the same problem. But actually, my mistake appears associated with “Location of Maxent jar File”. It appears as Parameters Syntaz Error No module named arcpy. And do not run because of it. Have any idea what to try?

  4. Sin duda alguna un excelente trabajo, mil gracias por compartir su conocimiento sin costo alguno, es usted muy brillante. Saludos desde Cali-Colombia. Soy Geógrafo!! 😀

  5. Hello ..
    Dear John..
    Thank you for your contribution to this blog, as it represents an easy way of automating lots of computational calculations for joining Maxent and ArcGIS……….

    I have a quick question: How can I modify the Maxent settings parameters in the script ? For example to do various replicas for each species model…..
    And how do I change the regularization multiplier parameters
    Thank you

  6. Hi, is this tool still available? Would love to gain access to it but it seems like the zipped files do not work.

  7. Hello!! I wold like to download this toolbox, but the link is over! You can disponibilize the link again? Thanks!!!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create a free website or blog at WordPress.com.

Up ↑

%d bloggers like this: