# Path: imas_utility/idsinstance.py
# class ImasObject:
#     def __init__(self, shot, run, user, machine):
#         assert isinstance(shot, int)
#         self.shot = shot
# 
#         assert isinstance(run, int)
#         self.run = run
# 
#         if user is None:
#             self.user = os.getenv('USER')
#             self.local_data_base = False
#         else:
#             assert isinstance(user, str)
#             self.user = user
#             self.local_data_base = True
# 
#         if machine is None:
#             self.machine = 'iter'
#         else:
#             assert isinstance(machine, str)
#             self.machine = machine
# 
#         self.build_imas_pointer()
# 
#     def build_imas_pointer(self):
#         try:
#             if self.local_data_base is True:
#                 self.imas_pointer = pyual.Client(self.shot, self.run, user=self.user, machine=self.machine)
#             else:
#                 self.imas_pointer = pyual.Client(self.shot, self.run)
#         except:
#             raise IdsLoadError('IDS for shot ' + str(self.shot) + ', @ run ' + str(self.run) +
#                                ' could not be found. Check input, local idsdb and common idsdb')
# 
# Path: utility/exceptions.py
# class IdsAttributeLoadError(Exception):
#     def __init__(self, *args, **kwargs):
#         pass
# 
#     @staticmethod
#     def __new__(*args, **kwargs):
#         """ Create and return a new object.  See help(type) for accurate signature. """
#         pass
# 
# Path: utility/exceptions.py
# class IdsInstanceLoadError(Exception):
#     def __init__(self, *args, **kwargs):
#         pass
# 
#     @staticmethod
#     def __new__(*args, **kwargs):
#         """ Create and return a new object.  See help(type) for accurate signature. """
#         pass


from imas_utility.idsinstance import ImasObject
from scipy.interpolate import interp2d
from utility.exceptions import IdsAttributeLoadError
from utility.exceptions import IdsInstanceLoadError
import numpy as np
        super().__init__(shot, run, user, machine)
        self.load_equilibrium_ids()

    def load_equilibrium_ids(self):
        try:
            self.equilibrium = self.imas_pointer.get('equilibrium')
        except:
            raise IdsInstanceLoadError('Equilibrium IDS not found in shot ' + str(self.shot) +
                                       ' at run ' + str(self.run))

    def get_time_index(self, time):
        try:
            time_array = self.equilibrium.time
        except:
            raise IdsAttributeLoadError('No time array available for the requested Shot: ' +
                                        str(self.shot) + ' and Run: ' + str(self.run) + ' in equilibrium IDS.')

        if (time_array[time_array.argmin()] <= time) and (time_array[time_array.argmax()] >= time):
            return (np.abs(time_array - time)).argmin()
        else:
            raise ValueError('Time value : '+str(time)+' is out of bound. Min time instance is ' +
                             str(time_array[time_array.argmin]) + '. Max time instance is : ' +
                             str(time_array[time_array.argmax]))

    def get_2d_equilibrium_grid(self, time):
        time_index = self.get_time_index(time)
        try:
            return self.equilibrium.time_slice[time_index].profiles_2d[0].r, \
                   self.equilibrium.time_slice[time_index].profiles_2d[0].z
        except:

# Path: imas_utility/idsinstance.py
# class ImasObject:
#     def __init__(self, shot, run, user, machine):
#         assert isinstance(shot, int)
#         self.shot = shot
# 
#         assert isinstance(run, int)
#         self.run = run
# 
#         if user is None:
#             self.user = os.getenv('USER')
#             self.local_data_base = False
#         else:
#             assert isinstance(user, str)
#             self.user = user
#             self.local_data_base = True
# 
#         if machine is None:
#             self.machine = 'iter'
#         else:
#             assert isinstance(machine, str)
#             self.machine = machine
# 
#         self.build_imas_pointer()
# 
#     def build_imas_pointer(self):
#         try:
#             if self.local_data_base is True:
#                 self.imas_pointer = pyual.Client(self.shot, self.run, user=self.user, machine=self.machine)
#             else:
#                 self.imas_pointer = pyual.Client(self.shot, self.run)
#         except:
#             raise IdsLoadError('IDS for shot ' + str(self.shot) + ', @ run ' + str(self.run) +
#                                ' could not be found. Check input, local idsdb and common idsdb')
# 
# Path: utility/exceptions.py
# class IdsAttributeLoadError(Exception):
#     def __init__(self, *args, **kwargs):
#         pass
# 
#     @staticmethod
#     def __new__(*args, **kwargs):
#         """ Create and return a new object.  See help(type) for accurate signature. """
#         pass
# 
# Path: utility/exceptions.py
# class IdsInstanceLoadError(Exception):
#     def __init__(self, *args, **kwargs):
#         pass
# 
#     @staticmethod
#     def __new__(*args, **kwargs):
#         """ Create and return a new object.  See help(type) for accurate signature. """
#         pass


# Path: imas_utility/idsequilibrium.py
from imas_utility.idsinstance import ImasObject
from scipy.interpolate import interp2d
from utility.exceptions import IdsAttributeLoadError
from utility.exceptions import IdsInstanceLoadError
import numpy as np

        super().__init__(shot, run, user, machine)
        self.load_equilibrium_ids()

    def load_equilibrium_ids(self):
        try:
            self.equilibrium = self.imas_pointer.get('equilibrium')
        except:
            raise IdsInstanceLoadError('Equilibrium IDS not found in shot ' + str(self.shot) +
                                       ' at run ' + str(self.run))

    def get_time_index(self, time):
        try:
            time_array = self.equilibrium.time
        except:
            raise IdsAttributeLoadError('No time array available for the requested Shot: ' +
                                        str(self.shot) + ' and Run: ' + str(self.run) + ' in equilibrium IDS.')

        if (time_array[time_array.argmin()] <= time) and (time_array[time_array.argmax()] >= time):
            return (np.abs(time_array - time)).argmin()
        else:
            raise ValueError('Time value : '+str(time)+' is out of bound. Min time instance is ' +
                             str(time_array[time_array.argmin]) + '. Max time instance is : ' +
                             str(time_array[time_array.argmax]))

    def get_2d_equilibrium_grid(self, time):
        time_index = self.get_time_index(time)
        try:
            return self.equilibrium.time_slice[time_index].profiles_2d[0].r, \
                   self.equilibrium.time_slice[time_index].profiles_2d[0].z
        except:

            raise IdsAttributeLoadError('There is no R,Z grid data in equilibrium IDS @ Shot: ' +