With a few short steps, you can leverage ArcGIS Insights to run scripts and expand what’s possible in your analysis. This article explains how to use Insights to run a script to analyze the impact of COVID-19 on hospitals in your health care region
The CHIME (COVID-19 Hospital Impact Model for Epidemics) application was developed in collaboration between Code for Philly and Penn Medicine to analyze hospital capacity. The application uses an SIR (Susceptible, Infected, Recovered) model to determine required capacity.
The code from the CHIME application can be run in the scripting environment in ArcGIS Insights, which is available to agencies responding to the COVID-19 pandemic through Esri’s Disaster Response Program (DRP). The code creates an output dataset, which can be used in Insights to create spatial and nonspatial visualizations to analyze epidemiology at a county level.
See the full page example here.
Before you begin
Insights in ArcGIS Enterprise and Insights desktop support connections to a Jupyter Kernel Gateway, which can be used to open a scripting environment and run scripts in Python and R. If you have access to Insights in ArcGIS Online, either through your organization or from the DRP, you can download Insights desktop and use it to access the Insights scripting environment. You can use your Insights in ArcGIS Online account to activate Insights desktop.
You must also set up a Jupyter Kernel Gateway. Steps to set up a Jupyter Kernel Gateway can be found in the Insights Scripting Guide on GitHub.
The dataset used in this example contains the following fields. If you want to run the script using data from your own region, you will need a dataset with the equivalent information and field names.
- countyname – County name
- Unacast_ch – Doubling time in days (contact rate)
- Hospitaliz – Currently hospitalized COVID-19 patients
- Population – County-wide population
- Hospital_1 – Hospital market share (%)
Open Insights and connect to your Jupyter Kernel Gateway
1. Download the CHIME_Example.zip file. Extract the compressed CHIME_Example folder, but do not extract the HA_2018 folder. The HA_2018 folder contains a shapefile, which must be in a compressed format to upload in Insights.
2. Open Insights in ArcGIS Enterprise or launch Insights desktop.
If you are opening Insights desktop for the first time, you will be asked to activate your account. You can activate Insights desktop using an Insights in ArcGIS Enterprise account or Insights in ArcGIS Online account.
If this is your first time signing in to your Insights account, the Welcome to Insights window appears.
3. If necessary, in the Welcome to Insights window, click Skip.
4. Click the Workbooks tab.
5. Click New workbook.
A workbook is created and the Add to page window appears. Your content is shown by default. You will upload a shapefile in a compressed folder to use in the script.
6. In the Add to page pane, click Upload file.
7. Browse to the CHIME_Example folder and open the HA_2018.zip file. Repeat the steps to open the BC_Covid.xlsx file.
8. Click Add.
The datasets are added to the data pane. Next, you will open the Insights scripting environment and run a script.
9. Click the Scripting button to open the scripting environment.
10. In the Kernel Gateway connection window, enter the URL for your Jupyter Kernel Gateway. The web socket will be updated automatically using your URL.
11. Click Connect.
The scripting environment opens. The script was written using Python, so you will select the Python kernel.
12. Click Select Kernel and choose Python 3 from the menu.
The scripting environment is ready now to start creating and running scripts.
Run a script in Insights
In this step you will open and run a script using the data you added to Insights.
1. Click Import File.
2. Open the CHIME.ipynb file you downloaded with the data (in the CHIME_Example folder).
3. Click the first cell in the script and click Run. You can also use the keyboard command Shift+Enter to execute the code in the selected cell.
The script executes. There will not be any outputs for the first cell in the script. Next you will use fields from the dataset in the data pane to populate the second cell in the script.
4. Scroll down to the second cell in the script. The comment says that five fields are required.
5. Expand the Cases.March2020 dataset to display the field names.
6. Select countyname, Hospitaliz, Unacast_ch, Hospital_1, and Population.
7. Drag the fields to the scripting environment and use your pointer to drop them in the code in the second cell after chime_df =.
The fields are added to the code in the data frame definition.
8. Select the second cell and click Run.
An Out cell is created and shows the outputs from executing the cell. The dataset created by the script can be added to the data pane using the code in the third cell.
9. Select the third input cell and click Run.
The cell executes and a dataset called Layer is added to the data pane. You can give the dataset a more descriptive name.
10. Click Rename dataset to make the name editable. Give your dataset a descriptive name (for example, BC_Regions_Model) and press Enter to apply the change.
11. Expand the output dataset to review the fields.
The dataset includes the fields calculated using the script, but does not include a location field. You will use the location in the original dataset to create a location field in the output dataset.
12. Click the Dataset options, then choose Enable location from the menu.
13. Set the following parameters:
- Location type: Geography
- Location fields: countyname
- Matching geography level: HA_2018, or a layer with the boundaries for your region
14. Click Run.
A location field is added to the dataset. You are now ready to use the dataset to create visualizations like maps and charts.
Create visualizations to analyze regional epidemiology
In the final section of this activity, you will create maps, charts, and tables that will help you understand the epidemiology of each county or region.
1. Minimize the scripting environment so you can see the entire page in your Insights workbook.
2. Expand the output dataset, if necessary, and select the status field.
3. Drag the field to the page and drop it on the Map drop zone.
The map shows each county with a value for status. However, there can be more than one status per county. You will change the map to show the proportions of the statuses using pie charts.
4. Click the arrow next to status on the map to expand the Layer options pane. Click the Options tab.
5. For Symbol type, choose Pies.
The map is now styled by pies. Some of the symbols may overlap other counties or regions. You can change the maximum size of the symbols to fit the size of the areas on the map.
6. Click the Style tab. Change the maximum size to 20 px. Close the Layer options pane.
Next, you will create a chart to show how the model predicts statuses to change over time.
7. In the data pane, select date, Value, and status.
8. Drag the fields to the page, hover over the Chart drop zone, and drop the fields on Time Series.
9. Select the countyname, Value, and type fields, drag them to the page, and drop them on the Table drop zone.
A table is created showing the type and value field grouped by health authorities. You want to look at the data for each health authority individually. To do that, you will create cross filters on your cards, which will allow you to filter your data using selections on other cards.
10. Click the map card to activate it and click the Enable cross filters button. Repeat to enable cross filters on the chart and table.
The final visualization you will make is a table showing the count for each value in the type field.
11. Select the type field and drag it to the page to create a second table.
You now have all the tables needed to analyze the impact of COVID-19 on hospitals in health authorities in British Columbia, or in your own region. You can select health authorities on your table or map to filter the time series to show the epidemiological model for an individual authority.
Try other scenario-based lessons for responding to COVID-19 with the Use ArcGIS Insights for Understanding and Responding to COVID-19 discovery path.
Use the following resources to learn more about the skills developed in this lesson: