-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The get_info API returns run_statuses and end_statuses.
- Loading branch information
wei
committed
Aug 23, 2024
1 parent
89e8491
commit 80aeb0d
Showing
6 changed files
with
268 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import subprocess | ||
|
||
import h5py | ||
|
||
|
||
def remove_metadata(input_file, output_file): | ||
with h5py.File(input_file, "r") as src, h5py.File(output_file, "w") as dst: | ||
|
||
def copy_attrs(src_obj, dst_obj): | ||
# 不复制属性(元数据) | ||
pass | ||
|
||
def copy_group(src_group, dst_group): | ||
copy_attrs(src_group, dst_group) | ||
for name, item in src_group.items(): | ||
if isinstance(item, h5py.Group): | ||
new_group = dst_group.create_group(name) | ||
copy_group(item, new_group) | ||
elif isinstance(item, h5py.Dataset): | ||
dst_group.create_dataset(name, data=item[...]) | ||
|
||
copy_group(src, dst) | ||
|
||
|
||
def get_file_md5(file) -> str: | ||
""" | ||
Get the file md5 | ||
Args: | ||
file (str): The path of the gzip input file. | ||
""" | ||
try: | ||
result = subprocess.run(["md5sum", file], capture_output=True, text=True) | ||
return result.stdout.split(" ")[0] | ||
except Exception as e: | ||
return "" | ||
|
||
|
||
if __name__ == "__main__": | ||
f1 = "11.hdf5.gz" | ||
f2 = "22.hdf5.gz" | ||
f3 = "33.hdf5" # 输出去除元数据后的 HDF5 文件路径 | ||
f4 = "44.hdf5" # 输出去除元数据后的 HDF5 文件路径 | ||
|
||
md5_f1 = get_file_md5("11.hdf5.gz") | ||
print(md5_f1) | ||
md5_f2 = get_file_md5("22.hdf5.gz") | ||
print(md5_f2) | ||
|
||
# 移除元数据 | ||
remove_metadata(f1, f3) | ||
remove_metadata(f2, f4) | ||
|
||
md5_f3 = get_file_md5(f3) | ||
print(md5_f3) | ||
md5_f4 = get_file_md5(f4) | ||
print(md5_f4) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Tests webapi and things that depend on it | ||
|
||
import pytest | ||
import responses | ||
import tidy3d as td | ||
from tidy3d.web.api.webapi import ( | ||
get_system_config, | ||
) | ||
from tidy3d.web.core.environment import Env | ||
|
||
task_core_path = "tidy3d.web.core.task_core" | ||
api_path = "tidy3d.web.api.webapi" | ||
|
||
Env.dev.active() | ||
|
||
|
||
@pytest.fixture | ||
def set_api_key(monkeypatch): | ||
"""Set the api key.""" | ||
import tidy3d.web.core.http_util as http_module | ||
|
||
monkeypatch.setattr(http_module, "api_key", lambda: "apikey") | ||
monkeypatch.setattr(http_module, "get_version", lambda: td.version.__version__) | ||
|
||
|
||
@pytest.fixture | ||
def mock_get_system_config(monkeypatch, set_api_key): | ||
"""Mocks webapi.get_info.""" | ||
|
||
responses.add( | ||
responses.GET, | ||
f"{Env.current.web_api_endpoint}/tidy3d/system/py/config", | ||
json={ | ||
"data": { | ||
"runStatuses": [], | ||
"endStatuses": [], | ||
} | ||
}, | ||
status=200, | ||
) | ||
|
||
|
||
@responses.activate | ||
def test_system_config(mock_get_system_config): | ||
info = get_system_config() | ||
assert info is not None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
"""Tidy3d system config.""" | ||
|
||
from __future__ import annotations | ||
|
||
from typing import Optional | ||
|
||
from pydantic.v1 import Extra, Field | ||
|
||
from .http_util import http | ||
from .types import Tidy3DResource | ||
|
||
|
||
class SystemConfig(Tidy3DResource, extra=Extra.allow): | ||
"""Tidy3D system config.""" | ||
|
||
end_statuses: Optional[tuple] = Field( | ||
None, | ||
title="End Statuses", | ||
description="Tuple of status keys that signify that the task has completed.", | ||
alias="endStatuses", | ||
) | ||
run_statuses: Optional[tuple] = Field( | ||
None, | ||
title="Run Statuses", | ||
description="Tuple of ordered status keys that signify that the task is in progress.", | ||
alias="runStatuses", | ||
) | ||
|
||
@classmethod | ||
def get(cls): | ||
"""Get user SystemConfig information. | ||
Parameters | ||
---------- | ||
Returns | ||
------- | ||
systemConfig : SystemConfig | ||
""" | ||
resp = http.get("tidy3d/system/py/config") | ||
if resp: | ||
config = SystemConfig(**resp) | ||
return config | ||
else: | ||
return None |