【问题标题】:How to save Python dataset (previously exported from IDL) back to IDL format如何将 Python 数据集(之前从 IDL 导出)保存回 IDL 格式
【发布时间】:2019-06-14 01:14:10
【问题描述】:

我在 IDL 中有一个文件,我使用 scipy 中的 readsav 将其导入 Python,我更改了文件中的一个参数,我想将其导出/保存回原始格式,IDL 可读。

这是我导入它的方式:

from scipy.io.idl import readsav
input = readsav('Original_file.inp')

【问题讨论】:

    标签: python type-conversion export idl-programming-language


    【解决方案1】:

    我还没有测试过这些,但这里有几个选项可以尝试:

    Python 到 IDL/IDL 到 Python 桥

    Python to IDL bridge 提供了一种在 python 中运行 IDL 例程的方法。您可以尝试以下方法

    from idlpy import *
    from scipy.io.idl import readsav
    input = readsav('Original_file.inp')
    **change parameter**
    IDL.run("SAVE, /VARIABLES, FILENAME = 'New_file.sav'")
    

    还有一个IDL to Python bridge,它可能允许您在 IDL 中执行所需的 Python 操作,并跳过所有文件的加载和保存...

    读/写 JSON

    看起来readsav() 只是返回IDL 保存文件内容的字典。我不确定您文件的内容,所以我不知道这是否可行,但也许您可以将其写为 JSON 字符串,

    import json
    from scipy.io.idl import readsav
    input = readsav('Original_file.inp')
    **change parameter**
    with open('New_file.txt', 'w') as outfile:  
        json.dump(modified_input, outfile)
    

    然后使用JSON_PARSE()(文档here)将其读回IDL。

    编写自己的 hack

    如果一切都失败了,您可以查看 Craig Markwardt 的 Unofficial Format Specification of the IDL "SAVE" File,并编写一些自定义代码以直接从 Python 编写 IDL 保存文件。如果不出意外,这将是一个有趣的练习。

    【讨论】:

      猜你喜欢
      • 2015-03-05
      • 1970-01-01
      • 2011-02-19
      • 1970-01-01
      • 1970-01-01
      • 2023-02-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多