idx int64 0 63k | question stringlengths 53 5.28k | target stringlengths 5 805 |
|---|---|---|
32,300 | def set_cookie ( self , cookie = None ) : if cookie : self . _cookie = cookie . encode ( ) else : self . _cookie = None | Set the Cookie header . |
32,301 | def on ( self , event_name , callback ) : if not event_name : return False _LOGGER . debug ( "Adding callback for event name: %s" , event_name ) self . _callbacks [ event_name ] . append ( ( callback ) ) return True | Register callback for a SocketIO event . |
32,302 | def start ( self ) : if not self . _thread : _LOGGER . info ( "Starting SocketIO thread..." ) self . _thread = threading . Thread ( target = self . _run_socketio_thread , name = 'SocketIOThread' ) self . _thread . deamon = True self . _thread . start ( ) | Start a thread to handle SocketIO notifications . |
32,303 | def stop ( self ) : if self . _thread : _LOGGER . info ( "Stopping SocketIO thread..." ) self . _running = False if self . _exit_event : self . _exit_event . set ( ) self . _thread . join ( ) | Tell the SocketIO thread to terminate . |
32,304 | def add_device_callback ( self , devices , callback ) : if not devices : return False if not isinstance ( devices , ( tuple , list ) ) : devices = [ devices ] for device in devices : device_id = device if isinstance ( device , AbodeDevice ) : device_id = device . device_id if not self . _abode . get_device ( device_id ... | Register a device callback . |
32,305 | def add_event_callback ( self , event_groups , callback ) : if not event_groups : return False if not isinstance ( event_groups , ( tuple , list ) ) : event_groups = [ event_groups ] for event_group in event_groups : if event_group not in TIMELINE . ALL_EVENT_GROUPS : raise AbodeException ( ERROR . EVENT_GROUP_INVALID ... | Register callback for a group of timeline events . |
32,306 | def add_timeline_callback ( self , timeline_events , callback ) : if not timeline_events : return False if not isinstance ( timeline_events , ( tuple , list ) ) : timeline_events = [ timeline_events ] for timeline_event in timeline_events : if not isinstance ( timeline_event , dict ) : raise AbodeException ( ( ERROR . ... | Register a callback for a specific timeline event . |
32,307 | def _on_socket_started ( self ) : cookies = self . _abode . _get_session ( ) . cookies . get_dict ( ) cookie_string = "; " . join ( [ str ( x ) + "=" + str ( y ) for x , y in cookies . items ( ) ] ) self . _socketio . set_cookie ( cookie_string ) | Socket IO startup callback . |
32,308 | def _on_device_update ( self , devid ) : if isinstance ( devid , ( tuple , list ) ) : devid = devid [ 0 ] if devid is None : _LOGGER . warning ( "Device update with no device id." ) return _LOGGER . debug ( "Device update event for device ID: %s" , devid ) device = self . _abode . get_device ( devid , True ) if not dev... | Device callback from Abode SocketIO server . |
32,309 | def _on_mode_change ( self , mode ) : if isinstance ( mode , ( tuple , list ) ) : mode = mode [ 0 ] if mode is None : _LOGGER . warning ( "Mode change event with no mode." ) return if not mode or mode . lower ( ) not in CONST . ALL_MODES : _LOGGER . warning ( "Mode change event with unknown mode: %s" , mode ) return _L... | Mode change broadcast from Abode SocketIO server . |
32,310 | def _on_timeline_update ( self , event ) : if isinstance ( event , ( tuple , list ) ) : event = event [ 0 ] event_type = event . get ( 'event_type' ) event_code = event . get ( 'event_code' ) if not event_type or not event_code : _LOGGER . warning ( "Invalid timeline update event: %s" , event ) return _LOGGER . debug (... | Timeline update broadcast from Abode SocketIO server . |
32,311 | def _on_automation_update ( self , event ) : event_group = TIMELINE . AUTOMATION_EDIT_GROUP if isinstance ( event , ( tuple , list ) ) : event = event [ 0 ] for callback in self . _event_callbacks . get ( event_group , ( ) ) : _execute_callback ( callback , event ) | Automation update broadcast from Abode SocketIO server . |
32,312 | def login ( self , username = None , password = None ) : if username is not None : self . _cache [ CONST . ID ] = username if password is not None : self . _cache [ CONST . PASSWORD ] = password if ( self . _cache [ CONST . ID ] is None or not isinstance ( self . _cache [ CONST . ID ] , str ) ) : raise AbodeAuthenticat... | Explicit Abode login . |
32,313 | def logout ( self ) : if self . _token : header_data = { 'ABODE-API-KEY' : self . _token } self . _session = requests . session ( ) self . _token = None self . _panel = None self . _user = None self . _devices = None self . _automations = None try : response = self . _session . post ( CONST . LOGOUT_URL , headers = hea... | Explicit Abode logout . |
32,314 | def refresh ( self ) : self . get_devices ( refresh = True ) self . get_automations ( refresh = True ) | Do a full refresh of all devices and automations . |
32,315 | def get_device ( self , device_id , refresh = False ) : if self . _devices is None : self . get_devices ( ) refresh = False device = self . _devices . get ( device_id ) if device and refresh : device . refresh ( ) return device | Get a single device . |
32,316 | def get_automations ( self , refresh = False , generic_type = None ) : if refresh or self . _automations is None : if self . _automations is None : self . _automations = { } _LOGGER . info ( "Updating all automations..." ) response = self . send_request ( "get" , CONST . AUTOMATION_URL ) response_object = json . loads ... | Get all automations . |
32,317 | def get_automation ( self , automation_id , refresh = False ) : if self . _automations is None : self . get_automations ( ) refresh = False automation = self . _automations . get ( str ( automation_id ) ) if automation and refresh : automation . refresh ( ) return automation | Get a single automation . |
32,318 | def get_alarm ( self , area = '1' , refresh = False ) : if self . _devices is None : self . get_devices ( ) refresh = False return self . get_device ( CONST . ALARM_DEVICE_ID + area , refresh ) | Shortcut method to get the alarm device . |
32,319 | def set_default_mode ( self , default_mode ) : if default_mode . lower ( ) not in ( CONST . MODE_AWAY , CONST . MODE_HOME ) : raise AbodeException ( ERROR . INVALID_DEFAULT_ALARM_MODE ) self . _default_alarm_mode = default_mode . lower ( ) | Set the default mode when alarms are turned on . |
32,320 | def set_setting ( self , setting , value , area = '1' , validate_value = True ) : setting = setting . lower ( ) if setting not in CONST . ALL_SETTINGS : raise AbodeException ( ERROR . INVALID_SETTING , CONST . ALL_SETTINGS ) if setting in CONST . PANEL_SETTINGS : url = CONST . SETTINGS_URL data = self . _panel_settings... | Set an abode system setting to a given value . |
32,321 | def _panel_settings ( setting , value , validate_value ) : if validate_value : if ( setting == CONST . SETTING_CAMERA_RESOLUTION and value not in CONST . SETTING_ALL_CAMERA_RES ) : raise AbodeException ( ERROR . INVALID_SETTING_VALUE , CONST . SETTING_ALL_CAMERA_RES ) elif ( setting in [ CONST . SETTING_CAMERA_GRAYSCAL... | Will validate panel settings and values returns data packet . |
32,322 | def _area_settings ( area , setting , value , validate_value ) : if validate_value : if ( setting == CONST . SETTING_EXIT_DELAY_AWAY and value not in CONST . VALID_SETTING_EXIT_AWAY ) : raise AbodeException ( ERROR . INVALID_SETTING_VALUE , CONST . VALID_SETTING_EXIT_AWAY ) elif value not in CONST . ALL_SETTING_ENTRY_E... | Will validate area settings and values returns data packet . |
32,323 | def _sound_settings ( area , setting , value , validate_value ) : if validate_value : if ( setting in CONST . VALID_SOUND_SETTINGS and value not in CONST . ALL_SETTING_SOUND ) : raise AbodeException ( ERROR . INVALID_SETTING_VALUE , CONST . ALL_SETTING_SOUND ) elif ( setting == CONST . SETTING_ALARM_LENGTH and value no... | Will validate sound settings and values returns data packet . |
32,324 | def _siren_settings ( setting , value , validate_value ) : if validate_value : if value not in CONST . SETTING_DISABLE_ENABLE : raise AbodeException ( ERROR . INVALID_SETTING_VALUE , CONST . SETTING_DISABLE_ENABLE ) return { 'action' : setting , 'option' : value } | Will validate siren settings and values returns data packet . |
32,325 | def send_request ( self , method , url , headers = None , data = None , is_retry = False ) : if not self . _token : self . login ( ) if not headers : headers = { } headers [ 'Authorization' ] = 'Bearer ' + self . _oauth_token headers [ 'ABODE-API-KEY' ] = self . _token try : response = getattr ( self . _session , metho... | Send requests to Abode . |
32,326 | def _save_cache ( self ) : if not self . _disable_cache : UTILS . save_cache ( self . _cache , self . _cache_path ) | Trigger a cache save . |
32,327 | def get_generic_type ( type_tag ) : return { DEVICE_ALARM : TYPE_ALARM , DEVICE_GLASS_BREAK : TYPE_CONNECTIVITY , DEVICE_KEYPAD : TYPE_CONNECTIVITY , DEVICE_REMOTE_CONTROLLER : TYPE_CONNECTIVITY , DEVICE_SIREN : TYPE_CONNECTIVITY , DEVICE_STATUS_DISPLAY : TYPE_CONNECTIVITY , DEVICE_DOOR_CONTACT : TYPE_OPENING , DEVICE_... | Map type tag to generic type . |
32,328 | def lock ( self ) : success = self . set_status ( CONST . STATUS_LOCKCLOSED_INT ) if success : self . _json_state [ 'status' ] = CONST . STATUS_LOCKCLOSED return success | Lock the device . |
32,329 | def unlock ( self ) : success = self . set_status ( CONST . STATUS_LOCKOPEN_INT ) if success : self . _json_state [ 'status' ] = CONST . STATUS_LOCKOPEN return success | Unlock the device . |
32,330 | def set_status ( self , status ) : if self . _json_state [ 'control_url' ] : url = CONST . BASE_URL + self . _json_state [ 'control_url' ] status_data = { 'status' : str ( status ) } response = self . _abode . send_request ( method = "put" , url = url , data = status_data ) response_object = json . loads ( response . t... | Set device status . |
32,331 | def set_level ( self , level ) : if self . _json_state [ 'control_url' ] : url = CONST . BASE_URL + self . _json_state [ 'control_url' ] level_data = { 'level' : str ( level ) } response = self . _abode . send_request ( "put" , url , data = level_data ) response_object = json . loads ( response . text ) _LOGGER . debug... | Set device level . |
32,332 | def _update_name ( self ) : self . _name = self . _json_state . get ( 'name' ) if not self . _name : self . _name = self . type + ' ' + self . device_id | Set the device name from _json_state with a sensible default . |
32,333 | def set_color_temp ( self , color_temp ) : if self . _json_state [ 'control_url' ] : url = CONST . INTEGRATIONS_URL + self . _device_uuid color_data = { 'action' : 'setcolortemperature' , 'colorTemperature' : int ( color_temp ) } response = self . _abode . send_request ( "post" , url , data = color_data ) response_obje... | Set device color . |
32,334 | def color ( self ) : return ( self . get_value ( CONST . STATUSES_KEY ) . get ( 'hue' ) , self . get_value ( CONST . STATUSES_KEY ) . get ( 'saturation' ) ) | Get light color . |
32,335 | def has_color ( self ) : if ( self . get_value ( CONST . STATUSES_KEY ) . get ( 'color_mode' ) == str ( CONST . COLOR_MODE_ON ) ) : return True return False | Device is using color mode . |
32,336 | def capture ( self ) : url = str . replace ( CONST . CAMS_ID_CAPTURE_URL , '$DEVID$' , self . device_id ) try : response = self . _abode . send_request ( "put" , url ) _LOGGER . debug ( "Capture image response: %s" , response . text ) return True except AbodeException as exc : _LOGGER . warning ( "Failed to capture ima... | Request a new camera image . |
32,337 | def refresh_image ( self ) : url = str . replace ( CONST . TIMELINE_IMAGES_ID_URL , '$DEVID$' , self . device_id ) response = self . _abode . send_request ( "get" , url ) _LOGGER . debug ( "Get image response: %s" , response . text ) return self . update_image_location ( json . loads ( response . text ) ) | Get the most recent camera image . |
32,338 | def update_image_location ( self , timeline_json ) : if not timeline_json : return False if isinstance ( timeline_json , ( tuple , list ) ) : timeline_json = timeline_json [ 0 ] event_code = timeline_json . get ( 'event_code' ) if event_code != TIMELINE . CAPTURE_IMAGE [ 'event_code' ] : raise AbodeException ( ( ERROR ... | Update the image location . |
32,339 | def image_to_file ( self , path , get_image = True ) : if not self . image_url or get_image : if not self . refresh_image ( ) : return False response = requests . get ( self . image_url , stream = True ) if response . status_code != 200 : _LOGGER . warning ( "Unexpected response code %s when requesting image: %s" , str... | Write the image to a file . |
32,340 | def create_alarm ( panel_json , abode , area = '1' ) : panel_json [ 'name' ] = CONST . ALARM_NAME panel_json [ 'id' ] = CONST . ALARM_DEVICE_ID + area panel_json [ 'type' ] = CONST . ALARM_TYPE panel_json [ 'type_tag' ] = CONST . DEVICE_ALARM panel_json [ 'generic_type' ] = CONST . TYPE_ALARM return AbodeAlarm ( panel_... | Create a new alarm device from a panel response . |
32,341 | def set_mode ( self , mode ) : if not mode : raise AbodeException ( ERROR . MISSING_ALARM_MODE ) elif mode . lower ( ) not in CONST . ALL_MODES : raise AbodeException ( ERROR . INVALID_ALARM_MODE , CONST . ALL_MODES ) mode = mode . lower ( ) response = self . _abode . send_request ( "put" , CONST . get_panel_mode_url (... | Set Abode alarm mode . |
32,342 | def refresh ( self , url = CONST . PANEL_URL ) : response_object = AbodeDevice . refresh ( self , url ) self . _abode . _panel . update ( response_object [ 0 ] ) return response_object | Refresh the alarm device . |
32,343 | def mode ( self ) : mode = self . get_value ( 'mode' ) . get ( self . device_id , None ) return mode . lower ( ) | Get alarm mode . |
32,344 | def update ( dct , dct_merge ) : for key , value in dct_merge . items ( ) : if key in dct and isinstance ( dct [ key ] , dict ) : dct [ key ] = update ( dct [ key ] , value ) else : dct [ key ] = value return dct | Recursively merge dicts . |
32,345 | def check_valid_device ( self , path , run_as_root = True ) : if self . im_root : try : with open ( path , 'r' ) as f : f . read ( 4096 ) except Exception : return False return True try : self . _execute ( 'dd' , 'if=' + path , 'of=/dev/null' , 'bs=4096' , 'count=1' , root_helper = self . _root_helper , run_as_root = T... | Verify an existing RBD handle is connected and valid . |
32,346 | def setup ( config ) : if config is None : config = { } else : config = config . copy ( ) volume_cmd . CONF . _ConfigOpts__cache = MyDict ( ) storage = config . pop ( 'storage' , None ) or DEFAULT_STORAGE if isinstance ( storage , base . PersistenceDriverBase ) : return storage if inspect . isclass ( storage ) and issu... | Setup persistence to be used in cinderlib . |
32,347 | def _transform_legacy_stats ( self , stats ) : if stats and 'pools' not in stats : pool = stats . copy ( ) pool [ 'pool_name' ] = self . id for key in ( 'driver_version' , 'shared_targets' , 'sparse_copy_volume' , 'storage_protocol' , 'vendor_name' , 'volume_backend_name' ) : pool . pop ( key , None ) stats [ 'pools' ]... | Convert legacy stats to new stats with pools key . |
32,348 | def _config_parse ( self ) : res = super ( cfg . ConfigParser , self ) . parse ( Backend . _config_string_io ) return res | Replacer oslo_config . cfg . ConfigParser . parse for in - memory cfg . |
32,349 | def _update_cinder_config ( cls ) : cls . _config_string_io . seek ( 0 ) cls . _parser . write ( cls . _config_string_io ) cls . _config_string_io . seek ( 0 ) current_cfg = cls . _config_string_io . read ( ) if '\n\t' in current_cfg : cls . _config_string_io . seek ( 0 ) cls . _config_string_io . write ( current_cfg .... | Parse in - memory file to update OSLO configuration used by Cinder . |
32,350 | def _set_cinder_config ( cls , host , locks_path , cinder_config_params ) : cfg . CONF . set_default ( 'state_path' , os . getcwd ( ) ) cfg . CONF . set_default ( 'lock_path' , '$state_path' , 'oslo_concurrency' ) cls . _parser = six . moves . configparser . SafeConfigParser ( ) cls . _parser . set ( 'DEFAULT' , 'enabl... | Setup the parser with all the known Cinder configuration . |
32,351 | def list_supported_drivers ( ) : def convert_oslo_config ( oslo_options ) : options = [ ] for opt in oslo_options : tmp_dict = { k : str ( v ) for k , v in vars ( opt ) . items ( ) if not k . startswith ( '_' ) } options . append ( tmp_dict ) return options def list_drivers ( queue ) : cwd = os . getcwd ( ) os . chdir ... | Returns dictionary with driver classes names as keys . |
32,352 | def load ( json_src , save = False ) : if isinstance ( json_src , six . string_types ) : json_src = json_lib . loads ( json_src ) if isinstance ( json_src , list ) : return [ getattr ( objects , obj [ 'class' ] ) . load ( obj , save ) for obj in json_src ] return getattr ( objects , json_src [ 'class' ] ) . load ( json... | Load any json serialized cinderlib object . |
32,353 | def memoize ( func ) : def model ( cls , energy , * args , ** kwargs ) : try : memoize = cls . _memoize cache = cls . _cache queue = cls . _queue except AttributeError : memoize = False if memoize : try : with warnings . catch_warnings ( ) : warnings . simplefilter ( "ignore" , getattr ( np , "VisibleDeprecationWarning... | Cache decorator for functions inside model classes |
32,354 | def lnprior ( pars ) : logprob = ( naima . uniform_prior ( pars [ 0 ] , 0.0 , np . inf ) + naima . uniform_prior ( pars [ 1 ] , - 1 , 5 ) + naima . uniform_prior ( pars [ 3 ] , 0 , np . inf ) ) return logprob | Return probability of parameter values according to prior knowledge . Parameter limits should be done here through uniform prior ditributions |
32,355 | def normal_prior ( value , mean , sigma ) : return - 0.5 * ( 2 * np . pi * sigma ) - ( value - mean ) ** 2 / ( 2.0 * sigma ) | Normal prior distribution . |
32,356 | def log_uniform_prior ( value , umin = 0 , umax = None ) : if value > 0 and value >= umin : if umax is not None : if value <= umax : return 1 / value else : return - np . inf else : return 1 / value else : return - np . inf | Log - uniform prior distribution . |
32,357 | def run_sampler ( nrun = 100 , sampler = None , pos = None , ** kwargs ) : if sampler is None or pos is None : sampler , pos = get_sampler ( ** kwargs ) sampler . run_info [ "n_run" ] = nrun print ( "\nWalker burn in finished, running {0} steps..." . format ( nrun ) ) sampler . reset ( ) sampler , pos = _run_mcmc ( sam... | Run an MCMC sampler . |
32,358 | def _fact_to_tuple ( self , fact ) : if fact . category : category = fact . category . name else : category = '' description = fact . description or '' return FactTuple ( start = fact . start . strftime ( self . datetime_format ) , end = fact . end . strftime ( self . datetime_format ) , activity = text_type ( fact . a... | Convert a Fact to its normalized tuple . |
32,359 | def _write_fact ( self , fact_tuple ) : fact = self . document . createElement ( "fact" ) fact . setAttribute ( 'start' , fact_tuple . start ) fact . setAttribute ( 'end' , fact_tuple . end ) fact . setAttribute ( 'activity' , fact_tuple . activity ) fact . setAttribute ( 'duration' , fact_tuple . duration ) fact . set... | Create new fact element and populate attributes . |
32,360 | def _close ( self ) : self . document . appendChild ( self . fact_list ) self . file . write ( self . document . toxml ( encoding = 'utf-8' ) ) return super ( XMLWriter , self ) . _close ( ) | Append the xml fact list to the main document write file and cleanup . |
32,361 | def execute_sql ( server_context , schema_name , sql , container_path = None , max_rows = None , sort = None , offset = None , container_filter = None , save_in_session = None , parameters = None , required_version = None , timeout = _default_timeout ) : url = server_context . build_url ( 'query' , 'executeSql.api' , c... | Execute sql query against a LabKey server . |
32,362 | def update_rows ( server_context , schema_name , query_name , rows , container_path = None , timeout = _default_timeout ) : url = server_context . build_url ( 'query' , 'updateRows.api' , container_path = container_path ) payload = { 'schemaName' : schema_name , 'queryName' : query_name , 'rows' : rows } return server_... | Update a set of rows |
32,363 | def get_day_end ( config ) : day_start_datetime = datetime . datetime . combine ( datetime . date . today ( ) , config [ 'day_start' ] ) day_end_datetime = day_start_datetime - datetime . timedelta ( seconds = 1 ) return day_end_datetime . time ( ) | Get the day end time given the day start . This assumes full 24h day . |
32,364 | def end_day_to_datetime ( end_day , config ) : day_start_time = config [ 'day_start' ] day_end_time = get_day_end ( config ) if day_start_time == datetime . time ( 0 , 0 , 0 ) : end = datetime . datetime . combine ( end_day , day_end_time ) else : end = datetime . datetime . combine ( end_day , day_end_time ) + datetim... | Convert a given end day to its proper datetime . |
32,365 | def complete_timeframe ( timeframe , config , partial = False ) : def complete_start_date ( date ) : if not date : date = datetime . date . today ( ) else : if not isinstance ( date , datetime . date ) : raise TypeError ( _ ( "Expected datetime.date instance, got {type} instead." . format ( type = type ( date ) ) ) ) r... | Apply fallback strategy to incomplete timeframes . |
32,366 | def validate_start_end_range ( range_tuple ) : start , end = range_tuple if ( start and end ) and ( start > end ) : raise ValueError ( _ ( "Start after end!" ) ) return range_tuple | Perform basic sanity checks on a timeframe . |
32,367 | def validate_data_table ( data_table , sed = None ) : if isinstance ( data_table , Table ) or isinstance ( data_table , QTable ) : data_table = [ data_table ] try : for dt in data_table : if not isinstance ( dt , Table ) and not isinstance ( dt , QTable ) : raise TypeError ( "An object passed as data_table is not an as... | Validate all columns of a data table . If a list of tables is passed all tables will be validated and then concatenated |
32,368 | def sed_conversion ( energy , model_unit , sed ) : model_pt = model_unit . physical_type ones = np . ones ( energy . shape ) if sed : f_unit = u . Unit ( "erg/s" ) if model_pt == "power" or model_pt == "flux" or model_pt == "energy" : sedf = ones elif "differential" in model_pt : sedf = energy ** 2 else : raise u . Uni... | Manage conversion between differential spectrum and SED |
32,369 | def trapz_loglog ( y , x , axis = - 1 , intervals = False ) : try : y_unit = y . unit y = y . value except AttributeError : y_unit = 1.0 try : x_unit = x . unit x = x . value except AttributeError : x_unit = 1.0 y = np . asanyarray ( y ) x = np . asanyarray ( x ) slice1 = [ slice ( None ) ] * y . ndim slice2 = [ slice ... | Integrate along the given axis using the composite trapezoidal rule in loglog space . |
32,370 | def _generate_energy_edges_single ( ene ) : midene = np . sqrt ( ( ene [ 1 : ] * ene [ : - 1 ] ) ) elo , ehi = np . zeros ( len ( ene ) ) * ene . unit , np . zeros ( len ( ene ) ) * ene . unit elo [ 1 : ] = ene [ 1 : ] - midene ehi [ : - 1 ] = midene - ene [ : - 1 ] elo [ 0 ] = ene [ 0 ] * ( 1 - ene [ 0 ] / ( ene [ 0 ]... | Generate energy edges for single group |
32,371 | def generate_energy_edges ( ene , groups = None ) : if groups is None or len ( ene ) != len ( groups ) : return _generate_energy_edges_single ( ene ) else : eloehi = np . zeros ( ( 2 , len ( ene ) ) ) * ene . unit for g in np . unique ( groups ) : group_edges = _generate_energy_edges_single ( ene [ groups == g ] ) eloe... | Generate energy bin edges from given energy array . |
32,372 | def build_data_table ( energy , flux , flux_error = None , flux_error_lo = None , flux_error_hi = None , energy_width = None , energy_lo = None , energy_hi = None , ul = None , cl = None , ) : table = QTable ( ) if cl is not None : cl = validate_scalar ( "cl" , cl ) table . meta [ "keywords" ] = { "cl" : { "value" : cl... | Read data into data dict . |
32,373 | def estimate_B ( xray_table , vhe_table , photon_energy_density = 0.261 * u . eV / u . cm ** 3 ) : xray = validate_data_table ( xray_table , sed = False ) vhe = validate_data_table ( vhe_table , sed = False ) xray_lum = trapz_loglog ( xray [ "flux" ] * xray [ "energy" ] , xray [ "energy" ] ) vhe_lum = trapz_loglog ( vh... | Estimate magnetic field from synchrotron to Inverse Compton luminosity ratio |
32,374 | def _initializer_wrapper ( actual_initializer , * rest ) : signal . signal ( signal . SIGINT , signal . SIG_IGN ) if actual_initializer is not None : actual_initializer ( * rest ) | We ignore SIGINT . It s up to our parent to kill us in the typical condition of this arising from ^C on a terminal . If someone is manually killing us with that signal well ... nothing will happen . |
32,375 | def eval ( e , amplitude , e_0 , alpha ) : xx = e / e_0 return amplitude * xx ** ( - alpha ) | One dimensional power law model function |
32,376 | def eval ( e , amplitude , e_0 , alpha , e_cutoff , beta ) : xx = e / e_0 return amplitude * xx ** ( - alpha ) * np . exp ( - ( e / e_cutoff ) ** beta ) | One dimensional power law with an exponential cutoff model function |
32,377 | def eval ( e , amplitude , e_0 , alpha , beta ) : ee = e / e_0 eeponent = - alpha - beta * np . log ( ee ) return amplitude * ee ** eeponent | One dimenional log parabola model function |
32,378 | def flux ( self , photon_energy , distance = 1 * u . kpc ) : spec = self . _spectrum ( photon_energy ) if distance != 0 : distance = validate_scalar ( "distance" , distance , physical_type = "length" ) spec /= 4 * np . pi * distance . to ( "cm" ) ** 2 out_unit = "1/(s cm2 eV)" else : out_unit = "1/(s eV)" return spec .... | Differential flux at a given distance from the source . |
32,379 | def sed ( self , photon_energy , distance = 1 * u . kpc ) : if distance != 0 : out_unit = "erg/(cm2 s)" else : out_unit = "erg/s" photon_energy = _validate_ene ( photon_energy ) sed = ( self . flux ( photon_energy , distance ) * photon_energy ** 2.0 ) . to ( out_unit ) return sed | Spectral energy distribution at a given distance from the source . |
32,380 | def _gam ( self ) : log10gmin = np . log10 ( self . Eemin / mec2 ) . value log10gmax = np . log10 ( self . Eemax / mec2 ) . value return np . logspace ( log10gmin , log10gmax , int ( self . nEed * ( log10gmax - log10gmin ) ) ) | Lorentz factor array |
32,381 | def _nelec ( self ) : pd = self . particle_distribution ( self . _gam * mec2 ) return pd . to ( 1 / mec2_unit ) . value | Particles per unit lorentz factor |
32,382 | def We ( self ) : We = trapz_loglog ( self . _gam * self . _nelec , self . _gam * mec2 ) return We | Total energy in electrons used for the radiative calculation |
32,383 | def compute_We ( self , Eemin = None , Eemax = None ) : if Eemin is None and Eemax is None : We = self . We else : if Eemax is None : Eemax = self . Eemax if Eemin is None : Eemin = self . Eemin log10gmin = np . log10 ( Eemin / mec2 ) . value log10gmax = np . log10 ( Eemax / mec2 ) . value gam = np . logspace ( log10gm... | Total energy in electrons between energies Eemin and Eemax |
32,384 | def set_We ( self , We , Eemin = None , Eemax = None , amplitude_name = None ) : We = validate_scalar ( "We" , We , physical_type = "energy" ) oldWe = self . compute_We ( Eemin = Eemin , Eemax = Eemax ) if amplitude_name is None : try : self . particle_distribution . amplitude *= ( We / oldWe ) . decompose ( ) except A... | Normalize particle distribution so that the total energy in electrons between Eemin and Eemax is We |
32,385 | def _spectrum ( self , photon_energy ) : outspecene = _validate_ene ( photon_energy ) from scipy . special import cbrt def Gtilde ( x ) : cb = cbrt ( x ) gt1 = 1.808 * cb / np . sqrt ( 1 + 3.4 * cb ** 2.0 ) gt2 = 1 + 2.210 * cb ** 2.0 + 0.347 * cb ** 4.0 gt3 = 1 + 1.353 * cb ** 2.0 + 0.217 * cb ** 4.0 return gt1 * ( gt... | Compute intrinsic synchrotron differential spectrum for energies in photon_energy |
32,386 | def _spectrum ( self , photon_energy ) : outspecene = _validate_ene ( photon_energy ) self . specic = [ ] for seed in self . seed_photon_fields : self . specic . append ( self . _calc_specic ( seed , outspecene ) . to ( "1/(s eV)" ) ) return np . sum ( u . Quantity ( self . specic ) , axis = 0 ) | Compute differential IC spectrum for energies in photon_energy . |
32,387 | def flux ( self , photon_energy , distance = 1 * u . kpc , seed = None ) : model = super ( InverseCompton , self ) . flux ( photon_energy , distance = distance ) if seed is not None : if not isinstance ( seed , int ) : if seed not in self . seed_photon_fields : raise ValueError ( "Provided seed photon field name is not... | Differential flux at a given distance from the source from a single seed photon field |
32,388 | def sed ( self , photon_energy , distance = 1 * u . kpc , seed = None ) : sed = super ( InverseCompton , self ) . sed ( photon_energy , distance = distance ) if seed is not None : if distance != 0 : out_unit = "erg/(cm2 s)" else : out_unit = "erg/s" sed = ( self . flux ( photon_energy , distance = distance , seed = see... | Spectral energy distribution at a given distance from the source |
32,389 | def _emiss_ee ( self , Eph ) : if self . weight_ee == 0.0 : return np . zeros_like ( Eph ) gam = np . vstack ( self . _gam ) emiss = c . cgs * trapz_loglog ( np . vstack ( self . _nelec ) * self . _sigma_ee ( gam , Eph ) , self . _gam , axis = 0 , ) return emiss | Electron - electron bremsstrahlung emissivity per unit photon energy |
32,390 | def _emiss_ep ( self , Eph ) : if self . weight_ep == 0.0 : return np . zeros_like ( Eph ) gam = np . vstack ( self . _gam ) eps = ( Eph / mec2 ) . decompose ( ) . value emiss = c . cgs * trapz_loglog ( np . vstack ( self . _nelec ) * self . _sigma_ep ( gam , eps ) , self . _gam , axis = 0 , ) . to ( u . cm ** 2 / Eph ... | Electron - proton bremsstrahlung emissivity per unit photon energy |
32,391 | def _spectrum ( self , photon_energy ) : Eph = _validate_ene ( photon_energy ) spec = self . n0 * ( self . weight_ee * self . _emiss_ee ( Eph ) + self . weight_ep * self . _emiss_ep ( Eph ) ) return spec | Compute differential bremsstrahlung spectrum for energies in photon_energy . |
32,392 | def _Ep ( self ) : return np . logspace ( np . log10 ( self . Epmin . to ( "GeV" ) . value ) , np . log10 ( self . Epmax . to ( "GeV" ) . value ) , int ( self . nEpd * ( np . log10 ( self . Epmax / self . Epmin ) ) ) , ) | Proton energy array in GeV |
32,393 | def _J ( self ) : pd = self . particle_distribution ( self . _Ep * u . GeV ) return pd . to ( "1/GeV" ) . value | Particles per unit proton energy in particles per GeV |
32,394 | def Wp ( self ) : Wp = trapz_loglog ( self . _Ep * self . _J , self . _Ep ) * u . GeV return Wp . to ( "erg" ) | Total energy in protons |
32,395 | def compute_Wp ( self , Epmin = None , Epmax = None ) : if Epmin is None and Epmax is None : Wp = self . Wp else : if Epmax is None : Epmax = self . Epmax if Epmin is None : Epmin = self . Epmin log10Epmin = np . log10 ( Epmin . to ( "GeV" ) . value ) log10Epmax = np . log10 ( Epmax . to ( "GeV" ) . value ) Ep = ( np .... | Total energy in protons between energies Epmin and Epmax |
32,396 | def set_Wp ( self , Wp , Epmin = None , Epmax = None , amplitude_name = None ) : Wp = validate_scalar ( "Wp" , Wp , physical_type = "energy" ) oldWp = self . compute_Wp ( Epmin = Epmin , Epmax = Epmax ) if amplitude_name is None : try : self . particle_distribution . amplitude *= ( Wp / oldWp ) . decompose ( ) except A... | Normalize particle distribution so that the total energy in protons between Epmin and Epmax is Wp |
32,397 | def _sigma_inel ( self , Tp ) : L = np . log ( Tp / self . _Tth ) sigma = 30.7 - 0.96 * L + 0.18 * L ** 2 sigma *= ( 1 - ( self . _Tth / Tp ) ** 1.9 ) ** 3 return sigma * 1e-27 | Inelastic cross - section for p - p interaction . KATV14 Eq . 1 |
32,398 | def _sigma_pi_loE ( self , Tp ) : m_p = self . _m_p m_pi = self . _m_pi Mres = 1.1883 Gres = 0.2264 s = 2 * m_p * ( Tp + 2 * m_p ) gamma = np . sqrt ( Mres ** 2 * ( Mres ** 2 + Gres ** 2 ) ) K = np . sqrt ( 8 ) * Mres * Gres * gamma K /= np . pi * np . sqrt ( Mres ** 2 + gamma ) fBW = m_p * K fBW /= ( ( np . sqrt ( s )... | inclusive cross section for Tth < Tp < 2 GeV Fit from experimental data |
32,399 | def _sigma_pi_midE ( self , Tp ) : m_p = self . _m_p Qp = ( Tp - self . _Tth ) / m_p multip = - 6e-3 + 0.237 * Qp - 0.023 * Qp ** 2 return self . _sigma_inel ( Tp ) * multip | Geant 4 . 10 . 0 model for 2 GeV < Tp < 5 GeV |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.