#  High-Throughput Phenotyping using Computer Vision and Machine Learning
SMC Data Challenge #1

Vivaan Singhvi  Langalibalele Lunga  Pragya Nidhi  Chris Keum  Varrun Prakash

###### Abstract

High-throughput phenotyping refers to the non-destructive and efficient
evaluation of plant phenotypes. In recent years, it has been coupled with
machine learning in order to improve the process of phenotyping plants by
increasing efficiency in handling large datasets and developing methods for
the extraction of specific traits. Previous studies have developed methods to
advance these challenges through the application of deep neural networks in
tandem with automated cameras; however, the datasets being studied often
excluded physical labels. In this study, we used a dataset provided by Oak
Ridge National Laboratory with 1,672 images of Populus Trichocarpa with white
labels displaying treatment (control or drought), block, row, position, and
genotype. Optical character recognition (OCR) was used to read these labels on
the plants, image segmentation techniques in conjunction with machine learning
algorithms were used for morphological classifications, machine learning
models were used to predict treatment based on those classifications, and
analyzed encoded EXIF tags were used for the purpose of finding leaf size and
correlations between phenotypes. We found that our OCR model had an accuracy
of 94.31% for non-null text extractions, allowing for the information to be
accurately placed in a spreadsheet. Our classification models identified leaf
shape, color, and level of brown splotches with an average accuracy of 62.82%,
and plant treatment with an accuracy of 60.08%. Finally, we identified a few
crucial pieces of information absent from the EXIF tags that prevented the
assessment of the leaf size. There was also missing information that prevented
the assessment of correlations between phenotypes and conditions. However,
future studies could improve upon this to allow for the assessment of these
features. The use of machine learning and computer vision in high-throughput
phenotyping has shown to be effective in analyzing large plant datasets,
leading to a more comprehensive phenotype analysis in plants and showing
potential in various agricultural and environmental applications.

###### keywords:

computer vision , machine learning , high-throughput phenotyping

††journal: SMCDC23

[fhs]organization=Farragut High School, addressline=11237 Kingston Pike,
city=Knoxville, postcode=37922, state=Tennessee, country=United States

##  1 Introduction

###  1.1 Background Information

High-throughput phenotyping is defined as a breakthrough technology used in
plant biology and agriculture to examine and assess plants’ ”anatomical,
ontological, physiological, and biochemical features” through the use of
images. Previous studies have shown its potential as a noninvasive replacement
for traditional on-field techniques used to extract important phenotypic data.
In recent years, this potential has been further intensified by coupling
image-based phenotyping techniques with machine learning algorithms. This new
approach has enabled the extraction of phenotypes from ”complex” plant image
datasets that were previously challenging to analyze efficiently. Furthermore,
newer studies have shown that the technology has potential to identifying
correlations between phenotype, genotype, and environmental metadata.

###  1.2 Research Objective

In this study, we aim to develop an accurate machine learning model for high-
throughput phenotyping of leaves’ morphological traits (e.g. leaf size, shape,
color) in plant images; unlike datasets in previous research, the dataset used
in this study contains physical labels within the images, each containing
important information on treatment (control or drought), block, row, position,
and genotype. As a result, this study will address a new aspect of image-based
phenotyping, namely, extracting data from the white labels to identify
correlations between leaves’ phenotypes and data embedded within the white
labels. During this project, we aim to answer the following questions:

  1. 1.

Is it possible to use optical character recognition (OCR) or machine learning
techniques to “read” the label on each tag and generate a spreadsheet
containing the treatment, block, row, position, and genotype? Doing this would
dramatically simplify data collection, as this information is usually
collected manually.

  2. 2.

Can machine learning differentiate and classify different leaf morphologies
among genotypes by classifying leaf shape or color characteristics?

  3. 3.

Can a predictive model be built using leaf morphology classifications that may
indicate that a particular genotype was cultivated in a “drought” or “control”
condition?

  4. 4.

GPS and other camera information are encoded in EXIF tags. Can this data be
used to determine characteristics such as leaf size? Can other data, such as
soil maps, weather, etc. be used to find correlations among phenotypes?

##  2 Related Works

Traditionally, plant morphologies would be analyzed manually, wasting time and
potentially damaging the environment. However, current breakthroughs in high-
throughput phenotyping led by machine learning techniques (Koh et al., 2021;
Pound et al., 2017) and computer vision with deep learning (Mochida et al.,
2019) have allowed for efficient and timely analyses of plant phenotypes. With
these methods, researchers can extract features from plants and classify their
morphologies effectively while having little effect on the plant itself.

###  2.1 Advancements in High Throughput Phenotyping Techniques

Advancements in the field of plant phenotyping have been pioneered by
technology. From using hardware, such as Raspberry Pi imaging systems (Tausen
et al., 2020) to thermographic sensing techniques (Walter et al., 2015),
research in the field of high-throughput phenotyping has led to an
acceleration in working efficiency. Plants are now able to be analyzed in
fast, effective, and accurate methods allowing for them to be used in
scientific discoveries. In our study, we rely on machine learning techniques
to classify morphologies based on a plant image dataset provided.

###  2.2 Machine Learning Approaches for Phenotypic Analysis

Machine learning has enabled researchers with computer vision, allowing them
to create programs that “read” image information in real-time. In addition, it
increases the efficiency of obtaining leaf morphology data. However,
researchers have found that traditional classification techniques, such as
Random Forest Classification, have high performance but do not generalize well
across datasets (Pound et al., 2017). In order to increase the accuracy of
models and the generalization of the model, deep learning techniques have been
introduced. With deep learning models, models train themselves iteratively
until they reach a desired outcome. These techniques, such as convolutional
neural networks (Koh et al., 2021; Pound et al., 2017) have shown to be highly
accurate in classifying plant structures while maintaining performance across
different datasets. Convolutional neural networks consist of several layers,
which allow for a more discriminative and detailed analysis of plant images,
leading to highly accurate classifications. In our study, we use traditional
methods to classify plant morphology, as our focus is performing
classifications with a single dataset rather than creating models highly
transferable across datasets.

###  2.3 Applications of High Throughput Phenotyping with Machine Learning

Due to global events, such as climate change and global population increase,
the ability to produce large amounts of healthy crops will be crucial to
society. With machine learning being used for phenotyping, researchers will be
able to rapidly analyze food crops to maximize production and breeding (Arya
et al., 2022; Shakoor et al., 2017).

As climate change and the global population increase, global crop yield will
have to increase to provide for the growing populations. Further research has
shown that climate change will continue to negatively affect crops and cause
crop diseases (Newton et al., 2011), hence the need for effective and precise
analysis of plants, which can be done with machine learning models. In our
study, we aim to show how machine learning can be used to organize plant data,
dissect plant images into meaningful classifications, and allow for rapid
investigation of plants for scientists in the field of plant phenotyping.

##  3 Methodology

Given the nature of the project, there are many aspects requiring obtaining
large files, such as the dataset itself or large models. Therefore, all
scripts needed to fully set up the project (downloading large files or setting
up a large virtual environment), are viewable in the `scripts/` folder of the
GitHub repository, linked in Section 6.

All solutions to the challenge were implemented in Python 3.9/3.10. Several
notable libraries used throughout the project include: OpenCV (Bradski, 2000),
the open-source computer vision library; Scikit-Learn (Pedregosa et al.,
2011), Python implementations of dozens of machine learning algorithms and
data processing tools; Pandas (McKinney et al., 2010), a data manipulation
library featuring the powerful `DataFrame` object; and NumPy (Harris et al.,
2020), an array manipulation library crucial for fast operations on images.

All models used in this project are trained and tested on data split by
Scikit-Learn’s `train_test_split`. Additionally, Scikit-Learn’s
`accuracy_score` is used to determine the accuracy of said models.

###  3.1 Reading Labels with Optical Character Recognition

To read the text, a pre-trained optical character recognition (OCR) model
seemed like the optimal choice. However, there are several high-performing
models available for use. The three candidates chosen for this project were
`PyTesseract` (Lee, 2017), `EasyOCR` (JaidedAI, 2020), and `PaddleOCR` (Du et
al., 2020).

The three models were tested using metrics of performance and efficiency,
which were measured through their accuracy score and time taken on a sample
dataset of nine images. The results of the testing can be viewed in A.

`PaddleOCR` was superior in speed, being significantly faster than `EasyOCR`
and marginally faster than `PyTesseract`. It is also more accurate in both
measurements, having a higher accuracy score with and without null values.

In order to fix the aforementioned null values from the OCRs, images went
through augmentation, with subsequent attempts being made to read text during
each step. First, images are rotated 45 degrees in order to fix potential
orientation issues. Then, the original image is thresholded using OpenCV’s
`adaptiveThreshold` to amplify the edges. Finally, if nothing works, the image
is both rotated and thresholded.

Figure 1: Different versions of images tried for optical character
recognition, in order

After the text was read by the OCR, regular expressions (RegEx) were used to
find the precise details mentioned in the dataset: treatment, block, row,
position, and genotype. A subjective analysis of the images in the dataset
showed that the treatment was either a `C` or a `D`, and the remaining
features followed the RegEx patterns below (note: `\d` represents a digit,
anything between 0-9) :

      Block:      B\d+
      Row:        R\d+
      Position:   P\d+
      Genotype:   [A-Z]{2,}(-\d+)+(_\d+)*(_[A-Z]+)?

After all the text is read and processed, it is converted to a Pandas
`DataFrame` and saved to an Excel spreadsheet, which will be used in the
following steps. Then, 30 random images are selected and the accuracy of the
results is tested by comparing inputted to read features. As with the OCR
testing earlier, it is calculated both with and without unread values.

###  3.2 Classifying Leaf Morphologies with Image Processing

In order to be able to determine the morphological characteristics of the
plants, it was necessary to perfectly segment the leaves from each image. This
proved to be a challenging endeavor due to the complexity of the background of
the images; other datasets, such as the Komatsuna dataset, (Uchiyama et al.,
2017) had ’cleaner’ image backgrounds.

To obtain perfect masks for leaves in each image, the Segment Anything Model
(SAM) (Kirillov et al., 2023) was the obvious choice, due to its
groundbreaking accuracy and ease of use. Being a relatively new model, this
paper is one of the first to utilize a pre-trained model of its caliber.

The `AutomaticMaskGenerator` provided generates accurate masks for everything
in an image. However, it has two issues: it may generate too many masks
(especially for images as cluttered as those in the dataset), and is
computationally expensive, taking too long to be a plausible approach for all
1672 images in this dataset. Through a `SamPredictor` in conjunction with an
ONNX (Bai et al., 2019) `InferenceSession`, masks would generate much quicker,
and only from desired points. However, to obtain these desired points, the
images would have to be processed to approximate the locations of the leaves.

The first step was to hide non-leaf elements in the image. A popular technique
called HSV filtering was employed, used in a similar project by Szachowicz
(2021). This involves filtering all pixels that are not between an HSV-encoded
color range, helping eliminate many background objects such as wood, dirt, and
of course, the label.

Then, OpenCV’s implementation of the `Canny` algorithm was used to highlight
significant edges in the image, which were present around the boundary of
leaves but were minimal inside of them. However, some leaves had boundary
edges with gaps, causing most contours detected (using OpenCV’s
`findContours`) to be sporadic. Therefore, the edges were dilated in multiple
iterations by using a large kernel, causing the boundaries to be closed. After
contours were found on the resulting image, they were filtered by pruning
those that had a height or width (found using the `boundingRect` function
around each contour) too small compared to that of the image. Additionally,
contours with not enough green inside them (namely less than $\frac{100}{255}$
green) were removed.

Figure 2: Pipeline of image transformations for leaf approximation, read left
to right. The last image visualizes detected contours

To find the approximate points of these leaf contours, the midpoint was
calculated using this simple formula, with $x,y,w,h$ being the outputs of
OpenCV’s `boundingRect` function:

$\mbox{midpoint}=(x+\frac{w}{2},y+\frac{h}{2})$ (1)

