Skip to content

Commit

Permalink
Fix docs typos and style
Browse files Browse the repository at this point in the history
  • Loading branch information
peterrrock2 committed Feb 2, 2024
1 parent 000fbfb commit ea56d4e
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 51 deletions.
11 changes: 11 additions & 0 deletions docs/_static/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,15 @@
.center-container {
text-align: center;
width: 100%;
}


table {
width: 100%;
border-collapse: collapse;
}
th, td {
border: 1px solid #DDDDDD;
padding: 8px;
text-align: center;
}
3 changes: 2 additions & 1 deletion docs/topics/reproducibility.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ in the conda documentation.
If you've published your code on GitHub, it is a good idea to include your ``environment.yml``
file in the root folder of your code repository.

.. _`conda`: https://conda.io/projects/conda/en/latest/index.html
.. _`Sharing your environment`: https://conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#sharing-an-environment
.. _`Creating an environment from an environment.yml file`: https://conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#creating-an-environment-from-an-environment-yml-file

Expand Down Expand Up @@ -155,7 +156,7 @@ Python environment by running ``python`` from the command line and typing

If you are using a jupyter notebook, you will need to make sure that you have
installed the ``ipykernel`` package in your virtual environment as well as
either ``jypyternotebook`` or ``jupyterlab``. To install these packages, run
either ``jupyternotebook`` or ``jupyterlab``. To install these packages, run
``pip install <package-name>`` from the command line. Then, to use the virtual
python environment in your jupyter notebook, you need to invoke

Expand Down
2 changes: 1 addition & 1 deletion docs/topics/tools.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Evaluating districting plans in the real world
==============================================

GerryChain is used to analyze redistricting plans in the real world. For example, it's
been used in states ranging from Pennsylvania to North Carolina to Wisconsin for to
been used in states ranging from Pennsylvania to North Carolina to Wisconsin for
defend civil rights. So, `MGGG`_ has developed a toolkit of functions for use to analyze
a redistricting plan. Here, we will describe these tools and how they are used to
analyze real-world districting plans.
Expand Down
42 changes: 24 additions & 18 deletions docs/user/data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ Pennsylvania data:
from gerrychain.accept import always_accept
from functools import partial
import random
random.seed(42)
graph = Graph.from_json("./PA_VTDs.json")
Expand Down Expand Up @@ -72,6 +75,7 @@ Pennsylvania data:
accept=always_accept,
initial_state=initial_partition,
total_steps=20
)
And now we can run the chain and write the data to a JSONL file:

