Skip to content

Commit

Permalink
three yml examples working
Browse files Browse the repository at this point in the history
  • Loading branch information
hovey committed Dec 16, 2024
1 parent 74b3ee0 commit 9da28bc
Show file tree
Hide file tree
Showing 11 changed files with 212 additions and 17 deletions.
98 changes: 98 additions & 0 deletions cli/io/example/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,103 @@
# xyfigure

Given a comma separated values (`.csv`) file, plot columns with `xyfigure`

* Create the example data [file](data.xlsx) in Microsoft Excel. Here we create a time column `t` (the x-axis), and two functions (two different data series for the y-axis) of time columns `sin(t)` and `cos(2t)`.
* Then, from within Excel, export the .xlsx file as a .csv [file](data.csv).

## Getting Started

Activate the virtual environment:

```sh
cd ~/sibl/cli
source ~/sibl/.venv/bin/activate
```

## Example 1

With the input [recipe.yml](recipe.yml):

```sh
xyfigure io/example/recipe.yml
```

Output:

```sh
Processing file: io/example/recipe.yml
Finished XYViewBase constructor.
Creating view with guid = "figure"
Adding all models to current view.
Figure dpi set to 100
Figure size set to [8.0, 6.0] inches.
Serialized view to: /Users/chovey/sibl/cli/io/example/recipe.png
====================================
End of xyfigure/client.py execution.
```

Result:

![recipe.png](recipe.png)

## Example 2

A minimum working example, with [recipe_minimal.yml](recipe_minimal.yml):

```sh
xyfigure io/example/recipe_minimal.yml
```

Output:

```sh
Processing file: io/example/recipe_minimal.yml
Finished XYViewBase constructor.
Creating view with guid = "figure-output"
Adding all models to current view.
Figure dpi set to 100
Figure size set to [11.0, 8.5] inches.
No artists with labels found to put in legend. Note that artists whose label start with an underscore are ignored when legend() is called with no argument.
Serialized view to: /Users/chovey/sibl/cli/io/example/recipe_minimal.png
====================================
End of xyfigure/client.py execution.
```

Result:

![recipe_minimal.png](recipe_minimal.png)

## Example 3

An elaborate example, with [recipe_with_background.yml](recipe_with_background.yml):

```sh
xyfigure io/example/recipe_with_background.yml
```

Output:

```sh
Processing file: io/example/recipe_with_background.yml
Finished XYViewBase constructor.
Creating view with guid = "figure"
Adding all models to current view.
Figure dpi set to 100
Figure size set to [8.0, 6.0] inches.
Serialized view to: /Users/chovey/sibl/cli/io/example/recipe_with_background.png
====================================
End of xyfigure/client.py execution.
```

Result:

![recipe_with_background.png](recipe_with_background.png)

---
> **Deprecation Warning:**
> `.json` files still work as input files, but they have been deprecated on 2024-12-16 in favor a `.yml` format input files.
---

## Getting Started