By using these points as target points for the SAM/ONNX mask predictor, leaves
could reliably be obtained from the image. Masks could then be saved for each
image by converting each of an image’s masks to a random uniform grayscale
value and combining them all into an image. While very accurate, however, some
leaves detected by the program were not appropriate for use in morphology
analysis. For example, some leaves could be cut off by another object, or, in
rare cases, be green wood misinterpreted as leaves.

Thus, it was necessary to train a machine learning model that was able to
accurately detect these kinds of ’bad’ leaves. Training data was generated by
showing randomly selected leaves and getting human input regarding their
suitability, extracting their features, and storing the data in a file. The
model was implemented using Scikit-Learn’s `RandomForestClassifier`, and had
an accuracy of 90.91% on testing data.

Figure 3: From leaf approximations with image processing to filtered leaf
segmentations, from the SAM/ONNX Runtime (green leaves fit for classification)

Then, each leaf could be cropped and rotated, which, when combined with
masking every pixel outside its border, effectively highlighted and isolated
it for visual purposes. By repeating this process for each image in the
dataset, random leaves could then be selected to generate data for training
the morphological classification model.

The features selected for morphology prediction were: color, between light-
green, dark-green, yellow-green, and yellow; shape, between ovate, lanceolate,
elliptical, and oblong (Nakano, 2020); and level of brown splotches
(representing the level of the withering of the leaf), between none, low,
medium, and high.

Figure 4: Leaf shape reference from the article by Nakano (2020)

By using a slightly modified version of the aforementioned feature extraction
function in conjunction with a Scikit-Learn `LabelEncoder` to prepare the
target features, the classifier could be implemented with Scikit-Learn’s
`MultiOutputClassifier`. This is a framework for using the same algorithm on
three different features at once; namely, the algorithm used was `XGBoost`,
which seemed to trump other models in terms of accuracy.

After the model was trained, it was used on each image in the dataset by
finding all eligible leaves and determining the mode classification after each
eligible leaf was run through the aforementioned model. The results were saved
in a copy of the spreadsheet from the previous step.

###  3.3 Treatment Predictions using Morphological Classifications

The task for this step was to build a model to predict if a leaf was grown in
a control or drought environment, given morphological classifications from the
previous step.

The classifications were easily attainable because they were saved in a
spreadsheet. However, the challenge for using classification data as features
to train a model with is that they are categorical, rather than quantitative;
data needed to undergo extra transformations to prepare it for use in
predictions.

To properly represent the classifications, the method of one-hot encoding
(Brownlee, 2020) was implemented using the Pandas `get_dummies` method. This
is a process in which a feature is split into multiple columns, with each row
having a one if it matches the column or a zero if it doesn’t.

leaf_color | light_green | dark_green | yellow_green | yellow
---|---|---|---|---
light_green | 1 | 0 | 0 | 0
yellow_green | 0 | 0 | 1 | 0
dark_green | 0 | 1 | 0 | 0
light_green | 1 | 0 | 0 | 0
yellow | 0 | 0 | 0 | 1

Table 1: Example transformation of a column with one-hot encoding, with the
original column on the left and the encoded columns on the right

This process was done with the leaf color and shape variables. However, since
a leaf’s level of brown splotches is ordinal, it was assigned levels 0, 1, 2,
and 3, corresponding to ’none’, ’low’, ’medium,’ and ‘high.’ The data for
expected treatments were obtained by reading rows of the spreadsheet that had
treatments successfully read.

Now, using this data, a predictor could be trained and deployed. The chosen
classifier for this task was Scikit-Learn’s `RandomForestClassifier`, as it
has shown to be a capable model throughout the project. After the model was
trained, it was deployed on the spreadsheet, predicting treatments for rows
that lacked a properly read one.

###  3.4 Using EXIF Data to Assess Leaf Size and Analyze Correlations Between
Morphologies and Environments

First, we aimed to measure the size of a leaf through metadata encoded in EXIF
Tags, which are embedded within each of the images. These tags typically give
important information about the images, including the type of camera utilized,
the distance of the camera from a photo, and photo dimensions (in pixels). In
order to initiate the extraction of such metadata from the images, the `exif`
package was used and gave a variety of retrieval options.

Out of all the metadata extracted from the EXIF tags, the most notable pieces
of information included `ResolutionX`/`ResolutionY` tags and `FocalLength`.
Although these pieces of information can assist in developing a mechanism to
measure leaf size in the dataset, it simply does not suffice alone; additional
information, such as how far the leaf was from the camera, was needed. With
more information, such as `FocalPlaneResolution` \- showing the number of
pixels per real unit (`in` or `cm`) - in addition to previously mentioned
features, it is possible to assess the size of specific components of an
image. For example, a study on maize phenotyping by Liu et al. (2021) showed
that embedded information in images was enough for a smartphone application to
accurately determine measurements of plant height and leaf area in a photo.

Another approach we considered to measure leaf size included using the white
labels, held up by the researcher in each image, as a known reference object.
Although this method seemed promising, there were certain limitations in most
images in the dataset that prevented a consistent measurement. First, the
white label in the image was often obstructed by the researcher’s hands, as
shown in C. This obstruction would ultimately interfere with the alignment of
the white label, making the label unreliable as an object of reference.
Another limitation to this method came from the fact that the labels were
often tilted, not in the same plane as the leaves. The tilt of the labels
caused inaccuracies in measurement and would lead to misrepresentation of the
true length. Along with that, there was no way of finding out how far forward
or behind the leaf was relative to the tag, meaning the method would result in
an inaccurate representation of the leaf. Again, this issue could have been
resolved with more careful documentation of images without obstruction and a
better-positioned label alignment.

In the second part of challenge 4, we aimed to find a correlation between
phenotypes and environmental features, such as soil type and weather
conditions. Using the EXIF tags, we were able to retrieve the coordinates
where the image was taken. However, we noticed all of the images contained
were taken in approximately the same location.

Figure 5: Geographical plot of all plants using encoded EXIF GPS data.

Therefore, any weather or soil API would be unable to provide specific
conditions. If we were given this information as part of the dataset, we would
have been better able to find correlations. Regardless, a study on how the
temperature affects the phenotype and development plasticity in Arabidopsis
Thaliana (Ibañez et al., 2017) placed the plants in different temperature
environments in order to measure their differences. If we had more information
regarding the conditions in which the plants were raised, we would be better
able to determine if there was a correlation between phenotypes and
environment.

##  4 Results and Discussion

All confusion matrices used in this section originate from Scikit-Learn’s
`confusion_matrix` and `ConfusionMatrixDisplay`.

###  4.1 Reading Labels with Optical Character Recognition

The OCR was able to read 91.3% of the labels in the images of the entire
dataset. On the 30 test images, the model had a 77.33% accuracy on extracted
features (94.31% with null values omitted). A subjective analysis showed that
for all features except for genotype, the interpreted values seem to match the
true values almost always.

filename | treatment | block | row | position | genotype
---|---|---|---|---|---
… | D | 1 | 8 | 32 | BESC-34
… | C | 1 | 10 | 12 | **BESC-417_LM**,core
… | C | 2 | 3 | 40 | BESC-468
… | C | 2 | 6 | 54 | BESC-28_LM
… | C | 1 | 24 | 22 | **LILD-26-5_LM**,core

Table 2: First five rows of data saved to the spreadsheet from step 1, with
filenames omitted to conserve space

Before the text was inserted into the above spreadsheet, it was present in a
Pandas `DataFrame`. Here, it was possible to analyze the statistics of the
data using the `info` method, containing useful information such as null value
count:

        RangeIndex: 1672 entries, 0 to 1671
        Data columns (total 6 columns):
         #   Column     Non-Null Count  Dtype
        ---  ------     --------------  -----
         0   filename   1672 non-null   object
         1   treatment  1098 non-null   object
         2   block      1306 non-null   float64
         3   row        1388 non-null   float64
         4   position   1414 non-null   float64
         5   genotype   1431 non-null   object

Evidently, the former attributes were read the least compared to those near
the end of the tag, with 66% non-null values for the treatment and 86% non-
null values for the genotype. This is likely due to the many forms of
obstructions in the images, such as a leaf, a data collector’s hand, or even
the boundary of the image itself. Examples of such can be seen in C.

Even though the information suggests that there is more error in reading the
treatment, it is more likely that it stems from text processing. The
interpreted genotype has more room for error, as there is an extensive number
of possibilities for it, while the treatment must be a `C` or a `D`, leaving
little room for error.

Regardless, it is undeniable that the use of `PaddleOCR`, a relatively new and
underused model, proved significantly beneficial and successful in reading
labels from the images in the dataset. However, one evident issue lies in the
fact that the suffix of the genotype (such as `_LM`) was often not read
properly, causing the text processing to drop it entirely. Increased text pre-
processing may have alleviated this issue.

###  4.2 Classifying Leaf Morphologies with Image Processing

The spreadsheet from the last step was successfully updated with morphological
predictions from this step.

genotype | leaf_color | leaf_shape | brown_splotches
---|---|---|---
BESC-34 | light_green | ovate | none
*BESC-417_LM**,core | yellow_green | ovate | high
BESC-468 | yellow | lanceolate | high
BESC-28_LM | dark_green | ovate | low
*LILD-26-5_LM**,core | yellow_green | lanceolate | medium

Table 3: A continuation of Table 2, with morphological data added from step 2

The model had an average accuracy of 62.82%, which, when considering the fact
that each feature had four different classes, is a reasonable accuracy level.
The confusion matrices generated by comparing test and predicted data for each
feature are below:

Figure 6: Confusion matrix for testing data on the leaf color predictor

This part of the model had an accuracy score of 69.23%. It seems to be
reliable in predicting leaf color but has difficulty classifying true yellow-
green leaves; however, it still correctly predicts yellow-green most of the
time. Because the testing data seems to lack yellow leaves, the model’s
accuracy regarding them is unknown.

Figure 7: Confusion matrix for testing data on the leaf shape predictor

While mostly reliable with color, the model is sporadic in predicting leaf
shape, with an accuracy of 50.00%. When leaves are truly shaped as oblong or
ovate, the predictions are essentially random, including many more wrong
guesses than correct guesses. However, this may be partially due to the
subtlety of the difference between leaf shapes, which may be difficult for a
model to predict.

Figure 8: Confusion matrix for testing data on the brown splotch level
predictor

While there is more ’noise’ in the predictions for brown splotch levels when
compared to those for leaf color, the model seems to have a moderate degree of
accuracy (at 69.23%), with the exception of classifying leaves with ”medium”
splotch levels.

A source for much of the error in the model’s predictions may lie in human
error. For example, when labeling data, we may have incorrectly labeled any of
the three features for a given leaf due to their aforementioned ambiguity. It
is also worth noting that many of the classes were difficult to distinguish
even subjectively, such as distinguishing between yellow-green and light-green
colors or between elliptical and ovate leaf shapes.

###  4.3 Treatment Predictions using Morphological Classifications

The predictive model on the treatment of the plants had an accuracy of 60.08%.

Figure 9: Confusion matrix for the treatment prediction model

While more predictions were true than false, it is undeniable that the model
is unreliable for determinate results. The inaccuracy is likely due to several
factors, including the fact that the only features used in the model were the
morphological classifications from step 2, which may have been inaccurate to
begin with. Additionally, there may have been overfitting on training data.

###  4.4 Using EXIF Data to Assess Leaf Size and Analyze Correlations Between
Morphologies and Environments

Overall, the metadata embedded in the EXIF tags specific to the dataset did
not prove to be enough for direct measurement of leaf size. Given more useful
tags, such as `FocalPlaneResolution`, the task may have been possible.
Additionally, using the label as a reference for measurement also proved
impossible due to the various augmentations of the labels in images. Future
studies could include additional calibration features to enable the
development of a more feasible method for leaf size assessment. For the second
part of the challenge, we needed larger differences in locations or times that
the images were taken in order to study how the conditions in those periods
affected the phenotypes.

##  5 Conclusions

