我试图编写一个程序,从用户那里获取一组经度和纬度坐标,将它们转换为Mollweide投影图的x&y坐标,然后报告这些坐标处的像素值(在本例中,是噪声温度)。在

我使用的地图/数据是Haslam 408 MHz All Sky Survey,它是作为Mollweide投影图提供的。这是一个.fits格式的数据,是一个408MHz波段的大范围全天噪声调查。在

根据Mollweide projection Wikipedia page,可以使用Newton-Raphson迭代将经度/纬度转换为x/y地图坐标。我在程序中的迭代方案主要基于Wikipedia页面和this GitHub post中的方法。在

但是,我的程序似乎没有报告我输入的经度和纬度的正确值。我主要怀疑是两个(或两个)因素中的一个导致了这个错误:我实现迭代方案的方式是不正确的,因此导致报告了不正确的值。在

我不能正确理解迭代方案中半径值R代表什么。除了“R是要投影的地球的半径”之外,我找不到任何关于如何确定正确的R值的文献。我假设这将基于地图的像素大小;在本例中,地图图像是4096x2048像素,所以我尝试使用20481024和简单的1作为R值,但是没有用。在

下面我提供了我的代码供审阅:from math import sin, cos, pi, sqrt, asin

from astropy.io import fits

hdulist = fits.open('data.fits')

hdulist.info()

data = hdulist[1].data

sqrt2 = sqrt(2)

def solveNR(lat, epsilon=1e-6): #this solves the Newton Raphson iteration

if abs(lat) == pi / 2:

return lat # avoid division by zero

theta = lat

while True:

nexttheta = theta - (

(2 * theta + sin(2 * theta) - pi * sin(lat)) /

(2 + 2 * cos(2 * theta))

)

if abs(theta - nexttheta) < epsilon:

break

theta = nexttheta

return nexttheta

def checktheta(theta, lat): #this function is also currently unused while debugging

return (2 * theta + sin(2 * theta), pi * sin(lat))

def mollweide(lat, lon, lon_0=0, R=1024):

lat = lat * pi / 180

lon = lon * pi / 180

lon_0 = lon_0 * pi / 180 # convert to radians

theta = solveNR(lat)

return (R * 2 * sqrt2 * (lon - lon_0) * cos(theta) / pi,

R * sqrt2 * sin(theta))

def inv_mollweide(x, y, lon_0=0, R=1024, degrees=True): # inverse procedure (x, y to lat, long). Currently unused

theta = asin(y / (R * sqrt2))

if degrees:

factor = 180 / pi

else:

factor = 1

return (

asin((2 * theta + sin(2 * theta)) / pi) * factor,

(lon_0 + pi * x / (2 * R * sqrt(2) * cos(theta))) * factor

)

def retrieve_temp(lat, long): #retrieves the noise temp from the data file after calling the mollweide function

lat = int(round(lat))

long = int(round(long))

coords = mollweide(lat, long)

x, y= coords

x = int(round(x))

y= int(round(y))

x = x-1

y = y-1

if x < 0:

x = x*(-1)

if y < 0:

y = y*(-1)

print("The noise temperature is: ",data[y, x],"K")

def prompt(): #this is the terminal UI

cont = 1

while cont == 1:

lat_cont = 1

while lat_cont == 1:

lat = float(input('Please enter the latitude: '))

lat_val = 1

while lat_val == 1:

if lat > 180 or lat < -180:

lat = float(input('Invalid input. Make sure your latitude value is in range -180 to 180 degrees \n'

'Please enter the latitude: '))

else:

lat_val = 0

lat_cont = 0

long_cont = 1

while long_cont == 1:

long = float(input('Please enter the longitude: '))

long_val = 1

while long_val == 1:

if long > 90 or long < -90:

long = float(input('Invalid input. Make sure your latitude value is in range -90 to 90 degrees \n'

'Please enter the latitude: '))

else:

long_val = 0

long_cont = 0

retrieve_temp(lat, long)

valid = 1

while valid == 1:

ans = input('Would you like to continue? Y or N: ').lower()

ans_val = 1

while ans_val ==1:

if not (ans == 'y' or ans == 'n'):

ans = input('Invalid input. Please answer Y or N to continue or exit: ')

elif ans == 'y':

ans_val = 0

cont = 1

valid = 0

elif ans == 'n':

ans_val = 0

cont = 0

valid = 0

prompt()

hdulist.close()

如果我在上面的代码中没有遵循典型的Python约定,我很抱歉;我是Python新手。在

