position = map.world_to_pixel( TypeError: world_to_pixel() got an unexpected keyword argument 'origin'
时间: 2024-01-10 18:04:34 浏览: 30
很抱歉,我之前的回答中有误。在 SunPy 中,`world_to_pixel()` 函数没有 `origin` 参数。如果你需要将原点位置设置为左下角,可以使用以下方法:
1. 获取图像的大小,然后计算出左下角的像素坐标。例如:
```
height, width = map.data.shape
position = (x_value_in_arcsec / map.scale.axis1, height - y_value_in_arcsec / map.scale.axis2)
```
在这个例子中,`x_value_in_arcsec` 和 `y_value_in_arcsec` 分别是你要转换为像素坐标的角秒值。`map.scale.axis1` 和 `map.scale.axis2` 分别是图像在 x 和 y 方向上的比例因子。`height` 和 `width` 分别是图像的高度和宽度。这个方法计算出的像素坐标以左下角为原点。
2. 或者,你可以将 `world_to_pixel()` 函数返回的像素坐标翻转一下,以将原点位置从左上角转换为左下角。例如:
```
position = map.world_to_pixel(SkyCoord(827 * u.arcsec, 189 * u.arcsec, frame=frames.Helioprojective, observer=map.observer_coordinate))
height, _ = map.data.shape
position = (position[0], height - position[1])
```
在这个例子中,`height` 是图像的高度,`position` 是 `world_to_pixel()` 函数返回的像素坐标。`position[0]` 和 `position[1]` 分别是像素坐标的 x 和 y 值。这个方法首先将原始的像素坐标转换为左下角为原点的坐标系,然后返回转换后的坐标。