High throughput phenotyping has gained prominence due to its potential in
solving a wide variety of agricultural problems. With the world population
projected to reach 9.3 billion people by 2050 and a need to produce 60% more
food (Silva, 2012), it will become crucial for researchers to discover a
method for identifying productive genotypes for plant breeding. With computer
vision techniques, such as optical character recognition and image processing,
and machine learning methods, such as classifiers to predict morphologies and
treatments, productivity in the field of plant/crop production will increase
rapidly, along with the accurate analysis of plants.

###  5.1 Originality and Uniqueness

This project is one of the first to utilize `PaddleOCR` (Du et al., 2020), an
extremely lightweight and capable optical character recognition model, in the
context of reading plant labels. Unlike other approaches, it is resilient to
augmentations in data, such as label rotation or minor interruptions in
labels.

It is also one of the first to use the Segment Anything Model (SAM) (Kirillov
et al., 2023) in the context of leaf segmentation. When combined with image
processing, leaves can now be extracted from an image with no training or
processing steps for the user. The SAM allows for much more accurate masks to
be obtained and is robust towards heavily noisy data such as ours. This is
especially important when leaf shape needs to be classified, as accurate masks
have more accurate features.

Through the use of pre-built classifiers like `RandomForestClassifier`, this
paper shows that such models can be useful despite the little effort used by
the programmer.

###  5.2 Significance and Specific Contributions

By successfully applying an OCR to read labels, our research shows potential
for automating a data extraction process, which can significantly reduce the
manual labor needed to organize information. Large datasets can be processed
within minutes, with minimal effort from the user.

The use of machine learning on leaves allows for easy analysis of plant
morphologies, which reduces the need for subjective determinations. Although
the model has room for improvement, the process shows promise and can be
easily optimized. Moreover, using another model to predict the kind of
environment a plant was grown, as was done in step 3, allows for even more
valuable information to be obtained just from a single photograph. Researchers
can save hours of effort analyzing thousands of images by utilizing tools such
as these.

Even though the EXIF tags provided by the dataset proved insufficient for
determining leaf size, with the proper additional information, this task could
become trivial and greatly benefit researchers who would otherwise have to
manually measure each leaf with a ruler.

###  5.3 Limitations and Possible Improvements

To achieve higher accuracy in OCR label reading, future research could use
datasets that are more uniform with clearer labels. On a similar note, the
images in the dataset could have a clear focus on a specific leaf, making leaf
classification models better.

The dataset’s lack of metadata prevented the use of EXIF tags to determine
leaf size and correlations between phenotypes and environmental features.
Therefore, a dataset with more information both embedded into images and
embedded into separate files (such as files with soil condition information)
could allow researchers to meet these objectives.

However, if the same dataset is used, future researchers could build more
accurate and complex neural networks for classification. The models used in
this paper were all prebuilt and not fine-tuned to our needs. Additionally,
the image processing could have improved reliability, making data more fit for
use in training or feature prediction.

###  5.4 Future Directions

Future research could be done to expand the species analyzed for morphology
classifications. In this study, only Populus Trichocarpae were used, so the
models used may only be effective on this species.

Since a pre-trained segmentation model (the SAM) was used in this study,
researchers could attempt to build segmentation models fine-tuned to only
recognize leaves, which could increase model efficiency and provide more
consistent results.

##  6 Code Availability

All code is publicly available under the MIT License on GitHub here:
https://github.com/vivaansinghvi07/smoky-mountain-data-comp.

## Acknowledgements

We thank Dr. Ty Frazier at Oak Ridge National Laboratory for his helpful
suggestions and mentoring throughout this project.

## References

  * Arya et al. (2022) Arya, S., Sandhu, K.S., Singh, J., Kumar, S., 2022\.  Deep learning: As the new frontier in high-throughput plant phenotyping.  Euphytica 218, 47\.
  * Bai et al. (2019) Bai, J., Lu, F., Zhang, K., et al., 2019.  Onnx: Open neural network exchange.  URL: https://github.com/onnx.
  * Bradski (2000) Bradski, G., 2000.  The OpenCV Library.
  * Brownlee (2020) Brownlee, J., 2020.  Why one-hot encode data in machine learning?  URL: https://machinelearningmastery.com/why-one-hot-encode-data-in-machine-learning/.
  * Du et al. (2020) Du, Y., Li, C., Guo, R., Yin, X., Liu, W., Zhou, J., Bai, Y., Yu, Z., Yang, Y., Dang, Q., Wang, H., 2020.  Pp-ocr: A practical ultra lightweight ocr system.  URL: https://github.com/PaddlePaddle/PaddleOCR, arXiv:2009.09941.
  * Harris et al. (2020) Harris, C.R., Millman, K.J., van der Walt, S.J., Gommers, R., Virtanen, P., Cournapeau, D., Wieser, E., Taylor, J., Berg, S., Smith, N.J., Kern, R., Picus, M., Hoyer, S., van Kerkwijk, M.H., Brett, M., Haldane, A., del Río, J.F., Wiebe, M., Peterson, P., Gérard-Marchant, P., Sheppard, K., Reddy, T., Weckesser, W., Abbasi, H., Gohlke, C., Oliphant, T.E., 2020\.  Array programming with NumPy.  Nature 585, 357–362.  URL: https://doi.org/10.1038/s41586-020-2649-2, doi:10.1038/s41586-020-2649-2.
  * Ibañez et al. (2017) Ibañez, C., Poeschl, Y., Peterson, T., Bellstädt, J., Denk, K., Gogol-Döring, A., Quint, M., Delker, C., 2017\.  Ambient temperature and genotype differentially affect developmental and phenotypic plasticity in arabidopsis thaliana.  URL: https://www.ncbi.nlm.nih.gov/pmc/articles/PMC5501000/.
  * JaidedAI (2020) JaidedAI, 2020.  Easyocr.  URL: https://github.com/JaidedAI/EasyOCR.
  * Kirillov et al. (2023) Kirillov, A., Mintun, E., Ravi, N., Mao, H., Rolland, C., Gustafson, L., Xiao, T., Whitehead, S., Berg, A.C., Lo, W.Y., Dollár, P., Girshick, R., 2023\.  Segment anything.  URL: https://github.com/facebookresearch/segment-anything, arXiv:2304.02643.
  * Koh et al. (2021) Koh, J.C., Spangenberg, G., Kant, S., 2021.  Automated machine learning for high-throughput image-based plant phenotyping.  Remote Sensing 13, 858\.
  * Lee (2017) Lee, M.A., 2017.  Python-tesseract.  URL: https://github.com/madmaze/pytesseract.
  * Liu et al. (2021) Liu, L., Yu, L., Wu, D., Ye, J., Feng, H., Liu, Q., Yang, W., 2021.  Pocketmaize: An android-smartphone application for maize plant phenotyping.  Frontiers URL: https://www.frontiersin.org/articles/10.3389/fpls.2021.770217/full.
  * McKinney et al. (2010) McKinney, W., et al., 2010.  Data structures for statistical computing in python, in: Proceedings of the 9th Python in Science Conference, Austin, TX. pp. 51–56.
  * Mochida et al. (2019) Mochida, K., Koda, S., Inoue, K., Hirayama, T., Tanaka, S., Nishii, R., Melgani, F., 2019.  Computer vision-based phenotyping for improvement of plant productivity: a machine learning perspective.  GigaScience 8, giy153.
  * Nakano (2020) Nakano, M., 2020.  Plant morphology – leaves.  URL: https://kpu.pressbooks.pub/plant-identification/chapter/plant-morphology-leaves/.
  * Newton et al. (2011) Newton, A.C., Johnson, S.N., Gregory, P.J., 2011.  Implications of climate change for diseases, crop yields and food security.  Euphytica 179, 3–18.
  * Pedregosa et al. (2011) Pedregosa, F., Varoquaux, G., Gramfort, A., Michel, V., Thirion, B., Grisel, O., Blondel, M., Prettenhofer, P., Weiss, R., Dubourg, V., Vanderplas, J., Passos, A., Cournapeau, D., Brucher, M., Perrot, M., Duchesnay, E., 2011\.  Scikit-learn: Machine learning in Python.  Journal of Machine Learning Research 12, 2825–2830.
  * Pound et al. (2017) Pound, M.P., Atkinson, J.A., Townsend, A.J., Wilson, M.H., Griffiths, M., Jackson, A.S., Bulat, A., Tzimiropoulos, G., Wells, D.M., Murchie, E.H., et al., 2017\.  Deep machine learning provides state-of-the-art performance in image-based plant phenotyping.  Gigascience 6, gix083.
  * Shakoor et al. (2017) Shakoor, N., Lee, S., Mockler, T.C., 2017.  High throughput phenotyping to accelerate crop breeding and monitoring of diseases in the field.  Current opinion in plant biology 38, 184–192.
  * Silva (2012) Silva, J.G.D., 2012.  Feeding the world sustainably.  The Future We Want? 49.
  * Szachowicz (2021) Szachowicz, J., 2021.  The komatsuna dataset with python and opencv.  URL: https://github.com/julzerinos/python-opencv-leaf-detection.
  * Tausen et al. (2020) Tausen, M., Clausen, M., Moeskjær, S., Shihavuddin, A., Dahl, A.B., Janss, L., Andersen, S.U., 2020.  Greenotyper: Image-based plant phenotyping using distributed computing and deep learning.  Frontiers in plant science 11, 1181\.
  * Uchiyama et al. (2017) Uchiyama, H., Sakurai, S., Mishima, M., Arita, D., Okayasu, T., Shimada, A., Taniguchi, R.i., 2017.  An easy-to-setup 3d phenotyping platform for komatsuna dataset, in: Proceedings of the IEEE international conference on computer vision workshops, pp. 2038–2045.
  * Walter et al. (2015) Walter, A., Liebisch, F., Hund, A., 2015.  Plant phenotyping: from bean weighing to image analysis.  Plant methods 11, 1–11.

##  Appendix A Results of OCR Model Testing

Figure 10: Average accuracy score for reading the sample dataset for the three
OCR models

Figure 11: Average accuracy score only including non-zero values (only images
that were able to be read)

Figure 12: Total time taken for the three OCR models on the sample dataset

##  Appendix B Examples in the Leaf Segmentation Process

Figure 13: Example leaf segmentation image generated by the SAM/ONNX Runtime

Figure 14: Example leaf generated by cropping and rotating a filtered
segmentation

##  Appendix C Examples of Images with Obstructed Labels

Figure 15: Example of label blocked by a leaf

Figure 16: Example of label blocked by the researcher’s hand

Figure 17: Example of label cut by the boundary of the image


# Influence of the distribution of the properties of permanent magnets on the
field homogeneity of magnet assemblies for mobile NMR

Y.P.Klein1∗ 1 University of Twente, Enschede, The Netherlands
2 KIST Europe, Saarbrücken, Germany
L.Abelmann1,2 1 University of Twente, Enschede, The Netherlands
2 KIST Europe, Saarbrücken, Germany
J.G.E.Gardeniers 1∗ 1 University of Twente, Enschede, The Netherlands
2 KIST Europe, Saarbrücken, Germany

###### Abstract

We optimised the magnetic field homogeneity of two canonical designs for
mobile microfluidic NMR applications: two parallel magnets with an air gap and
a modified Halbach array. Along with the influence of the sample length,
general design guidelines will be presented. For a fair comparison the
sensitive length of the sample has been chosen to be the same as the gap size
between the magnets to ensure enough space for the transmitting and receiving
unit, as well as basic electric shimming components. Keeping the compactness
of the final device in mind, a box with an edge length 5 times the gap size
has been defined, in which the complete magnet configuration should fit. With
the chosen boundary conditions, the simple parallel cuboid configuration
reaches the best homogeneity without active shimming (0.5$\mathrm{B_{s}}$, 41
ppm), while the Pseudo-Halbach configuration has the highest field strength
(0.9$\mathrm{B_{s}}$, 994 ppm), assuming perfect magnets. However, permanent
magnet configurations suffer from imperfections, such as magnetisation,
fabrication and positioning errors, which results in worse magnetic field
homogeneities than expected from simulations using a fixed optimised parameter
set. We present a sensitivity analysis for a magnetic cube and the results of
studies of the variations in the magnetisation and angle of magnetisation of
magnets purchased from different suppliers, composed of different materials
and coatings, and of different sizes. We performed a detailed Monte Carlo
simulation on the effect of the measured distribution of magnetic properties
on the mentioned configurations. The cuboid design shows a mean homogeneity of
430 ppm (std dev. 350 ppm), the Pseudo-Halbach has a mean homogeneity of 1086
ppm (std dev. 8 ppm).

