Commit 2d0da25f authored by Michele Maris's avatar Michele Maris
Browse files

u

parent f0e0b26b
Loading
Loading
Loading
Loading
+6 −89
Original line number Diff line number Diff line
# YAPSUT
YAPSUT
Yet Another Python Sciece Utilty Toolkit

M.Maris - 0.0 - 2022 dec 01 -


## Getting started

To make it easy for you to get started with GitLab, here's a list of recommended next steps.

Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!

## Add your files

- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:

```
cd existing_repo
git remote add origin https://www.ict.inaf.it/gitlab/michele.maris/yapsut.git
git branch -M main
git push -uf origin main
```

## Integrate with your tools

- [ ] [Set up project integrations](https://www.ict.inaf.it/gitlab/michele.maris/yapsut/-/settings/integrations)

## Collaborate with your team

- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
- [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)

## Test and Deploy

Use the built-in continuous integration in GitLab.

- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)

***

# Editing this README

When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template.

## Suggestions for a good README
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.

## Name
Choose a self-explaining name for your project.

## Description
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.

## Badges
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.

## Visuals
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.

## Installation
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.

## Usage
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.

## Support
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.

## Roadmap
If you have ideas for releases in the future, it is a good idea to list them in the README.

## Contributing
State if you are open to contributions and what your requirements are for accepting them.

For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.

You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.

## Authors and acknowledgment
Show your appreciation to those who have contributed to the project.

## License
For open source projects, say how it is licensed.

