Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions tidy3d/components/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -767,16 +767,10 @@ def plot_field( # pylint:disable=too-many-arguments, too-many-locals
if "f" in xr_data.coords:
if freq is None:
raise DataError("'freq' must be supplied to plot a FieldMonitor.")
# if len(xr_data.f) == 1:
# field_data = xr_data.isel(f=0)
# else:
field_data = xr_data.sel(f=freq, method="nearest")
elif "t" in xr_data.coords:
if time is None:
raise DataError("'time' must be supplied to plot a FieldMonitor.")
# if len(xr_data.t) == 1:
# field_data = xr_data.isel(t=0)
# else:
field_data = xr_data.sel(t=time, method="nearest")
else:
raise DataError("Field data has neither time nor frequency data, something went wrong.")
Expand Down
20 changes: 10 additions & 10 deletions tidy3d/components/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,16 +170,16 @@ def set_none_to_zero_layers(cls, val):
_structure_names = set_names("structures")
_source_names = set_names("sources")

@pydantic.validator("structures", allow_reuse=True, always=True)
def set_medium_names(cls, val, values):
"""check for intersection of each structure with simulation bounds."""
background_medium = values.get("medium")
all_mediums = [background_medium] + [structure.medium for structure in val]
_, unique_indices = np.unique(all_mediums, return_inverse=True)
for unique_index, medium in zip(unique_indices, all_mediums):
if not medium.name:
medium.name = f"mediums[{unique_index}]"
return val
# @pydantic.validator("structures", allow_reuse=True, always=True)
# def set_medium_names(cls, val, values):
# """check for intersection of each structure with simulation bounds."""
# background_medium = values.get("medium")
# all_mediums = [background_medium] + [structure.medium for structure in val]
# _, unique_indices = np.unique(all_mediums, return_inverse=True)
# for unique_index, medium in zip(unique_indices, all_mediums):
# if not medium.name:
# medium.name = f"mediums[{unique_index}]"
# return val

# make sure all names are unique
_unique_structure_names = assert_unique_names("structures")
Expand Down
7 changes: 4 additions & 3 deletions tidy3d/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,13 +477,14 @@ def load_old_monitor_data(simulation: Simulation, data_file: str) -> SolverDataD
with h5py.File(data_file, "r") as f_handle:
for monitor in simulation.monitors:
name = monitor.name
data_group = f_handle[name]

if isinstance(monitor, FreqMonitor):
sampler_values = np.array(monitor.freqs)
sampler_label = "f"

elif isinstance(monitor, TimeMonitor):
sampler_values = np.array(f_handle[name]["tmesh"]).ravel()
sampler_values = np.array(data_group["tmesh"]).ravel()
sampler_label = "t"

if isinstance(monitor, AbstractFieldMonitor):
Expand All @@ -503,11 +504,11 @@ def load_old_monitor_data(simulation: Simulation, data_file: str) -> SolverDataD
}

elif isinstance(monitor, AbstractFluxMonitor):
values = np.array(f_handle[name]["flux"]).ravel()
values = np.array(data_group["flux"]).ravel()
data_dict[name] = {"values": values, sampler_label: sampler_values}

elif isinstance(monitor, ModeMonitor):
values = np.array(f_handle[name]["mode_amps"])
values = np.array(data_group["mode_amps"])
values = np.swapaxes(values, 1, 2) # put frequency at last axis
mode_index = np.arange(values.shape[1])
data_dict[name] = {
Expand Down
11 changes: 9 additions & 2 deletions tidy3d/web/webapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,20 @@ def download(task_id: TaskId, simulation: Simulation, path: str = "simulation_da
Original simulation.
path : str = "simulation_data.hdf5"
Download path to .hdf5 data file (including filename).

Note
----
To load downloaded results into data, call :meth:`load` with option `replace_existing=False`.
"""

task_info = get_info(task_id)
if task_info.status in ("error", "diverged", "deleted", "draft"):
raise WebError(f"can't download task '{task_id}', status = '{task_info.status}'")

directory, _ = os.path.split(path)
if directory and not os.path.exists(directory):
raise WebError(f"Can't download to path '{path}', directory {directory} doesn't exist.")

sim_file = os.path.join(directory, "simulation.json")
mon_file = os.path.join(directory, "monitor_data.hdf5")
log_file = os.path.join(directory, "tidy3d.log")
Expand Down Expand Up @@ -276,7 +283,7 @@ def load(
task_id: TaskId,
simulation: Simulation,
path: str = "simulation_data.hdf5",
replace_existing=True,
replace_existing : bool = True,
) -> SimulationData:
"""Download and Load simultion results into :class:`.SimulationData` object.

Expand All @@ -289,7 +296,7 @@ def load(
path : str
Download path to .hdf5 data file (including filename).
replace_existing: bool = True
Downloads even if file exists (overwriting the existing).
Downloads the data even if path exists (overwriting the existing).

Returns
-------
Expand Down