###### Keywords:

mobile NMR, magnet imperfections, permanent magnets, Halbach, field
homogeneity, proof-reading-service

##  I Introduction

Low-field and low-cost mobile microfluidic nuclear magnetic resonance (NMR)
sensors are very suitable for applications in chemical process industry and in
research, for example chemical analysis, biomedical applications, and flow
measurements [1, 2, 3, 4, 5, 6, 7, 8, 9]. The design of a permanent magnet for
an NMR sensor requires both a strong magnetic field and a high field
homogeneity within a defined region of interest. In NMR, a high external
magnetic field results in a high spectral resolution and detection
sensitivity.

However, field inhomogeneities compromise the spectral resolution. Our aim
with this research was to determine how the distribution of the properties of
permanent magnets affect the magnetic field homogeneity of magnet
configurations for mobile NMR devices.

In the literature, several magnet shapes for mobile NMR sensors have been
reported. A broad overview of magnet developments up to 2009 can be found in
Demas et al. [10]. U-shaped single-sided magnets [11, 12] and magnets with
specially shaped iron pole magnets [13] have been used to explore surfaces.
Mobile pseudo-Halbach configurations [14] and two cylindrical magnets [15]
have been applied for solid and liquid NMR measurements. While the pseudo-
Halbach generates a higher field, ranging from $0.7\text{\,}$ to
$2.0\text{\,}\mathrm{T}$ [16, 17, 18] compared to $0.35\text{\,}$ to
$0.6\text{\,}\mathrm{T}$ for the other configurations [11, 12, 13, 5], the
reported field homogeneities without electric shimming seem to be independent
of the design, ranging from $20\text{\,}\mathrm{p}\mathrm{p}\mathrm{m}$ to
$606\text{\,}\mathrm{p}\mathrm{p}\mathrm{m}$ [15, 5, 19, 18, 1, 20]. Comparing
the two most reported mobile liquid NMR sensors, it further stands out that
there is no obvious relation between the size of the sensor and the choice of
the magnet configuration.

To achieve more insight into possible guidelines for the magnet design, in
this paper a modelling study will be presented from which the homogeneity and
field strength at specific locations in the gap of the magnet configuration is
derived numerically. It is widely experienced that after building such a
permanent magnet configuration, the homogeneity reached in practice does not
exhibit the same results as in the simulation [16, 18, 21, 22, 23], which can
be caused by several factors. The magnetisation of permanent magnets depends
highly on the temperature, as well as on the remanent magnetisation [24]. This
remanent magnetisation can change over time due to shock-induced
demagnetisation [25, 26], external magnetic fields [27], a degrading of the
magnetic material caused by oxidation [28], as well as broken or chipped off
pieces (since magnets are very brittle) [21]. Next to material related
differences, fabrication inaccuracies such as variations in the dimensions and
magnetisation angles affect the field created by a permanent magnet. On top of
that, magnet configurations can never be assembled perfectly. Errors in
placement may induce a tilt or an axial offset of the magnet.

We carried out an extensive numerical sensitivity analysis of a single cubic
magnet using these variations. We measured the variations in the magnetisation
and magnetisation angle of magnets composed of different materials, with
different coatings, and with different sizes, obtained from different
manufacturers. The two main magnet configurations investigated are a system of
two parallel magnets and a Pseudo-Halbach configuration [10], shown in Fig. 1.
One configuration of each type has been designed and optimised for the
following boundary conditions. The sensitive length of the channel (s) has
been chosen to be the same as the gap size (d). For example: In case a maximal
magnet size of $50\text{\times}50\text{\times}50\text{\,}\mathrm{m}\mathrm{m}$
is required, the gap size turns out to be $10\text{\,}\mathrm{m}\mathrm{m}$.
All dimension specifications are scalable and will be normalised by the gap
length. Scaling the dimensions bigger or smaller will result in an increased
or decreased sample length relative to the dimensions of the gap, while the
magnetic field properties within the region of interest will stay the same.
The magnetic field has been normalised to the residual magnetic flux density
$B_{\text{s}}$ (T) of the used magnetic material. The cuboid configuration
consists of two cuboid magnets with a height of $2d$ and a width of $4.72$$d$.
The Pseudo-Halbach configuration consists of eight bar magnets, each with the
dimensions $d\times d\times 5d$. The measured variations in the magnets have
been used to perform a Monte Carlo simulation to provide insight into how the
homogeneity of those configurations varies after assembling. The results have
been verified with field measurements done with a Tesla meter. The sample
channel in most published microfluidic NMR sensors has a high ratio of sample
length over inner diameter ($s/d_{\text{i}}$) ($5.0\text{\,}$ over
$0.4\text{\,}\mathrm{m}\mathrm{m}$ in [29], $30\text{\,}$ over
$1.0\text{\,}\mathrm{m}\mathrm{m}$ in [30], and $2.9\text{\,}$ over
$0.15\text{\,}\mathrm{m}\mathrm{m}$ in [31]). Therefore we focus on a high
field homogeneity in mainly one dimension ($x$-axis).

Figure 1: Magnet configurations for microfluidic NMR. The sample under
investigation is inside a tubular channel running through the center of the
configurations, and has a length $s$. The arrows indicate the magnetisation of
each individual magnet. Left: Cuboid configuration. The height of the stack
$l$ is fixed at five times the gap between the magnets $d$. The width $w$ of
the stack is optimised for minimum field inhomogeneity over the sample length
$s$. Right: Pseudo-Halbach configuration. Again $l$ is fixed to $5d$, but now
the magnet recess $c$ is optimised.

##  II Methods

###  II-A Determination of variation in magnet properties

The variations in the properties of the magnets have been measured with a 3D
Hall-probe (THM1176 Three-axis Hall Magnetometer, Metrolab). The setup for the
configuration measurements contains a stable temperature environment
($38.0(5)\text{\,}\mathrm{\SIUnitSymbolCelsius}$) and a Hall sensor from
Projekt Elektronik GmbH (Teslameter 3002/Transverse Probe T3-1,4-5,0-70) in
combination with a motorised linear stage. Since the sensor is in a fixed
position and only the magnet was moved for the measurement, field variations
within the oven have no influence on the measurement. Different kinds of
magnets have been purchased. We chose different materials, coatings, sizes and
manufacturers, shown in Table I.

TABLE I: Purchased permanent magnets.

Manufacturer | Dimension | Material | $B_{\text{r}}$ | $BH_{\text{max}}$ | Coating | Abbreviation
---|---|---|---|---|---|---
| (mm) |  | (mT) | (kJ/m3) |  |
Supermagnete | 45$\times$30 1 | NdFeB (N45) | 1320-1360 | 340-372 | Ni-Cu-Ni | Su45Nd45NCN
Supermagnete | 7$\times$7$\times$7 | NdFeB (N42) | 1290-1330 | 318-342 | Ni-Cu-Ni | Su7Nd42NCN
Supermagnete | 7$\times$7$\times$7 | NdFeB (N42) | 1290-1330 | 318-342 | Ni-Cu | Su7Nd42NC
HKCM | 7$\times$7$\times$7 | NdFeB (N35) | 1180-1230 | 263-287 | Ni | HK7Nd35N
HKCM | 7$\times$7$\times$7 | Sm2Co17 (YXG28) | 1030-1080 | 207-220 | Ni | HK7Sm28N
Schallenkammer Magnetsyteme | 7$\times$7$\times$7 | Sm2Co17 (YXG26H) | 1020-1050 | 191-207 | - | Sc7Sm26

  * 1

diameter$\times$height, axially magnetised

###  II-B Stray field calculation

Calculations of the magnetic stray fields were performed using CADES
simulation software, described by Delinchant et al. [32]. The magnetic
interactions are modelled with the MacMMems tool, which uses the Coulombian
equivalent charge method to generate a semi-analytic model.

$\displaystyle\textbf{B}(\textbf{r})=\iint\limits\dfrac{\sigma(\textbf{r}-\textbf{r}^{\prime})}{\lvert\textbf{r}-\textbf{r}^{\prime}\rvert^{3}}ds\text{,
}\sigma=\mu_{0}\textbf{M}\cdot\textbf{n}$

Here, B is the magnetic field (T) and M the magnetisation of the permanent
magnet ($\text{\,}\mathrm{A}\mathrm{/}\mathrm{m}$), r and
$\textbf{r}^{\prime}$ define the observation point and its distance to the
elementary field source area $ds$. The integral is taken over the surface of
the magnets. $\sigma$ (T) is the magnetic surface charge, and n the unit
vector normal to the surface.

The CADES framework, including a component generator, component calculator,
and component optimiser, generated the final equations, which are used to
calculate and optimise the designs.

###  II-C Design optimisation procedure

The stray field calculations are used to optimize particular magnet
configurations with respect to the inhomogeneity of the magnetic field over
the length of the sample. This inhomogeniety is captured in a single valued
metric defined as the root mean square of the difference between the
z-component of the mean field $B_{\text{mean}}$ and the z-component of field
along the sample $B_{z}$, averaged of the sample length $s$ and related to the
mean field:

$\displaystyle\frac{1}{sB_{\text{mean}}}\int_{-s/2}^{s/2}\sqrt{(B_{z}-B_{\text{mean}})^{2}}dx$

Figure 2: Field profile of the cuboid configuration as a function of the
relative distance from the centre between the magnets. In the optimised
situation for a sample length equal to the gap size, the field in the centre
equals the field at the edges ($x$ = $\pm 0.5d$).

Minimisation of this metric leads to the simple rule that the field at the
edges of the sample should equal the field in the center. We illustrate this
for the cuboid configuration, illustrated in Fig. 1. Fig. 2 shows the magnetic
field along the sample of the optimised cuboid configuration, in which the
field is the same in the centre and at the edge of a sample. The field is
symmetric, showing a valley in the middle and two peaks in the directions of
the edges. After those maxima, the field decreases with the distance to the
centre.

Figure 3: Field inhomogeneity and field as a function of the sample length for
the cuboid configuration. The homogeneity has been optimised for a sample
length equal to the gap size. With increasing sample length, both the field
and the field inhomogeneity increase theoretically (region I). The field
reaches a local maximum of $0.500\,41$$B_{\text{s}}$ at a distance of
$0.71$$d$ from the centre. Above this distance the homogeneity of the sample
stays approximately the same (region II). When the sample length increases
more than the gap size, the inhomogeneity strongly increases (region III). If
we choose the field at the edge of the sample to be equal to the centre of the
sample, we are very close to the minimum homogeneity in region II.

Fig. 3 shows how the field homogeneity develops with increasing sample length
while keeping the previously optimised parameter set constant. Three regions
can be seen. In the first one the field increases from
$0.500\,35$$B_{\text{s}}$ to $0.500\,41$$B_{\text{s}}$, which means that the
minimum field of $0.500\,35$$B_{\text{s}}$ stays the same while the maximum
field is increasing until it reaches its global maximum, hence the
inhomogeneity is also increasing. In the second region the inhomogeneity stays
almost constant. In the third region the field decreases below the previous
minimum, which results in a drastic increase of the inhomogeneity. Therefore,
the lowest inhomogeneity between two points can either be reached by keeping
the sample as short as possible or when the field at the sample edges is
approximately equal to the field at the center. Since the signal in NMR is
proportional to the sample volume, we optimise for the latter condition.

##  III Results and Discussion

The field uniformity of the various designs is determined by the design itself
as well as the manufacturability. One major point of concern is the variation
in the value and alignment of the magnetic moment of the permanent magnets.
Therefore we first present the distribution of these properties for a range of
commercial magnets. We subsequently optimise the designs with respect to
uniformity and analyse their sensitivity to magnet variation using sensitivity
matrices and Monte-Carlo simulations. These model predictions are than
compared with six realisations of the different designs.

###  III-A Variation of properties of commercial permanent magnets

We measured the variations in the magnetisation and magnetisation angle of
magnets obtained from different companies (Supermagnete, HKCM and
Schallenkammer Magnetsysteme), compositions (NdFeB N45, NdFeB N42, Sm2Co17
YXG28, Sm2Co17 YXG26H), coatings (Ni-Cu-Ni, Ni-Cu, Ni, no coating), and sizes
(cylinders with a diameter of $45\text{\,}$ and height of
$30\text{\,}\mathrm{m}\mathrm{m}$ or cubes of
$7\text{\times}7\text{\times}7\text{\,}\mathrm{m}\mathrm{m}$). Of each set,
$50$ magnets were analysed. An overview of the distributions in residual
magnetic flux density and angle of magnetisation is given in Table II. The raw
data is provided in the supplementary material (Appendix A).

TABLE II: Measured coefficient of variation (CV) of residual magnetic flux
density and standard deviations of magnetisation angle of magnets with
different materials, coatings, sizes and manufacturers.

Magnet | $B_{\text{mean}},CV[$\mathrm{\char 37\relax}$]$ |  $\phi$ [$\mathrm{\SIUnitSymbolDegree}$]
---|---|---
Su45Nd45NCN | $0.7(3)$ |  $0.0(1)$1
Su7Nd42NCN | $0.8(2)$ | $0.7(2)$
Su7Nd42NC | $0.6(3)$ | $0.0(1)$
HK7Nd35N | $0.3(3)$ | $0.4(2)$
HK7Sm28N | $1.0(3)$ | $0.2(1)$
Sc7Sm26 | $1.6(2)$ | $1.0(2)$

  * 1

The values between brackets are the absolute standard errors of the last shown
digits.

On average, the residual flux density varies by 1% of $B_{\text{mean}}$. The
cylindrical magnet, which has a more than $50\text{\,}$ times higher magnetic
volume than the cubes, shows roughly the same variation in magnetisation. From
this, we can conclude that inaccuracies in the dimensions are not the main
cause of the variation in the magnetisation. The uncoated Sm2Co17 shows a
higher variation in magnetisation than the coated magnets, which could be
caused by oxidation or small damage to the magnet since unprotected sharp
edges of magnets tend to break off easily. Different coatings do not show a
clear trend regarding the magnetisation standard variation or the variation in
the magnetisation angle. The offset angle varies on average by less than
$1\text{\,}\mathrm{\SIUnitSymbolDegree}$. There is no clear relation between
the variation in magnetisation strength or orientation and material, coating
or manufacturer.

###  III-B Design optimisation

The optimisation method described in section II-C was applied to both the
cuboid and the pseudo-Halbach design.

##### Optimisation of the cuboid configuration

The cuboid configuration consists of two parallel cuboid magnets. The length
$L$ of the entire configuration has been chosen to be five times the gap size
$d$. The width $W$ was used to tune the field in between the magnets. The
optimisation procedure aims to find a width for which the field in the centre
and at the sample edge is the same.

Figure 4: Field strength in the middle of the configuration and difference of
the field centre and the edge of the sample, both as functions of the ratio of
the cuboid width over the length. The field increases up to
$0.54$$B_{\text{s}}$ at a cuboid width of $3.0375$ times the gap size. The
inset shows the field difference dropping to zero at a width/gap ratio of
$4.72$.

Fig. 4 shows that the magnetic field in the centre increases to its maximum of
$0.54$$B_{\text{s}}$ at a width of $3.0375$$d$. Increasing the width further
results in a reduction of the magnetic field, caused by the larger distance
from the edges of the magnet to the centre. The difference between the
magnetic field in the centre and that at the sample edge increases until it
reaches a maximum, when the width equals the gap size. From this point the
difference decreases until it reaches a minimum at a width/gap ratio of
$4.72$. The stray field at a distance equal to the gap size is
$0.24$$B_{\text{s}}$.

##### Pseudo-Halbach

The pseudo-Halbach configuration consists of eight magnets, arranged in such a
way that the field in the bore is enhanced while the external stray field is
minimised. The magnets have a fixed dimension $d\times d\times 5d$. To tune
the homogeneity, the position of the magnets in the corners is fixed, while
the other magnets are spread out over a distance $c$ (Fig. 1). The width
starts at $w=3d$ to ensure a minimum bore width $d$ and ends at $w=l$, due to
the previously chosen boundary conditions.

Figure 5: Spreading the middle magnets has been used to change the normalised
field strength and field difference. At a spread parameter $c=0$, a minimal
field difference of $3365\text{\,}\mathrm{p}\mathrm{p}\mathrm{m}$ and a field
strength of $0.90$$B_{\text{s}}$ can be reached.

Spreading the configuration increases the distance of the middle magnets,
which produces a decreased magnetic field strength (Fig. 5). With this
configuration the convex field profile has no chance to change to a concave
profile. Therefore a minimum can not be reached. With the most compact magnet
arrangement ($c$=0), a field of $0.9$$B_{\text{s}}$ and a field difference of
$3365\text{\,}\mathrm{p}\mathrm{p}\mathrm{m}$ can be achieved. The stray field
at a distance equal to the gap size from the surface is $0.07$$B_{\text{s}}$.

In table III the major specifications of the two optimised configurations are
compared. The pseudo-Halbach configuration achieves $0.9$$B_{\text{s}}$, a
$1.8$ times higher field than the Cuboid configuration, while the stray field
at a distance of $d$ from the magnet surface is $0.07$$B_{\text{s}}$, which is
$3.4$ times lower. In terms of homogeneity, the Cuboid configuration achieves
a homogeneity of $41\text{\,}\mathrm{p}\mathrm{p}\mathrm{m}$, which, compared
to the pseudo-Halbach configuration, is $24.2$ times better.

TABLE III: Comparison of magnetic properties of different magnet configurations. | $B_{\text{max}}$ | $B_{\text{stray}}$ | $\Delta B_{\text{rms}}/B_{\text{mean}}$
---|---|---|---
| $[B_{\text{s}}]$ | $[B_{\text{s}}]$ |  $[$ppm$]$
Cuboid | $0.5$ | $0.24$ | $41$
Pseudo-Halbach | $0.9$ | $0.07$ | $994$

Neither of the two designs reach a field uniformity below
$0.01\text{\,}\mathrm{p}\mathrm{p}\mathrm{m}$, which is required for high
resolution NMR, so additional field shimming will remain necessary. However,
it is interesting to analyse whether high resolution NMR systems without
shimming are reachable by reducing the sample length. Therefore, we optimised
the homogeneity of the configuration as a function of sample lengths, while
keeping the outer boundary conditions intact. Fig. 6 shows how the homogeneity
improves with a reducing ratio of the gap size to the sample length. The
cuboid configuration can indeed reach in theory
$0.01\text{\,}\mathrm{p}\mathrm{p}\mathrm{m}$ with a sample length of $0.22d$.
The pseudo-Halbach configuration however needs an absurd sample length of
$0.01d$ to reach the critical value.

Figure 6: Inhomogeneity of the magnetic field as a function of the sample
length/gap ratio with a constant configuration width/gap ratio of $5$. For
every sample length, the width of the cuboid configurations has been optimised
to reach the lowest possible inhomogeneity. For a homogeneity reasonable for
NMR applications of $0.1\text{\,}\mathrm{p}\mathrm{p}\mathrm{m}$, the sample
length for a cuboid configuration needs to be $0.22d$, whereas it has to
become unrealistically short ($0.01d$) for the pseudo-Halbach configuration.

###  III-C Influence of variations in the magnet properties

To analyse the effect of variation in magnet properties and positioning on the
performance of both designs, we applied a two step approach. First we analysed
the sensitivity of the magnetic field to the variation in strength and
position of a single cubic magnet using the method of sensitivity matrices.
From this we determined that variations in magnetic moment and angle of
magnetisation are most severe. Focussing on these two parameters only, we
analysed the combined effect of all magnets using a Monte-Carlo approach.

####  III-C1 Single cubic magnet

We determined the sensitivity of the magnetic stray field of a single cubic
magnet of nominal size $a$ to a variation of the dimensions, position, and
tilt of the magnet, as well as in the magnetisation strength and angle (Fig.
7). We consider the field components $B_{x},B_{y},B_{z}$ at a point above the
centre of the top (north) face, at a height of 10% of the length $a$ of the
edge of the magnet.

Figure 7: Schematic drawing of the cubic magnet used for sensitivity analysis.
The length width and depth have a nominal size of $a$. The arrows indicate the
direction of magnetisation. $\phi$ shows the total offset angle, $\theta$ the
offset direction in cylindrical coordinates.

Table IV shows the most important elements of the sensitivity matrix of the
magnetic field in the $x$ and $z$-directions on the $x$-axis at a distance of
0.1$a$, given as percentages of $B_{\text{s}}$. Parameters related to the
sizes have been varied by $10\text{\,}\mathrm{\char 37\relax}$ of the length
of the edge of the cube. Parameters related to the angle have been varied by
$1\text{\,}\mathrm{\SIUnitSymbolDegree}$. Appendix B gives the sensitivities
for $B_{y}$ and the field at $x$=0.1$a$ in Table IX, as well as the absolute
field values in Figure 13.

The first row in Table IV shows that the $B_{\text{z}}$ component changes
proportionally with the magnetisation. Since the $B_{\text{x}}$ component is
zero (see Figure 13 of appendix B ), variation in magnetisation has no effect.
Similarly, a tilt of the cube or rotation of the magnetisation around the
$y$-axis has a significant influence only on $B_{\text{x}}$, but not on
$B_{\text{z}}$. Displacement of the cube has an effect only on the field
components in the direction of displacement. The effect is relatively small: a
$10\text{\,}\mathrm{\char 37\relax}$ variation in position only lead to a
$2\text{\,}\mathrm{\char 37\relax}$ variation in field strength.

TABLE IV: Sensitivity matrix of the magnetic field components ($B_{x}$ and $B_{z}$) at a distance of $0.1a$ above the center of a cubic magnet with the edge length $a$ . | Variation |  $B_{x}$ ($\text{\,}\mathrm{\char 37\relax}$) |  $B_{z}$ ($\text{\,}\mathrm{\char 37\relax}$)
---|---|---|---
$M$ | 1% | $0.00$ | $1.00$
tilt $x$ | $1\text{\,}\mathrm{\SIUnitSymbolDegree}$ | $0.00$ | $0.00$
tilt $y$ | $1\text{\,}\mathrm{\SIUnitSymbolDegree}$ | $0.61$ | $0.00$
$\phi$ ($\theta$= $0\text{\,}\mathrm{\SIUnitSymbolDegree}$) | $1\text{\,}\mathrm{\SIUnitSymbolDegree}$ | $0.00$ | $0.00$
$\phi$ ($\theta$=$90\text{\,}\mathrm{\SIUnitSymbolDegree}$) | $1\text{\,}\mathrm{\SIUnitSymbolDegree}$ | $-0.87$ | $0.00$
$x$ | 0.1$a$ | $-1.09$ | $0.00$
$z$ | 0.1$a$ | $0.00$ | $-2.17$

####  III-C2 Monte-Carlo simulations

To analyse the combined effect of all magnets on the field, we performed a
Monte Carlo simulation with $50\,000$ draws. Based on the above analysis of
the cube, we consider only variation in the magnetisation strength and
direction. Since for the two configurations the dimensional variation is
smaller than $0.03\text{\,}\mathrm{a}$, no dimensional errors were considered.
Normal distributions were assumed, with standard deviations of
$1\text{\,}\mathrm{\SIUnitSymbolDegree}$ and $1\text{\,}\mathrm{\char
37\relax}$ for strength and angle respectively.

Figure 8: Density plot (top) and cumulative distribution function (bottom) of
the Monte Carlo simulation for the cubic and Pseudo-Halbach configurations.
The simulation shows that the Pseudo-Halbach configuration has a mean
homogeneity of $1020\text{\,}\mathrm{p}\mathrm{p}\mathrm{m}$, while the cuboid
configuration reaches $386\text{\,}\mathrm{p}\mathrm{p}\mathrm{m}$ (Squares in
bottom figure). The circles indicate the average inhomogeneity measured on
three implementations of each configuration (Table VI).

Fig. 8 shows the distribution and probability plot of the simulated
homogeneities of the magnetic field in the $z$-direction. The mean homogeneity
of the cuboid configuration is $430\text{\,}\mathrm{p}\mathrm{p}\mathrm{m}$,
the pseudo-Halbach configuration achieves
$1086\text{\,}\mathrm{p}\mathrm{p}\mathrm{m}$. However, the cuboid
configuration has a high spread in the homogeneity (standard deviation
$350\text{\,}\mathrm{p}\mathrm{p}\mathrm{m}$) while the pseudo-Halbach has a
standard deviation of only $8\text{\,}\mathrm{p}\mathrm{p}\mathrm{m}$. With a
probability of $94.4\text{\,}\mathrm{\char 37\relax}$, both the cuboid
configuration and the pseudo-Halbach configuration obtain a homogeneity of
$1098\text{\,}\mathrm{p}\mathrm{p}\mathrm{m}$ or better. With a probability of
$10\text{\,}\mathrm{\char 37\relax}$, the cuboid configuration achieves
$64\text{\,}\mathrm{p}\mathrm{p}\mathrm{m}$ whereas the pseudo-Halbach
achieves not less than $1076\text{\,}\mathrm{p}\mathrm{p}\mathrm{m}$.

The reason for the strong sensitivity of the cuboid configuration to magnet
variations is largely due to the distribution in magnetisation direction.
Table V) shows the sensitivity of the $z$ component of the field at the center
and the edge of the sample to a variation of
$1\text{\,}\mathrm{\SIUnitSymbolDegree}$ of the magnetisation ($x=d/2$) angle.
At the edge of the sample, the cuboid configuration is ten times more
sensitive to angular variations.

TABLE V: Sensitivity to variation in magnetisation angle of $B_{z}$ at the center and edge of the sample for the pseudo-Halbach and cuboid configuration |  $B_{z}$ ($x=0$) |  $B_{z}$ ($x=d/2$) |
---|---|---|---
Halbach - top/bottom | $0$ | $59$ | ppm/deg
Halbach - side | $0$ | $0$ | ppm/deg
Halbach - corner | $0$ | $81$ | ppm/deg
Cuboid | $0$ | $985$ | ppm/deg

###  III-D Verification of simulations with implementations

Both configurations were assembled and measured three times. The measurement
results are shown in Table VI. There is a small spread in the homogeneity of
the pseudo-Halbach (mean value of
$1032\text{\,}\mathrm{p}\mathrm{p}\mathrm{m}$ and standard deviation of
$90\text{\,}\mathrm{p}\mathrm{p}\mathrm{m}$). A larger variation was found for
the cuboid configuration ($1340\text{\,}$ and
$800\text{\,}\mathrm{p}\mathrm{p}\mathrm{m}$). (Raw data of the six systems is
listed in Table XIII of appendix C ).

The three implementations represent a draw from the
$50\,000\text{\,}\mathrm{M}$onte Carlo simulations shown in figure Fig. 8.
From these curves we can estimate that the chance to realise a cuboid
configuration with an inhomogeneity _as bad as_
$1340\text{\,}\mathrm{p}\mathrm{p}\mathrm{m}$ is in the order of
$5\text{\,}\mathrm{\char 37\relax}$ (blue dot in figure). Similarly, a pseudo-
Halbach configuration with a inhomogeneity of
$1032\text{\,}\mathrm{p}\mathrm{p}\mathrm{m}$ or worse has a chance of
$8\text{\,}\mathrm{\char 37\relax}$ of occurring. These likelihoods are low,
but not unrealistic. More implementations would be required to determine
whether other variation than magnetisation strength and direction should be
considered.

In general, the pseudo-Halbach configuration has a more predictable field
profile, which makes this design more favourable for industrial applications
than the cuboid configuration. Since shimming is needed anyway, a measurement
of the field profile is not necessary. We therefore recommend restricting the
use of the cuboid configurations to research systems, where selecting the
magnets and measuring the final assembly is feasible.

TABLE VI: Mean (standard deviation) of the homogeneity of the field in the $z$-direction of measured and simulated magnet configurations | Measured | Simulated
---|---|---
| Inhomogeneity | Inhomogeneity
|  $[$ppm$]$ |  $[$ppm$]$
Cuboid | $1340(800)$ | $386$
Pseudo-Halbach | $1032(90)$ | $1020$

##  IV Conclusion

We have investigated the effect on the homogeneity of the field of permanent
magnet configurations for mobile NMR applications of variations in the
properties of the magnets. We measured the variations in the magnetisation and
magnetisation angle of permanent magnets but could not observe a decisive
difference between the manufacturers, materials, or magnet coatings. On
average, the standard deviation of the magnetisation is less than
$1\text{\,}\mathrm{\char 37\relax}$ and for the variations in the
magnetisation angle it is less than $1\text{\,}\mathrm{\SIUnitSymbolDegree}$.

We compared a cuboid and a pseudo-Halbach magnet configuration, in terms of
their field strength and field homogeneity, for our optimised boundary
conditions, in which the sample length $s$ is equal to the gap size $d$ and
the whole configuration should fit in a box with an edge length five times the
gap size. For a fixed parameter set, assuming perfectly magnetised magnets,
the field in the centre of the cuboid configuration is $0.5$$B_{\text{s}}$ and
its homogeneity is $41\text{\,}\mathrm{p}\mathrm{p}\mathrm{m}$. For the same
boundary conditions, the pseudo-Halbach configuration achieves a higher field
($0.9$$B_{\text{s}}$) in the centre but less homogeneity
($994\text{\,}\mathrm{p}\mathrm{p}\mathrm{m}$). It is worth mentioning that
the pseudo-Halbach configuration has a much lower stray field, and so less
interference with the environment, than the cuboid configuration.

For samples with a length the same as the gap size, the theoretical
homogeneity of both configurations is above the sub-ppm range, which is
necessary to produce a high resolution spectrum. Optimising the homogeneity
for shorter samples while respecting the maximum outer dimensions yields in a
much better homogeneity. Using a sample length of $0.22d$ improves the
homogeneity from $41\text{\,}$ to $0.1\text{\,}\mathrm{p}\mathrm{p}\mathrm{m}$
for the cuboid configuration, whereas the pseudo-Halbach configuration would
need a impractical sample length of $0.01d$.

We analysed the effect of the variation in magnetic properties on the
uniformity of the generated fields. The sensitivity matrix shows that the
magnetisation, magnetisation angle, and tilt have the most significant
influence on the magnetic field. Positioning errors mainly change the field,
in case the positioning variation is in the same direction as the field.
Theoretically, the cuboid has good homogeneity (on average
$430\text{\,}\mathrm{p}\mathrm{p}\mathrm{m}$), but the effect of variation in
the magnets’ properties is large (standard deviation
$350\text{\,}\mathrm{p}\mathrm{p}\mathrm{m}$). The pseudo-Halbach
configuration has worse homogeneity
($1080\text{\,}\mathrm{p}\mathrm{p}\mathrm{m}$), but is $44$ times less
sensitive to variation in the properties of the magnet.

We verified the modelled field inhomogeneities with three realisations for
each of the two designs. The average inhomogeneity agree within measurement
error with the model.

Based on our analysis, we advise using the cuboid configuration for scientific
use, where it is possible to preselect the permanent magnets and the external
stray field is not a big issue. Mechanical shimming of this configuration can
be done, changing the distance between the magnets (counteracting
magnetisation differences) or by tilting the magnet (counteracting
magnetisation angle variations). Using rather large magnets helps to achieve
the homogeneity needed for NMR measurements. If preselecting the magnets is
not an option, we recommend the pseudo-Halbach configuration, which has a more
robust homogeneity regarding variations in the magnetisation and angle. The
field profile of this configuration is predictable, which makes it easier to
shim afterwards to achieve the field homogeneity needed for NMR applications.
Also the lower stray field makes this configuration easier to handle and
therefore more favourable especially for industrial applications.

## Acknowledgements

This work is part of the research programme FLOW+ with project number 15025,
which is (partly) financed by the Dutch Research Council (NWO). The authors
thank Jankees Hogendoorn and Lucas Cerioni of Krohne New Technologies BV for
their input and support.

