Comments (4)
Please take a look at the new branch feature-metadata, which implements a first version of a Metadata class.
- I moved Asig.sr, Asig.cn, Asig.label to Metadata, (as this is meta data ;-)
- but I added @properties, so that they can also be accessed and set as we are used to
- the notebook Asig-metadata-test.ipynb shows how it works
- the output is still a bit verbose yet...
- a new Asig._copy_update() method facilitates a deep copy of an asig while excluding the deep copy of the contained sig in case a sig is updated.
- This will facilitate lots of method returns
- However, so far only few (fade_out, norm, plot, getitem) are rewritten, mainly for testing.
Pros:
- metadata are flexible, extensible
- better handling of revision, as list in metadata
- simpler compilation of an Asig-to-return, no risk of forgetting to set values
- context always copied on chained method invocations
Cons:
- explicit access to new metadata (e.g. author, timestamp, etc.) takes
asig.md.author
(which is less readable than asig.author would be. However, I dislike the idea to clutter the Asig with lots of attributes.
Summary:
- I am not 100% happy as of now... Ideas/ Suggestions welcome.
Next Steps:
- please could you take a look and comment?
- improve design,
- when we are satified, roll out to all methods
from pya.
Naming
just a thought. maybe info
or meta
is more comprehensive as a metadata name... asig.info.timestamp
Metadata object
Metadata could be moved to a separate file to declutter Asig.py. As it is a pure helper class I'd make it less verbose:
import time
class Metadata(dict):
__getattr__ = dict.get
__setattr__ = dict.__setitem__
__delattr__ = dict.__delitem__
def __repr__(self):
res = "Asig metadata:\n"
for attr, value in self.items(): # sorted(self.items()) if keys should be in alphabetical order
if value:
if attr == 'timestamp':
value = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(value))
res += f" {attr:>15} = {value}\n"
return res
md = Metadata(foo="bar", bar=1, timestamp=time.time())
md.baz = 2.4
print(md)
In this less verbose form with less than 20 LOC it may also stay in Asig.py.
If possible do not name variables str
, input
or such alike. This will shadow and sometimes even overload builtins with nasty side effects.
from pya.
Three years later I'd probably use dataclasses for Metadata. Also we might want to introduce proper typing when we are at it. Python 2 support should not be an issue any longer (or is it)?
from pya.
wow. three years it is! tempus fugit.
Yes agreed. Data classes sounds very appropriate. Thanks for the suggestion.
from pya.
Related Issues (20)
- Ugen().noise() range from 0-1. rather than -1 - 1. HOT 1
- Release 0.3.2
- Aserver-nodes
- Improve Asig indexing HOT 1
- Release 0.3.3
- Make sanic optional
- Ugen docstring outdated
- Convolution
- determine_backend error HOT 4
- Ugen, numpy sine array result in different precision on different environment HOT 3
- Python 3.10 support HOT 2
- (Binder) notebooks not compatible with recent sanic and jupyter versions HOT 1
- m2r is deprecated and not supported any longer. We should switch to sphinx-mdinclude HOT 1
- Aserver, Arecorder channels argument of the constructor is buggy
- Improve type hints
- Refactor, pre-commit HOT 1
- Make class transformation one-way only HOT 7
- Arecorder uses default device when 0 is used a input
- Asig.cn and Asig.col_names are confusing and unnecessary to have both HOT 2
- Add more data type support.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pya.