We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Order of arguments in `scale` input to `make_fitswcs_header` is wrong in AIA/EUVI reprojection example
In [the AIA/EUVI reprojection mosaic example](https://docs.sunpy.org/en/latest/generated/gallery/map_transformations/reprojection_aia_euvi_mosaic.html), the ordering of the `scale` argument to `make_fitswcs_header` is incorrect. The ordering should be Cartesian (lon, lat) [according to the `make_fitswcs_header` docstring](https://docs.sunpy.org/en/stable/api/sunpy.map.make_fitswcs_header.html#sunpy.map.make_fitswcs_header), but in this example, the order is according to the array index. This actually has no effect on the example output as the scale in both directions is the same (1 deg/pix), but is potentially confusing and conflicts with the function docstring.

--- 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/map_transformations/reprojection_heliographic_stonyhurst.py`
Content:
```
1 """
2 ===========================
3 Creating a Heliographic Map
4 ===========================
5 
6 In this example we use the `reproject` generate an image in heliographic coordinates from an AIA image.
7 
8 You will need `reproject <https://reproject.readthedocs.io/en/stable/>`__ v0.6 or higher installed.
9 """
10 # sphinx_gallery_thumbnail_number = 2
11 
12 import matplotlib.pyplot as plt
13 from reproject import reproject_interp
14 
15 import astropy.units as u
16 from astropy.coordinates import SkyCoord
17 from astropy.wcs import WCS
18 
19 import sunpy.data.sample
20 import sunpy.map
21 
22 ###############################################################################
23 # We will start with using sunpy's sample data for this example.
24 
25 aia_map = sunpy.map.Map(sunpy.data.sample.AIA_193_IMAGE)
26 
27 fig = plt.figure()
28 ax = plt.subplot(projection=aia_map)
29 aia_map.plot(ax)
30 
31 ###############################################################################
32 # Reproject works by transforming an input image (with a `~astropy.wcs.WCS`) to
33 # a output image, specified by a different WCS object. Therefore we need to
34 # build a `~astropy.wcs.WCS` object describing the output we desire.
35 # To do this we use the `sunpy.map.make_fitswcs_header` which assists us in
36 # constructing this World Coordinate System (WCS) object.
37 # Here we create a WCS based on a heliographic
38 # Stonyhurst reference coordinate and with the CAR (plate carree) projection.
39 
40 shape_out = [720, 1440]
41 frame_out = SkyCoord(0, 0, unit=u.deg,
42                      frame="heliographic_stonyhurst",
43                      obstime=aia_map.date)
44 header = sunpy.map.make_fitswcs_header(shape_out,
45                                        frame_out,
46                                        scale=[180 / shape_out[0],
47                                               360 / shape_out[1]] * u.deg / u.pix,
48                                        projection_code="CAR")
49 
50 out_wcs = WCS(header)
51 
52 ###############################################################################
53 # With the new header, re-project the data into the new coordinate system.
54 # Here we are using the fastest but least accurate method of reprojection,
55 # `reproject.reproject_interp`, a more accurate but slower method is
56 # `reproject.reproject_adaptive`.
57 
58 array, footprint = reproject_interp(aia_map, out_wcs, shape_out=shape_out)
59 outmap = sunpy.map.Map((array, header))
60 outmap.plot_settings = aia_map.plot_settings
61 
62 ###############################################################################
63 # Plot the result.
64 
65 fig = plt.figure()
66 ax = plt.subplot(projection=outmap)
67 outmap.plot(ax)
68 
69 ax.set_xlim(0, shape_out[1])
70 ax.set_ylim(0, shape_out[0])
71 
72 plt.show()
73
```

Path: `examples/map_transformations/reprojection_aia_euvi_mosaic.py`
Content:
```
1 """
2 =========================================
3 Creating a Full Sun Map with AIA and EUVI
4 =========================================
5 
6 With SDO/AIA and STEREO/A and STEREO/B, it is now possible (given specific dates)
7 to combine combine three EUV images from these satellites
8 to produce a full latitude / longitude map of the Sun.
9 
10 You will need an active internet connection as well as
11 `reproject <https://reproject.readthedocs.io/en/stable/>`__ v0.6 or higher installed.
12 """
13 # sphinx_gallery_thumbnail_number = 4
14 
15 import matplotlib.pyplot as plt
16 import numpy as np
17 from reproject import reproject_interp
18 from reproject.mosaicking import reproject_and_coadd
19 
20 import astropy.units as u
21 from astropy.coordinates import SkyCoord
22 from astropy.wcs import WCS
23 
24 import sunpy.map
25 import sunpy.sun
26 from sunpy.coordinates import get_body_heliographic_stonyhurst
27 from sunpy.net import Fido
28 from sunpy.net import attrs as a
29 
30 ######################################################################
31 # To get started, let's download the data:
32 
33 stereo = (a.Instrument("EUVI") &
34           a.Time('2011-11-01', '2011-11-01T00:10:00'))
35 aia = (a.Instrument.aia &
36        a.Sample(24 * u.hour) &
37        a.Time('2011-11-01', '2011-11-02'))
38 wave = a.Wavelength(19.5 * u.nm, 19.5 * u.nm)
39 res = Fido.search(wave, aia | stereo)
40 files = Fido.fetch(res)
41 
42 ######################################################################
43 # Next we create a sunpy map for each of the files.
44 
45 maps = sunpy.map.Map(sorted(files))
46 
47 ######################################################################
48 # To reduce memory consumption we also downsample these maps before continuing,
49 # you can disable this.
50 
51 maps = [m.resample((1024, 1024)*u.pix) for m in maps]
52 
53 ######################################################################
54 # When combining these images all three need to assume the same radius of
55 # the Sun for the data. The AIA images specify a slightly different value
56 # than the IAU 2015 constant. To avoid coordinate transformation issues we
57 # reset this here.
58 
59 maps[0].meta['rsun_ref'] = sunpy.sun.constants.radius.to_value(u.m)
60 
61 ######################################################################
62 # Next we will plot the locations of the three spacecraft with respect to
63 # the Sun so we can easily see the relative separations.
64 
65 earth = get_body_heliographic_stonyhurst('earth', maps[0].date)
66 
67 plt.figure(figsize=(8, 8))
68 r_unit = u.AU
69 
70 ax = plt.subplot(projection='polar')
71 circle = plt.Circle((0.0, 0.0), (10*u.Rsun).to_value(r_unit),
72                     transform=ax.transProjectionAffine + ax.transAxes, color="yellow",
73                     alpha=1, label="Sun")
74 ax.add_artist(circle)
75 ax.text(earth.lon.to_value("rad")+0.05, earth.radius.to_value(r_unit), "Earth")
76 
77 for this_satellite, this_coord in [(m.observatory, m.observer_coordinate) for m in maps]:
78     ax.plot(this_coord.lon.to('rad'), this_coord.radius.to(r_unit), 'o', label=this_satellite)
79 
80 ax.set_theta_zero_location("S")
81 ax.set_rlim(0, 1.3)
82 
83 ax.legend()
84 
85 plt.show()
86 
87 ######################################################################
88 # The next step is to calculate the output coordinate system for the combined
89 # map. We select a heliographic Stonyhurst frame, and a Plate Carree (CAR)
90 # projection, and generate a header using `sunpy.map.make_fitswcs_header` and
91 # then construct a World Coordinate System (WCS) object for that header.
92 
93 shape_out = (180, 360)  # This is set deliberately low to reduce memory consumption
94 header = sunpy.map.make_fitswcs_header(shape_out,
95                                        SkyCoord(0, 0, unit=u.deg,
96                                                 frame="heliographic_stonyhurst",
97                                                 obstime=maps[0].date),
98                                        scale=[180 / shape_out[0],
99                                               360 / shape_out[1]] * u.deg / u.pix,
100                                        wavelength=int(maps[0].meta['wavelnth']) * u.AA,
101                                        projection_code="CAR")
102 out_wcs = WCS(header)
103 
104 ######################################################################
105 # Next we call the `reproject.mosaicking.reproject_and_coadd` function, which
106 # takes a list of maps, and the desired output WCS and array shape.
107 
108 array, footprint = reproject_and_coadd(maps, out_wcs, shape_out,
109                                        reproject_function=reproject_interp)
110 
111 ######################################################################
112 # To display the output we construct a new map using the new array and our
113 # generated header. We also borrow the plot settings from the AIA map.
114 
115 outmap = sunpy.map.Map((array, header))
116 outmap.plot_settings = maps[0].plot_settings
117 outmap.plot()
118 
119 plt.show()
120 
121 ######################################################################
122 # Improving the Output
123 # --------------------
124 #
125 # As you can see this leaves a little to be desired. To reduce the obvious
126 # warping towards the points which are close to the limb in the input
127 # images, we can define a set of weights to use when co-adding the output
128 # arrays. To reduce this warping we want to calculate an set of weights
129 # which highly weigh points close to the centre of the disk in the input
130 # image.
131 #
132 # We can achieve this by using sunpy's coordinate framework. First we
133 # calculate all the world coordinates for all the pixels in all three
134 # input maps.
135 
136 coordinates = tuple(map(sunpy.map.all_coordinates_from_map, maps))
137 
138 ######################################################################
139 # To get a weighting which is high close to disk centre and low towards
140 # the limb, we can use the Z coordinate in the heliocentric frame. This
141 # coordinate is the distance of the sphere from the centre of the Sun
142 # towards the observer.
143 
144 weights = [coord.transform_to("heliocentric").z.value for coord in coordinates]
145 
146 ######################################################################
147 # These weights are good, but they are better if the ramp down is a little
148 # smoother, and more biased to the centre. Also we can scale them to the
149 # range 0-1, and set any off disk (NaN) regions to 0.
150 
151 weights = [(w / np.nanmax(w)) ** 3 for w in weights]
152 for w in weights:
153     w[np.isnan(w)] = 0
154 
155 plt.figure()
156 plt.imshow(weights[0])
157 plt.colorbar()
158 
159 plt.show()
160 
161 ######################################################################
162 # Now we can rerun the reprojection. This time we also set
163 # ``match_background=True`` which scales the images by a single scaling
164 # factor so they are of similar brightness. We also set
165 # ``background_reference=0`` which uses the AIA map as the reference for
166 # the background scaling.
167 #
168 # Here we are using the fastest but least accurate method of reprojection,
169 # `reproject.reproject_interp`, a more accurate but slower method is
170 # `reproject.reproject_adaptive`.
171 
172 array, _ = reproject_and_coadd(maps, out_wcs, shape_out,
173                                input_weights=weights,
174                                reproject_function=reproject_interp,
175                                match_background=True,
176                                background_reference=0)
177 
178 ######################################################################
179 # Once again we create a new map, and this time we customise the plot a
180 # little.
181 
182 outmap = sunpy.map.Map((array, header))
183 outmap.plot_settings = maps[0].plot_settings
184 outmap.nickname = 'AIA + EUVI/A + EUVI/B'
185 
186 plt.figure(figsize=(10, 5))
187 ax = plt.subplot(projection=out_wcs)
188 im = outmap.plot(vmin=400)
189 
190 lon, lat = ax.coords
191 lon.set_coord_type("longitude")
192 lon.coord_wrap = 180
193 lon.set_format_unit(u.deg)
194 lat.set_coord_type("latitude")
195 lat.set_format_unit(u.deg)
196 
197 lon.set_axislabel('Heliographic Longitude', minpad=0.8)
198 lat.set_axislabel('Heliographic Latitude', minpad=0.9)
199 lon.set_ticks(spacing=25*u.deg, color='k')
200 lat.set_ticks(spacing=15*u.deg, color='k')
201 
202 plt.colorbar(im, ax=ax)
203 
204 # Reset the view to pixel centers
205 _ = ax.axis((0, shape_out[1], 0, shape_out[0]))
206 
207 plt.show()
208
```
--- 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()

```

diff --git a/examples/map_transformations/reprojection_aia_euvi_mosaic.py b/examples/map_transformations/reprojection_aia_euvi_mosaic.py
--- a/examples/map_transformations/reprojection_aia_euvi_mosaic.py
+++ b/examples/map_transformations/reprojection_aia_euvi_mosaic.py
@@ -95,8 +95,8 @@
                                        SkyCoord(0, 0, unit=u.deg,
                                                 frame="heliographic_stonyhurst",
                                                 obstime=maps[0].date),
-                                       scale=[180 / shape_out[0],
-                                              360 / shape_out[1]] * u.deg / u.pix,
+                                       scale=[360 / shape_out[1],
+                                              180 / shape_out[0]] * u.deg / u.pix,
                                        wavelength=int(maps[0].meta['wavelnth']) * u.AA,
                                        projection_code="CAR")
 out_wcs = WCS(header)