## References

  * [1] M. Meribout and S. Sonowan, “Optimal halbach magnet array design for portable NMR targeting multiphase flow metering applications,” _IEEE Transactions on Magnetics_ , vol. 55, no. 1, pp. 1–7, jan 2019.
  * [2] S. S. Zalesskiy, E. Danieli, B. Blümich, and V. P. Ananikov, “Miniaturization of NMR systems: Desktop spectrometers, microcoil spectroscopy, and “NMR on a chip” for chemistry, biochemistry, and industry,” _Chemical Reviews_ , vol. 114, no. 11, pp. 5641–5694, apr 2014.
  * [3] J. Mitchell, L. Gladden, T. Chandrasekera, and E. Fordham, “Low-field permanent magnets for industrial process and quality control,” _Progress in Nuclear Magnetic Resonance Spectroscopy_ , vol. 76, pp. 1–60, jan 2014.
  * [4] E. Danieli, J. Perlo, B. Blümich, and F. Casanova, “Small magnets for portable NMR spectrometers,” _Angewandte Chemie International Edition_ , vol. 49, no. 24, pp. 4133–4135, may 2010.
  * [5] H. Lee, E. Sun, D. Ham, and R. Weissleder, “Chip–NMR biosensor for detection and molecular analysis of cells,” _Nature Medicine_ , vol. 14, no. 8, pp. 869–874, jul 2008.
  * [6] D. Kreyenschulte, E. Paciok, L. Regestein, B. Blümich, and J. Büchs, “Online monitoring of fermentation processes via non-invasive low-field NMR,” _Biotechnology and Bioengineering_ , vol. 112, no. 9, pp. 1810–1821, may 2015.
  * [7] M. K. Sørensen, O. Jensen, O. N. Bakharev, T. Nyord, and N. C. Nielsen, “NPK NMR sensor: Online monitoring of nitrogen, phosphorus, and potassium in animal slurry,” _Analytical Chemistry_ , vol. 87, no. 13, pp. 6446–6450, jun 2015.
  * [8] M. K. Sørensen, M. S. Vinding, O. N. Bakharev, T. Nesgaard, O. Jensen, and N. C. Nielsen, “NMR sensor for onboard ship detection of catalytic fines in marine fuel oils,” _Analytical Chemistry_ , vol. 86, no. 15, pp. 7205–7208, jul 2014.
  * [9] G. Mozzhukhin, G. Kupriyanova, S. Mamadazizov, A. Maraşlı, and B. Rameev, “Low-field 14n nuclear magnetic resonance for detection of dangerous liquids,” _Chemical Physics_ , vol. 513, pp. 129–134, sep 2018\.
  * [10] V. Demas and P. J. Prado, “Compact magnets for magnetic resonance,” _Concepts in Magnetic Resonance Part A_ , vol. 34A, no. 1, pp. 48–59, jan 2009.
  * [11] B. Blümich, P. Blümler, G. Eidmann, A. Guthausen, R. Haken, U. Schmitz, K. Saito, and G. Zimmer, “The NMR-mouse: construction, excitation, and applications,” _Magnetic Resonance Imaging_ , vol. 16, no. 5-6, pp. 479–484, jun 1998.
  * [12] W. Meethan, I. Thomas, and C. Thomas, “Calculation of the sensitive region of a u-shaped permanent magnet for a single-sided NMR spectrometer,” _Chiang Mai University Journal of Natural Sciences_ , vol. 13, no. 1, 2014\.
  * [13] A. E. Marble, I. V. Mastikhin, B. G. Colpitts, and B. J. Balcom, “An analytical methodology for magnetic field control in unilateral NMR,” _Journal of Magnetic Resonance_ , vol. 174, no. 1, pp. 78–87, may 2005.
  * [14] M. W. Vogel, A. Giorni, V. Vegh, R. Pellicer-Guridi, and D. C. Reutens, “Rotatable small permanent magnet array for ultra-low field nuclear magnetic resonance instrumentation: A concept study,” _PLOS ONE_ , vol. 11, no. 6, p. e0157040, jun 2016.
  * [15] N. Sun, Y. Liu, L. Qin, H. Lee, R. Weissleder, and D. Ham, “Small NMR biomolecular sensors,” _Solid-State Electronics_ , vol. 84, pp. 13 – 21, 2013, selected Papers from the ESSDERC 2012 Conference.
  * [16] E. Danieli, J. Perlo, B. Blümich, and F. Casanova, “Small magnets for portable NMR spectrometers,” _Angewandte Chemie International Edition_ , vol. 49, no. 24, pp. 4133–4135, may 2010.
  * [17] M. C. Tayler and D. Sakellariou, “Low-cost, pseudo-halbach dipole magnets for NMR,” _Journal of Magnetic Resonance_ , vol. 277, pp. 143–148, apr 2017\.
  * [18] G. Moresi and R. Magin, “Miniature permanent magnet for table-top NMR,” _Concepts in Magnetic Resonance_ , vol. 19B, no. 1, pp. 35–43, 2003.
  * [19] R. S. Sahebjavaher, K. Walus, and B. Stoeber, “Permanent magnet desktop magnetic resonance imaging system with microfabricated multiturn gradient coils for microflow imaging in capillary tubes,” _Review of Scientific Instruments_ , vol. 81, no. 2, p. 023706, feb 2010.
  * [20] J. Chen and C. Xu, “Design and analysis of the novel test tlibe magnet as a device for portable nuclear magnetic resonance,” _IEEE Transactions on Magnetics_ , vol. 43, no. 9, pp. 3555–3557, 2007, cited By 4.
  * [21] J. Horton, J. Wright, and J. Herchenroeder, “Fracture toughness of commercial magnets,” _IEEE Transactions on Magnetics_ , vol. 32, no. 5, pp. 4374–4376, 1996.
  * [22] H. Soltner and P. Blümler, “Dipolar halbach magnet stacks made from identically shaped permanent magnets for magnetic resonance,” _Concepts in Magnetic Resonance Part A_ , vol. 36A, no. 4, pp. 211–222, jul 2010.
  * [23] A. Ambrisi, A. Formisano, and R. Martone, “Tolerance analysis of nmr magnets,” _IEEE Transactions on Magnetics_ , vol. 46, no. 8, pp. 2747–2750, 2010, cited By 9.
  * [24] M. Haavisto, H. Kankaanpaa, and M. Paju, “Estimation of time-dependent polarization losses in sintered ndfeb permanent magnets,” _IEEE Transactions on Magnetics_ , vol. 47, no. 1, pp. 170–174, jan 2011.
  * [25] Y.-F. Li, M.-G. Zhu, W. Li, D. Zhou, F. Lu, L. Chen, J.-Y. Wu, Y. Qi, and A. Du, “The impact induced demagnetization mechanism in ndfeb permanent magnets,” _Chinese Physics Letters_ , vol. 30, no. 9, p. 097501, sep 2013\.
  * [26] E. B. Royce, “Anomalous shock-induced demagnetization of nickel ferrite,” _Journal of Applied Physics_ , vol. 37, no. 11, pp. 4066–4070, oct 1966.
  * [27] C. J. Lee, C. I. Lee, and G. H. Jang, “Source and reduction of uneven magnetization of the permanent magnet of a HDD spindle motor,” _IEEE Transactions on Magnetics_ , vol. 47, no. 7, pp. 1929–1932, jul 2011\.
  * [28] Y. Li, H. Evans, I. Harris, and I. Jones, “The oxidation of ndfeb magnets,” _Oxidation of Metals_ , vol. 59, no. 1/2, pp. 167–182, 2003.
  * [29] J. Gardeniers, J. Bart, A. Kolkman, A.-J. de Vries, J. Janssen, P. van Bentum, K. Ampt, S. Wijmenga, and A. Kentgens, “Microfluidic high-resolution NMR chip for biological fluids,” in _TRANSDUCERS 2009 - 2009 International Solid-State Sensors, Actuators and Microsystems Conference_. IEEE, jun 2009.
  * [30] A. Kalfe, A. Telfah, J. Lambert, and R. Hergenröder, “Looking into living cell systems: Planar waveguide microfluidic NMR detector for in vitro metabolomics of tumor spheroids,” _Analytical Chemistry_ , vol. 87, no. 14, pp. 7402–7410, jul 2015.
  * [31] E. E. McDonnell, S. Han, C. Hilty, K. L. Pierce, and A. Pines, “Nmr analysis on microfluidic devices by remote detection,” _Anal. Chem._ , vol. 77, pp. 8109–8114, 2005.
  * [32] B. Delinchant, D. Duret, L. Estrabaut, L. Gerbaud, H. N. Huu, B. D. Peloux, H. Rakotoarison, F. Verdiere, and F. Wurtz, “An optimizer using the software component paradigm for the optimization of engineering systems,” _COMPEL - The international journal for computation and mathematics in electrical and electronic engineering_ , vol. 26, no. 2, pp. 368–379, 2007.

##  V Appendix

##  Appendix A Distribution of permanent magnet properties

We measured the magnetisation strength and orientation for a range of
commercially available permanent magnets (listed in table I of main text). The
results are summarized in table II in the main text. The underlying data is
reported in this appendix.

Figure 9 shows the cumulative distribution of the residual flux density,
normalized to the mean value. The measurement uncertainty is estimated from
the cumulative distribution for $50$ measurements of the same magnet (black
curve). The distribution in magnetisation of the commercial magnets exceeds
our measurement uncertainty. The standard deviation is in the order of
$1\text{\,}\mathrm{\char 37\relax}$.

In a similar fashion, the variation in field direction was measured (Figure
10). The base uncertainly measurement is again shown as a black curve. The
histogram presentation is shown in figure 11. The HKCM magnets appear to have
a smaller angular variation that the other small magnets. The angular varation
of type HK7Nd35N cannot be measured accurately by our method. The variation of
the angular variation of the big Supermagnete magnet (Su45Nd45NCN) was assesed
only on $10$ magnets. It appears however that the variation is well below our
measurement uncertainty.

Figure 11 shows the offset angle from the same magnet, which has been measured
$50$ times resulting in a standard deviation of
$0.645\text{\,}\mathrm{\SIUnitSymbolDegree}$.

Table VII and VIII summarize the measured angle and magnetization variations
with confidence intervals.

Figures 12 shows the raw measured angular variations for the series of
commercial magnets investigated.

Figure 9: Measured cumulative distribution of the residual flux density for a
range of commercial magnets. The black line indicates our sensitivity limit.
The sensitivity limit has been obtained from measuring $50$ times the same
magnet, indicated by the black line. We measured $10$ different magnets with a
diameter of $d$=$45\text{\,}\mathrm{m}\mathrm{m}$ and a height of
$h$=$30\text{\,}\mathrm{m}\mathrm{m}$ (orange), and $50$ magnets with a size
of $7\text{\times}7\text{\times}7\text{\,}\mathrm{m}\mathrm{m}$ for each of
the other kinds of material or manufacturer. On average, commercial magnets
have a magnetization variation of less than $1\text{\,}\mathrm{\char
37\relax}$. Figure 10: Measured cumulative distribution of the field direction
with respect to the $z$-axis ($\phi$ in figure 7) for a range of commercial
magnets. On average, commercial magnets have a field direction variation of
less than $None$. Figure 11: The offset angle from the same magnet has been
measured $50$ times resulting in a standard deviation of
$0.645\text{\,}\mathrm{\SIUnitSymbolDegree}$.

Figure 12: Measured field angles for the range of commercial magnets investigated  TABLE VII: Measured angle variations. |  |  |  | confidence interval
---|---|---|---|---
|  Material |  Coating | std $\rho$ [$\mathrm{\SIUnitSymbolDegree}$] | $95\text{\,}\mathrm{\char 37\relax}$ | $68.27\text{\,}\mathrm{\char 37\relax}$
Measurement error |  NdFeB N45 |  Ni-Cu-Ni | $0.65$ | $0.11$ | $0.06$
Supermagnete |  NdFeB N42 |  Ni-Cu-Ni | $1.33$ | $0.2$ | $0.11$
Supermagnete |  NdFeB N42 |  Ni-Cu | $0.69$ | $0.113$ | $0.06$
HKCM |  NdFeB N35 |  Ni | $1.05$ | $0.17$ | $0.09$
HKCM |  Sm2Co17 YXG28 |  Ni | $0.85$ | $0.14$ | $0.07$
Schallenkammer Magnetsysteme |  Sm2Co17 YXG-26H |  - | $1.72$ | $0.28$ | $0.14$
Supermagnete (Cylinder) |  NdFeB N45 |  Ni-Cu-Ni | $0.42$ | $0.13$ | $0.07$
TABLE VIII: Measured magnetization variations. |  Material |  Coating | B [T] | $\sigma$ | $68.27\text{\,}\mathrm{\char 37\relax}$
---|---|---|---|---|---
|  |  |  |  | confidence
Measurement error |  NdFeB N42 |  Ni-Cu-Ni | $0.5425$ | $0.1709$ | $0.0002$
Supermagnete |  NdFeB N42 |  Ni-Cu-Ni | $0.4196$ | $0.8631$ | $0.1374$
Supermagnete |  NdFeB N42 |  Ni-Cu | $0.5187$ | $0.7965$ | $0.0669$
HKCM |  NdFeB N35 |  Ni | $0.4503$ | $0.9208$ | $0.0773$
HKCM |  Sm2Co17 YXG28 |  Ni | $0.4362$ | $0.5025$ | $0.0422$
Schallenkammer Magnetsysteme |  Sm2Co17 YXG-26H |  - | $0.3852$ | $1.2024$ | $0.1010$
Supermagnete (Cylinder) |  NdFeB N45 |  Ni-Cu-Ni | $0.3687$ | $1.7225$ | $0.1447$

##  Appendix B Design optimisation

Figure 13: Magnetic field ($x,y,z$) above a cuboid magnet with the edge length
$a$ along the $x$-axis at a distance of $0.1$$a$.

Fig. 13 shows that for a cubic magnet, magnetized in the $z$-direction, there
is no field in the $y$-direction ($B_{y}$) along the $x$-axis at a distance of
$0.1$$a$ from the surface. The field $B_{x}$ is zero in the centre of the
magnet and rises linearly with a slope of $0.04$$B_{\text{s}}/a$ in the
positive $x$-direction, with $B_{\text{s}}$ the saturation magnetization of
the magnet material [T]. The field $B_{z}$ is $0.357$$B_{\text{s}}$ in the
centre which drops to $0.355$$B_{\text{s}}$ at $x=0.1a$.

In tables X, XI and XII the sensitivity matrix of $B_{x},B_{y},B_{z}$ above a
cuboid magnet with the edge length $d$ along $x$-axis at a distance of $0.1d$
is shown.

