Skip to content

Commit 58309b6

Browse files
Merge pull request #50 from AFM-SPM/SylviaWhittle/asd-add-9-volt-option
Add encoder option for 9.99 volt asd files
2 parents 216fef0 + 50989a1 commit 58309b6

File tree

2 files changed

+30
-31
lines changed

2 files changed

+30
-31
lines changed

AFMReader/asd.py

+28-29
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ class VoltageLevelConverter:
4242
----------
4343
analogue_digital_range : float
4444
The range of analogue voltage values.
45-
max_voltage : float
46-
Maximum voltage.
4745
scaling_factor : float
4846
A scaling factor calculated elsewhere that scales the heightmap appropriately based on the type of channel
4947
and sensor parameters.
@@ -52,32 +50,27 @@ class VoltageLevelConverter:
5250
values. Typically 12, hence 2^12 = 4096 sensitivity levels.
5351
"""
5452

55-
def __init__(
56-
self, analogue_digital_range: float, max_voltage: float, scaling_factor: float, resolution: int
57-
) -> None:
53+
def __init__(self, analogue_digital_range: float, scaling_factor: float, resolution: int) -> None:
5854
"""
5955
Convert arbitrary height levels from the AFM into real world nanometre heights.
6056
6157
Parameters
6258
----------
6359
analogue_digital_range : float
6460
The range of analogue voltage values.
65-
max_voltage : float
66-
Maximum voltage.
6761
scaling_factor : float
6862
A scaling factor calculated elsewhere that scales the heightmap appropriately based on the type of channel
6963
and sensor parameters.
7064
resolution : int
7165
The vertical resolution of the instrumen. Dependant on the number of bits used to store its
7266
values. Typically 12, hence 2^12 = 4096 sensitivity levels.
7367
"""
74-
self.ad_range = int(analogue_digital_range, 16)
75-
self.max_voltage = max_voltage
68+
self.ad_range = analogue_digital_range
7669
self.scaling_factor = scaling_factor
7770
self.resolution = resolution
7871
logger.info(
7972
f"created voltage converter. ad_range: {analogue_digital_range} -> {self.ad_range}, "
80-
f"max voltage: {max_voltage}, scaling factor: {scaling_factor}, resolution: {resolution}"
73+
f" scaling factor: {scaling_factor}, resolution: {resolution}"
8174
)
8275

8376

@@ -100,7 +93,8 @@ def level_to_voltage(self, level: float) -> float:
10093
float
10194
Real world nanometre height for the input height level.
10295
"""
103-
return (self.ad_range * level / self.resolution) * self.scaling_factor
96+
multiplier = -self.ad_range / self.resolution * self.scaling_factor
97+
return level * multiplier
10498

10599

