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

Include the conversion factor in a Unit #78

Merged
merged 7 commits into from
Dec 11, 2024
Merged

Include the conversion factor in a Unit #78

merged 7 commits into from
Dec 11, 2024

Conversation

chaoming0625
Copy link
Member

@chaoming0625 chaoming0625 commented Dec 11, 2024

This pull request includes several updates to the brainunit/_unit_common.py file, primarily focusing on the addition of new units and the standardization of formatting for unit creation. The most important changes include adding new derived units, introducing new units for modular dynamics, and standardizing the formatting of existing unit definitions.

This PR enables us to define the unit like

  • Electric voltage (eV) 1 eV = 1.602176565 * 10e-19 Joule
>>> import brainunit as u
>>> 1. * u.eV
1. * electronvolt

Close #63

Additions:

  • Added new units for modular dynamics, including eV, Angstrom, AMU, and IMF. [1] [2]
  • Added new derived units such as ysteradian2, ysteradian3, zsteradian2, zsteradian3, etc.

Formatting Standardization:

  • Standardized the formatting for the creation of several units by removing spaces around the ** operator and adjusting the scale formatting. [1] [2] [3] [4] [5]

Minor Changes:

  • Added a blank line for better readability in the __all__ list.
  • Added comments and section headers to improve code organization and readability.

@chaoming0625 chaoming0625 changed the title Enable Unit represent the conversion factor Include the conversion factor in a Unit Dec 11, 2024
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should also add x=x.factorless() for ldexp?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Should also add x=x.factorless() for divmod, power, float_power, multi_dot, matrix_power, and det.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Should also add x=x.factorless() for remove_diag, intersect1d, nan_to_num, interp, histogram, take, where, unique and modf.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Should also add x=x.factorless() for digitize, allclose, searchsorted,

@@ -121,6 +122,14 @@
additional_units += _u + ', '
additional_units += ']'


Copy link
Collaborator

Choose a reason for hiding this comment

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

May need to be compatible with units with factors

@@ -2730,15 +2928,19 @@ def __len__(self) -> int:
return len(self.mantissa)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Why __neg__, __pos__, __abs__ need self.factorless()

@@ -3369,6 +3613,7 @@ def transpose(self, *axes) -> 'Quantity':
out : ndarray
View of `a`, with axes suitably permuted.
"""
self = self.factorless()
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems that some methods like transpose do not require factorless()

@chaoming0625 chaoming0625 merged commit 4f33522 into main Dec 11, 2024
23 of 24 checks passed
@chaoming0625 chaoming0625 deleted the factor branch December 11, 2024 15:51
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.

[feat] More common units for modular dynamics simulation and Conversion between other units
2 participants