TABLE IX: Sensitivity matrix of the magnetic field ($x$,$y$,$z$), given in the change of $B_{\text{s}}$ at the same position in [$\text{\,}\mathrm{\char 37\relax}$] above a cuboid magnet with the edge length $a$ along the $x$-axis at a distance of $0.1a$. Variations in the magnetization angle and tilting the magnet perpendicular to the simulated axis affect the magnetic field significantly. Placement errors have an influence if parallel to the field. Variations in the dimensions have a minor effect. |  | $B_{x}$ | $B_{y}$ | $B_{z}$
---|---|---|---|---
| Variation | $x=0$ | $x=0.1a$ | $x=0$ | $x=0.1a$ | $x=0$ | $x=0.1a$
$M$ | 1% | $0.00$ | $1.10$ | $0.00$ | $0.00$ | $1.00$ | $0.99$
tilt $x$ | $1\text{\,}\mathrm{\SIUnitSymbolDegree}$ | $0.00$ | $0.00$ | $-0.61$ | $-0.62$ | $0.00$ | $0.00$
tilt $y$ | $1\text{\,}\mathrm{\SIUnitSymbolDegree}$ | $0.61$ | $0.51$ | $0.00$ | $0.00$ | $0.00$ | $-0.48$
$\phi$ ($\theta$= $0\text{\,}\mathrm{\SIUnitSymbolDegree}$) | $1\text{\,}\mathrm{\SIUnitSymbolDegree}$ | $0.00$ | $0.00$ | $0.00$ | $0.00$ | $0.00$ | $0.00$
$\phi$ ($\theta$=$90\text{\,}\mathrm{\SIUnitSymbolDegree}$) | $1\text{\,}\mathrm{\SIUnitSymbolDegree}$ | $-0.87$ | $-0.88$ | $-0.87$ | $-0.86$ | $0.00$ | $0.19$
$x$ | 0.1$a$ | $-1.09$ | $-1.15$ | $0.00$ | $0.00$ | $0.00$ | $0.10$
$y$ | 0.1$a$ | $0.00$ | $0.00$ | $1.09$ | $1.07$ | $0.00$ | $0.00$
$z$ | 0.1$a$ | $0.00$ | $-0.10$ | $0.00$ | $0.00$ | $-2.17$ | $-2.22$
height | 0.1$a$ | $0.00$ | $0.02$ | $0.00$ | $0.00$ | $0.23$ | $0.23$
depth | 0.1$a$ | $0.00$ | $-0.18$ | $0.00$ | $0.00$ | $-0.01$ | $0.01$
width | 0.1$a$ | $0.00$ | $0.05$ | $0.00$ | $0.00$ | $-0.01$ | $-0.01$

An indication of why the cuboid configuration has a much higher standard
deviation than the pseudo-Halbach configuration can be seen from the
sensitivity matrices of the $z$-field. We chose to show how the field in the
centre and at $x$=$d/2$ changes for a magnetization difference of
$1\text{\,}\mathrm{\char 37\relax}$ and an offset magnetization direction of
$1\text{\,}\mathrm{\SIUnitSymbolDegree}$ each in the direction which creates
the highest field difference at both locations. The Halbach configuration
consists of 8 magnets: 4 corner magnets, 2 at the side, and 1 each on top and
bottom. Adding up the sensitivity values of all the magnets results in a
difference of $314\text{\,}\mathrm{p}\mathrm{p}\mathrm{m}$ between the
$z$-field at $x$=0 and $x$=$d/2$. The cuboid shows a significantly higher
difference of $1970\text{\,}\mathrm{p}\mathrm{p}\mathrm{m}$.

TABLE X: Sensitivity matrix of $B_{x}$ above a cuboid magnet with the edge length $d$ along $x$-axis at a distance of $0.1d$ $B_{x}(x)$ | $-0.1d$ | $-0.075d$ | $-0.05d$ | $-0.025d$ | $0$ | $0.025d$ | $0.05d$ | $0.075d$ | $0.1d$
---|---|---|---|---|---|---|---|---|---
[${10}^{-6}$$B_{\text{s}}$] |  |  |  |  |  |  |  |  |
$B_{x}$ | $-39\,520.0$ | $-29\,365.0$ | $-19\,448.0$ | $-9685.3$ | $0$ | $9685.3$ | $19\,448.0$ | $29\,365.0$ | $39\,520.0$
$\Delta M$ | $-394.6$ | $-294.1$ | $-194.8$ | $-96.9$ | $0$ | $96.9$ | $194.8$ | $294.1$ | $394.6$
$\Delta$tilt $x$ | $0$ | $0$ | $0$ | $0$ | $0$ | $0$ | $0$ | $0$ | $0$
$\Delta$tilt $y$ | $1822.1$ | $1972.9$ | $2086.0$ | $2148.8$ | $2174.0$ | $2148.8$ | $2086.0$ | $1972.9$ | $1822.1$
$\Delta\phi$=$1\text{\,}\mathrm{\SIUnitSymbolDegree}$, $\theta$=$0\text{\,}\mathrm{\SIUnitSymbolDegree}$ | $0$ | $0$ | $0$ | $0$ | $0$ | $0$ | $0$ | $0$ | $0$
$\Delta\phi$=$1\text{\,}\mathrm{\SIUnitSymbolDegree}$, $\theta$=$90\text{\,}\mathrm{\SIUnitSymbolDegree}$ | $-3129.0$ | $-3116.5$ | $-3116.5$ | $-3116.5$ | $-3116.5$ | $-3116.5$ | $-3116.5$ | $-3116.5$ | $-3129.0$
$\Delta x$ | $-4121.8$ | $-4008.7$ | $-3933.3$ | $-3883.0$ | $-3870.4$ | $-3883.0$ | $-3933.3$ | $-4008.7$ | $-4121.8$
$\Delta y$ | $0$ | $0$ | $0$ | $0$ | $0$ | $0$ | $0$ | $0$ | $0$
$\Delta z$ | $360.7$ | $257.6$ | $165.9$ | $81.6$ | $0$ | $-81.6$ | $-165.9$ | $-257.6$ | $-360.6$
$\Delta$ height | $-88.7$ | $-66.8$ | $-44.7$ | $-22.4$ | $0$ | $22.4$ | $44.7$ | $66.8$ | $88.7$
$\Delta$ depth | $647.2$ | $478.8$ | $315.4$ | $157.1$ | $0$ | $-157.1$ | $-315.4$ | $-478.8$ | $-647.2$
$\Delta$ width | $-182.2$ | $-137.0$ | $-91.4$ | $-45.7$ | $0$ | $45.7$ | $91.4$ | $137.0$ | $182.2$
TABLE XI: Sensitivity matrix of$B_{y}$ above a cuboid magnet with the edge length $d$ along $x$-axis at a distance of $0.1d$ $B_{y}(x)$ | $-0.1d$ | $-0.075d$ | $-0.05d$ | $-0.025d$ | $0$ | $0.025d$ | $0.05d$ | $0.075d$ | $0.1d$
---|---|---|---|---|---|---|---|---|---
[${10}^{-6}$$B_{\text{s}}$] |  |  |  |  |  |  |  |  |
$B_{y}$ | $0$ | $0$ | $0$ | $0$ | $0$ | $0$ | $0$ | $0$ | $0$
$M$ | $0$ | $0$ | $0$ | $0$ | $0$ | $0$ | $0$ | $0$ | $0$
tilt $x$ | $-2211.7$ | $-2199.1$ | $-2186.5$ | $-2174.0$ | $-2174.0$ | $-2174.0$ | $-2186.5$ | $-2199.1$ | $-2211.7$
tilt $y$ | $0$ | $0$ | $0$ | $0$ | $0$ | $0$ | $0$ | $0$ | $0$
$\Delta\phi$=$1\text{\,}\mathrm{\SIUnitSymbolDegree}$, $\theta$=$0\text{\,}\mathrm{\SIUnitSymbolDegree}$ | $-3066.2$ | $-3091.3$ | $-3103.9$ | $-3103.9$ | $-3116.5$ | $-3103.9$ | $-3103.9$ | $-3091.3$ | $-3066.2$
$\Delta\phi$=$1\text{\,}\mathrm{\SIUnitSymbolDegree}$, $\theta$=$90\text{\,}\mathrm{\SIUnitSymbolDegree}$ | $0$ | $0$ | $0$ | $0$ | $0$ | $0$ | $0$ | $0$ | $0$
$\Delta x$ | $0$ | $0$ | $0$ | $0$ | $0$ | $0$ | $0$ | $0$ | $0$
$\Delta y$ | $3807.6$ | $3832.7$ | $3857.9$ | $3870.4$ | $3870.4$ | $3870.4$ | $3857.9$ | $3832.7$ | $3807.6$
$\Delta z$ | $0$ | $0$ | $0$ | $0$ | $0$ | $0$ | $0$ | $0$ | $0$
$\Delta$ height | $0$ | $0$ | $0$ | $0$ | $0$ | $0$ | $0$ | $0$ | $0$
$\Delta$ depth | $0$ | $0$ | $0$ | $0$ | $0$ | $0$ | $0$ | $0$ | $0$
$\Delta$ width | $0$ | $0$ | $0$ | $0$ | $0$ | $0$ | $0$ | $0$ | $0$
TABLE XII: Sensitivity matrix of $B_{z}$ above a cuboid magnet with the edge length $d$ along $x$-axis at a distance of 0.1d $B_{z}(x)$ | $-0.1d$ | $-0.075d$ | $-0.05d$ | $-0.025d$ | $0$ | $0.025d$ | $0.05d$ | $0.075d$ | $0.1d$
---|---|---|---|---|---|---|---|---|---
[${10}^{-6}$$B_{\text{s}}$] |  |  |  |  |  |  |  |  |
$B_{z}$ | $354\,950$ | $355\,720$ | $356\,250$ | $356\,550$ | $356\,660$ | $356\,550$ | $356\,250$ | $355\,720$ | $354\,950$
$M$ | $3543.7$ | $3556.3$ | $3556.3$ | $3568.8$ | $3568.8$ | $3568.8$ | $3556.3$ | $3556.3$ | $3543.7$
tilt $x$ | $0$ | $0$ | $0$ | $0$ | $0$ | $0$ | $0$ | $0$ | $0$
tilt $y$ | $1696.5$ | $1269.2$ | $844.5$ | $422.2$ | $0$ | $-422.2$ | $-844.5$ | $-1269.2$ | $-1696.5$
$\Delta\phi$=$1\text{\,}\mathrm{\SIUnitSymbolDegree}$, $\theta$=$0\text{\,}\mathrm{\SIUnitSymbolDegree}$ | $0$ | $0$ | $0$ | $0$ | $0$ | $0$ | $0$ | $0$ | $0$
$\Delta\phi$=$1\text{\,}\mathrm{\SIUnitSymbolDegree}$, $\theta$=$90\text{\,}\mathrm{\SIUnitSymbolDegree}$ | $-689.9$ | $-512.7$ | $-339.3$ | $-169.6$ | $0$ | $169.6$ | $339.3$ | $512.7$ | $689.9$
$\Delta x$ | $-360.7$ | $-257.6$ | $-165.9$ | $-81.6$ | $0$ | $81.6$ | $165.9$ | $257.6$ | $360.7$
$\Delta y$ | $0$ | $0$ | $0$ | $0$ | $0$ | $0$ | $0$ | $0$ | $0$
$\Delta z$ | $-7929.4$ | $-7841.4$ | $-7778.6$ | $-7753.5$ | $-7740.9$ | $-7753.5$ | $-7778.6$ | $-7841.4$ | $-7929.4$
$\Delta$ height | $821.8$ | $826.9$ | $830.6$ | $833.2$ | $833.2$ | $833.2$ | $830.6$ | $826.9$ | $821.8$
$\Delta$ depth | $40.0$ | $8.4$ | $-13.2$ | $-25.8$ | $-30.0$ | $-25.8$ | $-13.2$ | $8.4$ | $40.0$
$\Delta$ width | $-33.0$ | $-31.7$ | $-30.7$ | $-30.2$ | $-30.0$ | $-30.2$ | $-30.7$ | $-31.7$ | $-33.0$

##  Appendix C Measurements

Figure 14 shows the measured magnetic field ($B_{z}$) of Cuboid and Pseudo-
Halbach configuration along the $x$-axis for $d$ =
$8\text{\,}\mathrm{m}\mathrm{m}$. Table XIII shows the homogeneities of the
measured configurations.

Figure 14: Measured magnetic field ($z$) of Cuboid and Pseudo-Halbach configuration along $x$-axis.  TABLE XIII: Measured homogeneity of cuboid and pseudo-Halbach configurations | Inhomogeneity
---|---
|  $[$ppm$]$
Cuboid 1 | $748(3)$
Cuboid 2 | $2250(3)$
Cuboid 3 | $1021(3)$
Pseudo-Halbach 1 | $1088(3)$
Pseudo-Halbach 2 | $1081(3)$
Pseudo-Halbach 3 | $929(3)$