Order of indexing in microstructures and strange PCA

22 views
Skip to first unread message

Marat Latypov

unread,
Oct 26, 2015, 11:56:22 AM10/26/15
to pymks-...@googlegroups.com
​​​​​​Hello:

I have a couple of questions about microstructures in PyMKS

1. Order of indexing

What is the order of indexing of microstructures in PyMKS? That is, if I take one row of the microstructure matrix and go from column to column, am I going along X (horizontal, to the right) coordinate or Y coordinate?

For example, suppose I define a simple microstructure by

import numpy as np
ms = np.ndarray(shape=(1,5,5))
ms[0,:,:] = np.array((
    (1,1,1,1,1),
    (0,0,1,0,0),
    (0,0,0,0,0),
    (0,0,0,0,0),
    (0,0,0,0,0)))


I expected that the microstructure would look like shades below.



However, when I plot the microstructure by

from pymks.tools import draw_microstructures
draw_microstructures(ms)


I get an image rotated 90 deg counterclockwise from what I expected:



I have this question because I am trying to figure out the right way of exporting/importing microstructures from/to PyMKS without rotation artifacts, which comes down to reshaping numpy arrays with the right order (I typically need an ASCII table with x, y, phaseID columns outside of PyMKS).

2. Strange low-dimensional representations

I get strange PCA plots for my microstructures generated in PyMKS.
For example, if I follow the homogenization example and do

from pymks.datasets import make_elastic_stress_random
sample_size = 200
grain_size = [(47, 6), (4, 49), (14,14)]
n_samples = [sample_size] * 3
elastic_modulus = (410, 200)
poissons_ratio = (0.28, 0.3)
macro_strain = 0.001
size = (51, 51)


I can reproduce a plot similar to that in PyMKS example.



​However, when I slightly increase the dimensions (e.g. size=(64,64)), I get a PCA plot as shown below. I tried to scale the "grain sizes" with the same ratio as I increased dimensions but I still get the same shape.
 



After some adjustment of grain sizes and seeds, I can get PCA plots similar to those in the PyMKS example but I am wondering whether or not such strange plots are wrong and if there are "right" grain sizes to generate reasonable sets of microstructures.

Thanks in advance,
Marat

ms_expectation.png
ms_reality.png
pca_51x51.png
pca_64x64.png

David Brough

unread,
Oct 26, 2015, 10:42:18 PM10/26/15
to Marat Latypov, PyMKS General
Marat,

Thanks for providing clearly stated questions with example figures.

1. From what I have seen all of the image io packages in Python are built on top of the same code that was originally developed in the python library PIL.

http://www.pythonware.com/products/pil/

The package is no longer under active development, but many other packages such as matplotlib, scikit-image and PILLOW all use the image io code in PIL to load an image. When this happens the x and y axes are swapped (to follow the convention with images in a computer). The data itself remains unaltered, but the points for the x and y coordinates are different from what you expect. In PyMKS we display images such that the first index (which we have labeled as x) run horizontally along the image. I will add a ticket to the PyMKS repository that will give the option to switch the access back. For now try

$ >>> draw_microstructures(np.swapaxes(X, 1, 2))

and see if you images are displayed correctly. In short the images/data are not being rotated by 90 degrees. You can think of it as the x and y axes are being inverted.

2. I have seen this arc pattern with both experimental data as well as synthetic data using PyMKS. I will try and create a homogenization linkage using PyMKS and other machine learning code and get back to you with more information on this.

Thanks,

David

--
You received this message because you are subscribed to the Google Groups "PyMKS General" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pymks-genera...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pymks-general/CANBu90DEAdPkfvE3XViKVthhi3sUdp%3DmDnE_jWD-f443D83rvg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages