kopia lustrzana https://github.com/sepandhaghighi/samila
Equation warning (#125)
* add : CALCULATION_EXCEPTION_WARNING parameter added. * add : calculation exception warning added. (#121) * test : tests added. * fix : minor issue fixed. * edit : changelog.md edited. * fix : minor bug fixed. * edit : minor edits in functions. * fix : minor issues fixed in docstring. * fix : typo fixed in CHANGELOG.md. * rollback : random function are now in its last place. * fix : typo fixed.pull/127/head
rodzic
7444b9bd90
commit
d2b7585b1a
|
@ -6,9 +6,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
|||
|
||||
## [Unreleased]
|
||||
### Added
|
||||
- `fill_data` function
|
||||
- `random_hex_color_gen` function
|
||||
- `color`,`bgcolor` and `projection` parameters random mode
|
||||
### Changed
|
||||
- Calculation warning added to `generate` method
|
||||
- Hex color support for `color` and `bgcolor` parameters
|
||||
- Test system modified
|
||||
- Random mode modified
|
||||
|
|
|
@ -254,6 +254,27 @@ def generate_params_filter(
|
|||
g.seed, g.start, g.step, g.stop = seed, start, step, stop
|
||||
|
||||
|
||||
def fill_data(g, point):
|
||||
"""
|
||||
Fill data with functions in given points.
|
||||
|
||||
:param g: generative image instance
|
||||
:type g: GenerativeImage
|
||||
:param point: given point
|
||||
:type point: tuple
|
||||
:return: false if some exception occurred
|
||||
"""
|
||||
random.seed(g.seed)
|
||||
try:
|
||||
data1_ = g.function1(point[0], point[1]).real
|
||||
data2_ = g.function2(point[0], point[1]).real
|
||||
except Exception:
|
||||
return False
|
||||
g.data1.append(data1_)
|
||||
g.data2.append(data2_)
|
||||
return True
|
||||
|
||||
|
||||
def save_params_filter(g, depth=None):
|
||||
"""
|
||||
Filter save_image method parameters.
|
||||
|
|
|
@ -7,7 +7,7 @@ import matplotlib
|
|||
import matplotlib.pyplot as plt
|
||||
from .functions import _GI_initializer, plot_params_filter, generate_params_filter, save_params_filter
|
||||
from .functions import float_range, save_data_file, save_fig_file, save_fig_buf, save_config_file
|
||||
from .functions import load_data, load_config, random_equation_gen, nft_storage_upload
|
||||
from .functions import load_data, load_config, random_equation_gen, nft_storage_upload, fill_data
|
||||
from .params import *
|
||||
from warnings import warn
|
||||
|
||||
|
@ -80,10 +80,12 @@ class GenerativeImage:
|
|||
range1 = list(float_range(self.start, self.stop, self.step))
|
||||
range2 = list(float_range(self.start, self.stop, self.step))
|
||||
range_prod = list(itertools.product(range1, range2))
|
||||
for item in range_prod:
|
||||
random.seed(self.seed)
|
||||
self.data1.append(self.function1(item[0], item[1]).real)
|
||||
self.data2.append(self.function2(item[0], item[1]).real)
|
||||
calc_exception = False
|
||||
for point in range_prod:
|
||||
if not fill_data(self, point):
|
||||
calc_exception = True
|
||||
if calc_exception:
|
||||
warn(CALCULATION_EXCEPTION_WARNING, RuntimeWarning)
|
||||
|
||||
def plot(
|
||||
self,
|
||||
|
|
|
@ -40,6 +40,7 @@ CONFIG_NO_STR_FUNCTION_ERROR = "Config file can't be saved. At least one of the
|
|||
PLOT_DATA_ERROR = "Plotting process can't be Done because data{0} is empty. Use generate method first."
|
||||
SAVE_NO_DATA_ERROR = "Data file can't be saved. At least one of the data1 or data2 is None."
|
||||
MATPLOTLIB_VERSION_WARNING = "Source matplotlib version({0}) is different from yours, plots may be different."
|
||||
CALCULATION_EXCEPTION_WARNING = "The given functions are undefined at some points. Your plot may not be complete."
|
||||
|
||||
|
||||
class Projection(Enum):
|
||||
|
|
|
@ -20,6 +20,9 @@ True
|
|||
... json.dump({'f1': 'x', 'f2': 'y', 'matplotlib_version': '0'}, fp)
|
||||
>>> with warns(RuntimeWarning, match=r"Source matplotlib version(.*) is different from yours, plots may be different."):
|
||||
... g = GenerativeImage(config=open('config.json', 'r'))
|
||||
>>> 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."):
|
||||
... g.generate(start=0, stop=2, step=0.1)
|
||||
>>> os.remove('data.json')
|
||||
>>> os.remove('config.json')
|
||||
"""
|
||||
|
|
Ładowanie…
Reference in New Issue