Expand Down Expand Up @@ -176,6 +180,7 @@ is to store the data in a pandas dataframe.
.. code-block:: python
import pandas as pd
random.seed(42)
district_data = []
Expand Down Expand Up @@ -212,41 +217,42 @@ which will produce:
+-----+------+---------------+------------+----------+-------------+
| | step | district_name | population | area | n_cut_edges |
+=====+======+===============+============+==========+=============+
| 198 | 11 | 3 | 699782 | 2.525530 | 2223 |
| 198 | 11 | 3 | 699433 | 0.831304 | 2162 |
+-----+------+---------------+------------+----------+-------------+
| 199 | 11 | 10 | 702412 | 2.415365 | 2223 |
| 199 | 11 | 10 | 700040 | 1.562749 | 2162 |
+-----+------+---------------+------------+----------+-------------+
| 200 | 11 | 9 | 708113 | 0.390251 | 2223 |
| 200 | 11 | 9 | 702500 | 1.579113 | 2162 |
+-----+------+---------------+------------+----------+-------------+
| 201 | 11 | 5 | 707368 | 1.525625 | 2223 |
| 201 | 11 | 5 | 695917 | 3.012263 | 2162 |
+-----+------+---------------+------------+----------+-------------+
| 202 | 11 | 15 | 706363 | 0.353504 | 2223 |
| 202 | 11 | 15 | 700895 | 1.616416 | 2162 |
+-----+------+---------------+------------+----------+-------------+
| 203 | 11 | 6 | 705876 | 0.171570 | 2223 |
| 203 | 11 | 6 | 705782 | 0.239069 | 2162 |
+-----+------+---------------+------------+----------+-------------+
| 204 | 11 | 11 | 700225 | 0.451046 | 2223 |
| 204 | 11 | 11 | 709813 | 0.357564 | 2162 |
+-----+------+---------------+------------+----------+-------------+
| 205 | 11 | 8 | 705689 | 0.199275 | 2223 |
| 205 | 11 | 8 | 705689 | 0.199275 | 2162 |
+-----+------+---------------+------------+----------+-------------+
| 206 | 11 | 4 | 710559 | 0.917088 | 2223 |
| 206 | 11 | 4 | 705669 | 0.418513 | 2162 |
+-----+------+---------------+------------+----------+-------------+
| 207 | 11 | 18 | 700234 | 1.758021 | 2223 |
| 207 | 11 | 18 | 706380 | 0.421818 | 2162 |
+-----+------+---------------+------------+----------+-------------+
| 208 | 11 | 12 | 709229 | 0.465270 | 2223 |
| 208 | 11 | 12 | 713452 | 0.856847 | 2162 |
+-----+------+---------------+------------+----------+-------------+
| 209 | 11 | 17 | 699133 | 0.484794 | 2223 |
| 209 | 11 | 17 | 706041 | 0.622091 | 2162 |
+-----+------+---------------+------------+----------+-------------+
| 210 | 11 | 7 | 698979 | 0.210185 | 2223 |
| 210 | 11 | 7 | 697675 | 0.329930 | 2162 |
+-----+------+---------------+------------+----------+-------------+
| 211 | 11 | 16 | 698649 | 0.354682 | 2223 |
| 211 | 11 | 16 | 716162 | 0.194045 | 2162 |
+-----+------+---------------+------------+----------+-------------+
| 212 | 11 | 14 | 702529 | 0.196075 | 2223 |
| 212 | 11 | 14 | 704993 | 0.207707 | 2162 |
+-----+------+---------------+------------+----------+-------------+
| 213 | 11 | 13 | 710081 | 0.034325 | 2223 |
| 213 | 11 | 13 | 705028 | 0.042608 | 2162 |
+-----+------+---------------+------------+----------+-------------+
| 214 | 11 | 2 | 708473 | 0.022472 | 2223 |
| 214 | 11 | 2 | 710286 | 0.021872 | 2162 |
+-----+------+---------------+------------+----------+-------------+
| 215 | 11 | 1 | 711235 | 0.059248 | 2223 |
| 215 | 11 | 1 | 699174 | 0.021139 | 2162 |
+-----+------+---------------+------------+----------+-------------+



67 changes: 36 additions & 31 deletions docs/user/geometries.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Working With Geometries
=======================

In the course of working with legislative redistricting data, it is inevitalble that
In the course of working with legislative redistricting data, it is inevitable that
we will have to work with files that contain geometries. Most often, these geometries
come in the form of shapefiles, which, while nice in theory, can be a bit of a pain to
work with in practice. For now, we will focus on the basics of working with geometries,
Expand Down Expand Up @@ -40,10 +40,11 @@ Loading and Running a Plan
<br style="line-height: 5px;">

For this example, we will make use of a Minnesota GeoJSON file that contains
the geometries of the state's precincts. We will follow a similar workflow to
what we already covered in the `Recom Section <./recom.html>`_, but with an
eye towards some of the conveniences afforded by ``GeographicPartition``
objects. As always, we'll start with the imports:
the geometries of the state's precincts (you will need to unzip the above
folder to get to the file -- it's a bit large). We will follow a similar workflow to
what we already covered in the `ReCom Section <./recom.html>`_, but with an eye
towards some of the conveniences afforded by ``GeographicPartition`` objects. As always,
we'll start with the imports:

.. code-block:: python
Expand Down Expand Up @@ -88,8 +89,8 @@ The observant reader will notice that we have added two new updaters, ``perimete
and ``area``, [1]_ and we are now using the ``GeographicPartition`` class instead of the
``Partition`` class. The ``GeographicPartition`` class is a subclass of the
``Partition`` class that allows us the capability of working with geometries throughout
our Markov chain, and the``perimeter`` and ``area`` updaters are examples of such a
geometric updater that was previously unavailable to us. These updaters necessary for
our Markov chain, and the ``perimeter`` and ``area`` updaters are examples of such a
geometric updater that was previously unavailable to us. These updaters are necessary for
monitoring things like geometric compactness and area via metrics such as the Polsby-Popper
test. [2]_

