DMU


NameDMU JSON
Version 0.3.3 PyPI version JSON
download
home_pagehttps://github.com/DeltaMod/DMU
SummaryThis package is used to store commonly used functions on pip for the sake of easy pulling for other code.
upload_time2024-12-16 11:13:46
maintainerNone
docs_urlNone
authorAtli Vidar Már FLodgren
requires_pythonNone
licenseNone
keywords hello world example examples
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # ATTENTION
This is just a code-storage repository for small functions I use normally. 
 
# LDI

 """ 
    General Help:

    NAME
    DMU

    DESCRIPTION
    Dunno Why I named it DMU, but it's catchy
    Created on Thurs Aug 04 17:00:00 2022
    @author: Vidar Flodgren
    Github: https://github.com/DeltaMod

    FUNCTIONS
    -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    AbsPowIntegrator(Data, x, y, z, WL)
        "A function that uses a RectBivariateSpline function to determine the total absorbed power from a pabs_adv lumerical file."
        Calculating total power absorption as a power fraction:s
        Lumerical initially gives P_abs in terms of W/m^3, but then converts it by dividing by the source power - which is why the values are seemingly massive. 
        SP   = meshgrid4d(4,x,y,z,sourcepower(f));
        Pabs = Pabs / SP;
        
        If we then look inside the P_abs_tot analysis group script, we can see that this simply becomes an integration over each 2d slice:
        Pabs_integrated = integrate2(Pabs,1:3,x,y,z);
        We could simply export Pabs_tot, but I think we get more control if we do it manually, and we also save data!
    
    CUV(**kwargs)
        Change_User_Variables -- or CUV -- is a function used to save and load user defined variables at the start, and then at the end, of any session.
        Parameters
        ----------
        **kwargs : 
            [act,action,a]              : 
                ['reset','r','res'] - fully replaces the current DataImportSettings.json default file with default settings. This action cannot be undone
                ['load','l']        - loads a specific file. This function opens up a file dialog for selection, so you don't need to add anything else. This also saves the location to Aux_File.
                ['init','i','initialise'] - initialises your file with the current DataImportSettings. It will load Aux_File if the field is not None
                ['sesh','save session','session'] - requires a data kwarg field with a dictionary listed. It will accept ANY dictionary, and save this to the currently active DataImportSettings file (or Aux_File, if loaded)
                ['ddir','data dir','directories'] - will allow you to select a new data directories file. If the file does not exist, you can save it as a new file by writing a new name for it. 
                
            [co, console, console out]  = Select if console output is set to [True/False]
            [path, pathtype, pt]        = Choose path type preference ['rel','abs']. Selecting 'rel' will save the directory of selected files in using a relative address, but only if it can! It the start of the address does not match the current working directory, absolute address will be used automatically.
            [data, d, dat]              = Specify DataImportSettings data <type: Dict>. Must be included in act='sesh' and 'save' (when implemented), but is ignored otherwise. 
            
        
        Returns 
        -------
        Dictionary data saved to DataImportSettings.json or Aux_File indicated within DataImportSettings.json!
    
    DataDir(**kwargs)
        Function to handle loading new data from other directories - should be expanded to support an infinitely large list of directories, by appending new data to the file.
        Note: to change currently active data-dir, you need to select a new file in CUV. I'm going to set up a function that allows you to both select a file, and to make a new one! 
        
        What to do here? I'm saving a file with directories, and I'm giving an option to set the save location in a different directory, isn't that a bit much?
        Maybe I should just have the option in CUV to select a new DataDirectories file, and let this one only pull the directory from CUV?
        
        Current implementation:
            UVAR = CUV(act='init') means UVAR now contains all your variables, and to save you would do CUV(d=UVAR,act = 'session'), which keeps all changes and additions you made to UVAR.
            If you want to add a data directory using DataDir, it too will use CUV(act='init') to load the file, but this does not take into account any changes made in UVAR.
            Solution: Add CUV(act='data_dir') to add a new empty .json file with a particular name, or to select a previously created data_dir file, and make that file the new 
            UVAR['Data_Directories_File']. 
            
            How do you make sure that UVAR is updated properly? 
            Current solution is to give a cprint call telling you to load UVAR again if you make this change, or to return the newly edited file with the function...
    
    FirstLaunch()
        A function that aims to set up the file structureof a new file. Running this function first will create the DataImportSettings.json and populate it with the default settings.
        Then, it will call an "add" command for DataDirectories.json, prompting you to select a data folder.
    
    Get_FileList(path, **kwargs)
        A function that gives you a list of filenames from a specific folder
        path = path to files. Is relative unless you use kwarg pathtype = 'abs'
        kwargs**:
            pathtype: enum in ['rel','abs'], default = 'rel'. Allows you to manually enter absolute path    
            ext: file extension to look for, use format '.txt'. You can use a list e.g. ['.txt','.mat','.png'] to collect multiple files. Default is all files
            sorting: "alphabetical" or "numeric" sorting, default is "alphabetical"
    
    KwargEval(fkwargs, kwargdict, **kwargs)
        A short function that handles kwarg assignment and definition using the same kwargdict as before. To preassign values in the kw.class, you use the kwargs at the end
        use: provide the kwargs fed to the function as fkwargs, then give a kwarg dictionary. 
        
        Example:
            
            kw = KwargEval(kwargs,kwargdict,pathtype='rel',co=True,data=None)
            does the same as what used to be in each individual function. Note that this function only has error handling when inputting the command within which this is called.
            Ideally, you'd use this for ALL kwarg assigments to cut down on work needed.
    
    MatLoader(file, **kwargs)
    
    MultChoiceCom(**kwargs)
    
    PathSet(filename, **kwargs)
        "
        p/pt/pathtype in [rel,relative,abs,absolute]
        Note that rel means you input a relative path, and it auto-completes it to be an absolute path, 
        whereas abs means that you input an absolute path!
    
    cprint(String, **kwargs)
            WARNING: The format of this script's kwarg importing is severely different from all other functions in this sheet - consider revising to make use instead of the kwargdict and assigning variables through that!
            Note that some light colour variations do not work on all terminals! To get light colours on style-inedpendent terminals, you can use ts = bold!
            kwargs:
            
            mt: Message type - a string that defines one from a list of preset message formats. 
                List of acceptable entries: ['err','error','note','warning','caution','wrn','curio','status','stat','custom']. Note: only custom supports further kwargs
            fg: Foreground colour - a string with the full name or abbrviation of a colour to give to the text.
                List of acceptable entries: ['black','k','red','r','green','g','orange','o','blue','b','purple','p','cyan','c','lightgrey','lg',
                                             'darkgrey','dg','lightgreen','lgr','yellow','y','lightblue','lb','pink','pk','lightcyan','lc']
                                            Note that some light colours are accessed using bold style instead of this!
            bg: Background colour - a string with the full name or abbrviation of a colour to highlight text with.
                List of acceptable entries: ['black','k','red','r','green','g','orange','o','blue','b','purple','p','cyan','c','lightgrey','lg']
            ts: Text Style - a string indicating what style to apply to the text. Some do not work as intended.
                List of acceptable entries: ['bold','b','italic','it','underline','ul','strikethrough','st','reverse','rev','disable','db','invisible','inv']
            sc: StartCode - A custom startcode if you want to use specific colours not listed in the code. 
                Note: overwrites any bs/fg inputs, is compatible only with "custom" message type, but supports text style ts kwargs!
            jc: Join character - This is the character that will join the strings in a list together, recommend '
        ' or ' ' but anything works 
            cprint also supports lists with different styles and options applied. Use:
                cprint([string1,string2],fg = [fg1,fg2],bg = [bg1,bg2],ts = [ts1,ts2])
            tr: textreturn - returns the escape character strng instead - does not produce a print output!
            co: console output - a global variable if you want an option to disable console ouput throughout your code!
                list of acceptable entries: [True,False], default: False
    
    jsonhandler(**kwargs)
         DESCRIPTION.
         A simple script that handles saving/loading json files from/to python dictionaries. 
        
        Parameters
        ----------
        **kwargs :
                kwargdict = {'f':'filename','fn':'filename','filename':'filename',
                     'd':'data','dat':'data','data':'data',
                     'a':'action','act':'action','action':'action',
                     'p':'pathtype','pt':'pathtype','pathtype':'pathtype'}
        
        Returns
        -------
        Depends: If loading, returns the file, if saving - returns nothing
    
    maxRepeating(str, **kwargs)
        DESCRIPTION.
        A function used to find and count the max repeating string, can be used to guess
        Parameters
        ----------
        str : TYPE
            DESCRIPTION.
        **kwargs : 
            guess : TYPE = str
            allows you to guess the escape character, and it will find the total number of that character only!
        
        Returns
        -------
        res,count
        Character and total number consecutive

"""

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/DeltaMod/DMU",
    "name": "DMU",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "hello world example examples",
    "author": "Atli Vidar M\u00e1r FLodgren",
    "author_email": "vidar.flodgren@sljus.lu.se",
    "download_url": "https://files.pythonhosted.org/packages/5e/c0/4cfb8d49804b69afeefe1796293f5eea5cee7143581bc8efaf0fbb2c9cfd/dmu-0.3.3.tar.gz",
    "platform": null,
    "description": "# ATTENTION\r\nThis is just a code-storage repository for small functions I use normally. \r\n \r\n# LDI\r\n\r\n \"\"\" \r\n    General Help:\r\n\r\n    NAME\r\n    DMU\r\n\r\n    DESCRIPTION\r\n    Dunno Why I named it DMU, but it's catchy\r\n    Created on Thurs Aug 04 17:00:00 2022\r\n    @author: Vidar Flodgren\r\n    Github: https://github.com/DeltaMod\r\n\r\n    FUNCTIONS\r\n    -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\r\n    AbsPowIntegrator(Data, x, y, z, WL)\r\n        \"A function that uses a RectBivariateSpline function to determine the total absorbed power from a pabs_adv lumerical file.\"\r\n        Calculating total power absorption as a power fraction:s\r\n        Lumerical initially gives P_abs in terms of W/m^3, but then converts it by dividing by the source power - which is why the values are seemingly massive. \r\n        SP   = meshgrid4d(4,x,y,z,sourcepower(f));\r\n        Pabs = Pabs / SP;\r\n        \r\n        If we then look inside the P_abs_tot analysis group script, we can see that this simply becomes an integration over each 2d slice:\r\n        Pabs_integrated = integrate2(Pabs,1:3,x,y,z);\r\n        We could simply export Pabs_tot, but I think we get more control if we do it manually, and we also save data!\r\n    \r\n    CUV(**kwargs)\r\n        Change_User_Variables -- or CUV -- is a function used to save and load user defined variables at the start, and then at the end, of any session.\r\n        Parameters\r\n        ----------\r\n        **kwargs : \r\n            [act,action,a]              : \r\n                ['reset','r','res'] - fully replaces the current DataImportSettings.json default file with default settings. This action cannot be undone\r\n                ['load','l']        - loads a specific file. This function opens up a file dialog for selection, so you don't need to add anything else. This also saves the location to Aux_File.\r\n                ['init','i','initialise'] - initialises your file with the current DataImportSettings. It will load Aux_File if the field is not None\r\n                ['sesh','save session','session'] - requires a data kwarg field with a dictionary listed. It will accept ANY dictionary, and save this to the currently active DataImportSettings file (or Aux_File, if loaded)\r\n                ['ddir','data dir','directories'] - will allow you to select a new data directories file. If the file does not exist, you can save it as a new file by writing a new name for it. \r\n                \r\n            [co, console, console out]  = Select if console output is set to [True/False]\r\n            [path, pathtype, pt]        = Choose path type preference ['rel','abs']. Selecting 'rel' will save the directory of selected files in using a relative address, but only if it can! It the start of the address does not match the current working directory, absolute address will be used automatically.\r\n            [data, d, dat]              = Specify DataImportSettings data <type: Dict>. Must be included in act='sesh' and 'save' (when implemented), but is ignored otherwise. \r\n            \r\n        \r\n        Returns \r\n        -------\r\n        Dictionary data saved to DataImportSettings.json or Aux_File indicated within DataImportSettings.json!\r\n    \r\n    DataDir(**kwargs)\r\n        Function to handle loading new data from other directories - should be expanded to support an infinitely large list of directories, by appending new data to the file.\r\n        Note: to change currently active data-dir, you need to select a new file in CUV. I'm going to set up a function that allows you to both select a file, and to make a new one! \r\n        \r\n        What to do here? I'm saving a file with directories, and I'm giving an option to set the save location in a different directory, isn't that a bit much?\r\n        Maybe I should just have the option in CUV to select a new DataDirectories file, and let this one only pull the directory from CUV?\r\n        \r\n        Current implementation:\r\n            UVAR = CUV(act='init') means UVAR now contains all your variables, and to save you would do CUV(d=UVAR,act = 'session'), which keeps all changes and additions you made to UVAR.\r\n            If you want to add a data directory using DataDir, it too will use CUV(act='init') to load the file, but this does not take into account any changes made in UVAR.\r\n            Solution: Add CUV(act='data_dir') to add a new empty .json file with a particular name, or to select a previously created data_dir file, and make that file the new \r\n            UVAR['Data_Directories_File']. \r\n            \r\n            How do you make sure that UVAR is updated properly? \r\n            Current solution is to give a cprint call telling you to load UVAR again if you make this change, or to return the newly edited file with the function...\r\n    \r\n    FirstLaunch()\r\n        A function that aims to set up the file structureof a new file. Running this function first will create the DataImportSettings.json and populate it with the default settings.\r\n        Then, it will call an \"add\" command for DataDirectories.json, prompting you to select a data folder.\r\n    \r\n    Get_FileList(path, **kwargs)\r\n        A function that gives you a list of filenames from a specific folder\r\n        path = path to files. Is relative unless you use kwarg pathtype = 'abs'\r\n        kwargs**:\r\n            pathtype: enum in ['rel','abs'], default = 'rel'. Allows you to manually enter absolute path    \r\n            ext: file extension to look for, use format '.txt'. You can use a list e.g. ['.txt','.mat','.png'] to collect multiple files. Default is all files\r\n            sorting: \"alphabetical\" or \"numeric\" sorting, default is \"alphabetical\"\r\n    \r\n    KwargEval(fkwargs, kwargdict, **kwargs)\r\n        A short function that handles kwarg assignment and definition using the same kwargdict as before. To preassign values in the kw.class, you use the kwargs at the end\r\n        use: provide the kwargs fed to the function as fkwargs, then give a kwarg dictionary. \r\n        \r\n        Example:\r\n            \r\n            kw = KwargEval(kwargs,kwargdict,pathtype='rel',co=True,data=None)\r\n            does the same as what used to be in each individual function. Note that this function only has error handling when inputting the command within which this is called.\r\n            Ideally, you'd use this for ALL kwarg assigments to cut down on work needed.\r\n    \r\n    MatLoader(file, **kwargs)\r\n    \r\n    MultChoiceCom(**kwargs)\r\n    \r\n    PathSet(filename, **kwargs)\r\n        \"\r\n        p/pt/pathtype in [rel,relative,abs,absolute]\r\n        Note that rel means you input a relative path, and it auto-completes it to be an absolute path, \r\n        whereas abs means that you input an absolute path!\r\n    \r\n    cprint(String, **kwargs)\r\n            WARNING: The format of this script's kwarg importing is severely different from all other functions in this sheet - consider revising to make use instead of the kwargdict and assigning variables through that!\r\n            Note that some light colour variations do not work on all terminals! To get light colours on style-inedpendent terminals, you can use ts = bold!\r\n            kwargs:\r\n            \r\n            mt: Message type - a string that defines one from a list of preset message formats. \r\n                List of acceptable entries: ['err','error','note','warning','caution','wrn','curio','status','stat','custom']. Note: only custom supports further kwargs\r\n            fg: Foreground colour - a string with the full name or abbrviation of a colour to give to the text.\r\n                List of acceptable entries: ['black','k','red','r','green','g','orange','o','blue','b','purple','p','cyan','c','lightgrey','lg',\r\n                                             'darkgrey','dg','lightgreen','lgr','yellow','y','lightblue','lb','pink','pk','lightcyan','lc']\r\n                                            Note that some light colours are accessed using bold style instead of this!\r\n            bg: Background colour - a string with the full name or abbrviation of a colour to highlight text with.\r\n                List of acceptable entries: ['black','k','red','r','green','g','orange','o','blue','b','purple','p','cyan','c','lightgrey','lg']\r\n            ts: Text Style - a string indicating what style to apply to the text. Some do not work as intended.\r\n                List of acceptable entries: ['bold','b','italic','it','underline','ul','strikethrough','st','reverse','rev','disable','db','invisible','inv']\r\n            sc: StartCode - A custom startcode if you want to use specific colours not listed in the code. \r\n                Note: overwrites any bs/fg inputs, is compatible only with \"custom\" message type, but supports text style ts kwargs!\r\n            jc: Join character - This is the character that will join the strings in a list together, recommend '\r\n        ' or ' ' but anything works \r\n            cprint also supports lists with different styles and options applied. Use:\r\n                cprint([string1,string2],fg = [fg1,fg2],bg = [bg1,bg2],ts = [ts1,ts2])\r\n            tr: textreturn - returns the escape character strng instead - does not produce a print output!\r\n            co: console output - a global variable if you want an option to disable console ouput throughout your code!\r\n                list of acceptable entries: [True,False], default: False\r\n    \r\n    jsonhandler(**kwargs)\r\n         DESCRIPTION.\r\n         A simple script that handles saving/loading json files from/to python dictionaries. \r\n        \r\n        Parameters\r\n        ----------\r\n        **kwargs :\r\n                kwargdict = {'f':'filename','fn':'filename','filename':'filename',\r\n                     'd':'data','dat':'data','data':'data',\r\n                     'a':'action','act':'action','action':'action',\r\n                     'p':'pathtype','pt':'pathtype','pathtype':'pathtype'}\r\n        \r\n        Returns\r\n        -------\r\n        Depends: If loading, returns the file, if saving - returns nothing\r\n    \r\n    maxRepeating(str, **kwargs)\r\n        DESCRIPTION.\r\n        A function used to find and count the max repeating string, can be used to guess\r\n        Parameters\r\n        ----------\r\n        str : TYPE\r\n            DESCRIPTION.\r\n        **kwargs : \r\n            guess : TYPE = str\r\n            allows you to guess the escape character, and it will find the total number of that character only!\r\n        \r\n        Returns\r\n        -------\r\n        res,count\r\n        Character and total number consecutive\r\n\r\n\"\"\"\r\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "This package is used to store commonly used functions on pip for the sake of easy pulling for other code.",
    "version": "0.3.3",
    "project_urls": {
        "Homepage": "https://github.com/DeltaMod/DMU"
    },
    "split_keywords": [
        "hello",
        "world",
        "example",
        "examples"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a6500cbb1a8720946688eaee591dc6b40865cc2c89ce14a29ee06fb792a177fb",
                "md5": "ad91d91f9effe09040aeea896a77788e",
                "sha256": "7c0e06b159546f7d9d4ceed5498536093b93b6bc9ac49fa465341d8dc2806619"
            },
            "downloads": -1,
            "filename": "DMU-0.3.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ad91d91f9effe09040aeea896a77788e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 100187,
            "upload_time": "2024-12-16T11:13:45",
            "upload_time_iso_8601": "2024-12-16T11:13:45.109012Z",
            "url": "https://files.pythonhosted.org/packages/a6/50/0cbb1a8720946688eaee591dc6b40865cc2c89ce14a29ee06fb792a177fb/DMU-0.3.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5ec04cfb8d49804b69afeefe1796293f5eea5cee7143581bc8efaf0fbb2c9cfd",
                "md5": "1b0b4bfd4f85fe0ead7f5cba409c074b",
                "sha256": "6a9fdb1fe13893777e6d5b574938b54cf9cf92bc7196594d872d50286b71decb"
            },
            "downloads": -1,
            "filename": "dmu-0.3.3.tar.gz",
            "has_sig": false,
            "md5_digest": "1b0b4bfd4f85fe0ead7f5cba409c074b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 60602,
            "upload_time": "2024-12-16T11:13:46",
            "upload_time_iso_8601": "2024-12-16T11:13:46.310074Z",
            "url": "https://files.pythonhosted.org/packages/5e/c0/4cfb8d49804b69afeefe1796293f5eea5cee7143581bc8efaf0fbb2c9cfd/dmu-0.3.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-16 11:13:46",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "DeltaMod",
    "github_project": "DMU",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "dmu"
}
        
Elapsed time: 0.39431s