Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add coordinates notebook #6

Merged
merged 29 commits into from Mar 7, 2024
Merged

add coordinates notebook #6

merged 29 commits into from Mar 7, 2024

Conversation

ahms5
Copy link
Member

@ahms5 ahms5 commented Feb 25, 2024

  • Move overview of coordinate systems and table to pyfar class documentation.

@ahms5 ahms5 mentioned this pull request Feb 27, 2024
29 tasks
@ahms5 ahms5 marked this pull request as ready for review February 27, 2024 12:32
Copy link
Member

@f-brinkmann f-brinkmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for drafting, I mostly had comments for small improvements. Apart from that

  • should we add the table that explains each coordinate, which is currently located here: https://pyfar.readthedocs.io/en/latest/concepts/pyfar.coordinates.html. I would vote yes, if the new notebook replaces the concepts in pyfar.
  • I could add a thumbnail showing the cartesian coordinate system (top left in the image). Might be more intuituve than the scatter plot that currently shows up.

"source": [
"import pyfar as pf\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would sugest to add %matplotlib inline. In this case you don't have to use plt.show() below.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, thanks, i didn't know.

"source": [
"## Coordinates\n",
"\n",
"In acoustics research, we often deal with different coordinate systems when handling sampling points. This can get complicated. That's why we have the Coordinates class in pyfar. The :py:func:`Coordinates class <pyfar.classes.coordinates.Coordinates>` was designed for storing, working with, and accessing coordinate points. You can easily switch between different coordinate systems, rotate points, and do other useful stuff. For example, you can store microphone positions in a spherical microphone array or loudspeaker positions in a sound field synthesis system."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The link to the pyfar documentation does not work and should probably be replaced with a URL.

"source": [
"## Supported Coordinate systems\n",
"\n",
"Coordinate systems come in different flavors, like cartesian, spherical or cylindrical, where spherical has a couple of subdefinitions. The image below shows the available coordinate systems.\n",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could already make clear that

  • a coodinate system is defined by a set of coordinates, e.g. 'cartesian' consists of x, y, and z.
  • each coordinate has a unique name. If a coordinate is contained in multiple coordinate systems (e.g. 'z' in cartesian and cylindrical) this means the values for z are the same in both cases.

"source": [
"### Entering coordinate points\n",
"\n",
"You can input coordinate points manually into the system. By default, the system assumes Cartesian coordinates. Internally, all points are consistently stored in the Cartesian coordinate system."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe make clear here or by a comment in the code that you are entering x, y, and z-vales.

I think the information that everything is stored in cartesian internally is important. But it might be too early here and I would add that this can cause small rounding errors when entering points in other coordinate systems.

"cell_type": "markdown",
"metadata": {},
"source": [
"To initialize `Coordinates` objects for different coordinate systems, you can use specific constructors like `pf.Coordinates.from_spherical_elevation(azimuth, elevation, radius)`. The naming convention for these constructors is always `pf.Coordinates.from_coordinate_system(red, green, blue)`, where `coordinate_system` should be replaced with the desired coordinate system, and `red`, `green`, `blue` describe the order of the coordinate properties. Remember, angles are always defined in radians.\n",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could spcifically link to the figure to mention that this is also in accordance with the colours shown there.

"cell_type": "markdown",
"metadata": {},
"source": [
"The cshape of the data is (40,). The term cshape refers to the shape of a single coordinate."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe provide a bit more detail here and mention that the coordinates are stored in a numpy array whose last dimension is always 3 and that the cshape ignores this to only show how the coordinate points are organized

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, in this way it would be more complex then nessesary. The coords are even saves in 3 separte variables _x, _y, and z. But i think the people must just understand that the cshape is the cshape of any of the coordinates. I added a bit more information to make it more clear.

"source": [
"### Retrieving coordinate points\n",
"\n",
"There are different ways to retrieve points from a `Coordinates` object. All points can be obtained in cartesian, spherical, and cylindrical coordinates using the related properties `c.cartesian`, `c.sperical_evaluation` and `c.cylindrical`. Also single properties of each coordinate system convention can be accessed by e.g. `c.azimuth`, `c.radius` or `c.x`. Visit the [coordinate class](https://pyfar.readthedocs.io/en/latest/classes/pyfar.coordinates.html) for more details.\""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"There are different ways to retrieve points from a `Coordinates` object. All points can be obtained in cartesian, spherical, and cylindrical coordinates using the related properties `c.cartesian`, `c.sperical_evaluation` and `c.cylindrical`. Also single properties of each coordinate system convention can be accessed by e.g. `c.azimuth`, `c.radius` or `c.x`. Visit the [coordinate class](https://pyfar.readthedocs.io/en/latest/classes/pyfar.coordinates.html) for more details.\""
"There are different ways to retrieve points from a `Coordinates` object. All points can be obtained in cartesian, spherical, and cylindrical coordinates using the related properties `c.cartesian`, `c.sperical_evaluation` and `c.cylindrical`. Also single properties of each coordinate system convention can be accessed by e.g. `c.azimuth`, `c.radius` or `c.x`. Visit the [coordinate class](https://pyfar.readthedocs.io/en/latest/classes/pyfar.coordinates.html) for more details."

"cell_type": "markdown",
"metadata": {},
"source": [
"Of course, we can convert it into other coordinate systems as well. Note that it returns angles always in radiance."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this would be the right place to mention coordinates conversion and underlying cartesian format.

"metadata": {},
"outputs": [],
"source": [
"azimuth = c.azimuth\n",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not directly c.azimuth[0] = 0?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see...

"metadata": {},
"source": [
"#### Find within\n",
"Another option is to find all points in a certain area around different points. Different distance measures are available see the [pyfar documentation](https://pyfar.readthedocs.io/en/latest/classes/pyfar.coordinates.html#pyfar.classes.coordinates.Coordinates.find_within) for more information."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe mention that this finds everything closer than 3 meters to the query point to more illustrative.

Copy link
Member

@f-brinkmann f-brinkmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, it already reads better to me. I made some specific suggestions that might improve the description of csize, cshape, and cdim and thought that it might be nice to mention our rad2deg converter

docs/gallery/interactive/pyfar_coordinates.ipynb Outdated Show resolved Hide resolved
"cell_type": "markdown",
"metadata": {},
"source": [
"We can observe that there are 40 points in total over all dimensions. This refers to the attribute `csize`. It corresponds the the `size` of each coordinate.\n"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still find the description of csize, cshape, and cdim a little confusing, how about using:

Suggested change
"We can observe that there are 40 points in total over all dimensions. This refers to the attribute `csize`. It corresponds the the `size` of each coordinate.\n"
"We can observe that there are 40 coordinate points in the object. This refers to the attribute *coordinate size* or in short `csize`. Note that this is different from the `size` of numpy arrays because the *Coordinates* object stores 3 $\times$ 40 values in total (40 azimuth angles, 40 elevation angles, and 40 radii).\n"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thats not correct, it always stores 40 x, 40y, and 40z values.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the last sententence is rather confusing.

docs/gallery/interactive/pyfar_coordinates.ipynb Outdated Show resolved Hide resolved
docs/gallery/interactive/pyfar_coordinates.ipynb Outdated Show resolved Hide resolved
"cell_type": "markdown",
"metadata": {},
"source": [
"The `cshape`, `csize`, and `cdim` attributes are similar to numpy's `shape`, `size`, and `dim` of each coordinate.\n"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we need this explanation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree. A link to the same logic for audio objects might be sufficient.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

docs/gallery/interactive/pyfar_coordinates.ipynb Outdated Show resolved Hide resolved
"cell_type": "markdown",
"metadata": {},
"source": [
"We can also directly access certain coordinates."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just thought that it might be nice to mention our rad2deg converter somewhere

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very goof point, thanks

"metadata": {},
"outputs": [],
"source": [
"azimuth = c.azimuth\n",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see...

@ahms5 ahms5 requested a review from f-brinkmann March 1, 2024 13:37
docs/gallery/interactive/pyfar_coordinates.ipynb Outdated Show resolved Hide resolved
docs/gallery/interactive/pyfar_coordinates.ipynb Outdated Show resolved Hide resolved
docs/gallery/interactive/pyfar_coordinates.ipynb Outdated Show resolved Hide resolved
docs/gallery/interactive/pyfar_coordinates.ipynb Outdated Show resolved Hide resolved
docs/gallery/interactive/pyfar_coordinates.ipynb Outdated Show resolved Hide resolved
docs/gallery/interactive/pyfar_coordinates.ipynb Outdated Show resolved Hide resolved
docs/gallery/interactive/pyfar_coordinates.ipynb Outdated Show resolved Hide resolved
docs/gallery/interactive/pyfar_coordinates.ipynb Outdated Show resolved Hide resolved
docs/gallery/interactive/pyfar_coordinates.ipynb Outdated Show resolved Hide resolved
docs/gallery/interactive/pyfar_coordinates.ipynb Outdated Show resolved Hide resolved
ahms5 and others added 3 commits March 4, 2024 13:42
"source": [
"import pyfar as pf\n",
"import numpy as np\n",
"%matplotlib inline"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"%matplotlib inline"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if i dont use it, i need to use plt.show() to show all the plots...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this environment dependent? Works without %matplotlib inline in my case (VScode, python 3.11.7)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ahms5 ahms5 requested a review from sikersten March 4, 2024 13:12
@sikersten sikersten self-requested a review March 5, 2024 10:17
ahms5 and others added 2 commits March 5, 2024 12:27
Co-authored-by: sikersten <70263411+sikersten@users.noreply.github.com>
Co-authored-by: sikersten <70263411+sikersten@users.noreply.github.com>
docs/gallery/interactive/pyfar_coordinates.ipynb Outdated Show resolved Hide resolved
docs/gallery/interactive/pyfar_coordinates.ipynb Outdated Show resolved Hide resolved
docs/gallery/interactive/pyfar_coordinates.ipynb Outdated Show resolved Hide resolved
docs/gallery/interactive/pyfar_coordinates.ipynb Outdated Show resolved Hide resolved
docs/gallery/interactive/pyfar_coordinates.ipynb Outdated Show resolved Hide resolved
docs/gallery/interactive/pyfar_coordinates.ipynb Outdated Show resolved Hide resolved
docs/gallery/interactive/pyfar_coordinates.ipynb Outdated Show resolved Hide resolved
docs/gallery/interactive/pyfar_coordinates.ipynb Outdated Show resolved Hide resolved
docs/gallery/interactive/pyfar_coordinates.ipynb Outdated Show resolved Hide resolved
Copy link
Member

@mberz mberz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of minor things. I'd prefer if there's minimum redundancy with the docs, but I'd also be okay with keeping the figure here. (Or maybe there's an option in-between, where we could link to the url of the file?)

"The image below shows the coordinate systems available with pyfar.\n",
"![alt text](../../resources/coordinate_systems.png)\n",
"\n",
"Note that each coordinate has a unique name. If a coordinate is contained in multiple coordinate systems (e.g. 'z' in cartesian and cylindrical) this means the values for z are the same in both cases.\n",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

During the last meeting we agreed to link to the pyfar docs for the table and figures showing the coordinate systems. I'd still vouch for that.

Comment on lines 170 to 171
"cartesian_coordinates = c.cartesian\n",
"cartesian_coordinates"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just?

Suggested change
"cartesian_coordinates = c.cartesian\n",
"cartesian_coordinates"
"c.cartesian\n",

Or do you need to access the generated variable later?

Comment on lines +394 to +395
"c.rotate('y', 45)\n",
"c.show()"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the default in degrees here? That's inconsistent with our convention of always using radians.
Should we fix this in pyfar?

Comment on lines 31 to 32
"The image below shows the coordinate systems available with pyfar.\n",
"![alt text](../../resources/coordinate_systems.png)\n",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd link to the pyfar docs on coordinates here to remove redundancy.

ahms5 and others added 4 commits March 7, 2024 09:32
@ahms5 ahms5 requested a review from mberz March 7, 2024 10:21
@f-brinkmann f-brinkmann merged commit 676360c into main Mar 7, 2024
6 checks passed
@f-brinkmann f-brinkmann deleted the pyfar_coords branch March 7, 2024 12:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants