prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Simplify semi_circular_loop function in asdf coordinates example
  In the [example that shows how to save a coordinate into an asdf file](https://docs.sunpy.org/en/stable/generated/gallery/saving_and_loading_data/coordinates_in_asdf.html#sphx-glr-generated-gallery-saving-and-loading-data-coordinates-in-asdf-py), there is a function called `semi_circular_loop` that is needlessly complicated.
  
  To make this example more straightforward, it would be better to replace it with,
  
  ```python
  @u.quantity_input
  def semi_circular_loop(length: u.cm, latitude: u.deg = 0*u.deg):
      """
      Return HGS coordinates for a semi-circular loop
      """
      s = np.linspace(0, length, 1000)
      z = length / np.pi * np.sin(np.pi * u.rad * s/length)
      x = np.sqrt((length / np.pi)**2 - z**2)
      x = np.where(s < length/2, -x, x)
      hcc_frame = frames.Heliocentric(
          observer=frames.HeliographicStonyhurst(lon=0 * u.deg, lat=latitude, radius=const.au))
      )
      return SkyCoord(x= x, y=np.zeros(x.shape)*u.cm, z=z + const.R_sun, frame=hcc_frame)
  ```
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `examples/saving_and_loading_data/coordinates_in_asdf.py`
  Content:
  ```
  1 """
  2 ========================================
  3 Saving and loading coordinates with asdf
  4 ========================================
  5 
  6 In this example we are going to look at saving and loading collections of
  7 coordinates with `asdf <https://asdf.readthedocs.io/en/latest/>`__.
  8 
  9 asdf is a modern file format designed to meet the needs of the astronomy
  10 community. It has deep integration with Python and SunPy and Astropy as well as
  11 implementations in other languages. It can be used to store known Python
  12 objects in a portable, well defined file format. It is primarily useful for
  13 storing complex Astropy and SunPy objects in a way that can be loaded back into
  14 the same form as they were saved.
  15 
  16 .. note::
  17     This example requires Astropy 3.2 and asdf 2.3.0
  18 
  19 """
  20 
  21 import matplotlib.pyplot as plt
  22 import numpy as np
  23 import scipy.optimize
  24 
  25 import asdf
  26 import astropy.units as u
  27 from astropy.coordinates import SkyCoord
  28 
  29 import sunpy.map
  30 from sunpy.coordinates import frames
  31 from sunpy.data.sample import AIA_171_IMAGE
  32 from sunpy.sun import constants
  33 
  34 ################################################################################
  35 # To get started let's use a function to get the coordinates of a semi-circular
  36 # loop from
  37 # `this <https://sunpy.org/posts/2018/2018-07-21-coronal-loop-coordinates.html>`__
  38 # blog post by Will Barnes to generate ourselves some coordinates.
  39 
  40 
  41 @u.quantity_input
  42 def semi_circular_loop(length: u.m, latitude: u.deg = 0*u.deg):
  43     """
  44     Return a Heliographic Stonyhurst coordinate object with points of a semi circular loop in it.
  45     """
  46     r_sun = constants.radius
  47 
  48     def r_2_func(x):
  49         return np.arccos(0.5 * x / r_sun.to(u.cm).value) - np.pi + length.to(u.cm).value / 2. / x
  50 
  51     # Find the loop radius corresponding to the loop length
  52     r_2 = scipy.optimize.bisect(r_2_func,
  53                                 length.to(u.cm).value / (2 * np.pi),
  54                                 length.to(u.cm).value / np.pi) * u.cm
  55     alpha = np.arccos(0.5 * (r_2 / r_sun))
  56     phi = np.linspace(-np.pi * u.rad + alpha, np.pi * u.rad - alpha, 2000)
  57 
  58     hcc_frame = frames.Heliocentric(
  59         observer=frames.HeliographicStonyhurst(lon=0 * u.deg, lat=latitude, radius=1 * u.AU))
  60 
  61     return SkyCoord(
  62         x=r_2 * np.sin(phi),
  63         y=0 * u.cm,
  64         z=r_2 * np.cos(phi) + r_sun,
  65         frame=hcc_frame).transform_to('heliographic_stonyhurst')
  66 
  67 
  68 ################################################################################
  69 # Use this function to generate a `~astropy.coordinates.SkyCoord` object.
  70 loop_coords = semi_circular_loop(500*u.Mm, 30*u.deg)
  71 print(loop_coords.shape)
  72 # print the first and last coordinate point
  73 print(loop_coords[[0, -1]])
  74 
  75 
  76 ################################################################################
  77 # This is a regular coordinate object that can be transformed to other frames
  78 # or overplotted on images. For instance we could overplot it on an AIA image
  79 
  80 aiamap = sunpy.map.Map(AIA_171_IMAGE)
  81 
  82 ax = plt.subplot(projection=aiamap)
  83 aiamap.plot(axes=ax, clip_interval=(1, 99.5) * u.percent)
  84 ax.plot_coord(loop_coords, 'r')
  85 
  86 plt.show()
  87 
  88 
  89 ################################################################################
  90 # We can now save these loop points to an asdf file to use later. The advantage
  91 # of saving them to asdf is that all the metadata about the coordinates will be
  92 # preserved, and when we load the asdf, we will get back an identical
  93 # `~astropy.coordinates.SkyCoord` object.
  94 #
  95 # asdf files save a dictionary to a file, so to save the loop coordinates we
  96 # need to put them into a dictionary. This becomes what asdf calls a tree.
  97 
  98 tree = {'loop_points': loop_coords}
  99 
  100 with asdf.AsdfFile(tree) as asdf_file:
  101     asdf_file.write_to("loop_coords.asdf")
  102 
  103 
  104 ################################################################################
  105 # This asdf file is a portable file and can be safely loaded by anyone with
  106 # Astropy and SunPy installed. We can reload the file like so:
  107 
  108 with asdf.open("loop_coords.asdf") as input_asdf:
  109     new_coords = input_asdf['loop_points']
  110 
  111 print(new_coords.shape)
  112 # print the first and last coordinate point
  113 print(new_coords[[0, -1]])
  114
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/examples/saving_and_loading_data/coordinates_in_asdf.py b/examples/saving_and_loading_data/coordinates_in_asdf.py
  --- a/examples/saving_and_loading_data/coordinates_in_asdf.py
  +++ b/examples/saving_and_loading_data/coordinates_in_asdf.py
  @@ -20,7 +20,6 @@
   
   import matplotlib.pyplot as plt
   import numpy as np
  -import scipy.optimize
   
   import asdf
   import astropy.units as u
  @@ -39,30 +38,21 @@
   
   
   @u.quantity_input
  -def semi_circular_loop(length: u.m, latitude: u.deg = 0*u.deg):
  +def semi_circular_loop(length: u.cm, latitude: u.deg = 0*u.deg):
       """
  -    Return a Heliographic Stonyhurst coordinate object with points of a semi circular loop in it.
  +    Return HGS coordinates for a semi-circular loop
       """
  -    r_sun = constants.radius
  -
  -    def r_2_func(x):
  -        return np.arccos(0.5 * x / r_sun.to(u.cm).value) - np.pi + length.to(u.cm).value / 2. / x
  -
  -    # Find the loop radius corresponding to the loop length
  -    r_2 = scipy.optimize.bisect(r_2_func,
  -                                length.to(u.cm).value / (2 * np.pi),
  -                                length.to(u.cm).value / np.pi) * u.cm
  -    alpha = np.arccos(0.5 * (r_2 / r_sun))
  -    phi = np.linspace(-np.pi * u.rad + alpha, np.pi * u.rad - alpha, 2000)
  -
  +    angles = np.linspace(0, 1, 1000) * np.pi * u.rad
  +    z = length / np.pi * np.sin(angles)
  +    x = length / np.pi * np.cos(angles)
       hcc_frame = frames.Heliocentric(
  -        observer=frames.HeliographicStonyhurst(lon=0 * u.deg, lat=latitude, radius=1 * u.AU))
  +        observer=frames.HeliographicStonyhurst(lon=0 * u.deg, lat=latitude, radius=constants.au))
   
       return SkyCoord(
  -        x=r_2 * np.sin(phi),
  -        y=0 * u.cm,
  -        z=r_2 * np.cos(phi) + r_sun,
  -        frame=hcc_frame).transform_to('heliographic_stonyhurst')
  +        x=x,
  +        y=np.zeros_like(x),
  +        z=z + constants.radius,
  +        frame=hcc_frame)
   
   
   ################################################################################
  
verification_info: {"golden_diff": "diff --git a/examples/saving_and_loading_data/coordinates_in_asdf.py b/examples/saving_and_loading_data/coordinates_in_asdf.py\n--- a/examples/saving_and_loading_data/coordinates_in_asdf.py\n+++ b/examples/saving_and_loading_data/coordinates_in_asdf.py\n@@ -20,7 +20,6 @@\n \n import matplotlib.pyplot as plt\n import numpy as np\n-import scipy.optimize\n \n import asdf\n import astropy.units as u\n@@ -39,30 +38,21 @@\n \n \n @u.quantity_input\n-def semi_circular_loop(length: u.m, latitude: u.deg = 0*u.deg):\n+def semi_circular_loop(length: u.cm, latitude: u.deg = 0*u.deg):\n     \"\"\"\n-    Return a Heliographic Stonyhurst coordinate object with points of a semi circular loop in it.\n+    Return HGS coordinates for a semi-circular loop\n     \"\"\"\n-    r_sun = constants.radius\n-\n-    def r_2_func(x):\n-        return np.arccos(0.5 * x / r_sun.to(u.cm).value) - np.pi + length.to(u.cm).value / 2. / x\n-\n-    # Find the loop radius corresponding to the loop length\n-    r_2 = scipy.optimize.bisect(r_2_func,\n-                                length.to(u.cm).value / (2 * np.pi),\n-                                length.to(u.cm).value / np.pi) * u.cm\n-    alpha = np.arccos(0.5 * (r_2 / r_sun))\n-    phi = np.linspace(-np.pi * u.rad + alpha, np.pi * u.rad - alpha, 2000)\n-\n+    angles = np.linspace(0, 1, 1000) * np.pi * u.rad\n+    z = length / np.pi * np.sin(angles)\n+    x = length / np.pi * np.cos(angles)\n     hcc_frame = frames.Heliocentric(\n-        observer=frames.HeliographicStonyhurst(lon=0 * u.deg, lat=latitude, radius=1 * u.AU))\n+        observer=frames.HeliographicStonyhurst(lon=0 * u.deg, lat=latitude, radius=constants.au))\n \n     return SkyCoord(\n-        x=r_2 * np.sin(phi),\n-        y=0 * u.cm,\n-        z=r_2 * np.cos(phi) + r_sun,\n-        frame=hcc_frame).transform_to('heliographic_stonyhurst')\n+        x=x,\n+        y=np.zeros_like(x),\n+        z=z + constants.radius,\n+        frame=hcc_frame)\n \n \n ################################################################################\n", "issue": "Simplify semi_circular_loop function in asdf coordinates example\nIn the [example that shows how to save a coordinate into an asdf file](https://docs.sunpy.org/en/stable/generated/gallery/saving_and_loading_data/coordinates_in_asdf.html#sphx-glr-generated-gallery-saving-and-loading-data-coordinates-in-asdf-py), there is a function called `semi_circular_loop` that is needlessly complicated.\r\n\r\nTo make this example more straightforward, it would be better to replace it with,\r\n\r\n```python\r\n@u.quantity_input\r\ndef semi_circular_loop(length: u.cm, latitude: u.deg = 0*u.deg):\r\n    \"\"\"\r\n    Return HGS coordinates for a semi-circular loop\r\n    \"\"\"\r\n    s = np.linspace(0, length, 1000)\r\n    z = length / np.pi * np.sin(np.pi * u.rad * s/length)\r\n    x = np.sqrt((length / np.pi)**2 - z**2)\r\n    x = np.where(s < length/2, -x, x)\r\n    hcc_frame = frames.Heliocentric(\r\n        observer=frames.HeliographicStonyhurst(lon=0 * u.deg, lat=latitude, radius=const.au))\r\n    )\r\n    return SkyCoord(x= x, y=np.zeros(x.shape)*u.cm, z=z + const.R_sun, frame=hcc_frame)\r\n```\n", "before_files": [{"content": "\"\"\"\n========================================\nSaving and loading coordinates with asdf\n========================================\n\nIn this example we are going to look at saving and loading collections of\ncoordinates with `asdf <https://asdf.readthedocs.io/en/latest/>`__.\n\nasdf is a modern file format designed to meet the needs of the astronomy\ncommunity. It has deep integration with Python and SunPy and Astropy as well as\nimplementations in other languages. It can be used to store known Python\nobjects in a portable, well defined file format. It is primarily useful for\nstoring complex Astropy and SunPy objects in a way that can be loaded back into\nthe same form as they were saved.\n\n.. note::\n    This example requires Astropy 3.2 and asdf 2.3.0\n\n\"\"\"\n\nimport matplotlib.pyplot as plt\nimport numpy as np\nimport scipy.optimize\n\nimport asdf\nimport astropy.units as u\nfrom astropy.coordinates import SkyCoord\n\nimport sunpy.map\nfrom sunpy.coordinates import frames\nfrom sunpy.data.sample import AIA_171_IMAGE\nfrom sunpy.sun import constants\n\n################################################################################\n# To get started let's use a function to get the coordinates of a semi-circular\n# loop from\n# `this <https://sunpy.org/posts/2018/2018-07-21-coronal-loop-coordinates.html>`__\n# blog post by Will Barnes to generate ourselves some coordinates.\n\n\n@u.quantity_input\ndef semi_circular_loop(length: u.m, latitude: u.deg = 0*u.deg):\n    \"\"\"\n    Return a Heliographic Stonyhurst coordinate object with points of a semi circular loop in it.\n    \"\"\"\n    r_sun = constants.radius\n\n    def r_2_func(x):\n        return np.arccos(0.5 * x / r_sun.to(u.cm).value) - np.pi + length.to(u.cm).value / 2. / x\n\n    # Find the loop radius corresponding to the loop length\n    r_2 = scipy.optimize.bisect(r_2_func,\n                                length.to(u.cm).value / (2 * np.pi),\n                                length.to(u.cm).value / np.pi) * u.cm\n    alpha = np.arccos(0.5 * (r_2 / r_sun))\n    phi = np.linspace(-np.pi * u.rad + alpha, np.pi * u.rad - alpha, 2000)\n\n    hcc_frame = frames.Heliocentric(\n        observer=frames.HeliographicStonyhurst(lon=0 * u.deg, lat=latitude, radius=1 * u.AU))\n\n    return SkyCoord(\n        x=r_2 * np.sin(phi),\n        y=0 * u.cm,\n        z=r_2 * np.cos(phi) + r_sun,\n        frame=hcc_frame).transform_to('heliographic_stonyhurst')\n\n\n################################################################################\n# Use this function to generate a `~astropy.coordinates.SkyCoord` object.\nloop_coords = semi_circular_loop(500*u.Mm, 30*u.deg)\nprint(loop_coords.shape)\n# print the first and last coordinate point\nprint(loop_coords[[0, -1]])\n\n\n################################################################################\n# This is a regular coordinate object that can be transformed to other frames\n# or overplotted on images. For instance we could overplot it on an AIA image\n\naiamap = sunpy.map.Map(AIA_171_IMAGE)\n\nax = plt.subplot(projection=aiamap)\naiamap.plot(axes=ax, clip_interval=(1, 99.5) * u.percent)\nax.plot_coord(loop_coords, 'r')\n\nplt.show()\n\n\n################################################################################\n# We can now save these loop points to an asdf file to use later. The advantage\n# of saving them to asdf is that all the metadata about the coordinates will be\n# preserved, and when we load the asdf, we will get back an identical\n# `~astropy.coordinates.SkyCoord` object.\n#\n# asdf files save a dictionary to a file, so to save the loop coordinates we\n# need to put them into a dictionary. This becomes what asdf calls a tree.\n\ntree = {'loop_points': loop_coords}\n\nwith asdf.AsdfFile(tree) as asdf_file:\n    asdf_file.write_to(\"loop_coords.asdf\")\n\n\n################################################################################\n# This asdf file is a portable file and can be safely loaded by anyone with\n# Astropy and SunPy installed. We can reload the file like so:\n\nwith asdf.open(\"loop_coords.asdf\") as input_asdf:\n    new_coords = input_asdf['loop_points']\n\nprint(new_coords.shape)\n# print the first and last coordinate point\nprint(new_coords[[0, -1]])\n", "path": "examples/saving_and_loading_data/coordinates_in_asdf.py"}], "after_files": [{"content": "\"\"\"\n========================================\nSaving and loading coordinates with asdf\n========================================\n\nIn this example we are going to look at saving and loading collections of\ncoordinates with `asdf <https://asdf.readthedocs.io/en/latest/>`__.\n\nasdf is a modern file format designed to meet the needs of the astronomy\ncommunity. It has deep integration with Python and SunPy and Astropy as well as\nimplementations in other languages. It can be used to store known Python\nobjects in a portable, well defined file format. It is primarily useful for\nstoring complex Astropy and SunPy objects in a way that can be loaded back into\nthe same form as they were saved.\n\n.. note::\n    This example requires Astropy 3.2 and asdf 2.3.0\n\n\"\"\"\n\nimport matplotlib.pyplot as plt\nimport numpy as np\n\nimport asdf\nimport astropy.units as u\nfrom astropy.coordinates import SkyCoord\n\nimport sunpy.map\nfrom sunpy.coordinates import frames\nfrom sunpy.data.sample import AIA_171_IMAGE\nfrom sunpy.sun import constants\n\n################################################################################\n# To get started let's use a function to get the coordinates of a semi-circular\n# loop from\n# `this <https://sunpy.org/posts/2018/2018-07-21-coronal-loop-coordinates.html>`__\n# blog post by Will Barnes to generate ourselves some coordinates.\n\n\n@u.quantity_input\ndef semi_circular_loop(length: u.cm, latitude: u.deg = 0*u.deg):\n    \"\"\"\n    Return HGS coordinates for a semi-circular loop\n    \"\"\"\n    angles = np.linspace(0, 1, 1000) * np.pi * u.rad\n    z = length / np.pi * np.sin(angles)\n    x = length / np.pi * np.cos(angles)\n    hcc_frame = frames.Heliocentric(\n        observer=frames.HeliographicStonyhurst(lon=0 * u.deg, lat=latitude, radius=constants.au))\n\n    return SkyCoord(\n        x=x,\n        y=np.zeros_like(x),\n        z=z + constants.radius,\n        frame=hcc_frame)\n\n\n################################################################################\n# Use this function to generate a `~astropy.coordinates.SkyCoord` object.\nloop_coords = semi_circular_loop(500*u.Mm, 30*u.deg)\nprint(loop_coords.shape)\n# print the first and last coordinate point\nprint(loop_coords[[0, -1]])\n\n\n################################################################################\n# This is a regular coordinate object that can be transformed to other frames\n# or overplotted on images. For instance we could overplot it on an AIA image\n\naiamap = sunpy.map.Map(AIA_171_IMAGE)\n\nax = plt.subplot(projection=aiamap)\naiamap.plot(axes=ax, clip_interval=(1, 99.5) * u.percent)\nax.plot_coord(loop_coords, 'r')\n\nplt.show()\n\n\n################################################################################\n# We can now save these loop points to an asdf file to use later. The advantage\n# of saving them to asdf is that all the metadata about the coordinates will be\n# preserved, and when we load the asdf, we will get back an identical\n# `~astropy.coordinates.SkyCoord` object.\n#\n# asdf files save a dictionary to a file, so to save the loop coordinates we\n# need to put them into a dictionary. This becomes what asdf calls a tree.\n\ntree = {'loop_points': loop_coords}\n\nwith asdf.AsdfFile(tree) as asdf_file:\n    asdf_file.write_to(\"loop_coords.asdf\")\n\n\n################################################################################\n# This asdf file is a portable file and can be safely loaded by anyone with\n# Astropy and SunPy installed. We can reload the file like so:\n\nwith asdf.open(\"loop_coords.asdf\") as input_asdf:\n    new_coords = input_asdf['loop_points']\n\nprint(new_coords.shape)\n# print the first and last coordinate point\nprint(new_coords[[0, -1]])\n", "path": "examples/saving_and_loading_data/coordinates_in_asdf.py"}]}