こんにちは、
JMP を使用してスクリプトで hdf5 ファイルを開こうとしています。Open() コマンドを使用して正常に開くことができます。
blobpath = "/Documents/myblob";
dtblob_lis = Open(blobpath);
しかし、どのデータセットを開くかを尋ねるポップアップが表示されます。

質問です。Open() コマンドに、BLOB 内のどのデータ セットを開きたいかを指定して、ポップアップを回避するためのオプションはありますか? よろしくお願いします。
...そしてそのアクションを記録する方法はありますか?
代わりに、h5py を使用します。
非常にスムーズなシンデ JMP18 : )
それが私が最初に試したことです。いいえ、ログや作成されたテーブルにはアクションの記録は見当たりません。
残念ながら、私の組織はまだ JMP18 を採用していません。
これは推測ですが、 HDF5 ファイルの自動オープンに関する議論に基づくと、Python 統合が答えかもしれません。 @briancorcoran
Python でファイルのオープン/変換を管理するために、JMP の Python 統合を使用する必要はありません。必要な入力 (少なくともファイル パス) を受け取り、それを .csv として保存し、その .csv を JMP で開く、コマンド ラインから実行できる Python スクリプトを作成します (Run Program() を使用)。これが、JMP18 より前の JMP で Python を使用した方法です (今でも時々使用しています)。もちろん、バージョン 18 より前の JMP で Python 統合を使用することもできますが、私は気にせずコマンド ラインから実行します。
JSL リストを使用して開くメンバーを指定することにより、HDF5 データセット内の個々の項目を開くことができます。たとえば、私の場合は次のコードが機能しました (ファイル拡張子も指定)。
開く("d:\testdata\HDF5\hdf5data.h5", {"/g2/float"});
あなたの場合は次のようになります:
開く("/Documents/myblob.h5", {"/CSIG_RAW_IMG_OFF/F0/FrameNumbers", "/CSIG_RAW_IMG_OFF/F0/Frames"});
それが役に立つことを願います。
ブライアン・コーコラン
JMP開発
これはまさに私が探していた解決策です。うまくいきました。ありがとうございます。
私は、Python と JMP 17 の間でデータを転送するより高速で効率的な方法を探していました。なぜなら、pandas と JMP はどちらも CSV の読み取り/書き込みがかなり遅く、少なくとも JMP 17 では GetTable() 関数でさえ内部で CSV を使用しているように見えるからです。pandas の to_hdf 関数は、文字列データを HDF 準拠のデータセットに格納する代わりに、カスタムの策略を使用して Numpy 配列を文字列として格納するため機能しません。これは、スペース効率が悪いだけでなく、Python で読み取るように制限されます。
私は、h5py を使用して .h5 テーブルを保存するカスタム概念実証 Python コードと、テーブルを読み取って個別のデータセットから元のテーブルを再構築する 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でCSVとして保存すると20秒、jmpで開くと24秒かかるのに対し、私のスクリプトでは保存に1.7秒、jmpで開くと11.5秒かかりました。さらに、gzip圧縮を使用することで、ファイルサイズは88.8MBから24.5MBに縮小されました。つまり、時間的には70%、スペース的には72%の節約となります。