python3基于spectral_cube.py抽取ALMA数据的分子谱线供XCLASS使用

本文介绍如何利用Python3的spectral_cube库处理ALMA观测数据,提取分子谱线,并准备供XCLASS进行进一步分析。
摘要由CSDN通过智能技术生成
from astropy.io import fits
from spectral_cube import SpectralCube as spec
import numpy as np
import matplotlib.pyplot as plt
import os
import sys
from astropy.coordinates import SkyCoord
from astropy.wcs import WCS
from astropy.table import Table
import astropy.units as u
import math

names = ['I14498_spw25',
         'I14498_spw27',
         'I14498_spw29',
         'I14498_spw31']

files = '
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
将 TensorFlow 代码转换为 PyTorch 代码,可以按照以下步骤进行: 1. 导入 PyTorch 库和相关模块: ```python import torch import torch.nn.functional as F ``` 2. 将 `tf.cast` 方法替换为 `torch.Tensor.to()` 方法: ```python # TensorFlow 代码 masked_response_function = tf.cast(masked_response_function, dtype=hyper_spectral_image.dtype) # PyTorch 代码 masked_response_function = masked_response_function.to(hyper_spectral_image.dtype) ``` 3. 将 `tf.reshape` 方法替换为 `torch.Tensor.view()` 方法: ```python # TensorFlow 代码 response3x3 = tf.reshape(masked_response_function,[3,3,31]) # PyTorch 代码 response3x3 = masked_response_function.view(3, 3, 31) ``` 4. 将 `tf.tile` 方法替换为 `torch.Tensor.repeat()` 方法: ```python # TensorFlow 代码 responsehxw = tf.tile(response3x3,[h//3,w//3,1]) # PyTorch 代码 responsehxw = response3x3.repeat(h // 3, w // 3, 1) ``` 5. 将 `tf.reduce_sum` 方法替换为 `torch.sum()` 方法: ```python # TensorFlow 代码 response_img = tf.reduce_sum(response_img,axis=-1)/ tf.reduce_sum(responsehxw,axis=-1) # PyTorch 代码 response_img = torch.sum(response_img, dim=-1) / torch.sum(responsehxw, dim=-1) ``` 6. 将 TensorFlow 的 `None` 替换为 PyTorch 的 `None`: ```python # TensorFlow 代码 keepdims=True # PyTorch 代码 keepdim=True ``` 7. 将 TensorFlow 的 `shape` 属性替换为 PyTorch 的 `size()` 或 `shape` 方法: ```python # TensorFlow 代码 batch_size,h,w,c = hyper_spectral_image.shape # PyTorch 代码 batch_size, h, w, c = hyper_spectral_image.size() ``` 最终的 PyTorch 代码如下: ```python import torch import torch.nn.functional as F def simulated_spectral9_camera_spectral_response_function(hyper_spectral_image, masked_response_function): masked_response_function = masked_response_function.to(hyper_spectral_image.dtype) hyper_spectral_image = hyper_spectral_image[:, 1:-1, 1:-1, :] batch_size, h, w, c = hyper_spectral_image.size() response3x3 = masked_response_function.view(3, 3, 31) responsehxw = response3x3.repeat(h // 3, w // 3, 1) response_img = hyper_spectral_image * responsehxw response_img = torch.sum(response_img, dim=-1) / torch.sum(responsehxw, dim=-1, keepdim=True) return response_img ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值