106100
# pylint: disable=too-few-public-methods
@@ -263,6 +257,7 @@ def load_asd(file_path: Path, channel: str):
263257
scanner_sensitivity=header_dict["scanner_sensitivity"],
264258
phase_sensitivity=header_dict["phase_sensitivity"],
265259
)
260+
266261
analogue_digital_converter = create_analogue_digital_converter(
267262
analogue_digital_range=header_dict["analogue_digital_range"],
268263
scaling_factor=scaling_factor,
@@ -739,64 +734,68 @@ def create_analogue_digital_converter(
739734
file. Note that this is file specific since the parameters will change between files.
740735
"""
741736
# Analogue to digital hex conversion range encoding:
742-
# unipolar_1_0V : 0x00000001 +0.0 to +1.0 V
743-
# unipolar_2_5V : 0x00000002 +0.0 to +2.5 V
744-
# unipolar_5_0V : 0x00000004 +0.0 to +5.0 V
745-
# bipolar_1_0V : 0x00010000 -1.0 to +1.0 V
746-
# bipolar_2_5V : 0x00020000 -2.5 to +2.5 V
747-
# bipolar_5_0V : 0x00040000 -5.0 to +5.0 V
737+
# unipolar_1_00V : 0x00000001 +0.00 to +1.00 V
738+
# unipolar_2_50V : 0x00000002 +0.00 to +2.50 V
739+
# unipolar_9.99v : 0x00000003 +0.00 to +9.99 V
740+
# unipolar_5_00V : 0x00000004 +0.00 to +5.00 V
741+
# bipolar_1_00V : 0x00010000 -1.00 to +1.00 V
742+
# bipolar_2_50V : 0x00020000 -2.50 to +2.50 V
743+
# bipolar_5_00V : 0x00040000 -5.00 to +5.00 V
744+
745+
converter: VoltageLevelConverter
748746

749747
if analogue_digital_range == hex(0x00000001):
750748
# unipolar 1.0V
751749
mapping = (0.0, 1.0)
752750
converter = UnipolarConverter(
753-
analogue_digital_range=analogue_digital_range,
754-
max_voltage=1.0,
751+
analogue_digital_range=1.0,
755752
resolution=resolution,
756753
scaling_factor=scaling_factor,
757754
)
758755
elif analogue_digital_range == hex(0x00000002):
759756
# unipolar 2.5V
760757
mapping = (0.0, 2.5)
761758
converter = UnipolarConverter(
762-
analogue_digital_range=analogue_digital_range,
763-
max_voltage=2.0,
759+
analogue_digital_range=2.5,
760+
resolution=resolution,
761+
scaling_factor=scaling_factor,
762+
)
763+
elif analogue_digital_range == hex(0x00000003):
764+
mapping = (0, 9.99)
765+
converter = UnipolarConverter(
766+
analogue_digital_range=9.99,
764767
resolution=resolution,
765768
scaling_factor=scaling_factor,
766769
)
767770
elif analogue_digital_range == hex(0x00000004):
768771
# unipolar 5.0V
769772
mapping = (0.0, 5.0)
770773
converter = UnipolarConverter(
771-
analogue_digital_range=analogue_digital_range,
772-
max_voltage=5.0,
774+
analogue_digital_range=5.0,
773775
resolution=resolution,
774776
scaling_factor=scaling_factor,
775777
)
776778
elif analogue_digital_range == hex(0x00010000):
777779
# bipolar 1.0V
778780
mapping = (-1.0, 1.0)
779781
converter = BipolarConverter(
780-
analogue_digital_range=analogue_digital_range,
781-
max_voltage=1.0,
782+
analogue_digital_range=1.0,
782783
resolution=resolution,
783784
scaling_factor=scaling_factor,
784785
)
785786
elif analogue_digital_range == hex(0x00020000):
786787
# bipolar 2.5V
787788
mapping = (-2.5, 2.5)
788789
converter = BipolarConverter(
789-
analogue_digital_range=analogue_digital_range,
790-
max_voltage=2.0,
790+
analogue_digital_range=2.5,
791791
resolution=resolution,
792792
scaling_factor=scaling_factor,
793793
)
794794
elif analogue_digital_range == hex(0x00040000):
795795
# bipolar 5.0V
796796
mapping = (-5.0, 5.0)
797797
converter = BipolarConverter(
798-
analogue_digital_range=analogue_digital_range,
799-
max_voltage=5.0,
798+
analogue_digital_range=5.0,
800799
resolution=resolution,
801800
scaling_factor=scaling_factor,
802801
)

pyproject.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ tests = [
6262
]
6363

6464
[project.urls]
65-
"Homepage" = "https://github.com/AFM-SPM/AFMReader"
66-
"Bug Tracker" = "https://github.com/AFM-SPM/AFMReader/issues"
65+
"Homepage" = "https://github.com/AFM-SPM/afmreader"
66+
"Bug Tracker" = "https://github.com/AFM-SPM/afmreader/issues"
6767

6868
[tool.setuptools_scm]
6969
write_to = "AFMReader/_version.py"

0 commit comments

Comments
 (0)