Here we create an example data file from an Excel spreadsheet and walk through the steps to create a simple `xyfigure`.
Expand Down
Binary file added cli/io/example/recipe.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 9 additions & 9 deletions cli/io/example/recipe.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
sine-data:
class: model
folder: .
folder: ~/sibl/cli/io/example
file: data.csv
skip_rows: 1
plot_kwargs:
Expand All @@ -11,28 +11,28 @@ sine-data:
alpha: 0.5
cosine-data:
class: model
folder: .
folder: ~/sibl/cli/io/example
file: data.csv
skip_rows": 1
skip_rows: 1
ycolumn: 2
plot_kwargs:
label: cos(2t)
linestyle: "-."
linewidth: 2
figure:
class: view,
folder: .
file: recipe.svg
class: view
folder: ~/sibl/cli/io/example
file: recipe.png
size: [ 8.0, 6.0 ]
title: Example using xyfigure
xlabel: time (s)
ylabel: functions of time f(t)
yaxis_rhs:
scale: 10,
scale: 10
label: right-hand-side label with 10 f(t) scale
yticks: [ -10, -5, 0, 5, 10 ]
details: false
display: true
dpi: 100
latex: false
serialize: false
latex: true
serialize: true
Binary file added cli/io/example/recipe_minimal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions cli/io/example/recipe_minimal.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
sine-data:
class: model
folder: ~/sibl/cli/io/example
file: data.csv
cosine-data:
class: model
folder: ~/sibl/cli/io/example
file: data.csv
ycolumn: 2
figure-output:
class: view
folder: ~/sibl/cli/io/example
file: recipe_minimal.png
serialize: true
Binary file added cli/io/example/recipe_with_background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 50 additions & 0 deletions cli/io/example/recipe_with_background.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
sine-data:
class: model
folder: ~/sibl/cli/io/example
file: data.csv
skip_rows: 1
plot_kwargs:
label: sin(t)
color: darkorange
linestyle: "-"
linewidth: 4
alpha : 0.5
cosine-data:
class: model
folder: ~/sibl/cli/io/example
file: data.csv
skip_rows: 1
ycolumn: 2
plot_kwargs:
label: cos(2t)
color: green
linestyle: "-."
linewidth: 2
figure:
class: view
folder: ~/sibl/cli/io/example
file: recipe_with_background.png
size: [8.0, 6.0]
xlim: [-0.25, 2.25]
ylim: [-1.25, 1.25]
title: Example using xyfigure
xlabel: time (s)
ylabel: functions of time f(t)
xticks: [0, 0.50, 0.785, 1, 1.57, 2]
yticks: [-1, -0.5, 0, 0.5, 1]
yaxis_rhs:
scale: 10
label: right-hand-side label with 10 f(t) scale
yticks: [-5, 0, 5]
background_image:
folder: ~/sibl/cli/io/example
file: chess_800_800_px.png
left: 1.0
right: 2.0
bottom: -0.5
top: 0.5
alpha: 0.5
details: false
display: true
latex: false
serialize: true
2 changes: 1 addition & 1 deletion cli/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ dependencies = [
# Entry Points
# https://setuptools.pypa.io/en/latest/userguide/entry_point.html
[project.scripts]
xyfigure="xyfigure.xyfigure:main"
xyfigure="xyfigure.command_line:main"
#fingerprint="xyfigure.fingerprint_md5:main"

[project.urls]
Expand Down
36 changes: 33 additions & 3 deletions cli/src/xyfigure/xyfigure.py → cli/src/xyfigure/command_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
import yaml

# import xyfigure.constants as cc
from xyfigure.factory import XYFactory
from xyfigure.xymodel import XYModel, XYModelAbaqus
from xyfigure.xyview import XYView, XYViewAbaqus


def process(yml_path_file: Path) -> bool:
Expand Down Expand Up @@ -45,10 +48,37 @@ def process(yml_path_file: Path) -> bool:
# raise yaml.YAMLError
raise OSError from error

found_keys = tuple(db.keys())
breakpoint()
# found_keys = tuple(db.keys())

items = [] # cart of items is empty, fill from factory
# factory = XYFactory() # it's static!

for item in db:
kwargs = db[item]
i = XYFactory.create(item, **kwargs)
if i:
items.append(i)
else:
print("Item is None from factory, nothing added to command_line items.")

models = [i for i in items if isinstance(i, (XYModel, XYModelAbaqus))]
views = [i for i in items if isinstance(i, (XYView, XYViewAbaqus))]

for view in views:
print(f'Creating view with guid = "{view.guid}"')

if view.model_keys: # register only selected models with current view
print(f" Adding {view.model_keys} model(s) to current view.")
view.models = [m for m in models if m.guid in view.model_keys]
view.figure() # must be within this subset scope
else:
print(" Adding all models to current view.")
view.models = models # register all models with current view
view.figure() # must be within this subset scope

print("====================================")
print("End of xyfigure execution.")

aa = 4
processed = True # overwrite
return processed # success if we reach this line

Expand Down
File renamed without changes.
11 changes: 7 additions & 4 deletions cli/src/xyfigure/xyview.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# related third-party imports
import matplotlib.pyplot as plt
from PIL import Image
from pathlib import Path

# local application/library specific imports
# from xyfigure.xybase import XYBase
Expand Down Expand Up @@ -169,10 +170,12 @@ def figure(self):
if self._background_image:
folder = self._background_image.get("folder", ".")
file = self._background_image.get("file", None)
rel_path_and_file = os.path.join(
folder, file
) # relative to current run location
im = Image.open(rel_path_and_file)
# rel_path_and_file = os.path.join(
# folder, file
# ) # relative to current run location
path_file = Path(folder).expanduser().joinpath(file)
# im = Image.open(rel_path_and_file)
im = Image.open(path_file)

left = self._background_image.get("left", 0.0)
right = self._background_image.get("right", 1.0)
Expand Down

0 comments on commit 9da28bc

Please sign in to comment.