kopia lustrzana https://github.com/sepandhaghighi/samila
Samila version added for reproducibility (#184)
* change : micro version is no longer saved. * add : `__version__` attribute for Samila version. (#171) * fix : minor mistake in CHANGELOG.md. * update : `VERSION_WARNING` updated.master
rodzic
a994902006
commit
2a98624138
|
@ -6,7 +6,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
### Added
|
### Added
|
||||||
|
- `__version__` attribute
|
||||||
- `python_version` attribute
|
- `python_version` attribute
|
||||||
|
- `get_python_version` function
|
||||||
- `RANDOM_EQUATION_MIN_COMPLEXITY` parameter
|
- `RANDOM_EQUATION_MIN_COMPLEXITY` parameter
|
||||||
- `RANDOM_EQUATION_FOF_MAX_DEPTH` parameter
|
- `RANDOM_EQUATION_FOF_MAX_DEPTH` parameter
|
||||||
- `RANDOM_EQUATION_FOF_MIN_DEPTH` parameter
|
- `RANDOM_EQUATION_FOF_MIN_DEPTH` parameter
|
||||||
|
|
|
@ -12,6 +12,7 @@ import matplotlib
|
||||||
from matplotlib import cm
|
from matplotlib import cm
|
||||||
from matplotlib.colors import ListedColormap
|
from matplotlib.colors import ListedColormap
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
from .params import SAMILA_VERSION
|
||||||
from .params import DEFAULT_MARKER, DEFAULT_START, DEFAULT_STOP, DEFAULT_STEP, DEFAULT_COLOR, DEFAULT_IMAGE_SIZE, DEFAULT_DEPTH
|
from .params import DEFAULT_MARKER, DEFAULT_START, DEFAULT_STOP, DEFAULT_STEP, DEFAULT_COLOR, DEFAULT_IMAGE_SIZE, DEFAULT_DEPTH
|
||||||
from .params import DEFAULT_CMAP, DEFAULT_CMAP_RANGE, DEFAULT_ROTATION
|
from .params import DEFAULT_CMAP, DEFAULT_CMAP_RANGE, DEFAULT_ROTATION
|
||||||
from .params import DEFAULT_BACKGROUND_COLOR, DEFAULT_SPOT_SIZE, DEFAULT_PROJECTION, DEFAULT_ALPHA, DEFAULT_LINEWIDTH
|
from .params import DEFAULT_BACKGROUND_COLOR, DEFAULT_SPOT_SIZE, DEFAULT_PROJECTION, DEFAULT_ALPHA, DEFAULT_LINEWIDTH
|
||||||
|
@ -472,6 +473,7 @@ def _GI_initializer(g, function1, function2):
|
||||||
:type function2: python or lambda function
|
:type function2: python or lambda function
|
||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
|
g.__version__ = SAMILA_VERSION
|
||||||
g.matplotlib_version = matplotlib.__version__
|
g.matplotlib_version = matplotlib.__version__
|
||||||
g.python_version = get_python_version()
|
g.python_version = get_python_version()
|
||||||
g.function1 = function1
|
g.function1 = function1
|
||||||
|
@ -559,12 +561,11 @@ def get_python_version():
|
||||||
"""
|
"""
|
||||||
Get Python's version.
|
Get Python's version.
|
||||||
|
|
||||||
:return: python's version as 'major.minor.micro'
|
:return: python's version as 'major.minor'
|
||||||
"""
|
"""
|
||||||
return "{}.{}.{}".format(
|
return "{}.{}".format(
|
||||||
sys.version_info.major,
|
sys.version_info.major,
|
||||||
sys.version_info.minor,
|
sys.version_info.minor
|
||||||
sys.version_info.micro
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -576,8 +577,6 @@ def get_data(g):
|
||||||
:type g: GenerativeImage
|
:type g: GenerativeImage
|
||||||
:return: data as a dict
|
:return: data as a dict
|
||||||
"""
|
"""
|
||||||
matplotlib_version = matplotlib.__version__
|
|
||||||
python_version = get_python_version()
|
|
||||||
data = {}
|
data = {}
|
||||||
if g.data1 is None or g.data2 is None:
|
if g.data1 is None or g.data2 is None:
|
||||||
raise samilaDataError(SAVE_NO_DATA_ERROR)
|
raise samilaDataError(SAVE_NO_DATA_ERROR)
|
||||||
|
@ -595,8 +594,9 @@ def get_data(g):
|
||||||
"depth": g.depth,
|
"depth": g.depth,
|
||||||
"rotation": g.rotation,
|
"rotation": g.rotation,
|
||||||
}
|
}
|
||||||
data['matplotlib_version'] = matplotlib_version
|
data['matplotlib_version'] = g.matplotlib_version
|
||||||
data['python_version'] = python_version
|
data['python_version'] = g.python_version
|
||||||
|
data['__version__'] = g.__version__
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
@ -608,8 +608,6 @@ def get_config(g):
|
||||||
:type g: GenerativeImage
|
:type g: GenerativeImage
|
||||||
:return: config as a dict
|
:return: config as a dict
|
||||||
"""
|
"""
|
||||||
matplotlib_version = matplotlib.__version__
|
|
||||||
python_version = get_python_version()
|
|
||||||
config = {}
|
config = {}
|
||||||
if g.function1_str is None or g.function2_str is None:
|
if g.function1_str is None or g.function2_str is None:
|
||||||
raise samilaConfigError(CONFIG_NO_STR_FUNCTION_ERROR)
|
raise samilaConfigError(CONFIG_NO_STR_FUNCTION_ERROR)
|
||||||
|
@ -633,8 +631,9 @@ def get_config(g):
|
||||||
"depth": g.depth,
|
"depth": g.depth,
|
||||||
"rotation": g.rotation,
|
"rotation": g.rotation,
|
||||||
}
|
}
|
||||||
config['matplotlib_version'] = matplotlib_version
|
config['matplotlib_version'] = g.matplotlib_version
|
||||||
config['python_version'] = python_version
|
config['python_version'] = g.python_version
|
||||||
|
config['__version__'] = g.__version__
|
||||||
return config
|
return config
|
||||||
|
|
||||||
|
|
||||||
|
@ -808,6 +807,8 @@ def load_data(g, data):
|
||||||
g.matplotlib_version = data['matplotlib_version']
|
g.matplotlib_version = data['matplotlib_version']
|
||||||
if 'python_version' in data:
|
if 'python_version' in data:
|
||||||
g.python_version = data['python_version']
|
g.python_version = data['python_version']
|
||||||
|
if '__version__' in data:
|
||||||
|
g.__version__ = data['__version__']
|
||||||
plot_config = data.get("plot")
|
plot_config = data.get("plot")
|
||||||
if plot_config is not None:
|
if plot_config is not None:
|
||||||
g.color = plot_config.get("color", DEFAULT_COLOR)
|
g.color = plot_config.get("color", DEFAULT_COLOR)
|
||||||
|
@ -844,6 +845,8 @@ def load_config(g, config):
|
||||||
g.matplotlib_version = config['matplotlib_version']
|
g.matplotlib_version = config['matplotlib_version']
|
||||||
if 'python_version' in config:
|
if 'python_version' in config:
|
||||||
g.python_version = config['python_version']
|
g.python_version = config['python_version']
|
||||||
|
if '__version__' in config:
|
||||||
|
g.__version__ = config['__version__']
|
||||||
generate_config = config.get("generate")
|
generate_config = config.get("generate")
|
||||||
if generate_config is not None:
|
if generate_config is not None:
|
||||||
g.seed = generate_config.get("seed")
|
g.seed = generate_config.get("seed")
|
||||||
|
|
|
@ -45,11 +45,13 @@ class GenerativeImage:
|
||||||
elif data is not None:
|
elif data is not None:
|
||||||
load_data(self, data)
|
load_data(self, data)
|
||||||
if self.matplotlib_version != matplotlib.__version__ or \
|
if self.matplotlib_version != matplotlib.__version__ or \
|
||||||
self.python_version != get_python_version():
|
self.python_version != get_python_version() or \
|
||||||
|
self.__version__ != SAMILA_VERSION:
|
||||||
warn(
|
warn(
|
||||||
VERSION_WARNING.format(
|
VERSION_WARNING.format(
|
||||||
self.matplotlib_version,
|
self.matplotlib_version,
|
||||||
self.python_version),
|
self.python_version,
|
||||||
|
self.__version__),
|
||||||
RuntimeWarning)
|
RuntimeWarning)
|
||||||
if self.function1 is None:
|
if self.function1 is None:
|
||||||
if self.function1_str is None:
|
if self.function1_str is None:
|
||||||
|
|
|
@ -48,7 +48,7 @@ PLOT_DATA_ERROR = "Plotting process can't be Done because data{0} is empty. Use
|
||||||
COLOR_SIZE_ERROR = "Color list size is not equal to the data size."
|
COLOR_SIZE_ERROR = "Color list size is not equal to the data size."
|
||||||
SAVE_NO_DATA_ERROR = "Data file can't be saved. At least one of the data1 or data2 is None."
|
SAVE_NO_DATA_ERROR = "Data file can't be saved. At least one of the data1 or data2 is None."
|
||||||
INVALID_COLOR_TYPE_ERROR = "Given color/bgcolor type is not supported."
|
INVALID_COLOR_TYPE_ERROR = "Given color/bgcolor type is not supported."
|
||||||
VERSION_WARNING = "Source matplotlib version({0}) or Python version({1}) is different from yours, plots may be different."
|
VERSION_WARNING = "Your plots may differ as the version of matplotlib ({0}), Python ({1}), or Samila ({2}) that you are using is not the same as the source."
|
||||||
CALCULATION_EXCEPTION_WARNING = "The given functions are undefined at some points. Your plot may not be complete."
|
CALCULATION_EXCEPTION_WARNING = "The given functions are undefined at some points. Your plot may not be complete."
|
||||||
BOTH_COLOR_COMPLEMENT_WARNING = "It is not possible to set color and bgcolor to 'complement' at the same time! Both are automatically set to the previous or default selection."
|
BOTH_COLOR_COMPLEMENT_WARNING = "It is not possible to set color and bgcolor to 'complement' at the same time! Both are automatically set to the previous or default selection."
|
||||||
COLOR_NOT_FOUND_WARNING = "color '{0}' not found. Replacing it with '{1}'"
|
COLOR_NOT_FOUND_WARNING = "color '{0}' not found. Replacing it with '{1}'"
|
||||||
|
|
|
@ -91,7 +91,7 @@ False
|
||||||
1
|
1
|
||||||
>>> distance_calc("test12","test234")
|
>>> distance_calc("test12","test234")
|
||||||
3
|
3
|
||||||
>>> get_python_version() == sys.version.split()[0]
|
>>> get_python_version() == '.'.join(sys.version.split()[0].split('.')[:2])
|
||||||
True
|
True
|
||||||
>>> samila_help()
|
>>> samila_help()
|
||||||
<BLANKLINE>
|
<BLANKLINE>
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
True
|
True
|
||||||
>>> g.function2 == f2
|
>>> g.function2 == f2
|
||||||
True
|
True
|
||||||
>>> g.python_version == sys.version.split()[0]
|
>>> g.python_version == '.'.join(sys.version.split()[0].split('.')[:2])
|
||||||
True
|
True
|
||||||
>>> g.fig
|
>>> g.fig
|
||||||
>>> g.generate()
|
>>> g.generate()
|
||||||
|
|
|
@ -13,20 +13,28 @@ True
|
||||||
>>> g_.data2 == g.data2
|
>>> g_.data2 == g.data2
|
||||||
True
|
True
|
||||||
>>> with open('data.json', 'w') as fp:
|
>>> with open('data.json', 'w') as fp:
|
||||||
|
... json.dump({'data1': [0], 'data2': [0], '__version__': '0'}, fp)
|
||||||
|
>>> with warns(RuntimeWarning, match=r"Your plots may differ as the version of matplotlib (.*), Python (.*), or Samila (.*) that you are using is not the same as the source."):
|
||||||
|
... g = GenerativeImage(data=open('data.json', 'r'))
|
||||||
|
>>> with open('config.json', 'w') as fp:
|
||||||
|
... json.dump({'f1': 'x', 'f2': 'y', '__version__': '0'}, fp)
|
||||||
|
>>> with warns(RuntimeWarning, match=r"Your plots may differ as the version of matplotlib (.*), Python (.*), or Samila (.*) that you are using is not the same as the source."):
|
||||||
|
... g = GenerativeImage(config=open('config.json', 'r'))
|
||||||
|
>>> with open('data.json', 'w') as fp:
|
||||||
... json.dump({'data1': [0], 'data2': [0], 'python_version': '0'}, fp)
|
... json.dump({'data1': [0], 'data2': [0], 'python_version': '0'}, fp)
|
||||||
>>> with warns(RuntimeWarning, match=r"Source matplotlib version(.*) or Python version(.*) is different from yours, plots may be different."):
|
>>> with warns(RuntimeWarning, match=r"Your plots may differ as the version of matplotlib (.*), Python (.*), or Samila (.*) that you are using is not the same as the source."):
|
||||||
... g = GenerativeImage(data=open('data.json', 'r'))
|
... g = GenerativeImage(data=open('data.json', 'r'))
|
||||||
>>> with open('config.json', 'w') as fp:
|
>>> with open('config.json', 'w') as fp:
|
||||||
... json.dump({'f1': 'x', 'f2': 'y', 'python_version': '0'}, fp)
|
... json.dump({'f1': 'x', 'f2': 'y', 'python_version': '0'}, fp)
|
||||||
>>> with warns(RuntimeWarning, match=r"Source matplotlib version(.*) or Python version(.*) is different from yours, plots may be different."):
|
>>> with warns(RuntimeWarning, match=r"Your plots may differ as the version of matplotlib (.*), Python (.*), or Samila (.*) that you are using is not the same as the source."):
|
||||||
... g = GenerativeImage(config=open('config.json', 'r'))
|
... g = GenerativeImage(config=open('config.json', 'r'))
|
||||||
>>> with open('data.json', 'w') as fp:
|
>>> with open('data.json', 'w') as fp:
|
||||||
... json.dump({'data1': [0], 'data2': [0], 'matplotlib_version': '0'}, fp)
|
... json.dump({'data1': [0], 'data2': [0], 'matplotlib_version': '0'}, fp)
|
||||||
>>> with warns(RuntimeWarning, match=r"Source matplotlib version(.*) or Python version(.*) is different from yours, plots may be different."):
|
>>> with warns(RuntimeWarning, match=r"Your plots may differ as the version of matplotlib (.*), Python (.*), or Samila (.*) that you are using is not the same as the source."):
|
||||||
... g = GenerativeImage(data=open('data.json', 'r'))
|
... g = GenerativeImage(data=open('data.json', 'r'))
|
||||||
>>> with open('config.json', 'w') as fp:
|
>>> with open('config.json', 'w') as fp:
|
||||||
... json.dump({'f1': 'x', 'f2': 'y', 'matplotlib_version': '0'}, fp)
|
... json.dump({'f1': 'x', 'f2': 'y', 'matplotlib_version': '0'}, fp)
|
||||||
>>> with warns(RuntimeWarning, match=r"Source matplotlib version(.*) or Python version(.*) is different from yours, plots may be different."):
|
>>> with warns(RuntimeWarning, match=r"Your plots may differ as the version of matplotlib (.*), Python (.*), or Samila (.*) that you are using is not the same as the source."):
|
||||||
... g = GenerativeImage(config=open('config.json', 'r'))
|
... g = GenerativeImage(config=open('config.json', 'r'))
|
||||||
>>> g = GenerativeImage(lambda x, y: 1 / x, lambda x, y: 1 / (y - 1))
|
>>> g = GenerativeImage(lambda x, y: 1 / x, lambda x, y: 1 / (y - 1))
|
||||||
>>> with warns(RuntimeWarning, match=r"The given functions are undefined at some points. Your plot may not be complete."):
|
>>> with warns(RuntimeWarning, match=r"The given functions are undefined at some points. Your plot may not be complete."):
|
||||||
|
|
Ładowanie…
Reference in New Issue