1616objects"""
1717import datetime
1818import importlib
19+ import pathlib
1920import os
2021from typing import Any
2122
2526
2627
2728def save_netCDF (
28- directory_path : str | None ,
29+ directory_path : str | pathlib . Path | None ,
2930 file_name : str | None ,
3031 IDS : IDSToplevel ,
3132):
@@ -42,14 +43,27 @@ def save_netCDF(
4243 Returns:
4344 None
4445 """
46+ from torax ._src .config .config_loader import torax_path
47+ directory_path = pathlib .Path (directory_path ) if isinstance (directory_path , str ) else directory_path
48+ if not directory_path .is_dir ():
49+ #Checks that the directory can be found.
50+ new_path = torax_path ().joinpath (directory_path )
51+ if not new_path .is_dir ():
52+ raise ValueError (f'Directory { directory_path } could not be found. If it is a relative path, it'
53+ ' could not be resolved relative to the working directory'
54+ f' { os .getcwd ()} or the Torax directory { torax_path ()} .'
55+ )
56+ directory_path = new_path
57+
4558 if directory_path is None :
46- directory_path = " torax/data/third_party/geo"
59+ directory_path = torax_path (). joinpath ( ' torax/data/third_party/geo' )
4760 if file_name is None :
4861 date_str = datetime .datetime .now ().strftime ("%Y%m%d_%H%M%S" )
4962 file_name = "IDS_file_" + date_str
5063 filepath = os .path .join (directory_path , file_name ) + ".nc"
5164 with imas .DBEntry (uri = filepath , mode = "w" ) as netcdf_entry :
5265 netcdf_entry .put (ids = IDS )
66+ print (f'Successfully saved file { filepath } ' )
5367
5468
5569def load_IMAS_data (uri : str , ids_name : str ) -> IDSToplevel :
0 commit comments