Depth parameter added (#108)

* remove : trailing whitespace removed.

* add : depth paramter added. (#100)

* add : save_image_filter function added.

* edit : save_image_filter -> save_params_filter.

* edit : CHANGELOG.md edited.

* add : depth added to load/save data.
pull/111/head
Sadra Sabouri 2022-04-03 11:05:52 +04:30 zatwierdzone przez GitHub
rodzic 7fd4f9123c
commit 4f25f846f8
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
3 zmienionych plików z 32 dodań i 9 usunięć

Wyświetl plik

@ -5,7 +5,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
## [Unreleased]
### Changed
### Added
- `save_params_filter` function
### Changed
- `depth` section added to config/data file
- `linewidth` parameter added to `plot` method
- `linewidth` parameter added to `plot_params_filter` function
## [0.5] - 2022-03-21

Wyświetl plik

@ -6,7 +6,7 @@ import io
import json
import random
import matplotlib
from .params import DEFAULT_START, DEFAULT_STOP, DEFAULT_STEP, DEFAULT_COLOR, DEFAULT_IMAGE_SIZE
from .params import DEFAULT_START, DEFAULT_STOP, DEFAULT_STEP, DEFAULT_COLOR, DEFAULT_IMAGE_SIZE, DEFAULT_DEPTH
from .params import DEFAULT_BACKGROUND_COLOR, DEFAULT_SPOT_SIZE, DEFAULT_PROJECTION, DEFAULT_ALPHA, DEFAULT_LINEWIDTH
from .params import Projection, VALID_COLORS, NFT_STORAGE_API, OVERVIEW
from .params import DATA_TYPE_ERROR, CONFIG_TYPE_ERROR, PLOT_DATA_ERROR, CONFIG_NO_STR_FUNCTION_ERROR
@ -233,6 +233,19 @@ def generate_params_filter(
g.seed, g.start, g.step, g.stop = seed, start, step, stop
def save_params_filter(g, depth=None):
"""
Filter save_image method parameters.
:param depth: depth of image
:type depth: float
:return: None
"""
if depth is None:
depth = g.depth
g.depth = depth
def _GI_initializer(g, function1, function2):
"""
Initialize the generative image.
@ -264,6 +277,7 @@ def _GI_initializer(g, function1, function2):
g.projection = DEFAULT_PROJECTION
g.alpha = DEFAULT_ALPHA
g.linewidth = DEFAULT_LINEWIDTH
g.depth = DEFAULT_DEPTH
def nft_storage_upload(api_key, data):
@ -317,7 +331,8 @@ def save_data_file(g, file_adr):
"spot_size": g.spot_size,
"projection": g.projection,
"alpha": g.alpha,
"linewidth": g.linewidth
"linewidth": g.linewidth,
"depth": g.depth
}
data['matplotlib_version'] = matplotlib_version
result = {"status": True, "message": DATA_SAVE_SUCCESS_MESSAGE}
@ -358,7 +373,8 @@ def save_config_file(g, file_adr):
"spot_size": g.spot_size,
"projection": g.projection,
"alpha": g.alpha,
"linewidth": g.linewidth
"linewidth": g.linewidth,
"depth": g.depth
}
data['matplotlib_version'] = matplotlib_version
result = {"status": True, "message": DATA_SAVE_SUCCESS_MESSAGE}
@ -481,6 +497,7 @@ def load_data(g, data):
g.projection = plot_config.get("projection", DEFAULT_PROJECTION)
g.alpha = plot_config.get("alpha", DEFAULT_ALPHA)
g.linewidth = plot_config.get("linewidth", DEFAULT_LINEWIDTH)
g.depth = plot_config.get("depth", DEFAULT_DEPTH)
return
raise samilaDataError(DATA_TYPE_ERROR)
@ -515,5 +532,6 @@ def load_config(g, config):
g.projection = plot_config.get("projection", DEFAULT_PROJECTION)
g.alpha = plot_config.get("alpha", DEFAULT_ALPHA)
g.linewidth = plot_config.get("linewidth", DEFAULT_LINEWIDTH)
g.depth = plot_config.get("depth", DEFAULT_DEPTH)
return
raise samilaConfigError(CONFIG_TYPE_ERROR)

Wyświetl plik

@ -5,7 +5,7 @@ import gc
import itertools
import matplotlib
import matplotlib.pyplot as plt
from .functions import _GI_initializer, plot_params_filter, generate_params_filter
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 .params import *
@ -139,7 +139,7 @@ class GenerativeImage:
ax.add_artist(ax.patch)
self.fig = fig
def nft_storage(self, api_key, depth=DEFAULT_DEPTH):
def nft_storage(self, api_key, depth=None):
"""
Upload image to nft.storage.
@ -149,14 +149,15 @@ class GenerativeImage:
:type depth: float
:return: result as dict
"""
response = save_fig_buf(self.fig, depth)
save_params_filter(self, depth)
response = save_fig_buf(self.fig, self.depth)
if not response["status"]:
return {"status": False, "message": response["message"]}
buf = response["buffer"]
response = nft_storage_upload(api_key=api_key, data=buf.getvalue())
return response
def save_image(self, file_adr, depth=DEFAULT_DEPTH):
def save_image(self, file_adr, depth=None):
"""
Save generated image.
@ -166,7 +167,8 @@ class GenerativeImage:
:type depth: float
:return: result as dict
"""
return save_fig_file(figure=self.fig, file_adr=file_adr, depth=depth)
save_params_filter(self, depth)
return save_fig_file(self.fig, file_adr, self.depth)
def save_data(self, file_adr='data.json'):
"""