<s> from __future__ import print_function , division <EOL> import numpy as np <EOL> from astropy . table import Table , Column <EOL> from . . grid . amr_grid import AMRGridView <EOL> from . . util . functions import B_nu , random_id , FreezableClass , is_numpy_array , bool2str , str2bool , monotonically_increasing <EOL> from . . util . integrate import integrate_loglog <EOL> from . . util . validator import validate_scalar <EOL> from astropy import log as logger <EOL> def read_source ( handle ) : <EOL> source_type = handle . attrs [ '<STR_LIT:type>' ] . decode ( '<STR_LIT:ascii>' ) <EOL> if source_type == '<STR_LIT>' : <EOL> return SpotSource . read ( handle ) <EOL> elif source_type == '<STR_LIT>' : <EOL> return PointSource . read ( handle ) <EOL> elif source_type == '<STR_LIT>' : <EOL> return PointSourceCollection . read ( handle ) <EOL> elif source_type == '<STR_LIT>' : <EOL> return SphericalSource . read ( handle ) <EOL> elif source_type == '<STR_LIT>' : <EOL> return ExternalSphericalSource . read ( handle ) <EOL> elif source_type == '<STR_LIT>' : <EOL> return ExternalBoxSource . read ( handle ) <EOL> elif source_type == '<STR_LIT>' : <EOL> return MapSource . read ( handle ) <EOL> elif source_type == '<STR_LIT>' : <EOL> return PlaneParallelSource . read ( handle ) <EOL> else : <EOL> raise ValueError ( "<STR_LIT>" . format ( source_type ) ) <EOL> class Source ( FreezableClass ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , name = None , peeloff = True , ** kwargs ) : <EOL> if name : <EOL> self . name = name <EOL> else : <EOL> self . name = random_id ( length = <NUM_LIT:8> ) <EOL> self . peeloff = peeloff <EOL> self . luminosity = None <EOL> self . spectrum = None <EOL> self . temperature = None <EOL> self . _freeze ( ) <EOL> for kwarg in kwargs : <EOL> self . __setattr__ ( kwarg , kwargs [ kwarg ] ) <EOL> @ property <EOL> def name ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _name <EOL> @ name . setter <EOL> def name ( self , value ) : <EOL> self . _name = value <EOL> @ property <EOL> def luminosity ( self ) : <EOL> '''<STR_LIT>''' <EOL> return self . _luminosity <EOL> @ luminosity . setter <EOL> def luminosity ( self , value ) : <EOL> if value is not None : <EOL> validate_scalar ( '<STR_LIT>' , value , domain = '<STR_LIT>' ) <EOL> self . _luminosity = value <EOL> def _read_luminosity ( self , handle ) : <EOL> self . luminosity = handle . attrs [ '<STR_LIT>' ] <EOL> def _write_luminosity ( self , handle ) : <EOL> handle . attrs [ '<STR_LIT>' ] = self . luminosity <EOL> @ property <EOL> def temperature ( self ) : <EOL> '''<STR_LIT>''' <EOL> return self . _temperature <EOL> @ temperature . setter <EOL> def temperature ( self , value ) : <EOL> if value is not None : <EOL> if hasattr ( self , '<STR_LIT>' ) and self . _spectrum is not None : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> validate_scalar ( '<STR_LIT>' , value , domain = '<STR_LIT>' ) <EOL> self . _temperature = value <EOL> @ property <EOL> def spectrum ( self ) : <EOL> '''<STR_LIT>''' <EOL> return self . _spectrum <EOL> @ spectrum . setter <EOL> def spectrum ( self , value ) : <EOL> if value is not None : <EOL> if hasattr ( self , '<STR_LIT>' ) and self . _temperature is not None : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> if isinstance ( value , Table ) : <EOL> if '<STR_LIT>' not in value . columns : <EOL> raise TypeError ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> if '<STR_LIT>' not in value . columns : <EOL> raise TypeError ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> nu , fnu = value [ '<STR_LIT>' ] , value [ '<STR_LIT>' ] <EOL> elif type ( value ) in ( tuple , list ) : <EOL> if len ( value ) == <NUM_LIT:2> : <EOL> nu , fnu = value <EOL> else : <EOL> raise TypeError ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> if type ( nu ) in [ list , tuple ] : <EOL> nu = np . array ( nu , dtype = float ) <EOL> else : <EOL> nu = nu . astype ( float ) <EOL> if type ( fnu ) in [ list , tuple ] : <EOL> fnu = np . array ( fnu , dtype = float ) <EOL> else : <EOL> fnu = fnu . astype ( float ) <EOL> if not is_numpy_array ( nu ) or nu . ndim != <NUM_LIT:1> : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> if not is_numpy_array ( fnu ) or fnu . ndim != <NUM_LIT:1> : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> if nu . shape != fnu . shape : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> else : <EOL> raise TypeError ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> if len ( np . unique ( nu ) ) != len ( nu ) : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if np . any ( nu <= <NUM_LIT:0.> ) : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if np . any ( fnu < <NUM_LIT:0.> ) : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if np . any ( np . isnan ( nu ) | np . isinf ( nu ) ) : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if np . any ( np . isnan ( fnu ) | np . isinf ( fnu ) ) : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if not monotonically_increasing ( nu ) : <EOL> logger . warn ( "<STR_LIT>" ) <EOL> order = np . argsort ( nu ) <EOL> nu = nu [ order ] <EOL> fnu = fnu [ order ] <EOL> self . _spectrum = { '<STR_LIT>' : nu , '<STR_LIT>' : fnu } <EOL> else : <EOL> self . _spectrum = value <EOL> def _check_all_set ( self ) : <EOL> if self . luminosity is None : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> def get_spectrum ( self , nu_range = None ) : <EOL> self . _check_all_set ( ) <EOL> if self . spectrum is not None : <EOL> nu , fnu = self . spectrum [ '<STR_LIT>' ] , self . spectrum [ '<STR_LIT>' ] <EOL> if nu_range is not None : <EOL> raise NotImplemented ( "<STR_LIT>" ) <EOL> elif self . temperature is not None : <EOL> if nu_range is None : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> nu = np . logspace ( np . log10 ( nu_range [ <NUM_LIT:0> ] ) , np . log10 ( nu_range [ <NUM_LIT:1> ] ) ) <EOL> nu [ <NUM_LIT:0> ] = nu_range [ <NUM_LIT:0> ] <EOL> nu [ - <NUM_LIT:1> ] = nu_range [ <NUM_LIT:1> ] <EOL> fnu = B_nu ( nu , self . temperature ) <EOL> else : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> norm = integrate_loglog ( nu , fnu ) <EOL> return nu , fnu / norm * self . luminosity <EOL> @ classmethod <EOL> def read ( cls , handle ) : <EOL> self = cls ( ) <EOL> self . _read_luminosity ( handle ) <EOL> self . name = handle . attrs [ '<STR_LIT:name>' ] . decode ( '<STR_LIT:utf-8>' ) <EOL> self . peeloff = str2bool ( handle . attrs [ '<STR_LIT>' ] ) <EOL> if handle . attrs [ '<STR_LIT>' ] == b'<STR_LIT>' : <EOL> self . spectrum = Table ( np . array ( handle [ '<STR_LIT>' ] ) ) <EOL> elif handle . attrs [ '<STR_LIT>' ] == b'<STR_LIT>' : <EOL> self . temperature = handle . attrs [ '<STR_LIT>' ] <EOL> elif handle . attrs [ '<STR_LIT>' ] == b'<STR_LIT>' : <EOL> pass <EOL> else : <EOL> raise ValueError ( '<STR_LIT>' % handle . attrs [ '<STR_LIT>' ] ) <EOL> return self <EOL> def write ( self , handle ) : <EOL> self . _check_all_set ( ) <EOL> self . _write_luminosity ( handle ) <EOL> handle . attrs [ '<STR_LIT:name>' ] = np . string_ ( self . name . encode ( '<STR_LIT:utf-8>' ) ) <EOL> handle . attrs [ '<STR_LIT>' ] = np . string_ ( bool2str ( self . peeloff ) ) <EOL> if self . spectrum is not None : <EOL> handle . attrs [ '<STR_LIT>' ] = np . string_ ( '<STR_LIT>' . encode ( '<STR_LIT:utf-8>' ) ) <EOL> table = Table ( ) <EOL> table . add_column ( Column ( data = self . spectrum [ '<STR_LIT>' ] , name = '<STR_LIT>' ) ) <EOL> table . add_column ( Column ( data = self . spectrum [ '<STR_LIT>' ] , name = '<STR_LIT>' ) ) <EOL> table . write ( handle , path = '<STR_LIT>' ) <EOL> elif self . temperature is not None : <EOL> handle . attrs [ '<STR_LIT>' ] = np . string_ ( '<STR_LIT>' . encode ( '<STR_LIT:utf-8>' ) ) <EOL> handle . attrs [ '<STR_LIT>' ] = self . temperature <EOL> else : <EOL> handle . attrs [ '<STR_LIT>' ] = np . string_ ( '<STR_LIT>' . encode ( '<STR_LIT:utf-8>' ) ) <EOL> def has_lte_spectrum ( self ) : <EOL> return self . spectrum is None and self . temperature is None <EOL> class SpotSource ( Source ) : <EOL> def __init__ ( self , name = None , peeloff = True , ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> self . longitude = None <EOL> self . latitude = None <EOL> self . radius = None <EOL> Source . __init__ ( self , name = name , peeloff = peeloff , ** kwargs ) <EOL> def _check_all_set ( self ) : <EOL> Source . _check_all_set ( self ) <EOL> if self . longitude is None : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if self . latitude is None : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if self . radius is None : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if self . has_lte_spectrum ( ) : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> @ classmethod <EOL> def read ( cls , handle ) : <EOL> if not handle . attrs [ '<STR_LIT:type>' ] == b'<STR_LIT>' : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> self = super ( SpotSource , cls ) . read ( handle ) <EOL> self . longitude = handle . attrs [ '<STR_LIT>' ] <EOL> self . latitude = handle . attrs [ '<STR_LIT>' ] <EOL> self . radius = handle . attrs [ '<STR_LIT>' ] <EOL> return self <EOL> def write ( self , handle , name ) : <EOL> self . _check_all_set ( ) <EOL> g = handle . create_group ( name ) <EOL> g . attrs [ '<STR_LIT:type>' ] = np . string_ ( '<STR_LIT>' . encode ( '<STR_LIT:utf-8>' ) ) <EOL> g . attrs [ '<STR_LIT>' ] = self . longitude <EOL> g . attrs [ '<STR_LIT>' ] = self . latitude <EOL> g . attrs [ '<STR_LIT>' ] = self . radius <EOL> Source . write ( self , g ) <EOL> def __setattr__ ( self , attribute , value ) : <EOL> if attribute == '<STR_LIT>' and value is not None : <EOL> validate_scalar ( '<STR_LIT>' , value , domain = [ <NUM_LIT:0> , <NUM_LIT> ] ) <EOL> elif attribute == '<STR_LIT>' and value is not None : <EOL> validate_scalar ( '<STR_LIT>' , value , domain = [ - <NUM_LIT> , <NUM_LIT> ] ) <EOL> elif attribute == '<STR_LIT>' and value is not None : <EOL> validate_scalar ( '<STR_LIT>' , value , domain = '<STR_LIT>' ) <EOL> Source . __setattr__ ( self , attribute , value ) <EOL> class PointSource ( Source ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , name = None , peeloff = True , ** kwargs ) : <EOL> self . position = ( <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:0.> ) <EOL> Source . __init__ ( self , name = name , peeloff = peeloff , ** kwargs ) <EOL> @ property <EOL> def position ( self ) : <EOL> '''<STR_LIT>''' <EOL> return self . _position <EOL> @ position . setter <EOL> def position ( self , value ) : <EOL> if value is not None : <EOL> if type ( value ) in [ tuple , list ] : <EOL> if len ( value ) != <NUM_LIT:3> : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> elif is_numpy_array ( value ) : <EOL> if value . ndim != <NUM_LIT:1> : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if len ( value ) != <NUM_LIT:3> : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> else : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> self . _position = value <EOL> def _check_all_set ( self ) : <EOL> Source . _check_all_set ( self ) <EOL> if self . position is None : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if self . has_lte_spectrum ( ) : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> @ classmethod <EOL> def read ( cls , handle ) : <EOL> if not handle . attrs [ '<STR_LIT:type>' ] == b'<STR_LIT>' : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> self = super ( PointSource , cls ) . read ( handle ) <EOL> self . position = ( handle . attrs [ '<STR_LIT:x>' ] , handle . attrs [ '<STR_LIT:y>' ] , handle . attrs [ '<STR_LIT:z>' ] ) <EOL> return self <EOL> def write ( self , handle , name ) : <EOL> self . _check_all_set ( ) <EOL> g = handle . create_group ( name ) <EOL> g . attrs [ '<STR_LIT:type>' ] = np . string_ ( '<STR_LIT>' . encode ( '<STR_LIT:utf-8>' ) ) <EOL> g . attrs [ '<STR_LIT:x>' ] = self . position [ <NUM_LIT:0> ] <EOL> g . attrs [ '<STR_LIT:y>' ] = self . position [ <NUM_LIT:1> ] <EOL> g . attrs [ '<STR_LIT:z>' ] = self . position [ <NUM_LIT:2> ] <EOL> Source . write ( self , g ) <EOL> class PointSourceCollection ( Source ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , name = None , peeloff = True , ** kwargs ) : <EOL> self . position = None <EOL> Source . __init__ ( self , name = name , peeloff = peeloff , ** kwargs ) <EOL> @ property <EOL> def luminosity ( self ) : <EOL> '''<STR_LIT>''' <EOL> return self . _luminosity <EOL> @ luminosity . setter <EOL> def luminosity ( self , value ) : <EOL> if value is not None : <EOL> if is_numpy_array ( value ) : <EOL> if value . ndim != <NUM_LIT:1> : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if not np . all ( value > <NUM_LIT:0.> ) : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if self . position is not None and value . shape [ <NUM_LIT:0> ] != self . position . shape [ <NUM_LIT:0> ] : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> else : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> self . _luminosity = value <EOL> def _read_luminosity ( self , handle ) : <EOL> self . luminosity = np . array ( handle [ '<STR_LIT>' ] ) <EOL> def _write_luminosity ( self , handle ) : <EOL> handle . create_dataset ( '<STR_LIT>' , data = self . luminosity , compression = True ) <EOL> @ property <EOL> def position ( self ) : <EOL> '''<STR_LIT>''' <EOL> return self . _position <EOL> @ position . setter <EOL> def position ( self , value ) : <EOL> if value is not None : <EOL> if is_numpy_array ( value ) : <EOL> if value . ndim != <NUM_LIT:2> : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if value . shape [ <NUM_LIT:1> ] != <NUM_LIT:3> : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if self . luminosity is not None and value . shape [ <NUM_LIT:0> ] != self . luminosity . shape [ <NUM_LIT:0> ] : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> else : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> self . _position = value <EOL> def _check_all_set ( self ) : <EOL> Source . _check_all_set ( self ) <EOL> if self . position is None : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if self . has_lte_spectrum ( ) : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> @ classmethod <EOL> def read ( cls , handle ) : <EOL> if not handle . attrs [ '<STR_LIT:type>' ] == b'<STR_LIT>' : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> self = super ( PointSourceCollection , cls ) . read ( handle ) <EOL> self . position = np . array ( handle [ '<STR_LIT>' ] ) <EOL> return self <EOL> def write ( self , handle , name ) : <EOL> self . _check_all_set ( ) <EOL> g = handle . create_group ( name ) <EOL> g . attrs [ '<STR_LIT:type>' ] = np . string_ ( '<STR_LIT>' . encode ( '<STR_LIT:utf-8>' ) ) <EOL> g . create_dataset ( '<STR_LIT>' , data = self . position , compression = True ) <EOL> Source . write ( self , g ) <EOL> class SphericalSource ( Source ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , name = None , peeloff = True , ** kwargs ) : <EOL> self . position = ( <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:0.> ) <EOL> self . radius = None <EOL> self . limb = False <EOL> self . _spots = [ ] <EOL> Source . __init__ ( self , name = name , peeloff = peeloff , ** kwargs ) <EOL> @ property <EOL> def radius ( self ) : <EOL> '''<STR_LIT>''' <EOL> return self . _radius <EOL> @ radius . setter <EOL> def radius ( self , value ) : <EOL> if value is not None : <EOL> validate_scalar ( '<STR_LIT>' , value , domain = '<STR_LIT>' ) <EOL> self . _radius = value <EOL> @ property <EOL> def position ( self ) : <EOL> '''<STR_LIT>''' <EOL> return self . _position <EOL> @ position . setter <EOL> def position ( self , value ) : <EOL> if value is not None : <EOL> if type ( value ) in [ tuple , list ] : <EOL> if len ( value ) != <NUM_LIT:3> : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> elif is_numpy_array ( value ) : <EOL> if value . ndim != <NUM_LIT:1> : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if len ( value ) != <NUM_LIT:3> : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> else : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> self . _position = value <EOL> @ property <EOL> def limb ( self ) : <EOL> '''<STR_LIT>''' <EOL> return self . _limb <EOL> @ limb . setter <EOL> def limb ( self , value ) : <EOL> if value is not None : <EOL> if not isinstance ( value , bool ) : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> self . _limb = value <EOL> def _check_all_set ( self ) : <EOL> Source . _check_all_set ( self ) <EOL> if self . position is None : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if self . radius is None : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if self . limb is None : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if self . has_lte_spectrum ( ) : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> @ classmethod <EOL> def read ( cls , handle ) : <EOL> if not handle . attrs [ '<STR_LIT:type>' ] == b'<STR_LIT>' : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> self = super ( SphericalSource , cls ) . read ( handle ) <EOL> self . position = ( handle . attrs [ '<STR_LIT:x>' ] , handle . attrs [ '<STR_LIT:y>' ] , handle . attrs [ '<STR_LIT:z>' ] ) <EOL> self . radius = handle . attrs [ '<STR_LIT:r>' ] <EOL> self . limb = str2bool ( handle . attrs [ '<STR_LIT>' ] ) <EOL> for group in handle : <EOL> if '<STR_LIT>' in group : <EOL> self . _spots . append ( SpotSource . read ( handle [ group ] ) ) <EOL> return self <EOL> def write ( self , handle , name ) : <EOL> self . _check_all_set ( ) <EOL> g = handle . create_group ( name ) <EOL> g . attrs [ '<STR_LIT:type>' ] = np . string_ ( '<STR_LIT>' . encode ( '<STR_LIT:utf-8>' ) ) <EOL> g . attrs [ '<STR_LIT:x>' ] = self . position [ <NUM_LIT:0> ] <EOL> g . attrs [ '<STR_LIT:y>' ] = self . position [ <NUM_LIT:1> ] <EOL> g . attrs [ '<STR_LIT:z>' ] = self . position [ <NUM_LIT:2> ] <EOL> g . attrs [ '<STR_LIT:r>' ] = self . radius <EOL> g . attrs [ '<STR_LIT>' ] = np . string_ ( bool2str ( self . limb ) ) <EOL> Source . write ( self , g ) <EOL> for i , spot in enumerate ( self . _spots ) : <EOL> spot . write ( g , '<STR_LIT>' % i ) <EOL> def add_spot ( self , * args , ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> spot = SpotSource ( * args , ** kwargs ) <EOL> self . _spots . append ( spot ) <EOL> return spot <EOL> class ExternalSphericalSource ( Source ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , name = None , peeloff = True , ** kwargs ) : <EOL> self . position = ( <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:0.> ) <EOL> self . radius = None <EOL> Source . __init__ ( self , name = name , peeloff = peeloff , ** kwargs ) <EOL> @ property <EOL> def radius ( self ) : <EOL> '''<STR_LIT>''' <EOL> return self . _radius <EOL> @ radius . setter <EOL> def radius ( self , value ) : <EOL> if value is not None : <EOL> validate_scalar ( '<STR_LIT>' , value , domain = '<STR_LIT>' ) <EOL> self . _radius = value <EOL> @ property <EOL> def position ( self ) : <EOL> '''<STR_LIT>''' <EOL> return self . _position <EOL> @ position . setter <EOL> def position ( self , value ) : <EOL> if value is not None : <EOL> if type ( value ) in [ tuple , list ] : <EOL> if len ( value ) != <NUM_LIT:3> : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> elif is_numpy_array ( value ) : <EOL> if value . ndim != <NUM_LIT:1> : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if len ( value ) != <NUM_LIT:3> : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> else : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> self . _position = value <EOL> def _check_all_set ( self ) : <EOL> Source . _check_all_set ( self ) <EOL> if self . position is None : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if self . radius is None : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if self . has_lte_spectrum ( ) : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> @ classmethod <EOL> def read ( cls , handle ) : <EOL> if not handle . attrs [ '<STR_LIT:type>' ] == b'<STR_LIT>' : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> self = super ( ExternalSphericalSource , cls ) . read ( handle ) <EOL> self . position = ( handle . attrs [ '<STR_LIT:x>' ] , handle . attrs [ '<STR_LIT:y>' ] , handle . attrs [ '<STR_LIT:z>' ] ) <EOL> self . radius = handle . attrs [ '<STR_LIT:r>' ] <EOL> return self <EOL> def write ( self , handle , name ) : <EOL> self . _check_all_set ( ) <EOL> g = handle . create_group ( name ) <EOL> g . attrs [ '<STR_LIT:type>' ] = np . string_ ( '<STR_LIT>' . encode ( '<STR_LIT:utf-8>' ) ) <EOL> g . attrs [ '<STR_LIT:x>' ] = self . position [ <NUM_LIT:0> ] <EOL> g . attrs [ '<STR_LIT:y>' ] = self . position [ <NUM_LIT:1> ] <EOL> g . attrs [ '<STR_LIT:z>' ] = self . position [ <NUM_LIT:2> ] <EOL> g . attrs [ '<STR_LIT:r>' ] = self . radius <EOL> Source . write ( self , g ) <EOL> class ExternalBoxSource ( Source ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , name = None , peeloff = True , ** kwargs ) : <EOL> self . bounds = None <EOL> Source . __init__ ( self , name = name , peeloff = peeloff , ** kwargs ) <EOL> @ property <EOL> def bounds ( self ) : <EOL> '''<STR_LIT>''' <EOL> return self . _bounds <EOL> @ bounds . setter <EOL> def bounds ( self , value ) : <EOL> if value is not None : <EOL> if type ( value ) in [ tuple , list ] : <EOL> if np . array ( value ) . shape != ( <NUM_LIT:3> , <NUM_LIT:2> ) : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> elif is_numpy_array ( value ) : <EOL> if value . ndim != <NUM_LIT:2> : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if value . shape != ( <NUM_LIT:3> , <NUM_LIT:2> ) : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> else : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> self . _bounds = value <EOL> def _check_all_set ( self ) : <EOL> Source . _check_all_set ( self ) <EOL> if self . bounds is None : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if self . has_lte_spectrum ( ) : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> @ classmethod <EOL> def read ( cls , handle ) : <EOL> if not handle . attrs [ '<STR_LIT:type>' ] == b'<STR_LIT>' : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> self = super ( ExternalBoxSource , cls ) . read ( handle ) <EOL> self . bounds = [ ( handle . attrs [ '<STR_LIT>' ] , handle . attrs [ '<STR_LIT>' ] ) , <EOL> ( handle . attrs [ '<STR_LIT>' ] , handle . attrs [ '<STR_LIT>' ] ) , <EOL> ( handle . attrs [ '<STR_LIT>' ] , handle . attrs [ '<STR_LIT>' ] ) ] <EOL> return self <EOL> def write ( self , handle , name ) : <EOL> self . _check_all_set ( ) <EOL> g = handle . create_group ( name ) <EOL> g . attrs [ '<STR_LIT:type>' ] = np . string_ ( '<STR_LIT>' . encode ( '<STR_LIT:utf-8>' ) ) <EOL> g . attrs [ '<STR_LIT>' ] = self . bounds [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] <EOL> g . attrs [ '<STR_LIT>' ] = self . bounds [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] <EOL> g . attrs [ '<STR_LIT>' ] = self . bounds [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] <EOL> g . attrs [ '<STR_LIT>' ] = self . bounds [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] <EOL> g . attrs [ '<STR_LIT>' ] = self . bounds [ <NUM_LIT:2> ] [ <NUM_LIT:0> ] <EOL> g . attrs [ '<STR_LIT>' ] = self . bounds [ <NUM_LIT:2> ] [ <NUM_LIT:1> ] <EOL> Source . write ( self , g ) <EOL> class MapSource ( Source ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , name = None , peeloff = True , ** kwargs ) : <EOL> self . map = None <EOL> Source . __init__ ( self , name = name , peeloff = peeloff , ** kwargs ) <EOL> @ property <EOL> def map ( self ) : <EOL> '''<STR_LIT>''' <EOL> return self . _map <EOL> @ map . setter <EOL> def map ( self , value ) : <EOL> if value is not None : <EOL> if not is_numpy_array ( value ) and not isinstance ( value , AMRGridView ) : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> self . _map = value <EOL> def _check_all_set ( self ) : <EOL> Source . _check_all_set ( self ) <EOL> if self . map is None : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if is_numpy_array ( self . map ) and np . all ( self . map == <NUM_LIT:0.> ) : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> @ classmethod <EOL> def read ( cls , handle ) : <EOL> if not handle . attrs [ '<STR_LIT:type>' ] == b'<STR_LIT>' : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> self = super ( MapSource , cls ) . read ( handle ) <EOL> self . map = np . array ( handle [ '<STR_LIT>' ] ) <EOL> return self <EOL> def write ( self , handle , name , grid , compression = True , map_dtype = float ) : <EOL> self . _check_all_set ( ) <EOL> g = handle . create_group ( name ) <EOL> g . attrs [ '<STR_LIT:type>' ] = np . string_ ( '<STR_LIT>' . encode ( '<STR_LIT:utf-8>' ) ) <EOL> grid . write_single_array ( g , "<STR_LIT>" , self . map , <EOL> compression = compression , <EOL> physics_dtype = map_dtype ) <EOL> Source . write ( self , g ) <EOL> class PlaneParallelSource ( Source ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , name = None , peeloff = False , ** kwargs ) : <EOL> if peeloff : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> self . position = ( <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:0.> ) <EOL> self . radius = None <EOL> self . direction = None <EOL> Source . __init__ ( self , name = name , peeloff = peeloff , ** kwargs ) <EOL> @ property <EOL> def radius ( self ) : <EOL> '''<STR_LIT>''' <EOL> return self . _radius <EOL> @ radius . setter <EOL> def radius ( self , value ) : <EOL> if value is not None : <EOL> validate_scalar ( '<STR_LIT>' , value , domain = '<STR_LIT>' ) <EOL> self . _radius = value <EOL> @ property <EOL> def position ( self ) : <EOL> '''<STR_LIT>''' <EOL> return self . _position <EOL> @ position . setter <EOL> def position ( self , value ) : <EOL> if value is not None : <EOL> if type ( value ) in [ tuple , list ] : <EOL> if len ( value ) != <NUM_LIT:3> : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> elif is_numpy_array ( value ) : <EOL> if value . ndim != <NUM_LIT:1> : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if len ( value ) != <NUM_LIT:3> : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> else : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> self . _position = value <EOL> @ property <EOL> def direction ( self ) : <EOL> '''<STR_LIT>''' <EOL> return self . _direction <EOL> @ direction . setter <EOL> def direction ( self , value ) : <EOL> if value is not None : <EOL> if type ( value ) in [ tuple , list ] : <EOL> if len ( value ) != <NUM_LIT:2> : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> elif is_numpy_array ( value ) : <EOL> if value . ndim != <NUM_LIT:1> : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if len ( value ) != <NUM_LIT:2> : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> else : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> self . _direction = value <EOL> def _check_all_set ( self ) : <EOL> Source . _check_all_set ( self ) <EOL> if self . position is None : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if self . radius is None : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if self . direction is None : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if self . has_lte_spectrum ( ) : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> @ classmethod <EOL> def read ( cls , handle ) : <EOL> if not handle . attrs [ '<STR_LIT:type>' ] == b'<STR_LIT>' : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> self = super ( PlaneParallelSource , cls ) . read ( handle ) <EOL> self . position = ( handle . attrs [ '<STR_LIT:x>' ] , handle . attrs [ '<STR_LIT:y>' ] , handle . attrs [ '<STR_LIT:z>' ] ) <EOL> self . radius = handle . attrs [ '<STR_LIT:r>' ] <EOL> self . direction = ( handle . attrs [ '<STR_LIT>' ] , handle . attrs [ '<STR_LIT>' ] ) <EOL> return self <EOL> def write ( self , handle , name ) : <EOL> self . _check_all_set ( ) <EOL> g = handle . create_group ( name ) <EOL> g . attrs [ '<STR_LIT:type>' ] = np . string_ ( '<STR_LIT>' . encode ( '<STR_LIT:utf-8>' ) ) <EOL> g . attrs [ '<STR_LIT:x>' ] = self . position [ <NUM_LIT:0> ] <EOL> g . attrs [ '<STR_LIT:y>' ] = self . position [ <NUM_LIT:1> ] <EOL> g . attrs [ '<STR_LIT:z>' ] = self . position [ <NUM_LIT:2> ] <EOL> g . attrs [ '<STR_LIT:r>' ] = self . radius <EOL> g . attrs [ '<STR_LIT>' ] = self . direction [ <NUM_LIT:0> ] <EOL> g . attrs [ '<STR_LIT>' ] = self . direction [ <NUM_LIT:1> ] <EOL> Source . write ( self , g ) </s>
