|
68 | 68 | "VOLUME_MESH": "VolumeMesher", |
69 | 69 | } |
70 | 70 |
|
| 71 | +# map task_type to default data filename |
| 72 | +DEFAULT_DATA_FILENAME = { |
| 73 | + "FDTD": "simulation_data.hdf5", |
| 74 | + "MODE_SOLVER": "simulation_data.hdf5", |
| 75 | + "MODE": "simulation_data.hdf5", |
| 76 | + "EME": "simulation_data.hdf5", |
| 77 | + "HEAT": "simulation_data.hdf5", |
| 78 | + "HEAT_CHARGE": "simulation_data.hdf5", |
| 79 | + "VOLUME_MESH": "simulation_data.hdf5", |
| 80 | + "COMPONENT_MODELER": "cm_data.hdf5", |
| 81 | + "TERMINAL_COMPONENT_MODELER": "cm_data.hdf5", |
| 82 | + "RF": "cm_data.hdf5", |
| 83 | +} |
| 84 | + |
| 85 | + |
| 86 | +def _get_default_path(task_id: str, provided_path: PathLike) -> Path: |
| 87 | + """Get the appropriate default path based on task type. |
| 88 | +
|
| 89 | + If the user provided a non-default path, returns it as-is. |
| 90 | + Otherwise, returns the task-type-specific default filename. |
| 91 | +
|
| 92 | + Parameters |
| 93 | + ---------- |
| 94 | + task_id : str |
| 95 | + Unique identifier of task on server. |
| 96 | + provided_path : PathLike |
| 97 | + Path provided by the user. |
| 98 | +
|
| 99 | + Returns |
| 100 | + ------- |
| 101 | + Path |
| 102 | + The appropriate path to use for this task type. |
| 103 | + """ |
| 104 | + path = Path(provided_path) |
| 105 | + |
| 106 | + # If user provided a custom path (not the generic default), respect it |
| 107 | + if path.name not in {"simulation_data.hdf5", "simulation_data.hdf5.gz"}: |
| 108 | + return path |
| 109 | + |
| 110 | + # Determine task type |
| 111 | + if _is_modeler_batch(task_id): |
| 112 | + task_type = "RF" |
| 113 | + else: |
| 114 | + task_info = get_info(task_id) |
| 115 | + task_type = task_info.taskType |
| 116 | + |
| 117 | + # Get the task-type-specific default filename |
| 118 | + default_filename = DEFAULT_DATA_FILENAME.get(task_type, "simulation_data.hdf5") |
| 119 | + |
| 120 | + # Preserve .gz extension if present |
| 121 | + if path.name.endswith(".gz") and not default_filename.endswith(".gz"): |
| 122 | + default_filename += ".gz" |
| 123 | + |
| 124 | + return path.with_name(default_filename) |
| 125 | + |
71 | 126 |
|
72 | 127 | def _get_url(task_id: str) -> str: |
73 | 128 | """Get the URL for a task on our server.""" |
@@ -1018,15 +1073,10 @@ def download( |
1018 | 1073 | Optional callback function called when downloading file with ``bytes_in_chunk`` as argument. |
1019 | 1074 |
|
1020 | 1075 | """ |
1021 | | - path = Path(path) |
| 1076 | + # Get the appropriate default path based on task type |
| 1077 | + path = _get_default_path(task_id, path) |
1022 | 1078 |
|
1023 | 1079 | if _is_modeler_batch(task_id): |
1024 | | - # Use a more descriptive default filename for component modeler downloads. |
1025 | | - # If the caller left the default as 'simulation_data.hdf5', prefer 'cm_data.hdf5'. |
1026 | | - # TODO: seems like the default should then be maybe set to None and defined somewhere else |
1027 | | - # per task type? |
1028 | | - if path.name == "simulation_data.hdf5": |
1029 | | - path = path.with_name("cm_data.hdf5") |
1030 | 1080 | BatchTask(task_id).get_data_hdf5( |
1031 | 1081 | remote_data_file_gz=CM_DATA_HDF5_GZ, |
1032 | 1082 | to_file=path, |
@@ -1182,14 +1232,11 @@ def load( |
1182 | 1232 | Union[:class:`.SimulationData`, :class:`.HeatSimulationData`, :class:`.EMESimulationData`] |
1183 | 1233 | Object containing simulation data. |
1184 | 1234 | """ |
1185 | | - path = Path(path) |
1186 | | - # For component modeler batches, default to a clearer filename if the default was used. |
1187 | | - if ( |
1188 | | - task_id |
1189 | | - and _is_modeler_batch(task_id) |
1190 | | - and path.name in {"simulation_data.hdf5", "simulation_data.hdf5.gz"} |
1191 | | - ): |
1192 | | - path = path.with_name(path.name.replace("simulation", "cm")) |
| 1235 | + # Get the appropriate default path based on task type |
| 1236 | + if task_id is not None: |
| 1237 | + path = _get_default_path(task_id, path) |
| 1238 | + else: |
| 1239 | + path = Path(path) |
1193 | 1240 |
|
1194 | 1241 | if task_id is None: |
1195 | 1242 | if not path.exists(): |
|
0 commit comments