## Project status
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
This is a simple example package. You can use
[Github-flavored Markdown](https://guides.github.com/features/mastering-markdown/)
to write your content.
+189 −0
Original line number Diff line number Diff line
from collections import OrderedDict
import numpy as np
import pandas
import io
import time

class AppendableDict :
   """ a dictionary, whose arguments are lists which can be appended 
   
   Example: 
      >AD=AppendableDict()
      >
      >AD['line1']=1
      >AD['line2']=10
      >
      >AD['line1']=2
      >AD['line2']=20
      >
      >AD['line1']=3
      >AD['line2']=30
      >
      >print(AD['line1'])
      [1,2,3]
      
   """
   def __init__(self,comment=None) :
      """
      Keys: 
        comment : comment string
      """
      self._k=[]
      self._d={}
      self._comment="" if comment is None else comment
   def keys(self) :
      """ list of arguments """
      return self._k
   def __getitem__(self,this) :
      return self._d[this]
   def __setitem__(self,this,that) :
      if this in self.keys() :
         self._d[this].append(that)
      else :
         self.keys().append(this)
         self._d[this]=[that]
   def isempty(self) :
      """ true if empty dictionary """
      return len(self.keys()) == 0
   def same_columns_length(self) :
      """ true if all the arguments have the same lenght """
      out=np.array([len(self[k]) for k in self.keys()])
      if out.ptp()==0 : return True
      return False
   def appendDict(self,_dict) :
      """ append another dictionary """
      for k in _dict.keys() :
         self[k]=_dict[k]
   def set(self,key,value) :
      if not key in self.keys() :
         self._k.append(key)
      self._d[key]=value
   def flatten_nested_columns(self) :
      """ treats contents as nested arrays and serializes them
          beware: after this operation any appending or inserting
          of new variables/values will produce unpredictable results
      """
      for k in self._k :
         self._d[k]=np.concatenate(self._d[k])
   def to_arrayDict(self,flatten=False) :
      """ dictionary to numpy.array
          if flatten==True applies .flatten_nested_columns() method
      """
      out=OrderedDict()
      if flatten :
         for k in self.keys() :
            out[k]=np.concatenate(self[k])
      else :
         for k in self.keys() :
            out[k]=np.array(self[k])
      return out
   def to_pandas(self,flatten=False) :
      """ dictionary to pandas.DataFrame
          if flatten==True applies .flatten_nested_columns() method
      """
      out=self.to_arrayDict(flatten=flatten)
      return pandas.DataFrame(out)
   def to_csv_slow(self,csvfile,justBody=False,creator="",index_label=None,sep=',',comment=None,addEnd=False,mode='w') :
      """ dictionary to csv, slow version """
#      from collections import OrderedDict 
#      import pandas
#      import time
#      import io
      #
      Dict=self._d
      #
      headf=','.join(Dict.keys())
      #
      n=np.array([len(self[i]) for i in Dict.keys()])
      if (n.ptp()!=0) :
         raise Error("columns of different lenght ",n)
      #
      body=io.StringIO()
      for i in range(int(n[0])) :
         l=[]
         for k in Dict.keys() :
            l.append(str(Dict[k][i]))
         l=(','.join(l))+'\n'
         body.write(l)
         print(l)
      body=body.getvalue()
      #
      if justBody :
         if not csvfile is None :
            open(csvfile,mode).write(body+'\n')
         return body
      #
      out=io.StringIO()
      out.write("#\n")
      out.write("#!filename="+(csvfile if not csvfile is None else "")+'\n')
      out.write("#!created="+time.asctime()+'\n')
      out.write("#!creatore="+(creator if type(creator)==type("") else "")+'\n')
      out.write("#\n")
      if not self._comment is None :
         cc='\n'.join(['#'+k for k in self._comment.split('\n')])
         out.write(cc+'\n')
         out.write('#\n')
      if not comment is None :
         cc='\n'.join(['#'+k for k in comment.split('\n')])
         out.write(cc+'\n')
         out.write('#\n')
      out.write("#!BEGIN\n")
      out.write(headf+'\n')
      out.write(body+'\n')
      if addEnd :
         out.write("#!END\n")
      out=out.getvalue()
      if not csvfile is None :
         open(csvfile,mode).write(out)
      return out
   def to_csv(self,csvfile,justBody=False,creator="",index_label='index',sep=',',comment=None,addEnd=True,mode='w',sort_by=None) :
      """ dictionary to csv"""
#      from collections import OrderedDict 
#      import pandas
#      import time
#      import io
      #
      opd=self.to_pandas()
      if not sort_by is None:
         opd['_'+sort_by]=np.array(opd[sort_by].values)
         opd.sort_values('_'+sort_by,inplace=True)
         opd=opd.reindex()
         opd.drop('_'+sort_by,inplace=True,axis=1)
      else :
         for k in self.keys() :
            opd[k]=np.array(self[k])
      #opd=self.to_pandas()
      #
      out=io.StringIO()
      if not justBody :
         out.write("#\n")
         out.write("#!filename="+csvfile+'\n')
         out.write("#!created="+time.asctime()+'\n')
         out.write("#!creator="+(creator if type(creator)==type("") else "")+'\n')
         out.write("#\n")
         if not self._comment is None :
            cc='\n'.join(['#'+k for k in self._comment.split('\n')])
            out.write(cc+'\n')
            out.write('#\n')
         if not comment is None :
            cc='\n'.join(['#'+k for k in comment.split('\n')])
            out.write(cc+'\n')
            out.write('#\n')
         out.write("#!BEGIN\n")
      opd.to_csv(out,sep=',',index=(not index_label is None),index_label=index_label)
      #
      if not justBody and addEnd :
         out.write("#!END\n")
      #
      #removes empty lines, if any
      out=[k.strip() for k in out.getvalue().split('\n') if k.strip()!='']
      #
      #removes header if just body is needed
      if justBody :
         out=out[1:]
      #
      out='\n'.join(out)+'\n'
      if not csvfile is None :
         open(csvfile,mode).write(out)
      return out

src/YAPSUT/README.md

0 → 100644
+9 −0
Original line number Diff line number Diff line
YAPSUT
Yet Another Python Sciece Utilty Toolkit

M.Maris - 0.0 - 2022 dec 01 -


This is a simple example package. You can use
[Github-flavored Markdown](https://guides.github.com/features/mastering-markdown/)
to write your content.

src/YAPSUT/__init__.py

0 → 100644
+8 −0
Original line number Diff line number Diff line
# Created : Thu Dec  1 20:04:27 2022
from .graphics import odot,ocirc,curveXY2patch,SaveFig,STANDARDFIG,StandarFig
from .pyblocks import pyBlocks
from .AppendableDict import AppendableDict
from .ya_config import YA_CONFIG
from .ya_hdr_parser import YA_HDR_PARSER
from .ya_extended_csv import ya_extended_csv
from .files import moveFile2backup

src/YAPSUT/files.py

0 → 100644
+10 −0
Original line number Diff line number Diff line
def moveFile2backup(fname,skipTestExists=False) :
   """if exists creates a backup file for the file fname
      skipTestExists=True skips the test
   """
   import time
   import os
   if os.path.exists(fname)==False and skipTestExists==False : return 
   tt=fname+'.'+time.strftime('%y%m%dl%H%M%S',time.localtime())+'~'
   print('Existing '+fname+' -> ',tt)
   os.rename(fname,tt)
Loading