Skip to content

Commit

Permalink
Remove warning
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeldeistler committed Oct 23, 2024
1 parent 55e915d commit 5ff35ca
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 78 deletions.
18 changes: 6 additions & 12 deletions jaxley/channels/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from abc import ABC, abstractmethod
from typing import Dict, Optional, Tuple
from warnings import warn

import jax.numpy as jnp


Expand All @@ -25,7 +26,10 @@ def __init__(self, name: Optional[str] = None):
"[email protected] or create an issue on Github: "
"https://github.com/jaxleyverse/jaxley/issues. Thank you!"
)
if not hasattr(self, "current_is_in_mA_per_cm2"):
if (
not hasattr(self, "current_is_in_mA_per_cm2")
and self.current_is_in_mA_per_cm2
):
raise ValueError(
"The channel you are using is deprecated. "
"In Jaxley version 0.5.0, we changed the unit of the current returned "
Expand All @@ -37,17 +41,7 @@ def __init__(self, name: Optional[str] = None):
"`self.current_is_in_mA_per_cm2=False` as the "
f"first line in the `__init__()` method of your channel. {contact}"
)
if not self.current_is_in_mA_per_cm2:
warn(
"You are using `current_is_in_mA_per_cm2=False`. This means that the "
"current through the channel will be considered in `uA/cm^2`. In "
"future versions of Jaxley, we will remove this option and force the "
"channel to return the current in `mA/cm^2`. We recommend to adapt "
"your `compute_current()` method now and return the current in "
"`mA/cm^2` (by dividing the current by 1000). After this has been "
"done, set `current_is_in_mA_per_cm2=True` to get rid of this "
f"warning. {contact}"
)

self._name = name if name else self.__class__.__name__

@property
Expand Down
12 changes: 3 additions & 9 deletions jaxley/modules/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1806,15 +1806,9 @@ def _channel_currents(
voltage_term = (membrane_currents[1] - membrane_currents[0]) / diff
constant_term = membrane_currents[0] - voltage_term * voltages[indices]

if channel.current_is_in_mA_per_cm2:
# * 1000 to convert from mA/cm^2 to uA/cm^2.
voltage_terms = voltage_terms.at[indices].add(voltage_term * 1000.0)
constant_terms = constant_terms.at[indices].add(-constant_term * 1000.0)
else:
# If `current_is_in_mA_per_cm2=False` then the current is assumed as
# `uA/cm^2`.
voltage_terms = voltage_terms.at[indices].add(voltage_term)
constant_terms = constant_terms.at[indices].add(-constant_term)
# * 1000 to convert from mA/cm^2 to uA/cm^2.
voltage_terms = voltage_terms.at[indices].add(voltage_term * 1000.0)
constant_terms = constant_terms.at[indices].add(-constant_term * 1000.0)

# Save the current (for the unperturbed voltage) as a state that will
# also be passed to the state update.
Expand Down
57 changes: 0 additions & 57 deletions tests/jaxley_identical/test_channel_current_units.py

This file was deleted.

0 comments on commit 5ff35ca

Please sign in to comment.