你好,
我正在嘗試使用 JMP 透過腳本開啟 hdf5 檔案。我可以使用 Open() 命令成功打開它:
blobpath = "/Documents/myblob";
dtblob_lis = Open(blobpath);
但我收到一個彈出窗口,詢問我要開啟哪個資料集:

我的問題: Open() 命令中是否有一個選項可以用來指定我希望打開的 blob 中的哪個資料集,並避免彈出視窗?謝謝。
作為替代方案:使用 h5py。
非常順利的信德 JMP18 
這是我嘗試的第一件事。否,日誌或建立的表中沒有明顯的操作記錄。
這是一個猜測,但基於自動開啟 hdf5 檔案的討論,Python 整合可能是答案。 @briancorcoran
您不必使用 JMP 的 Python 整合來使用 Python 管理檔案開啟/轉換,建立一個可以從命令列運行的 python 腳本(使用 Run Program()),該腳本接受您需要的輸入(至少檔案路徑),保存將其儲存為.csv,然後在JMP 中開啟該.csv。這就是我在 JMP 中的 JMP18 之前使用 Python 的方式(現在仍然時不時地這樣做)。您當然可以嘗試在 18 之前的版本中使用 JMP 的 Python 集成,但我不會打擾,只是從命令行運行它。
您可以使用 JSL 清單指定要開啟的成員來開啟 HDF5 資料集中的各個項目。例如,以下內容對我有用(也指定檔案副檔名):
open("d:\testdata\HDF5\hdf5data.h5", {"/g2/float"});
在你的情況下,它可能看起來像:
open("/Documents/myblob.h5", {"/CSIG_RAW_IMG_OFF/F0/FrameNumbers", "/CSIG_RAW_IMG_OFF/F0/Frames"});
我希望這有幫助。
布萊恩·科科倫
JMP開發
我一直在尋找在 Python 和 JMP 17 之間傳輸資料的更快、更有效的方法,因為 Pandas 和 JMP 在讀取/寫入 CSV 時都非常慢,甚至 GetTable() 函數似乎也在後台使用 CSV,至少在 JMP 17 中是如此。 Pandas 的 to_hdf 函數不起作用,因為它沒有將字串資料儲存在符合 HDF 的資料集中,而是使用一些自訂的詭計將 Numpy 陣列儲存為字串,這不僅空間效率低下,而且還會鎖定您使用 Python 讀取它。
我編寫了一個自訂概念驗證 Python 程式碼,使用 h5py 保存 .h5 表,並編寫了 JSL 程式碼讀取該表並從單獨的資料集重建原始表。
import pandas as pd
import numpy as np
from pathlib import Path
import h5py
from time import perf_counter
last_time = perf_counter()
compression = "gzip"
def log_time(msg):
global last_time
current_time = perf_counter()
elapsed_time = current_time - last_time
print(f"{elapsed_time:1.3f} s: {msg}")
last_time = current_time
# read dataframe (just for the development example)
df = pd.read_csv(Path(__file__).parent / "my_table.csv")
log_time("Read df")
string_columns = df.select_dtypes(include=["object"]).columns
# min_itemsize = {col: df[col].str.len().max() for col in string_columns}
max_string_length = np.max([df[col].str.len().max() for col in string_columns]) if len(string_columns) > 0 else 1
max_string_column_length = np.max([len(col) for col in string_columns]) if len(string_columns) > 0 else 1
log_time("max_string_length =" + str(max_string_length))
float_columns = df.select_dtypes(include=["float"]).columns
max_float_column_length = np.max([len(col) for col in float_columns]) if len(float_columns) > 0 else 1
log_time("max_float_column_length =" + str(max_float_column_length))
int_columns = df.select_dtypes(include=["int"]).columns
max_int_column_length = np.max([len(col) for col in int_columns]) if len(int_columns) > 0 else 1
log_time("max_int_column_length =" + str(max_int_column_length))
max_column_length = np.max(
[max_float_column_length, max_int_column_length, max_string_column_length]
)
log_time("max_column_length =" + str(max_column_length))
file = h5py.File(Path(__file__).parent / "sample.h5", "w")
log_time("Opened h5 file")
string_data = df[string_columns].astype(str).values
log_time("Converted string data to str")
string_data_ascii = np.array(
[[s.encode("ascii", "ignore") for s in row] for row in string_data]
)
log_time("Converted string data to ascii")
file.create_dataset(
"string_data",
data=string_data_ascii,
dtype=f"S{max_string_length}",
compression=compression,
)
log_time("Created string_data dataset")
file.create_dataset(
"string_columns",
data=np.array(string_columns, dtype=f"S{max_string_column_length}"),
compression=compression,
)
log_time("Created string_columns dataset")
file.create_dataset(
"float_data", data=df[float_columns].values, dtype="f4", compression=compression
)
log_time("Created float_data dataset")
file.create_dataset(
"float_columns",
data=np.array(float_columns, dtype=f"S{max_float_column_length}"),
compression=compression,
)
log_time("Created float_columns dataset")
file.create_dataset(
"int_data", data=df[int_columns].values, dtype="i4", compression=compression
)
log_time("Created int_data dataset")
file.create_dataset(
"int_columns",
data=np.array(int_columns, dtype=f"S{max_int_column_length}"),
compression=compression,
)
log_time("Created int_columns dataset")
file.create_dataset(
"column_order",
data=np.array(
df.columns,
dtype=f"S{max_column_length}",
),
compression=compression,
)
log_time("Created column_order dataset")
file.flush()
file.close
CloseAll(datatables, nosave);
last_time = TickSeconds();
log_time = Function({msg},
now = TickSeconds();
print(Char(now - last_time) || " - " || Char(msg));
last_time = now;
);
hdf5_file_path = "my_table.h5";
dataset_names = {
// "/column_order",
"/float_columns",
"/float_data",
"/int_columns",
"/int_data",
"/string_columns",
"/string_data"
};
// Open the hdf file
hdf5_file = Open(hdf5_file_path, dataset_names, invisible);
log_time("Opened HDF5 file: " || hdf5_file_path);
// Get list
// columns = As Column(DataTable("-column_order"), "Column 1"n) << get as matrix;
string_columns = As Column(DataTable("-string_columns"), "Column 1"n) << get as matrix;
float_columns = As Column(DataTable("-float_columns"), "Column 1"n) << get as matrix;
int_columns = As Column(DataTable("-int_columns"), "Column 1"n) << get as matrix;
Close(DataTable("-string_columns"), nosave);
Close(DataTable("-float_columns"), nosave);
Close(DataTable("-int_columns"), nosave);
log_time("Got columns");
dt_int = DataTable("-int_data");
ForEach({cname, i}, int_columns,
Column(dt_int, "Column " || Char(i)) << SetName(cname)
);
log_time("Assembled int table");
dt_float = DataTable("-float_data");
ForEach({cname, i}, float_columns,
Column(dt_float, "Column " || Char(i)) << SetName(cname)
);
log_time("Assembled float table");
dt_string = DataTable("-string_data");
ForEach({cname, i}, string_columns,
Column(dt_string, "Column " || Char(i)) << SetName(cname)
);
log_time("Assembled string table");
dt_string << Update(
With( dt_int ),
Replace Columns in Main Table( None )
);
Close(dt_int, nosave);
dt_string << Update(
With( dt_float ),
Replace Columns in Main Table( None )
);
Close(dt_float, nosave);
log_time("Combined table");
// For( i = N Items( columns ), i >= 1, i--,
// Eval( Parse( "combined_dt << Move Selected Columns(\!"" || columns[i] || "\!"n, To first )" ) )
// );
// log_time("Moved columns");
dt_string << SetName("my_table");
dt_string << ShowWindow(1);
我禁用了嘗試重建原始列順序的程式碼,因為對於寬表來說,這非常非常慢。另外,請注意,我沒有考慮沒有特定類型列的情況。如果您在乎這一點,那麼在 JSL 端需要做一些額外的工作。
結果:對於一個包含 80 行、115,791 列的資料表,通常情況下,Pandas 需要 20 秒才能將其儲存為 csv 文件,JMP 需要 24 秒才能打開,而我的腳本儲存只需 1.7 秒,JMP 則需要 11.5 秒才能開啟。此外,使用 gzip 壓縮後,檔案大小從 88.8 MB 減少到 24.5 MB。這意味著時間節省了 70%,空間節省了 72%。