diff --git a/examples/map_transformations/reprojection_heliographic_stonyhurst.py b/examples/map_transformations/reprojection_heliographic_stonyhurst.py
--- a/examples/map_transformations/reprojection_heliographic_stonyhurst.py
+++ b/examples/map_transformations/reprojection_heliographic_stonyhurst.py
@@ -43,8 +43,8 @@
                      obstime=aia_map.date)
 header = sunpy.map.make_fitswcs_header(shape_out,
                                        frame_out,
-                                       scale=[180 / shape_out[0],
-                                              360 / shape_out[1]] * u.deg / u.pix,
+                                       scale=[360 / shape_out[1],
+                                              180 / shape_out[0]] * u.deg / u.pix,
                                        projection_code="CAR")
 
 out_wcs = WCS(header)

{"golden_diff": "diff --git a/examples/map_transformations/reprojection_aia_euvi_mosaic.py b/examples/map_transformations/reprojection_aia_euvi_mosaic.py\n--- a/examples/map_transformations/reprojection_aia_euvi_mosaic.py\n+++ b/examples/map_transformations/reprojection_aia_euvi_mosaic.py\n@@ -95,8 +95,8 @@\n                                        SkyCoord(0, 0, unit=u.deg,\n                                                 frame=\"heliographic_stonyhurst\",\n                                                 obstime=maps[0].date),\n-                                       scale=[180 / shape_out[0],\n-                                              360 / shape_out[1]] * u.deg / u.pix,\n+                                       scale=[360 / shape_out[1],\n+                                              180 / shape_out[0]] * u.deg / u.pix,\n                                        wavelength=int(maps[0].meta['wavelnth']) * u.AA,\n                                        projection_code=\"CAR\")\n out_wcs = WCS(header)\ndiff --git a/examples/map_transformations/reprojection_heliographic_stonyhurst.py b/examples/map_transformations/reprojection_heliographic_stonyhurst.py\n--- a/examples/map_transformations/reprojection_heliographic_stonyhurst.py\n+++ b/examples/map_transformations/reprojection_heliographic_stonyhurst.py\n@@ -43,8 +43,8 @@\n                      obstime=aia_map.date)\n header = sunpy.map.make_fitswcs_header(shape_out,\n                                        frame_out,\n-                                       scale=[180 / shape_out[0],\n-                                              360 / shape_out[1]] * u.deg / u.pix,\n+                                       scale=[360 / shape_out[1],\n+                                              180 / shape_out[0]] * u.deg / u.pix,\n                                        projection_code=\"CAR\")\n \n out_wcs = WCS(header)\n", "issue": "Order of arguments in `scale` input to `make_fitswcs_header` is wrong in AIA/EUVI reprojection example\nIn [the AIA/EUVI reprojection mosaic example](https://docs.sunpy.org/en/latest/generated/gallery/map_transformations/reprojection_aia_euvi_mosaic.html), the ordering of the `scale` argument to `make_fitswcs_header` is incorrect. The ordering should be Cartesian (lon, lat) [according to the `make_fitswcs_header` docstring](https://docs.sunpy.org/en/stable/api/sunpy.map.make_fitswcs_header.html#sunpy.map.make_fitswcs_header), but in this example, the order is according to the array index. This actually has no effect on the example output as the scale in both directions is the same (1 deg/pix), but is potentially confusing and conflicts with the function docstring.\n", "before_files": [{"content": "\"\"\"\n===========================\nCreating a Heliographic Map\n===========================\n\nIn this example we use the `reproject` generate an image in heliographic coordinates from an AIA image.\n\nYou will need `reproject <https://reproject.readthedocs.io/en/stable/>`__ v0.6 or higher installed.\n\"\"\"\n# sphinx_gallery_thumbnail_number = 2\n\nimport matplotlib.pyplot as plt\nfrom reproject import reproject_interp\n\nimport astropy.units as u\nfrom astropy.coordinates import SkyCoord\nfrom astropy.wcs import WCS\n\nimport sunpy.data.sample\nimport sunpy.map\n\n###############################################################################\n# We will start with using sunpy's sample data for this example.\n\naia_map = sunpy.map.Map(sunpy.data.sample.AIA_193_IMAGE)\n\nfig = plt.figure()\nax = plt.subplot(projection=aia_map)\naia_map.plot(ax)\n\n###############################################################################\n# Reproject works by transforming an input image (with a `~astropy.wcs.WCS`) to\n# a output image, specified by a different WCS object. Therefore we need to\n# build a `~astropy.wcs.WCS` object describing the output we desire.\n# To do this we use the `sunpy.map.make_fitswcs_header` which assists us in\n# constructing this World Coordinate System (WCS) object.\n# Here we create a WCS based on a heliographic\n# Stonyhurst reference coordinate and with the CAR (plate carree) projection.\n\nshape_out = [720, 1440]\nframe_out = SkyCoord(0, 0, unit=u.deg,\n                     frame=\"heliographic_stonyhurst\",\n                     obstime=aia_map.date)\nheader = sunpy.map.make_fitswcs_header(shape_out,\n                                       frame_out,\n                                       scale=[180 / shape_out[0],\n                                              360 / shape_out[1]] * u.deg / u.pix,\n                                       projection_code=\"CAR\")\n\nout_wcs = WCS(header)\n\n###############################################################################\n# With the new header, re-project the data into the new coordinate system.\n# Here we are using the fastest but least accurate method of reprojection,\n# `reproject.reproject_interp`, a more accurate but slower method is\n# `reproject.reproject_adaptive`.\n\narray, footprint = reproject_interp(aia_map, out_wcs, shape_out=shape_out)\noutmap = sunpy.map.Map((array, header))\noutmap.plot_settings = aia_map.plot_settings\n\n###############################################################################\n# Plot the result.\n\nfig = plt.figure()\nax = plt.subplot(projection=outmap)\noutmap.plot(ax)\n\nax.set_xlim(0, shape_out[1])\nax.set_ylim(0, shape_out[0])\n\nplt.show()\n", "path": "examples/map_transformations/reprojection_heliographic_stonyhurst.py"}, {"content": "\"\"\"\n=========================================\nCreating a Full Sun Map with AIA and EUVI\n=========================================\n\nWith SDO/AIA and STEREO/A and STEREO/B, it is now possible (given specific dates)\nto combine combine three EUV images from these satellites\nto produce a full latitude / longitude map of the Sun.\n\nYou will need an active internet connection as well as\n`reproject <https://reproject.readthedocs.io/en/stable/>`__ v0.6 or higher installed.\n\"\"\"\n# sphinx_gallery_thumbnail_number = 4\n\nimport matplotlib.pyplot as plt\nimport numpy as np\nfrom reproject import reproject_interp\nfrom reproject.mosaicking import reproject_and_coadd\n\nimport astropy.units as u\nfrom astropy.coordinates import SkyCoord\nfrom astropy.wcs import WCS\n\nimport sunpy.map\nimport sunpy.sun\nfrom sunpy.coordinates import get_body_heliographic_stonyhurst\nfrom sunpy.net import Fido\nfrom sunpy.net import attrs as a\n\n######################################################################\n# To get started, let's download the data:\n\nstereo = (a.Instrument(\"EUVI\") &\n          a.Time('2011-11-01', '2011-11-01T00:10:00'))\naia = (a.Instrument.aia &\n       a.Sample(24 * u.hour) &\n       a.Time('2011-11-01', '2011-11-02'))\nwave = a.Wavelength(19.5 * u.nm, 19.5 * u.nm)\nres = Fido.search(wave, aia | stereo)\nfiles = Fido.fetch(res)\n\n######################################################################\n# Next we create a sunpy map for each of the files.\n\nmaps = sunpy.map.Map(sorted(files))\n\n######################################################################\n# To reduce memory consumption we also downsample these maps before continuing,\n# you can disable this.\n\nmaps = [m.resample((1024, 1024)*u.pix) for m in maps]\n\n######################################################################\n# When combining these images all three need to assume the same radius of\n# the Sun for the data. The AIA images specify a slightly different value\n# than the IAU 2015 constant. To avoid coordinate transformation issues we\n# reset this here.\n\nmaps[0].meta['rsun_ref'] = sunpy.sun.constants.radius.to_value(u.m)\n\n######################################################################\n# Next we will plot the locations of the three spacecraft with respect to\n# the Sun so we can easily see the relative separations.\n\nearth = get_body_heliographic_stonyhurst('earth', maps[0].date)\n\nplt.figure(figsize=(8, 8))\nr_unit = u.AU\n\nax = plt.subplot(projection='polar')\ncircle = plt.Circle((0.0, 0.0), (10*u.Rsun).to_value(r_unit),\n                    transform=ax.transProjectionAffine + ax.transAxes, color=\"yellow\",\n                    alpha=1, label=\"Sun\")\nax.add_artist(circle)\nax.text(earth.lon.to_value(\"rad\")+0.05, earth.radius.to_value(r_unit), \"Earth\")\n\nfor this_satellite, this_coord in [(m.observatory, m.observer_coordinate) for m in maps]:\n    ax.plot(this_coord.lon.to('rad'), this_coord.radius.to(r_unit), 'o', label=this_satellite)\n\nax.set_theta_zero_location(\"S\")\nax.set_rlim(0, 1.3)\n\nax.legend()\n\nplt.show()\n\n######################################################################\n# The next step is to calculate the output coordinate system for the combined\n# map. We select a heliographic Stonyhurst frame, and a Plate Carree (CAR)\n# projection, and generate a header using `sunpy.map.make_fitswcs_header` and\n# then construct a World Coordinate System (WCS) object for that header.\n\nshape_out = (180, 360)  # This is set deliberately low to reduce memory consumption\nheader = sunpy.map.make_fitswcs_header(shape_out,\n                                       SkyCoord(0, 0, unit=u.deg,\n                                                frame=\"heliographic_stonyhurst\",\n                                                obstime=maps[0].date),\n                                       scale=[180 / shape_out[0],\n                                              360 / shape_out[1]] * u.deg / u.pix,\n                                       wavelength=int(maps[0].meta['wavelnth']) * u.AA,\n                                       projection_code=\"CAR\")\nout_wcs = WCS(header)\n\n######################################################################\n# Next we call the `reproject.mosaicking.reproject_and_coadd` function, which\n# takes a list of maps, and the desired output WCS and array shape.\n\narray, footprint = reproject_and_coadd(maps, out_wcs, shape_out,\n                                       reproject_function=reproject_interp)\n\n######################################################################\n# To display the output we construct a new map using the new array and our\n# generated header. We also borrow the plot settings from the AIA map.\n\noutmap = sunpy.map.Map((array, header))\noutmap.plot_settings = maps[0].plot_settings\noutmap.plot()\n\nplt.show()\n\n######################################################################\n# Improving the Output\n# --------------------\n#\n# As you can see this leaves a little to be desired. To reduce the obvious\n# warping towards the points which are close to the limb in the input\n# images, we can define a set of weights to use when co-adding the output\n# arrays. To reduce this warping we want to calculate an set of weights\n# which highly weigh points close to the centre of the disk in the input\n# image.\n#\n# We can achieve this by using sunpy's coordinate framework. First we\n# calculate all the world coordinates for all the pixels in all three\n# input maps.\n\ncoordinates = tuple(map(sunpy.map.all_coordinates_from_map, maps))\n\n######################################################################\n# To get a weighting which is high close to disk centre and low towards\n# the limb, we can use the Z coordinate in the heliocentric frame. This\n# coordinate is the distance of the sphere from the centre of the Sun\n# towards the observer.\n\nweights = [coord.transform_to(\"heliocentric\").z.value for coord in coordinates]\n\n######################################################################\n# These weights are good, but they are better if the ramp down is a little\n# smoother, and more biased to the centre. Also we can scale them to the\n# range 0-1, and set any off disk (NaN) regions to 0.\n\nweights = [(w / np.nanmax(w)) ** 3 for w in weights]\nfor w in weights:\n    w[np.isnan(w)] = 0\n\nplt.figure()\nplt.imshow(weights[0])\nplt.colorbar()\n\nplt.show()\n\n######################################################################\n# Now we can rerun the reprojection. This time we also set\n# ``match_background=True`` which scales the images by a single scaling\n# factor so they are of similar brightness. We also set\n# ``background_reference=0`` which uses the AIA map as the reference for\n# the background scaling.\n#\n# Here we are using the fastest but least accurate method of reprojection,\n# `reproject.reproject_interp`, a more accurate but slower method is\n# `reproject.reproject_adaptive`.\n\narray, _ = reproject_and_coadd(maps, out_wcs, shape_out,\n                               input_weights=weights,\n                               reproject_function=reproject_interp,\n                               match_background=True,\n                               background_reference=0)\n\n######################################################################\n# Once again we create a new map, and this time we customise the plot a\n# little.\n\noutmap = sunpy.map.Map((array, header))\noutmap.plot_settings = maps[0].plot_settings\noutmap.nickname = 'AIA + EUVI/A + EUVI/B'\n\nplt.figure(figsize=(10, 5))\nax = plt.subplot(projection=out_wcs)\nim = outmap.plot(vmin=400)\n\nlon, lat = ax.coords\nlon.set_coord_type(\"longitude\")\nlon.coord_wrap = 180\nlon.set_format_unit(u.deg)\nlat.set_coord_type(\"latitude\")\nlat.set_format_unit(u.deg)\n\nlon.set_axislabel('Heliographic Longitude', minpad=0.8)\nlat.set_axislabel('Heliographic Latitude', minpad=0.9)\nlon.set_ticks(spacing=25*u.deg, color='k')\nlat.set_ticks(spacing=15*u.deg, color='k')\n\nplt.colorbar(im, ax=ax)\n\n# Reset the view to pixel centers\n_ = ax.axis((0, shape_out[1], 0, shape_out[0]))\n\nplt.show()\n", "path": "examples/map_transformations/reprojection_aia_euvi_mosaic.py"}], "after_files": [{"content": "\"\"\"\n===========================\nCreating a Heliographic Map\n===========================\n\nIn this example we use the `reproject` generate an image in heliographic coordinates from an AIA image.\n\nYou will need `reproject <https://reproject.readthedocs.io/en/stable/>`__ v0.6 or higher installed.\n\"\"\"\n# sphinx_gallery_thumbnail_number = 2\n\nimport matplotlib.pyplot as plt\nfrom reproject import reproject_interp\n\nimport astropy.units as u\nfrom astropy.coordinates import SkyCoord\nfrom astropy.wcs import WCS\n\nimport sunpy.data.sample\nimport sunpy.map\n\n###############################################################################\n# We will start with using sunpy's sample data for this example.\n\naia_map = sunpy.map.Map(sunpy.data.sample.AIA_193_IMAGE)\n\nfig = plt.figure()\nax = plt.subplot(projection=aia_map)\naia_map.plot(ax)\n\n###############################################################################\n# Reproject works by transforming an input image (with a `~astropy.wcs.WCS`) to\n# a output image, specified by a different WCS object. Therefore we need to\n# build a `~astropy.wcs.WCS` object describing the output we desire.\n# To do this we use the `sunpy.map.make_fitswcs_header` which assists us in\n# constructing this World Coordinate System (WCS) object.\n# Here we create a WCS based on a heliographic\n# Stonyhurst reference coordinate and with the CAR (plate carree) projection.\n\nshape_out = [720, 1440]\nframe_out = SkyCoord(0, 0, unit=u.deg,\n                     frame=\"heliographic_stonyhurst\",\n                     obstime=aia_map.date)\nheader = sunpy.map.make_fitswcs_header(shape_out,\n                                       frame_out,\n                                       scale=[360 / shape_out[1],\n                                              180 / shape_out[0]] * u.deg / u.pix,\n                                       projection_code=\"CAR\")\n\nout_wcs = WCS(header)\n\n###############################################################################\n# With the new header, re-project the data into the new coordinate system.\n# Here we are using the fastest but least accurate method of reprojection,\n# `reproject.reproject_interp`, a more accurate but slower method is\n# `reproject.reproject_adaptive`.\n\narray, footprint = reproject_interp(aia_map, out_wcs, shape_out=shape_out)\noutmap = sunpy.map.Map((array, header))\noutmap.plot_settings = aia_map.plot_settings\n\n###############################################################################\n# Plot the result.\n\nfig = plt.figure()\nax = plt.subplot(projection=outmap)\noutmap.plot(ax)\n\nax.set_xlim(0, shape_out[1])\nax.set_ylim(0, shape_out[0])\n\nplt.show()\n", "path": "examples/map_transformations/reprojection_heliographic_stonyhurst.py"}, {"content": "\"\"\"\n=========================================\nCreating a Full Sun Map with AIA and EUVI\n=========================================\n\nWith SDO/AIA and STEREO/A and STEREO/B, it is now possible (given specific dates)\nto combine combine three EUV images from these satellites\nto produce a full latitude / longitude map of the Sun.\n\nYou will need an active internet connection as well as\n`reproject <https://reproject.readthedocs.io/en/stable/>`__ v0.6 or higher installed.\n\"\"\"\n# sphinx_gallery_thumbnail_number = 4\n\nimport matplotlib.pyplot as plt\nimport numpy as np\nfrom reproject import reproject_interp\nfrom reproject.mosaicking import reproject_and_coadd\n\nimport astropy.units as u\nfrom astropy.coordinates import SkyCoord\nfrom astropy.wcs import WCS\n\nimport sunpy.map\nimport sunpy.sun\nfrom sunpy.coordinates import get_body_heliographic_stonyhurst\nfrom sunpy.net import Fido\nfrom sunpy.net import attrs as a\n\n######################################################################\n# To get started, let's download the data:\n\nstereo = (a.Instrument(\"EUVI\") &\n          a.Time('2011-11-01', '2011-11-01T00:10:00'))\naia = (a.Instrument.aia &\n       a.Sample(24 * u.hour) &\n       a.Time('2011-11-01', '2011-11-02'))\nwave = a.Wavelength(19.5 * u.nm, 19.5 * u.nm)\nres = Fido.search(wave, aia | stereo)\nfiles = Fido.fetch(res)\n\n######################################################################\n# Next we create a sunpy map for each of the files.\n\nmaps = sunpy.map.Map(sorted(files))\n\n######################################################################\n# To reduce memory consumption we also downsample these maps before continuing,\n# you can disable this.\n\nmaps = [m.resample((1024, 1024)*u.pix) for m in maps]\n\n######################################################################\n# When combining these images all three need to assume the same radius of\n# the Sun for the data. The AIA images specify a slightly different value\n# than the IAU 2015 constant. To avoid coordinate transformation issues we\n# reset this here.\n\nmaps[0].meta['rsun_ref'] = sunpy.sun.constants.radius.to_value(u.m)\n\n######################################################################\n# Next we will plot the locations of the three spacecraft with respect to\n# the Sun so we can easily see the relative separations.\n\nearth = get_body_heliographic_stonyhurst('earth', maps[0].date)\n\nplt.figure(figsize=(8, 8))\nr_unit = u.AU\n\nax = plt.subplot(projection='polar')\ncircle = plt.Circle((0.0, 0.0), (10*u.Rsun).to_value(r_unit),\n                    transform=ax.transProjectionAffine + ax.transAxes, color=\"yellow\",\n                    alpha=1, label=\"Sun\")\nax.add_artist(circle)\nax.text(earth.lon.to_value(\"rad\")+0.05, earth.radius.to_value(r_unit), \"Earth\")\n\nfor this_satellite, this_coord in [(m.observatory, m.observer_coordinate) for m in maps]:\n    ax.plot(this_coord.lon.to('rad'), this_coord.radius.to(r_unit), 'o', label=this_satellite)\n\nax.set_theta_zero_location(\"S\")\nax.set_rlim(0, 1.3)\n\nax.legend()\n\nplt.show()\n\n######################################################################\n# The next step is to calculate the output coordinate system for the combined\n# map. We select a heliographic Stonyhurst frame, and a Plate Carree (CAR)\n# projection, and generate a header using `sunpy.map.make_fitswcs_header` and\n# then construct a World Coordinate System (WCS) object for that header.\n\nshape_out = (180, 360)  # This is set deliberately low to reduce memory consumption\nheader = sunpy.map.make_fitswcs_header(shape_out,\n                                       SkyCoord(0, 0, unit=u.deg,\n                                                frame=\"heliographic_stonyhurst\",\n                                                obstime=maps[0].date),\n                                       scale=[360 / shape_out[1],\n                                              180 / shape_out[0]] * u.deg / u.pix,\n                                       wavelength=int(maps[0].meta['wavelnth']) * u.AA,\n                                       projection_code=\"CAR\")\nout_wcs = WCS(header)\n\n######################################################################\n# Next we call the `reproject.mosaicking.reproject_and_coadd` function, which\n# takes a list of maps, and the desired output WCS and array shape.\n\narray, footprint = reproject_and_coadd(maps, out_wcs, shape_out,\n                                       reproject_function=reproject_interp)\n\n######################################################################\n# To display the output we construct a new map using the new array and our\n# generated header. We also borrow the plot settings from the AIA map.\n\noutmap = sunpy.map.Map((array, header))\noutmap.plot_settings = maps[0].plot_settings\noutmap.plot()\n\nplt.show()\n\n######################################################################\n# Improving the Output\n# --------------------\n#\n# As you can see this leaves a little to be desired. To reduce the obvious\n# warping towards the points which are close to the limb in the input\n# images, we can define a set of weights to use when co-adding the output\n# arrays. To reduce this warping we want to calculate an set of weights\n# which highly weigh points close to the centre of the disk in the input\n# image.\n#\n# We can achieve this by using sunpy's coordinate framework. First we\n# calculate all the world coordinates for all the pixels in all three\n# input maps.\n\ncoordinates = tuple(map(sunpy.map.all_coordinates_from_map, maps))\n\n######################################################################\n# To get a weighting which is high close to disk centre and low towards\n# the limb, we can use the Z coordinate in the heliocentric frame. This\n# coordinate is the distance of the sphere from the centre of the Sun\n# towards the observer.\n\nweights = [coord.transform_to(\"heliocentric\").z.value for coord in coordinates]\n\n######################################################################\n# These weights are good, but they are better if the ramp down is a little\n# smoother, and more biased to the centre. Also we can scale them to the\n# range 0-1, and set any off disk (NaN) regions to 0.\n\nweights = [(w / np.nanmax(w)) ** 3 for w in weights]\nfor w in weights:\n    w[np.isnan(w)] = 0\n\nplt.figure()\nplt.imshow(weights[0])\nplt.colorbar()\n\nplt.show()\n\n######################################################################\n# Now we can rerun the reprojection. This time we also set\n# ``match_background=True`` which scales the images by a single scaling\n# factor so they are of similar brightness. We also set\n# ``background_reference=0`` which uses the AIA map as the reference for\n# the background scaling.\n#\n# Here we are using the fastest but least accurate method of reprojection,\n# `reproject.reproject_interp`, a more accurate but slower method is\n# `reproject.reproject_adaptive`.\n\narray, _ = reproject_and_coadd(maps, out_wcs, shape_out,\n                               input_weights=weights,\n                               reproject_function=reproject_interp,\n                               match_background=True,\n                               background_reference=0)\n\n######################################################################\n# Once again we create a new map, and this time we customise the plot a\n# little.\n\noutmap = sunpy.map.Map((array, header))\noutmap.plot_settings = maps[0].plot_settings\noutmap.nickname = 'AIA + EUVI/A + EUVI/B'\n\nplt.figure(figsize=(10, 5))\nax = plt.subplot(projection=out_wcs)\nim = outmap.plot(vmin=400)\n\nlon, lat = ax.coords\nlon.set_coord_type(\"longitude\")\nlon.coord_wrap = 180\nlon.set_format_unit(u.deg)\nlat.set_coord_type(\"latitude\")\nlat.set_format_unit(u.deg)\n\nlon.set_axislabel('Heliographic Longitude', minpad=0.8)\nlat.set_axislabel('Heliographic Latitude', minpad=0.9)\nlon.set_ticks(spacing=25*u.deg, color='k')\nlat.set_ticks(spacing=15*u.deg, color='k')\n\nplt.colorbar(im, ax=ax)\n\n# Reset the view to pixel centers\n_ = ax.axis((0, shape_out[1], 0, shape_out[0]))\n\nplt.show()\n", "path": "examples/map_transformations/reprojection_aia_euvi_mosaic.py"}]}