Expand All @@ -104,7 +105,7 @@ we can plot our map and see the initial partition!
:align: center
:height: 400px

of course, this isn't very pretty, so let's pass it some additional arguments to
Of course, this isn't very pretty, so let's pass it some additional arguments to
things a bit nicer:

.. code-block:: python
Expand All @@ -119,7 +120,7 @@ things a bit nicer:
:align: center
:height: 400px

Under the hood, the ``plot`` method is using the``geodataframe.plot`` method from
Under the hood, the ``plot`` method is using the ``geodataframe.plot`` method from
`geopandas <https://geopandas.org/>`_ to plot the geometries, and all of this is
built on top of ``matplotlib``, so most of the standard methods for modifying a
``matplotlib`` plot will work here as well.
Expand Down Expand Up @@ -155,7 +156,7 @@ watch the chain work!
%matplotlib inline
import matplotlib_inline.backend_inline
matplotlib_inline.backend_inline.set_matplotlib_formats('png')
matplotlib_inline.backend_inline.set_matplotlib_formats('png')
import pandas as pd
Expand All @@ -172,10 +173,10 @@ watch the chain work!
for i, partition in enumerate(recom_chain):
for district_name in partition.perimeter.keys():
perimeter = partition.perimeter[district_name]
population = partition.population[district_name]
area = partition.polsby_popper[district_name]
district_data.append((i, district_name, perimeter, population, area))
perimeter = partition.perimeter[district_name]
area = partition.area[district_name]
district_data.append((i, district_name, population, perimeter, area))
buffer = io.BytesIO()
fig, ax = plt.subplots(figsize=(10,10))
Expand All @@ -189,12 +190,12 @@ watch the chain work!
plt.close(fig)
df = pd.DataFrame(
district_data,
district_data,
columns=[
'step',
'district_name',
'perimeter',
'population',
'step',
'district_name',
'population',
'perimeter',
'area'
]
)
Expand All @@ -220,19 +221,23 @@ and our dataframe has collected all of the data we were interested in:
df.head(5)
+---+------+---------------+---------------+------------+----------+
| | step | district_name | perimeter | population | area |
+===+======+===============+===============+============+==========+
| 0 | 0 | 8 | 1.804646e+06 | 662998.0 | 0.301259 |
+---+------+---------------+---------------+------------+----------+
| 1 | 0 | 6 | 6.616450e+05 | 662979.0 | 0.225759 |
+---+------+---------------+---------------+------------+----------+
| 2 | 0 | 5 | 1.133867e+05 | 662985.0 | 0.359509 |
+---+------+---------------+---------------+------------+----------+
| 3 | 0 | 3 | 2.625007e+05 | 662994.0 | 0.275271 |
+---+------+---------------+---------------+------------+----------+
| 4 | 0 | 7 | 2.288428e+06 | 662997.0 | 0.219926 |
+---+------+---------------+---------------+------------+----------+
+---+------+---------------+------------+---------------+--------------+
| | step | district_name | population | perimeter | area |
+===+======+===============+============+===============+==============+
| 0 | 0 | 8 | 662998.0 | 1.804646e+06 | 7.807545e+10 |
+---+------+---------------+------------+---------------+--------------+
| 1 | 0 | 6 | 662979.0 | 6.616450e+05 | 7.864760e+09 |
+---+------+---------------+------------+---------------+--------------+
| 2 | 0 | 5 | 662985.0 | 1.133867e+05 | 3.678103e+08 |
+---+------+---------------+------------+---------------+--------------+
| 3 | 0 | 3 | 662994.0 | 2.625007e+05 | 1.509425e+09 |
+---+------+---------------+------------+---------------+--------------+
| 4 | 0 | 7 | 662997.0 | 2.288428e+06 | 9.165192e+10 |
+---+------+---------------+------------+---------------+--------------+






.. [1] The ``perimeter`` and ``area`` attributes are actually not present in the
Expand Down

0 comments on commit ea56d4e

Please sign in to comment.