Skip to content
This repository has been archived by the owner on Feb 1, 2023. It is now read-only.

Commit

Permalink
Fix up coadd example
Browse files Browse the repository at this point in the history
  • Loading branch information
dstansby committed Jan 11, 2022
1 parent 2df9faa commit 4025d94
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
4 changes: 3 additions & 1 deletion docs/index.rst
Expand Up @@ -47,7 +47,9 @@ Caching reprojected maps
Under the hood ``solarsynoptic`` can cache the reprojected map to a file on
disk, which avoids having to run the reprojection routine each time the
reprojected map is requested. This is enabled by default, and can be disabled
by passing ``cache=False`` to ``reproject_carrington``.
by passing ``cache=False`` to ``reproject_carrington``. The cached maps are
saved in a folder named ``solarsynoptic`` that is placed next to the ``sunpy``
data directory.

Combining multiple maps
-----------------------
Expand Down
16 changes: 9 additions & 7 deletions examples/plot_coadd.py
Expand Up @@ -12,7 +12,7 @@
import numpy as np
import sunpy.map

from solarsynoptic.coadd import coadd, long_weights
from solarsynoptic.combine import coadd, weights_longitude
from solarsynoptic.data import aia_start_of_day_map, stereo_start_of_day_map
from solarsynoptic.reprojection import reproject_carrington

Expand Down Expand Up @@ -51,33 +51,35 @@


def weight_function(smap):
weights = long_weights(30 * u.deg)(smap)
weights = weights_longitude(30 * u.deg)(smap)
factor = (datetime.now() - smap.date.to_datetime()) / timedelta(days=1)
return weights / factor


###############################################################################
# Add the maps together
dtime = datetime.now().strftime('%Y-%m-%d')

# Just the STEREO maps
map_out = coadd(maps_in_stereo, weight_function=weight_function)
fig = plt.figure()
map_out.plot(cmap='sdoaia193', norm=norm)
plt.gca().set_title(f'EUVI, updated {dtime}')
fig.savefig(f'figs/euvi_png_{dtime}.png')

# Just tthe AIA maps
map_out = coadd(maps_in_aia, weight_function=weight_function)
fig = plt.figure()
map_out.plot(cmap='sdoaia193', norm=norm)
map_out.save(f'maps/aia_synoptic_{dtime}.fits')
plt.gca().set_title(f'AIA, updated {dtime}')
fig.savefig(f'figs/aia_png_{dtime}.png')

# STEREO and AIA maps
map_out = coadd(maps_in_aia + maps_in_stereo, weight_function=weight_function)
map_out.save(f'maps/aia_euvi_synoptic_{dtime}.fits', overwrite=True)

fig = plt.figure()
map_out = sunpy.map.Map((norm(map_out.data), map_out.meta))
map_out.plot(cmap='sdoaia193', norm=mcolor.Normalize(vmin=0, vmax=1))
plt.gca().set_title(f'AIA + EUVI, udpated {dtime}')

fig.savefig(f'figs/combined_png_{dtime}.png')
fig.savefig(f'maps/aia_euvi_synoptic_png_{dtime}.png')
map_out.save(f'maps/aia_euvi_synoptic_{dtime}.fits')
plt.show()
4 changes: 2 additions & 2 deletions solarsynoptic/data/aia.py
Expand Up @@ -66,8 +66,8 @@ def aia_start_of_day_map(dtime, wlen, dl_path=None):
f"H0000/AIA{dtime.year}{dtime.month:02}{dtime.day:02}_"
f"000000_0{wlen_int}.fits")
dl.enqueue_file(url, filename=map_path)
log.info(f'Downloading AIA {int(wlen.to_value(u.Angstrom))} map '
f'to {map_path}')
log.info(f'Downloading AIA {int(wlen.to_value(u.Angstrom))} '
f'near real time map to {map_path}')
res = dl.download()
if len(res.errors):
log.info(res.errors)
Expand Down
3 changes: 2 additions & 1 deletion solarsynoptic/reprojection/database.py
Expand Up @@ -94,7 +94,8 @@ def __contains__(self, item):

def __getitem__(self, item):
fpath = self.db.loc[self.key(*item), 'Reprojected file path']
return sunpy.map.Map(fpath)
if Path(fpath).exists():
return sunpy.map.Map(fpath)

@staticmethod
def key(smap, projection):
Expand Down
1 change: 1 addition & 0 deletions solarsynoptic/reprojection/reprojection.py
Expand Up @@ -42,6 +42,7 @@ def reproject_carrington(smap, shape_out, latitude_projection='CAR',
map_out = DATABASE[smap, latitude_projection]

if map_out is None:
log.info(f'Reprojecting {smap.name}')
header_out = carrington_header(smap.date, shape_out,
smap.observer_coordinate,
projection_code=latitude_projection)
Expand Down

0 comments on commit 4025d94

Please sign in to comment.