idx int64 0 63k | question stringlengths 53 5.28k | target stringlengths 5 805 |
|---|---|---|
27,800 | def _set_xml_from_keys ( self , root , item , ** kwargs ) : key , val = item target_key = root . find ( key ) if target_key is None : target_key = ElementTree . SubElement ( root , key ) if isinstance ( val , dict ) : for dict_item in val . items ( ) : self . _set_xml_from_keys ( target_key , dict_item , ** kwargs ) re... | Create SubElements of root with kwargs . |
27,801 | def get_url ( cls , data ) : try : data = int ( data ) except ( ValueError , TypeError ) : pass if isinstance ( data , int ) : return "%s%s%s" % ( cls . _url , cls . id_url , data ) elif data is None : return cls . _url elif isinstance ( data , basestring ) : if "=" in data : key , value = data . split ( "=" ) if key i... | Return the URL for a get request based on data type . |
27,802 | def url ( self ) : if self . id : url = "%s%s%s" % ( self . _url , self . id_url , self . id ) else : url = None return url | Return the path subcomponent of the url to this object . |
27,803 | def delete ( self , data = None ) : if not self . can_delete : raise JSSMethodNotAllowedError ( self . __class__ . __name__ ) if data : self . jss . delete ( self . url , data ) else : self . jss . delete ( self . url ) | Delete this object from the JSS . |
27,804 | def save ( self ) : if self . can_put and ( not self . can_list or self . id ) : categories = [ elem for elem in self . findall ( "category" ) ] categories . extend ( [ elem for elem in self . findall ( "category/name" ) ] ) for cat_tag in categories : if cat_tag . text == "No category assigned" : cat_tag . text = "" t... | Update or create a new object on the JSS . |
27,805 | def _handle_location ( self , location ) : if not isinstance ( location , ElementTree . Element ) : element = self . find ( location ) if element is None : raise ValueError ( "Invalid path!" ) else : element = location return element | Return an element located at location with flexible args . |
27,806 | def set_bool ( self , location , value ) : element = self . _handle_location ( location ) if isinstance ( value , basestring ) : value = True if value . upper ( ) == "TRUE" else False elif not isinstance ( value , bool ) : raise ValueError if value is True : element . text = "true" else : element . text = "false" | Set a boolean value . |
27,807 | def add_object_to_path ( self , obj , location ) : location = self . _handle_location ( location ) location . append ( obj . as_list_data ( ) ) results = [ item for item in location . getchildren ( ) if item . findtext ( "id" ) == obj . id ] [ 0 ] return results | Add an object of type JSSContainerObject to location . |
27,808 | def remove_object_from_list ( self , obj , list_element ) : list_element = self . _handle_location ( list_element ) if isinstance ( obj , JSSObject ) : results = [ item for item in list_element . getchildren ( ) if item . findtext ( "id" ) == obj . id ] elif isinstance ( obj , ( int , basestring ) ) : results = [ item ... | Remove an object from a list element . |
27,809 | def from_file ( cls , jss , filename ) : tree = ElementTree . parse ( filename ) root = tree . getroot ( ) return cls ( jss , root ) | Create a new JSSObject from an external XML file . |
27,810 | def from_string ( cls , jss , xml_string ) : root = ElementTree . fromstring ( xml_string . encode ( 'utf-8' ) ) return cls ( jss , root ) | Creates a new JSSObject from an UTF - 8 XML string . |
27,811 | def to_file ( self , path ) : with open ( os . path . expanduser ( path ) , "w" ) as ofile : ofile . write ( self . __repr__ ( ) ) | Write object XML to path . |
27,812 | def as_list_data ( self ) : element = ElementTree . Element ( self . list_type ) id_ = ElementTree . SubElement ( element , "id" ) id_ . text = self . id name = ElementTree . SubElement ( element , "name" ) name . text = self . name return element | Return an Element to be used in a list . |
27,813 | def add_criterion ( self , name , priority , and_or , search_type , value ) : criterion = SearchCriteria ( name , priority , and_or , search_type , value ) self . criteria . append ( criterion ) | Add a search criteria object to a smart group . |
27,814 | def is_smart ( self , value ) : self . set_bool ( "is_smart" , value ) if value is True : if self . find ( "criteria" ) is None : self . criteria = ElementTree . SubElement ( self , "criteria" ) | Set group is_smart property to value . |
27,815 | def add_device ( self , device , container ) : if self . findtext ( "is_smart" ) == "false" : self . add_object_to_path ( device , container ) else : raise ValueError ( "Devices may not be added to smart groups." ) | Add a device to a group . Wraps JSSObject . add_object_to_path . |
27,816 | def has_member ( self , device_object ) : if device_object . tag == "computer" : container_search = "computers/computer" elif device_object . tag == "mobile_device" : container_search = "mobile_devices/mobile_device" else : raise ValueError return len ( [ device for device in self . findall ( container_search ) if devi... | Return bool whether group has a device as a member . |
27,817 | def copy ( self , filename , id_ = - 1 , pre_callback = None , post_callback = None ) : for repo in self . _children : if is_package ( filename ) : copy_method = repo . copy_pkg else : copy_method = repo . copy_script if pre_callback : pre_callback ( repo . connection ) copy_method ( filename , id_ ) if post_callback :... | Copy a package or script to all repos . |
27,818 | def copy_pkg ( self , filename , id_ = - 1 ) : for repo in self . _children : repo . copy_pkg ( filename , id_ ) | Copy a pkg dmg or zip to all repositories . |
27,819 | def copy_script ( self , filename , id_ = - 1 ) : for repo in self . _children : repo . copy_script ( filename , id_ ) | Copy a script to all repositories . |
27,820 | def delete ( self , filename ) : for repo in self . _children : if hasattr ( repo , "delete" ) : repo . delete ( filename ) | Delete a file from all repositories which support it . |
27,821 | def umount ( self , forced = True ) : for child in self . _children : if hasattr ( child , "umount" ) : child . umount ( forced ) | Umount all mountable distribution points . |
27,822 | def exists ( self , filename ) : result = True for repo in self . _children : if not repo . exists ( filename ) : result = False return result | Report whether a file exists on all distribution points . |
27,823 | def _get_user_input ( prompt , key_name , parent , input_func = raw_input ) : val = input_func ( prompt ) ElementTree . SubElement ( parent , "key" ) . text = key_name if isinstance ( val , bool ) : string_val = "true" if val else "false" ElementTree . SubElement ( parent , string_val ) else : ElementTree . SubElement ... | Prompt the user for a value and assign it to key_name . |
27,824 | def _handle_dist_server ( ds_type , repos_array ) : if ds_type not in ( "JDS" , "CDP" ) : raise ValueError ( "Must be JDS or CDP" ) prompt = "Does your JSS use a %s? (Y|N): " % ds_type result = loop_until_valid_response ( prompt ) if result : repo_dict = ElementTree . SubElement ( repos_array , "dict" ) repo_name_key =... | Ask user for whether to use a type of dist server . |
27,825 | def parse_plist ( self , preferences_file ) : preferences_file = os . path . expanduser ( preferences_file ) try : prefs = FoundationPlist . readPlist ( preferences_file ) except NameError : try : prefs = plistlib . readPlist ( preferences_file ) except ExpatError : if is_osx ( ) : subprocess . call ( [ "plutil" , "-co... | Try to reset preferences from preference_file . |
27,826 | def configure ( self ) : root = ElementTree . Element ( "dict" ) print ( "It seems like you do not have a preferences file configured. " "Please answer the following questions to generate a plist at " "%s for use with python-jss." % self . preferences_file ) self . url = _get_user_input ( "The complete URL to your JSS,... | Prompt user for config and write to plist |
27,827 | def _handle_repos ( self , root ) : ElementTree . SubElement ( root , "key" ) . text = "repos" repos_array = ElementTree . SubElement ( root , "array" ) jss_server = JSS ( url = self . url , user = self . user , password = self . password , ssl_verify = self . verify , suppress_warnings = True ) print "Fetching distrib... | Handle repo configuration . |
27,828 | def _write_plist ( self , root ) : indent_xml ( root ) tree = ElementTree . ElementTree ( root ) with open ( self . preferences_file , "w" ) as prefs_file : prefs_file . write ( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" " "\"http://www.apple.com/DTDs/Property... | Write plist file based on our generated tree . |
27,829 | def update ( self ) : response = self . jss . session . post ( self . url , data = self . auth ) response_xml = ElementTree . fromstring ( response . text . encode ( "utf_8" ) ) self . clear ( ) for child in response_xml . getchildren ( ) : self . append ( child ) | Request an updated set of data from casper . jxml . |
27,830 | def mount_share_at_path ( share_path , mount_path ) : sh_url = CFURLCreateWithString ( None , share_path , None ) mo_url = CFURLCreateWithString ( None , mount_path , None ) open_options = { NetFS . kNAUIOptionKey : NetFS . kNAUIOptionNoUI } mount_options = { NetFS . kNetFSAllowSubMountsKey : True , NetFS . kNetFSMount... | Mounts a share at the specified path |
27,831 | def auto_mounter ( original ) : def mounter ( * args ) : self = args [ 0 ] if not self . is_mounted ( ) : self . mount ( ) return original ( * args ) return mounter | Decorator for automatically mounting if needed . |
27,832 | def copy_pkg ( self , filename , _ ) : basename = os . path . basename ( filename ) self . _copy ( filename , os . path . join ( self . connection [ "mount_point" ] , "Packages" , basename ) ) | Copy a package to the repo s Package subdirectory . |
27,833 | def copy_script ( self , filename , id_ = - 1 ) : if ( "jss" in self . connection . keys ( ) and self . connection [ "jss" ] . jss_migrated ) : self . _copy_script_migrated ( filename , id_ , SCRIPT_FILE_TYPE ) else : basename = os . path . basename ( filename ) self . _copy ( filename , os . path . join ( self . conne... | Copy a script to the repo s Script subdirectory . |
27,834 | def _copy_script_migrated ( self , filename , id_ = - 1 , file_type = SCRIPT_FILE_TYPE ) : basefname = os . path . basename ( filename ) resource = open ( filename , "rb" ) headers = { "DESTINATION" : "1" , "OBJECT_ID" : str ( id_ ) , "FILE_TYPE" : file_type , "FILE_NAME" : basefname } response = self . connection [ "j... | Upload a script to a migrated JSS s database . |
27,835 | def delete ( self , filename ) : folder = "Packages" if is_package ( filename ) else "Scripts" path = os . path . join ( self . connection [ "mount_point" ] , folder , filename ) if os . path . isdir ( path ) : shutil . rmtree ( path ) elif os . path . isfile ( path ) : os . remove ( path ) | Delete a file from the repository . |
27,836 | def exists ( self , filename ) : if is_package ( filename ) : filepath = os . path . join ( self . connection [ "mount_point" ] , "Packages" , filename ) else : filepath = os . path . join ( self . connection [ "mount_point" ] , "Scripts" , filename ) return os . path . exists ( filepath ) | Report whether a file exists on the distribution point . |
27,837 | def mount ( self ) : if not self . is_mounted ( ) : if not is_osx ( ) : if not os . path . exists ( self . connection [ "mount_point" ] ) : os . mkdir ( self . connection [ "mount_point" ] ) self . _mount ( ) | Mount the repository . |
27,838 | def umount ( self , forced = True ) : if self . is_mounted ( ) : if is_osx ( ) : cmd = [ "/usr/sbin/diskutil" , "unmount" , self . connection [ "mount_point" ] ] if forced : cmd . insert ( 2 , "force" ) subprocess . check_call ( cmd ) else : cmd = [ "umount" , self . connection [ "mount_point" ] ] if forced : cmd . ins... | Try to unmount our mount point . |
27,839 | def is_mounted ( self ) : mount_check = subprocess . check_output ( "mount" ) . splitlines ( ) valid_mount_strings = self . _get_valid_mount_strings ( ) was_mounted = False if is_osx ( ) : mount_string_regex = re . compile ( r"\(([\w]*),*.*\)$" ) mount_point_regex = re . compile ( r"on ([\w/ -]*) \(.*$" ) elif is_linux... | Test for whether a mount point is mounted . |
27,840 | def _get_valid_mount_strings ( self ) : results = set ( ) join = os . path . join url = self . connection [ "url" ] share_name = urllib . quote ( self . connection [ "share_name" ] , safe = "~()*!.'" ) port = self . connection [ "port" ] results . add ( join ( url , share_name ) ) results . add ( join ( "%s:%s" % ( url... | Return a tuple of potential mount strings . |
27,841 | def _mount ( self ) : if is_osx ( ) : if self . connection [ "jss" ] . verbose : print self . connection [ "mount_url" ] if mount_share : self . connection [ "mount_point" ] = mount_share ( self . connection [ "mount_url" ] ) else : args = [ "mount" , "-t" , self . protocol , self . connection [ "mount_url" ] , self . ... | Mount based on which OS is running . |
27,842 | def _build_url ( self ) : self . connection [ "upload_url" ] = ( "%s/%s" % ( self . connection [ "jss" ] . base_url , "dbfileupload" ) ) self . connection [ "delete_url" ] = ( "%s/%s" % ( self . connection [ "jss" ] . base_url , "casperAdminSave.jxml" ) ) | Build the URL for POSTing files . |
27,843 | def copy_pkg ( self , filename , id_ = - 1 ) : self . _copy ( filename , id_ = id_ , file_type = PKG_FILE_TYPE ) | Copy a package to the distribution server . |
27,844 | def copy_script ( self , filename , id_ = - 1 ) : self . _copy ( filename , id_ = id_ , file_type = SCRIPT_FILE_TYPE ) | Copy a script to the distribution server . |
27,845 | def _copy ( self , filename , id_ = - 1 , file_type = 0 ) : if os . path . isdir ( filename ) : raise JSSUnsupportedFileType ( "Distribution Server type repos do not permit directory " "uploads. You are probably trying to upload a non-flat " "package. Please zip or create a flat package." ) basefname = os . path . base... | Upload a file to the distribution server . |
27,846 | def delete_with_casper_admin_save ( self , pkg ) : if pkg . __class__ . __name__ == "Package" : package_to_delete = pkg . id elif isinstance ( pkg , int ) : package_to_delete = pkg elif isinstance ( pkg , str ) : package_to_delete = self . connection [ "jss" ] . Package ( pkg ) . id else : raise TypeError data_dict = {... | Delete a pkg from the distribution server . |
27,847 | def delete ( self , filename ) : if is_package ( filename ) : self . connection [ "jss" ] . Package ( filename ) . delete ( ) else : self . connection [ "jss" ] . Script ( filename ) . delete ( ) | Delete a package or script from the distribution server . |
27,848 | def exists ( self , filename ) : result = False if is_package ( filename ) : packages = self . connection [ "jss" ] . Package ( ) . retrieve_all ( ) for package in packages : if package . findtext ( "filename" ) == filename : result = True break else : scripts = self . connection [ "jss" ] . Script ( ) . retrieve_all (... | Check for the existence of a package or script . |
27,849 | def exists_using_casper ( self , filename ) : casper_results = casper . Casper ( self . connection [ "jss" ] ) distribution_servers = casper_results . find ( "distributionservers" ) all_packages = [ ] for distribution_server in distribution_servers : packages = set ( ) for package in distribution_server . findall ( "pa... | Check for the existence of a package file . |
27,850 | def command_flush_for ( self , id_type , command_id , status ) : id_types = ( 'computers' , 'computergroups' , 'mobiledevices' , 'mobiledevicegroups' ) status_types = ( 'Pending' , 'Failed' , 'Pending+Failed' ) if id_type not in id_types or status not in status_types : raise ValueError ( "Invalid arguments." ) if isins... | Flush commands for an individual device . |
27,851 | def mac_addresses ( self ) : mac_addresses = [ self . findtext ( "general/mac_address" ) ] if self . findtext ( "general/alt_mac_address" ) : mac_addresses . append ( self . findtext ( "general/alt_mac_address" ) ) return mac_addresses | Return a list of mac addresses for this device . |
27,852 | def _set_upload_url ( self ) : self . _upload_url = "/" . join ( [ self . jss . _url , self . _url , self . resource_type , self . id_type , str ( self . _id ) ] ) | Generate the full URL for a POST . |
27,853 | def save ( self ) : try : response = requests . post ( self . _upload_url , auth = self . jss . session . auth , verify = self . jss . session . verify , files = self . resource ) except JSSPostError as error : if error . status_code == 409 : raise JSSPostError ( error ) else : raise JSSMethodNotAllowedError ( self . _... | POST the object to the JSS . |
27,854 | def search_users ( self , user ) : user_url = "%s/%s/%s" % ( self . url , "user" , user ) response = self . jss . get ( user_url ) return LDAPUsersResults ( self . jss , response ) | Search for LDAP users . |
27,855 | def search_groups ( self , group ) : group_url = "%s/%s/%s" % ( self . url , "group" , group ) response = self . jss . get ( group_url ) return LDAPGroupsResults ( self . jss , response ) | Search for LDAP groups . |
27,856 | def is_user_in_group ( self , user , group ) : search_url = "%s/%s/%s/%s/%s" % ( self . url , "group" , group , "user" , user ) response = self . jss . get ( search_url ) length = len ( response ) result = False if length == 1 : pass elif length == 2 : if response . findtext ( "ldap_user/username" ) == user : if respon... | Test for whether a user is in a group . |
27,857 | def log_flush_with_xml ( self , data ) : if not isinstance ( data , basestring ) : data = ElementTree . tostring ( data ) response = self . delete ( data ) | Flush logs for devices with a supplied xml string . |
27,858 | def log_flush_for_interval ( self , log_type , interval ) : if not log_type : log_type = "policies" interval = interval . replace ( " " , "+" ) flush_url = "{}/{}/interval/{}" . format ( self . url , log_type , interval ) self . jss . delete ( flush_url ) | Flush logs for an interval of time . |
27,859 | def log_flush_for_obj_for_interval ( self , log_type , obj_id , interval ) : if not log_type : log_type = "policies" interval = interval . replace ( " " , "+" ) flush_url = "{}/{}/id/{}/interval/{}" . format ( self . url , log_type , obj_id , interval ) self . jss . delete ( flush_url ) | Flush logs for an interval of time for a specific object . |
27,860 | def _new ( self , name , ** kwargs ) : super ( Package , self ) . _new ( name , ** kwargs ) ElementTree . SubElement ( self , "filename" ) . text = name | Create a new Package from scratch . |
27,861 | def set_category ( self , category ) : if isinstance ( category , Category ) : name = category . name else : name = category self . find ( "category" ) . text = name | Set package category |
27,862 | def add_object_to_scope ( self , obj ) : if isinstance ( obj , Computer ) : self . add_object_to_path ( obj , "scope/computers" ) elif isinstance ( obj , ComputerGroup ) : self . add_object_to_path ( obj , "scope/computer_groups" ) elif isinstance ( obj , Building ) : self . add_object_to_path ( obj , "scope/buildings"... | Add an object to the appropriate scope block . |
27,863 | def add_package ( self , pkg , action_type = "Install" ) : if isinstance ( pkg , Package ) : if action_type not in ( "Install" , "Cache" , "Install Cached" ) : raise ValueError package = self . add_object_to_path ( pkg , "package_configuration/packages" ) action = package . find ( "action" ) if not action : action = El... | Add a Package object to the policy with action = install . |
27,864 | def set_category ( self , category ) : pcategory = self . find ( "general/category" ) pcategory . clear ( ) name = ElementTree . SubElement ( pcategory , "name" ) if isinstance ( category , Category ) : id_ = ElementTree . SubElement ( pcategory , "id" ) id_ . text = category . id name . text = category . name elif isi... | Set the policy s category . |
27,865 | def cyvcf2 ( context , vcf , include , exclude , chrom , start , end , loglevel , silent , individual , no_inds ) : coloredlogs . install ( log_level = loglevel ) start_parsing = datetime . now ( ) log . info ( "Running cyvcf2 version %s" , __version__ ) if include and exclude : log . warning ( "Can not use include and... | fast vcf parsing with cython + htslib |
27,866 | def get_version ( ) : import ast with open ( os . path . join ( "cyvcf2" , "__init__.py" ) , "r" ) as init_file : module = ast . parse ( init_file . read ( ) ) version = ( ast . literal_eval ( node . value ) for node in ast . walk ( module ) if isinstance ( node , ast . Assign ) and node . targets [ 0 ] . id == "__vers... | Get the version info from the mpld3 package without importing it |
27,867 | def verify ( self , verify_locations : str ) -> None : with open ( verify_locations ) : pass try : self . _ocsp_response . basic_verify ( verify_locations ) except _nassl . OpenSSLError as e : if 'certificate verify error' in str ( e ) : raise OcspResponseNotTrustedError ( verify_locations ) raise | Verify that the OCSP response is trusted . |
27,868 | def _parse_ocsp_response_from_openssl_text ( cls , response_text : str , response_status : OcspResponseStatusEnum ) -> Dict [ str , Any ] : response_dict = { 'responseStatus' : cls . _get_value_from_text_output_no_p ( 'OCSP Response Status:' , response_text ) , 'version' : cls . _get_value_from_text_output_no_p ( 'Vers... | Parse OpenSSL s text output and make a lot of assumptions . |
27,869 | def _init_base_objects ( self , ssl_version : OpenSslVersionEnum , underlying_socket : Optional [ socket . socket ] ) -> None : self . _is_handshake_completed = False self . _ssl_version = ssl_version self . _ssl_ctx = self . _NASSL_MODULE . SSL_CTX ( ssl_version . value ) self . _sock = underlying_socket | Setup the socket and SSL_CTX objects . |
27,870 | def _init_server_authentication ( self , ssl_verify : OpenSslVerifyEnum , ssl_verify_locations : Optional [ str ] ) -> None : self . _ssl_ctx . set_verify ( ssl_verify . value ) if ssl_verify_locations : with open ( ssl_verify_locations ) : pass self . _ssl_ctx . load_verify_locations ( ssl_verify_locations ) | Setup the certificate validation logic for authenticating the server . |
27,871 | def _init_client_authentication ( self , client_certchain_file : Optional [ str ] , client_key_file : Optional [ str ] , client_key_type : OpenSslFileTypeEnum , client_key_password : str , ignore_client_authentication_requests : bool ) -> None : if client_certchain_file is not None and client_key_file is not None : sel... | Setup client authentication using the supplied certificate and key . |
27,872 | def shutdown ( self ) -> None : self . _is_handshake_completed = False try : self . _flush_ssl_engine ( ) except IOError : pass try : self . _ssl . shutdown ( ) except OpenSSLError as e : if 'SSL_shutdown:uninitialized' not in str ( e ) and 'shutdown while in init' not in str ( e ) : raise if self . _sock : self . _soc... | Close the TLS connection and the underlying network socket . |
27,873 | def _use_private_key ( self , client_certchain_file : str , client_key_file : str , client_key_type : OpenSslFileTypeEnum , client_key_password : str ) -> None : with open ( client_certchain_file ) : pass with open ( client_key_file ) : pass self . _ssl_ctx . use_certificate_chain_file ( client_certchain_file ) self . ... | The certificate chain file must be in PEM format . Private method because it should be set via the constructor . |
27,874 | def get_tlsext_status_ocsp_resp ( self ) -> Optional [ OcspResponse ] : ocsp_response = self . _ssl . get_tlsext_status_ocsp_resp ( ) if ocsp_response : return OcspResponse ( ocsp_response ) else : return None | Retrieve the server s OCSP Stapling status . |
27,875 | def fetch_source ( self ) -> None : import requests with TemporaryFile ( ) as temp_file : request = requests . get ( self . src_tar_gz_url ) temp_file . write ( request . content ) temp_file . seek ( 0 ) tar_file = tarfile . open ( fileobj = temp_file ) tar_file . extractall ( path = _DEPS_PATH ) | Download the tar archive that contains the source code for the library . |
27,876 | def do_renegotiate ( self ) -> None : if not self . _is_handshake_completed : raise IOError ( 'SSL Handshake was not completed; cannot renegotiate.' ) self . _ssl . renegotiate ( ) self . do_handshake ( ) | Initiate an SSL renegotiation . |
27,877 | def _download_file_vizier ( cat , filePath , catalogname = 'catalog.dat' ) : sys . stdout . write ( '\r' + "Downloading file %s ...\r" % ( os . path . basename ( filePath ) ) ) sys . stdout . flush ( ) try : os . makedirs ( os . path . dirname ( filePath ) ) except OSError : pass downloading = True interrupted = False ... | Stolen from Jo Bovy s gaia_tools package! |
27,878 | def ensure_dir ( f ) : d = os . path . dirname ( f ) if not os . path . exists ( d ) : os . makedirs ( d ) | Ensure a a file exists and if not make the relevant path |
27,879 | def dePeriod ( arr ) : diff = arr - nu . roll ( arr , 1 , axis = 1 ) w = diff < - 6. addto = nu . cumsum ( w . astype ( int ) , axis = 1 ) return arr + _TWOPI * addto | make an array of periodic angles increase linearly |
27,880 | def hinit ( func , x , t , pos_neg , f0 , iord , hmax , rtol , atol , args ) : sk = atol + rtol * np . fabs ( x ) dnf = np . sum ( np . square ( f0 / sk ) , axis = 0 ) dny = np . sum ( np . square ( x / sk ) , axis = 0 ) h = np . sqrt ( dny / dnf ) * 0.01 h = np . min ( [ h , np . fabs ( hmax ) ] ) h = custom_sign ( h ... | Estimate initial step size |
27,881 | def dense_output ( t_current , t_old , h_current , rcont ) : s = ( t_current - t_old ) / h_current s1 = 1.0 - s return rcont [ 0 ] + s * ( rcont [ 1 ] + s1 * ( rcont [ 2 ] + s * ( rcont [ 3 ] + s1 * ( rcont [ 4 ] + s * ( rcont [ 5 ] + s1 * ( rcont [ 6 ] + s * rcont [ 7 ] ) ) ) ) ) ) | Dense output function basically extrapolatin |
27,882 | def phiME_dens ( R , z , phi , dens , Sigma , dSigmadR , d2SigmadR2 , hz , Hz , dHzdz , Sigma_amp ) : r = numpy . sqrt ( R ** 2. + z ** 2. ) out = dens ( R , z , phi ) for a , s , ds , d2s , h , H , dH in zip ( Sigma_amp , Sigma , dSigmadR , d2SigmadR2 , hz , Hz , dHzdz ) : out -= a * ( s ( r ) * h ( z ) + d2s ( r ) * ... | The density corresponding to phi_ME |
27,883 | def _parse_integrator ( int_method ) : if int_method . lower ( ) == 'rk4_c' : int_method_c = 1 elif int_method . lower ( ) == 'rk6_c' : int_method_c = 2 elif int_method . lower ( ) == 'symplec4_c' : int_method_c = 3 elif int_method . lower ( ) == 'symplec6_c' : int_method_c = 4 elif int_method . lower ( ) == 'dopr54_c'... | parse the integrator method to pass to C |
27,884 | def _parse_tol ( rtol , atol ) : if rtol is None : rtol = - 12. * nu . log ( 10. ) else : rtol = nu . log ( rtol ) if atol is None : atol = - 12. * nu . log ( 10. ) else : atol = nu . log ( atol ) return ( rtol , atol ) | Parse the tolerance keywords |
27,885 | def _check_integrate_dt ( t , dt ) : if dt is None : return True mult = round ( ( t [ 1 ] - t [ 0 ] ) / dt ) if nu . fabs ( mult * dt - t [ 1 ] + t [ 0 ] ) < 10. ** - 10. : return True else : return False | Check that the stepszie in t is an integer x dt |
27,886 | def _forceInt ( x , y , z , dens , b2 , c2 , i , glx = None , glw = None ) : def integrand ( s ) : t = 1 / s ** 2. - 1. return dens ( numpy . sqrt ( x ** 2. / ( 1. + t ) + y ** 2. / ( b2 + t ) + z ** 2. / ( c2 + t ) ) ) * ( x / ( 1. + t ) * ( i == 0 ) + y / ( b2 + t ) * ( i == 1 ) + z / ( c2 + t ) * ( i == 2 ) ) / nump... | Integral that gives the force in x y z |
27,887 | def _2ndDerivInt ( x , y , z , dens , densDeriv , b2 , c2 , i , j , glx = None , glw = None ) : def integrand ( s ) : t = 1 / s ** 2. - 1. m = numpy . sqrt ( x ** 2. / ( 1. + t ) + y ** 2. / ( b2 + t ) + z ** 2. / ( c2 + t ) ) return ( densDeriv ( m ) * ( x / ( 1. + t ) * ( i == 0 ) + y / ( b2 + t ) * ( i == 1 ) + z / ... | Integral that gives the 2nd derivative of the potential in x y z |
27,888 | def _mdens ( self , m ) : return ( self . a / m ) ** self . alpha / ( 1. + m / self . a ) ** ( self . betaminusalpha ) | Density as a function of m |
27,889 | def _fit_orbit ( orb , vxvv , vxvv_err , pot , radec = False , lb = False , customsky = False , lb_to_customsky = None , pmllpmbb_to_customsky = None , tintJ = 100 , ntintJ = 1000 , integrate_method = 'dopr54_c' , ro = None , vo = None , obs = None , disp = False ) : coords . _APY_COORDS_ORIG = coords . _APY_COORDS coo... | Fit an orbit to data in a given potential |
27,890 | def actionAngle_physical_input ( method ) : @ wraps ( method ) def wrapper ( * args , ** kwargs ) : if len ( args ) < 3 : return method ( * args , ** kwargs ) ro = kwargs . get ( 'ro' , None ) if ro is None and hasattr ( args [ 0 ] , '_ro' ) : ro = args [ 0 ] . _ro if _APY_LOADED and isinstance ( ro , units . Quantity ... | Decorator to convert inputs to actionAngle functions from physical to internal coordinates |
27,891 | def _direct_nbody_force ( q , m , t , pot , softening , softening_args ) : nq = len ( q ) dim = len ( q [ 0 ] ) dist_vec = nu . zeros ( ( nq , nq , dim ) ) dist = nu . zeros ( ( nq , nq ) ) for ii in range ( nq ) : for jj in range ( ii + 1 , nq ) : dist_vec [ ii , jj , : ] = q [ jj ] - q [ ii ] dist_vec [ jj , ii , : ]... | Calculate the force |
27,892 | def _vmomentsurfaceIntegrand ( vR , vT , R , az , df , n , m , sigmaR1 , sigmaT1 , t , initvmoment ) : o = Orbit ( [ R , vR * sigmaR1 , vT * sigmaT1 , az ] ) return vR ** n * vT ** m * df ( o , t ) / initvmoment | Internal function that is the integrand for the velocity moment times surface mass integration |
27,893 | def _vmomentsurfacemassGrid ( self , n , m , grid ) : if len ( grid . df . shape ) == 3 : tlist = True else : tlist = False if tlist : nt = grid . df . shape [ 2 ] out = [ ] for ii in range ( nt ) : out . append ( nu . dot ( grid . vRgrid ** n , nu . dot ( grid . df [ : , : , ii ] , grid . vTgrid ** m ) ) * ( grid . vR... | Internal function to evaluate vmomentsurfacemass using a grid rather than direct integration |
27,894 | def _buildvgrid ( self , R , phi , nsigma , t , sigmaR1 , sigmaT1 , meanvR , meanvT , gridpoints , print_progress , integrate_method , deriv ) : out = evolveddiskdfGrid ( ) out . sigmaR1 = sigmaR1 out . sigmaT1 = sigmaT1 out . meanvR = meanvR out . meanvT = meanvT out . vRgrid = nu . linspace ( meanvR - nsigma * sigmaR... | Internal function to grid the vDF at a given location |
27,895 | def _determine_stream_spread_single ( sigomatrixEig , thetasTrack , sigOmega , sigAngle , allinvjacsTrack ) : sigObig2 = sigOmega ( thetasTrack ) ** 2. tsigOdiag = copy . copy ( sigomatrixEig [ 0 ] ) tsigOdiag [ numpy . argmax ( tsigOdiag ) ] = sigObig2 tsigO = numpy . dot ( sigomatrixEig [ 1 ] , numpy . dot ( numpy . ... | sigAngle input may either be a function that returns the dispersion in perpendicular angle as a function of parallel angle or a value |
27,896 | def _progenitor_setup ( self , progenitor , leading , useTMHessian ) : self . _progenitor = progenitor ( ) self . _progenitor . turn_physical_off ( ) acfs = self . _aA . actionsFreqsAngles ( self . _progenitor , _firstFlip = ( not leading ) , use_physical = False ) self . _progenitor_jr = acfs [ 0 ] [ 0 ] self . _proge... | The part of the setup relating to the progenitor s orbit |
27,897 | def _setup_progIsTrack ( self ) : self . _sigMeanSign *= - 1. prog_stream_offset = _determine_stream_track_single ( self . _aA , self . _progenitor , 0. , self . _progenitor_angle , self . _sigMeanSign , self . _dsigomeanProgDirection , lambda x : self . meanOmega ( x , use_physical = False ) , 0. ) progenitor = Orbit ... | If progIsTrack the progenitor orbit that was passed to the streamdf initialization is the track at zero angle separation ; this routine computes an actual progenitor position that gives the desired track given the parameters of the streamdf |
27,898 | def _determine_nTrackIterations ( self , nTrackIterations ) : if not nTrackIterations is None : self . nTrackIterations = nTrackIterations return None if numpy . fabs ( self . misalignment ( quantity = False ) ) < 1. / 180. * numpy . pi : self . nTrackIterations = 0 elif numpy . fabs ( self . misalignment ( quantity = ... | Determine a good value for nTrackIterations based on the misalignment between stream and orbit ; just based on some rough experience for now |
27,899 | def _interpolate_stream_track_aA ( self ) : if hasattr ( self , '_interpolatedObsTrackAA' ) : return None if not hasattr ( self , '_interpolatedThetasTrack' ) : self . _interpolate_stream_track ( ) dmOs = numpy . array ( [ self . meanOmega ( da , oned = True , use_physical = False ) for da in self . _interpolatedThetas... | Build interpolations of the stream track in action - angle coordinates |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.