Skip to content

Commit

Permalink
Merge pull request #1416 from ayshih/namedtuple
Browse files Browse the repository at this point in the history
Map attributes are now named tuples instead of dictionaries
  • Loading branch information
ayshih committed May 27, 2015
2 parents 00f3e9c + 8d0a3c6 commit dcbcbe5
Show file tree
Hide file tree
Showing 12 changed files with 130 additions and 134 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Latest
* map.shape has been replaced with map.dimensions, which is ordered
x first.
* map.rsun_arcseconds is now map.rsun_obs as it returns a quantity.
* Map properties are now named tuples rather than dictionaries.

0.5.0
-----
Expand Down
12 changes: 6 additions & 6 deletions sunpy/image/coalignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,8 @@ def apply_shifts(mc, yshift, xshift, clip=True):
new_meta = deepcopy(m.meta)

# Adjust the positioning information accordingly.
new_meta['crval1'] = new_meta['crval1'] - xshift[i].value * m.scale['x'].value
new_meta['crval2'] = new_meta['crval2'] - yshift[i].value * m.scale['y'].value
new_meta['crval1'] = new_meta['crval1'] - xshift[i].value * m.scale.x.value
new_meta['crval2'] = new_meta['crval2'] - yshift[i].value * m.scale.y.value

# Append to the list
newmc_list.append(sunpy.map.Map(shifted_data, new_meta))
Expand Down Expand Up @@ -478,8 +478,8 @@ def calculate_match_template_shift(mc, template=None, layer_index=0,
for i, m in enumerate(mc.maps):
# Calculate the shifts required in physical units, which are
# presumed to be arcseconds.
xshift_arcseconds[i] = xshift_keep[i] * m.scale['x']
yshift_arcseconds[i] = yshift_keep[i] * m.scale['y']
xshift_arcseconds[i] = xshift_keep[i] * m.scale.x
yshift_arcseconds[i] = yshift_keep[i] * m.scale.y

return {"x": xshift_arcseconds, "y": yshift_arcseconds}

Expand Down Expand Up @@ -571,8 +571,8 @@ def mapcube_coalign_by_match_template(mc, template=None, layer_index=0,

# Calculate the pixel shifts
for i, m in enumerate(mc):
xshift_keep[i] = (xshift_arcseconds[i] / m.scale['x'])
yshift_keep[i] = (yshift_arcseconds[i] / m.scale['y'])
xshift_keep[i] = (xshift_arcseconds[i] / m.scale.x)
yshift_keep[i] = (yshift_arcseconds[i] / m.scale.y)

# Apply the shifts and return the coaligned mapcube
return apply_shifts(mc, -yshift_keep, -xshift_keep, clip=clip)
12 changes: 6 additions & 6 deletions sunpy/image/tests/test_coalignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ def aia171_test_mc_pixel_displacements():

@pytest.fixture
def aia171_mc_arcsec_displacements(aia171_test_mc_pixel_displacements, aia171_test_map):
return {'x': np.asarray([0.0, aia171_test_mc_pixel_displacements[1] * aia171_test_map.scale['x'].value]) * u.arcsec,
'y': np.asarray([0.0, aia171_test_mc_pixel_displacements[0] * aia171_test_map.scale['y'].value]) * u.arcsec}
return {'x': np.asarray([0.0, aia171_test_mc_pixel_displacements[1] * aia171_test_map.scale.x.value]) * u.arcsec,
'y': np.asarray([0.0, aia171_test_mc_pixel_displacements[0] * aia171_test_map.scale.y.value]) * u.arcsec}


@pytest.fixture
Expand Down Expand Up @@ -241,8 +241,8 @@ def test_mapcube_coalign_by_match_template(aia171_test_mc,
# All output layers should have the same size
# which is smaller than the input by a known amount
test_mc = mapcube_coalign_by_match_template(aia171_test_mc)
x_displacement_pixels = test_displacements['x'] / test_mc[0].scale['x']
y_displacement_pixels = test_displacements['y'] / test_mc[0].scale['y']
x_displacement_pixels = test_displacements['x'] / test_mc[0].scale.x
y_displacement_pixels = test_displacements['y'] / test_mc[0].scale.y
expected_clipping = calculate_clipping(y_displacement_pixels, x_displacement_pixels)
number_of_pixels_clipped = [np.sum(np.abs(expected_clipping[0])), np.sum(np.abs(expected_clipping[1]))]

Expand All @@ -253,8 +253,8 @@ def test_mapcube_coalign_by_match_template(aia171_test_mc,
# All output layers should have the same size
# which is smaller than the input by a known amount
test_mc = mapcube_coalign_by_match_template(aia171_test_mc, clip=True)
x_displacement_pixels = test_displacements['x'] / test_mc[0].scale['x']
y_displacement_pixels = test_displacements['y'] / test_mc[0].scale['y']
x_displacement_pixels = test_displacements['x'] / test_mc[0].scale.x
y_displacement_pixels = test_displacements['y'] / test_mc[0].scale.y
expected_clipping = calculate_clipping(y_displacement_pixels, x_displacement_pixels)
number_of_pixels_clipped = [np.sum(np.abs(expected_clipping[0])), np.sum(np.abs(expected_clipping[1]))]

Expand Down
6 changes: 3 additions & 3 deletions sunpy/instr/aia.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ def aiaprep(aiamap):

# Taget scale is 0.6 arcsec/pixel, but this needs to be adjusted if the map
# has already been rescaled.
if (aiamap.scale['x']/0.6).round() != 1.0*u.arcsec and aiamap.data.shape != (4096, 4096):
scale = (aiamap.scale['x']/0.6).round() * 0.6*u.arcsec
if (aiamap.scale.x/0.6).round() != 1.0*u.arcsec and aiamap.data.shape != (4096, 4096):
scale = (aiamap.scale.x/0.6).round() * 0.6*u.arcsec
else:
scale = 0.6*u.arcsec # pragma: no cover # can't test this because it needs a full res image
scale_factor = aiamap.scale['x'] / scale
scale_factor = aiamap.scale.x / scale

newmap = aiamap.rotate(recenter=True, scale=scale_factor.value, missing=aiamap.min())
newmap.meta['lvl_num'] = 1.5
Expand Down
12 changes: 6 additions & 6 deletions sunpy/map/compositemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,16 +301,16 @@ def plot(self, axes=None, gamma=None, annotate=True, # pylint: disable=W0613

if annotate:
# x-axis label
if self._maps[0].coordinate_system['x'] == 'HG':
xlabel = 'Longitude [{lon}]'.format(lon=self._maps[0].units['x'])
if self._maps[0].coordinate_system.x == 'HG':
xlabel = 'Longitude [{lon}]'.format(lon=self._maps[0].units.x)
else:
xlabel = 'X-position [{solx}]'.format(solx=self._maps[0].units['x'])
xlabel = 'X-position [{solx}]'.format(solx=self._maps[0].units.x)

# y-axis label
if self._maps[0].coordinate_system['y'] == 'HG':
ylabel = 'Latitude [{lat}]'.format(lat=self._maps[0].units['y'])
if self._maps[0].coordinate_system.y == 'HG':
ylabel = 'Latitude [{lat}]'.format(lat=self._maps[0].units.y)
else:
ylabel = 'Y-position [{soly}]'.format(soly=self._maps[0].units['y'])
ylabel = 'Y-position [{soly}]'.format(soly=self._maps[0].units.y)

axes.set_xlabel(xlabel)
axes.set_ylabel(ylabel)
Expand Down

0 comments on commit dcbcbe5

Please sign in to comment.