# -*- coding: utf-8 -*-
"""
Created on Mon Mar 18 11:38:59 2024

@author: zilya
"""
from types import SimpleNamespace
from math import ceil


def param_hardware():
    hardware = SimpleNamespace()
    hardware.gamma = 42.576e6                   # Hz/T    Гиромагнитное отношение водорода
    G_amp_max = 37.8                            # mT/m.   Максимальный градиент
    hardware.G_amp_max = G_amp_max*1e-3*hardware.gamma   # Hz/m.   Максимальный градиент
    G_slew_max = 121                            # T/m/s.  Максимальная скорость нарастания
    hardware.G_slew_max = G_slew_max*hardware.gamma      # Hz/m/s. Максимальная скорость нарастания
    hardware.rf_raster_time = 1e-6              # s.      Растр РЧ импульса
    hardware.grad_raster_time = 10e-6           # s.      Растр градиентов
    tau_max = hardware.G_amp_max/hardware.G_slew_max              # s.      Максимальное время нарастания градиента с учетом макс скорости нарастания
    print(tau_max)
    hardware.tau_max = ceil(tau_max/ hardware.grad_raster_time)*hardware.grad_raster_time
    hardware.B0 = 1.5
    
    hardware.rf_ringdown_time=20e-6
    hardware.rf_dead_time=100e-6
    hardware.adc_dead_time=10e-6
    return hardware
    
def param_rf_SE(sl_thkn):
    gamma = 42.576e6 
    G_amp_max = 37.8                            
    G_amp_max = G_amp_max*1e-3*gamma  
    
    rf_SE = SimpleNamespace()
 
    rf_SE.t_BW_product_ex1 = 3.8
    rf_SE.t_BW_product_ref1 = 4.2
    rf_SE.t_BW_product_ex2 = 3.55
    rf_SE.t_BW_product_ref2 = 3.55

    rf_SE.t_ex1 = 2.05e-3
    rf_SE.t_ref1 = 2.56e-3
    rf_SE.t_ex2 = 3.10e-3
    rf_SE.t_ref2 = 3.88e-3

    if sl_thkn > rf_SE.t_BW_product_ex1/(rf_SE.t_ex1*G_amp_max):  
       rf_SE.t_BW_product_ex = rf_SE.t_BW_product_ex1
       rf_SE.t_BW_product_ref = rf_SE.t_BW_product_ref1
    else:
       rf_SE.t_BW_product_ex = rf_SE.t_BW_product_ex2
       rf_SE.t_BW_product_ref = rf_SE.t_BW_product_ref2
        
    if sl_thkn > rf_SE.t_BW_product_ex2/(rf_SE.t_ex1*G_amp_max):
       rf_SE.t_ex = rf_SE.t_ex1
       rf_SE.t_ref = rf_SE.t_ref1 
    else:
       rf_SE.t_ex = rf_SE.t_ex2
       rf_SE.t_ref = rf_SE.t_ref2
    
    rf_SE.apodization = 0.27
    return rf_SE

def param_rf_HASTE(sl_thkn):
    gamma = 42.576e6 
    G_amp_max = 37.8                            
    G_amp_max = G_amp_max*1e-3*gamma
    
    rf_HASTE = SimpleNamespace()
    
    t_BW_product_ex = 3.55
    t_BW_product_ref = 3.55
     
    t_ex1 = 1.02e-3
    t_ref1 = 1.28e-3
    t_ex2 = 1.28e-3
    t_ref2 = 1.79e-3
    
    if sl_thkn > t_BW_product_ex/(t_ex1*G_amp_max):
        rf_HASTE.t_ex = t_ex1
        rf_HASTE.t_ref = t_ref1 
    else:
        rf_HASTE.t_ex = t_ex2
        rf_HASTE.t_ref = t_ref2
        
    rf_HASTE.t_BW_product_ex = t_BW_product_ex
    rf_HASTE.t_BW_product_ref = t_BW_product_ref
     
    rf_HASTE.apodization = 0.27
    return rf_HASTE
    
def param_rf_GRE():
    rf_GRE = SimpleNamespace()
    
    rf_GRE.t_ex = 0.510e-3                      
    rf_GRE.t_BW_product_ex = 2.13               
    rf_GRE.apodization = 0.3
    return rf_GRE

    
def param_rf_FS():
    rf_FS = SimpleNamespace()
    
    rf_FS.ppm_fat = -3.45
    rf_FS.t_sat = 10e-3
    rf_FS.flip_angle_FS = 90
    return rf_FS

def param_rf_inv():
    rf_inv = SimpleNamespace()
    
    rf_inv.t_inv = 2.56e-3
    rf_inv.t_BW_product_inv = 4.2
    rf_inv.inv_flip_angle = 180
    return rf_inv

def param_rf_sat():
    rf_sat = SimpleNamespace()
    
    rf_sat.t_sat = 0.510e-3                      
    rf_sat.t_BW_product_sat = 2.13                                  
    rf_sat.sat_flip_angle = 90
    return rf_sat

def param_default():
    default = SimpleNamespace()
    default.sl_nb = 1
    default.sl_thkn = 10e-3
    default.sl_gap = 100
    default.slab_thkn = 100e-3
    
    default.FoV_f = 250e-3
    default.FoV_p_image = 250e-3
    default.Nf = 128
    default.Np_image = 128
    default.Nss = 128
    default.BW_pixel = 500
    
    default.TE = 50e-3
    default.N_TE = 1
    default.IE = 10e-3
    default.ETL = 8
    default.contrasts = 2
    default.concats = 1
    default.TR = 1000e-3
    default.TD = 0
    
    default.alpha = 90
    default.beta = 180
    default.spoil_strenght = 4
    default.RF_spoil = 117
    
    default.average = 1
    default.D_scans = 10
    default.ph_over_phase = 0
    default.ph_over_slice = 0
    
    default.TI = 200e-3
    default.N_TI = 1
    default.b = 1000
    return default
    

    