经纬度坐标转换xy坐标 python_在Python中使用NewtonRaphson迭代将经纬度转换为xy Mollweide地图坐标...相关推荐

  1. python中可迭代对象_什么是python中的可迭代对象(iterable object)?

    我们经常在打印报错信息中和英文的文档中看到iter这个词根,可以组合成iterable/iterate等派生词.这个iter可以翻译成"迭代",这样iterable object的 ...

  2. python中什么是迭代?

    python中什么是迭代? *如果给定一个list或tuple,我们可以通过for循环来遍历这个list或tuple,这种遍历我们称为迭代(Iteration). 在Python中,迭代是通过for ...

  3. 动量策略 python_在Python中使用动量通道进行交易

    动量策略 python Most traders use Bollinger Bands. However, price is not normally distributed. That's why ...

  4. pypypy python_聊聊Python中的pypy

    PyPy是一个虚拟机项目,主要分为两部分:一个Python的实现和 一个编译器 PyPy的第一部分: 用Python实现的Python 其实这么说并不准确,准确得说应该是用rPython实现的Pyth ...

  5. global在python_在Python中使用“global”关键字

    在Python中使用"global"关键字 我从阅读文档中了解到,Python有一个单独的函数命名空间,如果我想在该函数中使用全局变量,我需要使用global. 我正在使用Pyth ...

  6. 怎么把竖列中的数相加python_关于python中pandas.DataFrame对行与列求和及添加新行与列示例代码...

    pandas是python环境下最有名的数据统计包,而DataFrame翻译为数据框,是一种数据组织方式,这篇文章主要给大家介绍了关于python中pandas.DataFrame对行与列求和及添加新 ...

  7. 取模是什么意思python_原来Python中的取模运算方法竟然是这样的!

    今天小编就为大家分享一篇Python中的取模运算方法,具有很好的参考价值,希望对大家有所帮助.一起跟随小编过来看看吧 所谓取模运算,就是计算两个数相除之后的余数,符号是%.如a % b就是计算a除以b ...

  8. pdf 改变页面大小 python_在Python中使用PDF:阅读和拆分

    Python部落(python.freelycode.com)组织翻译,禁止转载,欢迎转发. PDF 文档格式 今天,可移植文档格式(PDF)属于最常用的数据格式. 1990年,Adobe定义了PDF ...

  9. 离散小波变换 python_用python中的“haar”小波对图像进行离散小波变换

    我试图在python中的图像上应用haar小波.这是代码from pywt import dwt2, idwt2 img = cv2.imread('xyz.png') cA, (cH, cV, cD ...

最新文章

  1. 什么样的代码为好代码?好代码的科学定义
  2. C++知识点6——数组与指针初步
  3. Linux和Windows栈帧机器码,栈溢出原理与 shellcode 开发
  4. PHP基础知识(二)
  5. 面试金典--min栈的实现
  6. 90后女科学家,四年完成清华大学硕博连读,解决多个世界级难题
  7. 公安网络安全部门封杀的2000家淘宝钓鱼网站
  8. MFC m_pMainWnd
  9. mysql下载了解压版怎么_Win10安装MySQL5.7版本 解压缩版方法
  10. 【数据结构】【cfs_rq】【task_struct】【sched_domain】
  11. 服务器wifi无线放大器,旧路由器改wifi放大器详细教程【图】
  12. 苹果悄悄在硅谷买楼 以古希腊诸神命名 据说跟造车有关
  13. xp系统简单tcpip服务器,Win XP系统下添加打印机的方式手工添加TCP/IP端口
  14. 区块链入门二:概念篇
  15. 草根互联网经理掀起的中国性解放运动
  16. 智能车浅谈——抗干扰技术软件篇
  17. WPS 两个 word 合并
  18. SQL——MySQL Driver
  19. AI System 人工智能系统 TVM深度学习编译器 DSL IR优化 计算图 编译 优化 内存内核调度优化 DAG 图优化 DFS TaiChi 函数注册机 Registry
  20. WPF中的渐变色动画

热门文章

  1. JDK 环境变量设置参考
  2. JAVA基础12-继承(3)
  3. slb健康检查方式_SLB健康检查也是“正常”-问答-阿里云开发者社区-阿里云
  4. mysql集群session_集群/分布式环境下5种session处理策略
  5. numpy 修改数组维度
  6. numpy 读写 npy npz 文件
  7. TensorFlow 制作自己的TFRecord数据集
  8. 大数据分布式集群搭建(9)
  9. 目标检测--Object Detection via Aspect Ratio and Context Aware
  10. 如何保证缓存和数据库的双写的一致性