diff --git a/tidy3d/components/data.py b/tidy3d/components/data.py index cf93f611b7..6eddaf3de9 100644 --- a/tidy3d/components/data.py +++ b/tidy3d/components/data.py @@ -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.") diff --git a/tidy3d/components/simulation.py b/tidy3d/components/simulation.py index c19f02da89..569ac4b629 100644 --- a/tidy3d/components/simulation.py +++ b/tidy3d/components/simulation.py @@ -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") diff --git a/tidy3d/convert.py b/tidy3d/convert.py index cc769a0048..848af153ea 100644 --- a/tidy3d/convert.py +++ b/tidy3d/convert.py @@ -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): @@ -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] = { diff --git a/tidy3d/web/webapi.py b/tidy3d/web/webapi.py index 62ba6aa199..cbef4173a8 100644 --- a/tidy3d/web/webapi.py +++ b/tidy3d/web/webapi.py @@ -226,6 +226,10 @@ 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) @@ -233,6 +237,9 @@ def download(task_id: TaskId, simulation: Simulation, path: str = "simulation_da 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") @@ -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. @@ -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 -------