Python代写 | PHYS2320 Computing 2 2019-20 Assessed Coursework

这个作业是用Python模拟分析X射线衍射光谱
PHYS2320 Computing 2 2019-20 Assessed Coursework
Coursework
1 Introduction
This document will give you all the details for the main project part of your Computing 2 Assessed
Coursework. This project carries a total of 85% of the credit for the overall module (unless
otherwise advised by Dr Burnell). Please remember that marks are awarded for the structure,
style, and robustness of your code as well as for its functionality. Please see the mark
sheet and grading criteria on Minerva for details.
You are strongly advised to read the whole of this task sheet thoroughly as you may
find information in the later sections that is helpful to completing the assignment.
1.1 Deadlines
You should submit your work via Minerva by 2pm on Thursday 26th March 2020. Late
submissions will incur the standard University penalty of 5% for each day and part of day that it
is late.
Please contact the Physics and Astronomy Taught Student Office if you require an extension
due to mitigating circumstances.
We hope to return a feedback sheet to you around the end of teaching in Week 11 of the semester.
1.2 Weekly Reports
There are no set times when you must work on the coursework, unlike in semester 1, attendance
at the timetabled sessions us not compulsory.
You are, however, required to complete a short weekly online progress report from
the start of semester 2 until the deadline to hand in the work. Completing the weekly
progress reports carries 10% of the marks for the assignment.
To complete your weekly report, you must go to the module website: https://phys2320.
leeds.ac.uk/ and click on the Progress Report link and complete and save a report. You
must do this at least once each week between 6am Monday and 10pm Friday.
1
Downloaded Assessment Tasksheet.pdf for None p.y.1.8.r Zheng from 86.2.66.201 on 6th February 2020 20:56
PHYS 2320 None p.y.1.8.r Zheng [py18rz] – Assessment Tasksheet.pdf : 86.2.66.201 6th February 2020 20:56 M2AD-2JKO-7BXS-SUEP
PHYS2320 Computing 2 2019-20 Assessed Coursework
1.3 Time Allocation
Although you are not required to attend the lab sessions, there will be demonstrators available
in the Computer lab clusters between 11am and 12am each Tuesday and Thursday and Dr Burnell
and/or Dr Barker will be available either in room 8.310 on the Physics Research Deck, or
their offices (8.303, 8.307) 1pm-2pm on Tuesdays and Thursdays for first-come, first-served
surgeries. You can also ask questions on the forums on Minerva and Dr Burnell will aim to answer
questions posted there within two working days.
To avoid answering the same question repeatedly, only questions which are confidential in nature,
such as mitigating cirucmstances – ill health, family bereavement and the like will be dealt
with by email. Emailed questions that are not about confidential matters will not be answered
via and should be posted on the forums so that other students can beenfit from the answer too.
Questions can be posted anomyously on the forums.
It is expected that this assignment will take up to 60 hours of programming time over the semester.
1.4 Overview
In this assessed project you will analyse some simulated data using Python code and prepare a
simple report that gives your key results and describes how your code works. You will submit
your code, report and a data file via Minerva.
Your code will be assessed first of all by an automatic checking script that will test whether
your code works with both the data file you submit with your code and with a second data file
of standard data. The testing program checks whether your code produces results in the format
specified here and whether the results match both the known correct answers and also match
results from a reference solution.
Your code and report will then be assessed by one of the module demonstrators who will grade
it for structure, style and documentation and whether your report describes the code you have
written accurately.
2 Background
The tasks in this coursework are based around the analysis of X-ray diffraction spectra. You
will be provided with simulated data sets representing diffraction from a sample of AuxCu1−x
metal alloys measured using a synchrotron radiation source such as the Diamond Light Source
at Harwell.
You will know from Physics 2 that a series of lattice planes with a spacing d will diffract coherently,
giving a maximum in intensity, if the Bragg equation is satisfied.
λ = 2d sin θ (2.1)
where λ is the wavelength of the radiation, and θ is half the angle between the incident and
diffracted beams of radiation.
2
Downloaded Assessment Tasksheet.pdf for None p.y.1.8.r Zheng from 86.2.66.201 on 6th February 2020 20:56
PHYS 2320 None p.y.1.8.r Zheng [py18rz] – Assessment Tasksheet.pdf : 86.2.66.201 6th February 2020 20:56 M2AD-2JKO-7BXS-SUEP
PHYS2320 Computing 2 2019-20 Assessed Coursework
For a crystal with a cubic lattice, the inter-plane spacing d can be related to the Miller Indices
(hkl) and the lattice parameter a with:
1
d
2
=
h
2 + k
2 + l
2
a
2
(2.2)
For crystals with more than one lattice point per unit cell, such as face-centred cubic and body
centred cubic – as shown above – not all combinations of h, k, l will result in diffraction. This
can be most easily seen in an example for the face centred cubic structure below, where the
(110) type planes do not give a diffracted beam as for every red atom that lies on the plane,
there is a blue atom exactly mid-way between the planes resulting in destructive interference.
Such a plane is said to be systematically absent from the diffraction pattern.
For a face-centred cubic lattice like this, the rule is that only planes where h, k, l are all even or
all odd numbers will give a diffraction spot. The list of planes that can give rise to diffraction is
therefore: (111),(200),(220),(311) and so on.
Copper and gold are both face centred cubic metals and when alloyed at high temperature and
allowed to cool quickly, will form a solid solution where each point in the face centred cubic
3
Downloaded Assessment Tasksheet.pdf for None p.y.1.8.r Zheng from 86.2.66.201 on 6th February 2020 20:56
PHYS 2320 None p.y.1.8.r Zheng [py18rz] – Assessment Tasksheet.pdf : 86.2.66.201 6th February 2020 20:56 M2AD-2JKO-7BXS-SUEP
PHYS2320 Computing 2 2019-20 Assessed Coursework
lattice will be either a copper or gold atom chosen at random. This means that averaged over
lots of unit cells, the alloy appears to be a uniform mixture of gold and copper with each atom
the same.
Although gold has a lattice parameter of aAu = 407.82 × 10−12 m and copper has a lattice parameter
of aCu = 361.49 × 10−12 m, an alloy of the two will have a lattice parameter that varies
linearly between the two with the composition – so that the lattice parameter of AuxCu(1−x)
will be:
aAuxCu(1−x) = xaAu + (1 − x)aCu (2.3)
(this is known as Vegard’s law).
2.1 Determining the lattice parameter
If you know the position of a peak in the diffraction pattern in 2θ, it is easy to calculate the
value of d from Bragg’s law. In order to determine the lattice parameter a, you need to work
out what the value of h
2 + k
2 + l
2
is in order to use equation 2.2 .
h, k, l are all integers, so the sum of their squares is also an integer. For a given material, you
will know an approximate value for the lattice parameter, aapprox – a possible choice here might
be the average of the copper and gold lattice parameters. From equation 2.2 , we can get an
approximate value for h
2 + k
2 + l
2
from the ratio of a
2
approx/d2
. Since we know that this should
be an integer (and from the rules of permitted h, k, l above, which integers), we can substitute
back the nearest integer into 2.2 and use it to refine the estimate of a. Repeating this for several
different peaks will get a better estimate still for a and a measure of the uncertainty in a.
2.2 Factors determining the peak intensity
If a sample consists of many small crystals in different orientations, then a diffraction scan will
contain diffraction peaks from all the possible planes. This includes the fact that for a particular
set of h, k, l, there are up to 48 different ways to arrange h, k, l and their negatives, all of which
result in the same value of d but for different orientations of planes. This number is reduced if
• any of h, kl are zero, or
• any of h, k, l are equal.
Thus, there are only 6 planes with the same spacing as (200), 12 as (220) and 8 as (111). This
factor is called the multiplicity of the planes and simply multiplies the intensity of the diffracted
peak for a given set of planes.
Further factors controlling the intensity of a diffraction peak are the atomic number and the
angle θ – generally speaking the intensity of diffraction is bigger for heavier atoms as there are
more electrons to scatter from, but falls for larger θ. These effects are all taken into account in
the simulated diffraction spectra for this coursework and explain why the peaks have different
heights (and will be different for different people’s datasets).
2.3 Factors determining the width of the diffraction peaks
In a real experiment the width of the diffraction peaks is determined by both the sample and
the instrument. Since we are simulating data from a synchrotron, we can assume that the instrument
is nearly perfect and all the width of the peaks is due to the samples. The size of the
individual crystals that are diffracting determines the peak width. As the crystals get smaller,
there is an increasing uncertainty in the d spacing of the planes (ultimately, this is a statement
4
Downloaded Assessment Tasksheet.pdf for None p.y.1.8.r Zheng from 86.2.66.201 on 6th February 2020 20:56
PHYS 2320 None p.y.1.8.r Zheng [py18rz] – Assessment Tasksheet.pdf : 86.2.66.201 6th February 2020 20:56 M2AD-2JKO-7BXS-SUEP
PHYS2320 Computing 2 2019-20 Assessed Coursework
of the uncertainty principle). This results in a broadening of the diffraction peaks via Bragg’s
law. The broader the peak, the bigger the uncertainty in the corresponding value of d and the
smaller the crystal must be.
Normally diffraction data is plotted as the intensity of the diffracted spot versus the angle 2θ
(i.e.the angle between the diffracted and straight through beams). The size of the crystals can
be related to the full-width-half-maximum (FWHM) size of the peak in 2θ by the Scherrer formula:
w ≈
λ
∆2θ cos θ
(2.4)
where ∆2θ is the FWHM of the peak.
In general it is difficult to give an analytical expression for the shape of a peak in a diffraction
pattern, however, for the purposes of the coursework you can take the peaks as being gaussian,
so that the intensity versus 2θ is given by:
I (2θ) = I0
σ


e

(2θ−2θ0)
2
2σ2 (2.5)
where 2θ0 is the position of the diffraction peak in 2θ, I0 is the intrensity of the diffraction peak
and σ is a measured of the width of the peak.
2.4 Summary
From measuring the diffraction pattern as a function of 2θ and identifying the peak location
and width it is possible to determine the lattice parameter a and hence alloy composition x and
also the crystal size w.
There are, however, two complications. Firstly, there is inevitably some background diffraction
arising from diffraction not from the sample – such as from the sample holder, parts of the instrument
etc. This background simply adds to the “real” signal and if its dependence on 2θ is
known, it can be subtracted from the data. The other complication is that all X-ray detectors
are subject to some level of noise due to background radiation, cosmic rays etc. This is another
addition to the “real” signal.
In the coursework data, the background signal is quadratic in 2θ, given by:
Ibackground = I1 −

(2θ − 2θ1)
2
/100
(2.6)
where I1, the background height and 2θ1, the background peak position are parameters set randomly
for each dataset and the angles are given in degrees.
3 Data
For this coursework you are provided with a set of simulated data that can be downloaded from
the Coursework menu item on the module website – a link is given on Minerva. Like the data
you used for the Planck’s Law classes, the exact parameters are determined based on the username
that you log into the website with.
The website lets you select either a practice set of data, which will contain a list of all the parameters
used to determine your spectra so that you can check whether your code finds the
right answers. Alternatively you can select the assessment data where the parameters are not
given in the file (and are different from the practice set !).
You can also select whether to include the complicating factors, such as multiple sets of planes
diffracting, quadratic background signal and experimental noise. The more of these features
5
Downloaded Assessment Tasksheet.pdf for None p.y.1.8.r Zheng from 86.2.66.201 on 6th February 2020 20:56
PHYS 2320 None p.y.1.8.r Zheng [py18rz] – Assessment Tasksheet.pdf : 86.2.66.201 6th February 2020 20:56 M2AD-2JKO-7BXS-SUEP
PHYS2320 Computing 2 2019-20 Assessed Coursework
your code can handle, the higher the grade you can get for the features component of the marks.
The number of lines of metadata wil vary between practice and assessment files.
The file format is a text file, but you will need to inspect it with a text editor (e.g.Notepad++,
or the spyder editor) to see how to read it. The actual format is the one used to produce data
on the I10 beamline at the Diamond Light Source. The data file will contain various bits of
metadata, including the wavelength of the X-rays used to produce the diffraction spectra.
Since a synchrotron can adjust the wavelength of X-rays is produces, the wavelength is different
for each set of data, but is always recorded in the file in both practice and assessment modes.
4 Tasks
Your code should attempt as many of tasks 1-7 as you are able to solve. The more of these
tasks that you complete, the greater the features score your code will get and the more scope
you have to get credt on the other marking criteria – note, however, that it is still possible
to get good marks on the other criteria even if you do not solve all 7 tasks.
1. Read in the data file and produce a plot of intensity versus 2θ with a log-scale for the
intensity axis. Your plot should include your IT login name (i.e.py12…) in the title. You
will need to annotate this plot and then include it in your report. Your plot should also
set appropriate limits on the intensity axis, bearing in mind that the intensity is measured
in counts and you cannot have a fractional count!
2. Find the exact location of all the peaks in 2θ. Note that this is likely to lie between data
points in your dataset. You should annotate your plot to show the located peaks – a label
of the (hkl) indices and arrow pointing at the peak is sufficient. The marking program
will automatically save your figures – your code should simply leave any plot windows
open when it finishes.
3. Remove any background signal if your code handles the background option in the dataset.
4. Determine the full-width-half-maximum value for each peak you found in task 2.
5. Determine the integrated intensity of each peak (i.e.the area under each peak).
6. Using the wavelength specified in the data file, calculate
a) the d spacing of each plane,
b) the lattice parameter a of the alloy
c) and hence the composition of your alloy x.
If your code works with more than one diffraction peak you can get an estimate of the
error in these as well.
7. Using your answers to part 4], estimate the crystalite size using the Scherrer equation
(equation 2.4 )
8. Write a report on your code. Your report should have your name, username and student
number in the title and have two sections:
6
Downloaded Assessment Tasksheet.pdf for None p.y.1.8.r Zheng from 86.2.66.201 on 6th February 2020 20:56
PHYS 2320 None p.y.1.8.r Zheng [py18rz] – Assessment Tasksheet.pdf : 86.2.66.201 6th February 2020 20:56 M2AD-2JKO-7BXS-SUEP
PHYS2320 Computing 2 2019-20 Assessed Coursework
a) A results section that tabulates for each peak in your data (which may be just a single
peak if your code doesn’t handle the multiple peaks option):
• the peak position in 2θ,
• the d spacing for those planes,
• the area under the peak,
• the FWHM value.
Your report should also include:
• a measurement of the lattice parameter a and
• composition x determined by your code, ideally with errors.
Finally your report should include a copy of the figure as produced by your code.
Your report does not have to include any discussion of the physics or experimental
method etc. The results section just has to have plots and numerical
results. Although your code does not have to round results correctly,
you should do so manually when including numerical results in the
text of your report.
b) A flow chart that describes how your code works. It should describe the functions
you have written and the overall logic of your program. It is not necessary to document
every single line, but the flow chart should be sufficient to allow someone else
to write a program that would work the same way as your code.
5 Submission
You should submit a minimum of three files to Minerva by the deadline.
1. The datafile used to generate the data in your report as downloaded from the website.
Your code will be tested with this datafile to check your report’s results. Your code will
also be checked with another data file with different parameters, but with the same features
turned on and off to ensure that it works with more than one set of data. (Every
set of practise data will have a different set of parameters, so you can check this for yourself.)
2. The report in pdf format (if you prepare it in Word then you can use the Save As… option
and select pdf format to generate your pdf).
Reports submitted in other formats will be marked down and whilst reasonable
efforts will be made to read them, reports not in pdf format may receive zero
marks if they cannot be read easily.
3. Your python code. This may be either one or more than one file, but the main file should
be called issid.py where issid is your computer login name. Your code must have a function
called ProcessData that takes a single parameter that is the name of a file. Further
details of what ProcessData should do are given in the next section. A template of a
suitable file is on Minerva.
7
Downloaded Assessment Tasksheet.pdf for None p.y.1.8.r Zheng from 86.2.66.201 on 6th February 2020 20:56
PHYS 2320 None p.y.1.8.r Zheng [py18rz] – Assessment Tasksheet.pdf : 86.2.66.201 6th February 2020 20:56 M2AD-2JKO-7BXS-SUEP
PHYS2320 Computing 2 2019-20 Assessed Coursework
5.1 The Python File
Your main Python script should be named after your University computer login name and have
the extension “.py”. It must define at least one function, ProcessData that takes a single parameter
that is the name of a data file to read in and process and returns a dictionary with the
parameters found by your code. A list of the dictionary keys is given in the template file – you
must either return a number or None for each key. Do not change the keys.
An example skeleton of the function is in a template file on Minerva and shown over:
de f P r o c e s sDa ta ( f i l e n a m e ) :
””” D ocumen ta ti on s t r i n g h e r e . ”””
#Your P r o c e s sDa ta code g o e s h e r e
#T hi s i s t h e da ta s t r u c t u r e t o r e t u r n y o u r r e s u l t s w i t h −
# r e p l a c e t h e None v a l u e s w i t h y o u r a n sw e r s . Do n o t
# rename any o f t h e key s , do n o t d e l e t e any o f t h e k e y s
# − i f y o u r code d oe s n ’ t f i n d a v a l u e , l e a v e i t a s None h e r e .
r e s u l t s ={” Peaks ” : [
#T hi s i s a l i s t o f d i c t i o n a r i e s f o r each peak
{
# L o c a t i o n o f peak i n two t h e t a i n d g r e e s , f o l l o w e d
# by t h e s t a d n a r d e r r o r
” t h e t a ” : None ,
” 2 t h e t a e r r o r ” : None ,
#Val ue o f d−s p a c e f o r t h i s peak and i t ’ s s t a d n a r d
# e r r o r (nm)
”d” : None ,
” d e r r o r ” : None ,
#Val ue o f t h e FWHM f o r f i r s t peak & e r r o r ( d e g r e e s )
”FWHM” : None ,
”FWHM erroe” : None ,
#Val ue o f t h e a r e a u n d e r t h e peak peak & e r r o r
” A rea ” : None ,
” A r e a e r r o r ” : None
} ,
#I f y o u r code f i n d s more t ha n one peak , t h e n r e p e a t
# t h i s d i c t i o n a r y f o r each peak you f i n d
] ,
#The f r a c t i o n o f Cu i n y o u r p a r t i o c u l a r a l l o y ( 0. 0 −1. 0 )
# and t h e e r r o r
” C om p o si ti o n ” : None ,
” C o m p o s i t i o n e r r o r ” : None ,
#S i z e o f t h e g r a i n s i n y o u r sam ple i n nm & e r r o r
” G r a i n s i z e ” : None ,
” G r a i n s i z e e r r o r ” : None
}
r e t u r n r e s u l t s
Your code will be used as a Python Module meaning that any code that is only to be run when
testing it should be protected from being run when imported like so:
8
Downloaded Assessment Tasksheet.pdf for None p.y.1.8.r Zheng from 86.2.66.201 on 6th February 2020 20:56
PHYS 2320 None p.y.1.8.r Zheng [py18rz] – Assessment Tasksheet.pdf : 86.2.66.201 6th February 2020 20:56 M2AD-2JKO-7BXS-SUEP
PHYS2320 Computing 2 2019-20 Assessed Coursework
i f n am e ==” m a i n ” :
# Put yo u r t e s t code i n s i d e t h i s i f s t a t em e n t to s t o p
#i t b e i n g r u n when you im po r t yo u r code
f i l e n a m e=”My Data F i l e . t x t ”
t e s t r e s u l t s=P ro c e s sD a t a ( f i l e n a m e )
p r i n t ( t e s t r e s u l t s )
A coursework checker python script will be made available during the semester to enable you
to check that your code has the correct ProcessData line and returns a correctly formatted
dictionary (the checker script does not check whether your code returns the correct results!)
6 Assessment
Your code will be assessed according to the sheet linked to on Minerva, both automatic checking
and manual checks by the demonstrators will be used. As the automatic tester will be importing
your code and then running the ProcessData function, it is important that your code
does not do anything unexpectedly when imported.
1. Make sure any module level code is not run when imported by using the code snippet
above to test if the code is being run or imported.
2. Do not use input or other python commands that will request inputs from the user –
when run with the automatic checker there is no user to type anything in ! (Likewise
there is no user to read anything printed to the screen)
3. Make sure that any breakpoint() function calls have been removed from the code before
you submit it.
The demonstrators will provide a grade (1st, 2.1, 2.2, 3rd, fail) for each assessment criteria.
These will be reviewed by the module leader and converted into a numerical mark for the module.
A random sample of 15% of the submissions will be second marked by the module academics.
You will be able to download the demonstrators grade sheet and comments from the module
website https://phys2320.leeds.ac.uk/accounts/summary) around the last week of lectures
for semester 2 – you can find a blank copy of the feedback sheet on Minerva too. You will
also receive a copy of the results of testing your code with the automatic tester.
7 Other Rules
1. You may use any of the standard Python library modules, numpy, scipy and matplotlib
for this coursework. The code will be tested using the versions of these modules as are
installed on the cluster computers for the Python 3.7 installation.
2. All submitted work for assessment must be your own individual work unless otherwise
declared. In particular, making use of code developed by another person, or jointly with
another person and not declared to be so in comments in the code is plagiarism
9
Downloaded Assessment Tasksheet.pdf for None p.y.1.8.r Zheng from 86.2.66.201 on 6th February 2020 20:56
PHYS 2320 None p.y.1.8.r Zheng [py18rz] – Assessment Tasksheet.pdf : 86.2.66.201 6th February 2020 20:56 M2AD-2JKO-7BXS-SUEP
PHYS2320 Computing 2 2019-20 Assessed Coursework
within the University’s definition and cases will be pursued to the fullest extent and may
result in loss of credits, a record of misconduct in your permanent file or other such penalties
as permitted by the University regulations.
3. That said, you may make use of code developed either in collaboration with, or entirely
by, other students, so long as you declare this in docstrings and comments in the
functions as relevant – see the examples below. Code which has been developed by
others, but used correctly by you will receive a pass mark, code developed in collaboration
with others will receive a higher mark but reflecting the number of collaborating authors.
Code examples taken from the official python, numpy, scipy and matplotlib documentation
does not require attribution, all other code taken from the internet does.
4. It is not permitted to employ, contract or buy code from any source even if declared as
such. Any actions which could be reasonably interpreted to be attempting to do so will
be considered as cheating and will be dealt with accordingly.
5. You may also use code copied from the official documentation for Python, numpy, scipy
or matplotlib, or copied from the materials for this module without needing to be acknowledged
separately.
6. Your report must be entirely your own individual work. Instances of copied or collaboratively
written reports will be considered to be plagiarism.
If the entirety of your code has been developed by someone else, then whether
you pass or fail will depend entirely on whether your report fully and correctly
describes the code you have submitted. Any omissions and errors in the explanation
will be marked down. Even a perfect report in these circumstances cannot
result in a mark higher than 50%
7.1 Examples of how to cite copied and collaboratively developed code
Code developed by another student or demonstrator:
de f C o p i e d F u n c t i o n ( p a r am e t e r s ) :
””” T h i s f u n c t i o n was w r i t t e n by Joe Smi th ( p y 1 2 j s )
. . . r e s t of t h e d o c s t r i n g f o r Joe ’ s f u n c t i o n . ”””
Code copied from the internet:
de f C o p i e d F u n c t i o n ( p a r am e t e r s ) :
””” T h i s f u n c t i o n was c o p i e d f rom u s e r gb119 on S t a c k O v e rf l ow
h t t p : / / s t a c k o v e r f l o w . com/ q u e s t i o n s /
19735670/ how−can−i−adap t−to−py thon−dja ngo ,
. . . . ”””
Code developed with other students:
10
Downloaded Assessment Tasksheet.pdf for None p.y.1.8.r Zheng from 86.2.66.201 on 6th February 2020 20:56
PHYS 2320 None p.y.1.8.r Zheng [py18rz] – Assessment Tasksheet.pdf : 86.2.66.201 6th February 2020 20:56 M2AD-2JKO-7BXS-SUEP
PHYS2320 Computing 2 2019-20 Assessed Coursework
de f C o l l a b o r a t i v e F u n c t i o n ( p a r am e t e r ) :
””” F u n c t i o n w r i t t e n j o i n t l y w i t h Joe Smi th ( p y 1 2 j s ) and
Jane Doe ( p y12j2 d )
. . . ”””
8 Hints and Tips
To complete all the parts of the assignment with all of the possible complicating features present
in the data is a significant challenge. You may find the following suggestions helpful.
• Make use of the template file from the start. Each year we see significant numbers of students
who did not follow this advice and then struggled to make their code work when
they placed it in the template in the last week/day/hour and as a result lost marks.
• If you want to make the code stop and go in to debug mode in the middle of a function
then there are two ways to do this:
1. Set a break point (F12 in spyder) on the line where you want to stop and then run
your code in Debug mode (CTRL+F5 in spyder), or
2. (Python 3.7 and newwer only) insert a breakpoint() function call before the line
where you want to stop, and run the code normally. Python will then stop at your
breakpoint and enter the debugger, letting you inspect variables and single step
through code.
• Start simple. Do not try to go and solve the problem for the most complex set of data
first. Start with a single peak, no background and no noise data set. Adding either background
or noise will make it a little harder – adding both makes it quite a bit more difficult.
Adding multiple peaks is more challenging still.
• The marking scheme rewards both well written and structured code more than bad code
that does everything, so you will be better off with code that doesn’t handle all the features,
but is well written and robust for what it does do. I strongly recommend that you
get a well-written working solution for the simpler cases before attempting to solve the
more complex ones.
• Interpolating data with noise in it generally doesn’t work well as the interpolation function
will try to interpolate the noise as much as the signal. You will therefore want to fit the
data with functions rather than use interpolation if you have noisy data.
• Both the full-width at half maximum and the area under a gaussian can be calculated
given a knowledge of σ and I0 – you will probably do better to try and find these parameters
than to directly calculate the FWHM and Area,
• To remove the background data you need to fit it with the function given in this task
sheet, but to do that you will need to roughly locate the peak(s) and remove data points
around it(them). Likewise, if you have multiple peaks, you will probably want to try just
fitting one at a time using just the data for angles of 2θ close to the peak. For both cases
you will need to create functions that can roughly estimate where a peak is and then find
the rows of data with 2θ close to this value.
11
Downloaded Assessment Tasksheet.pdf for None p.y.1.8.r Zheng from 86.2.66.201 on 6th February 2020 20:56
PHYS 2320 None p.y.1.8.r Zheng [py18rz] – Assessment Tasksheet.pdf : 86.2.66.201 6th February 2020 20:56 M2AD-2JKO-7BXS-SUEP
PHYS2320 Computing 2 2019-20 Assessed Coursework
• When fitting data it is usually necessary to give the fitting routine a rough idea of a starting
point for each parameter. By default 1.0 is often used, this may not be an appropriate
number. The numbers used in this coursework, whilst randomly chosen, are reasonable for
a real experiment. In particular:
1. The alloy is always an alloy of Cu and Au and does not have more than 100% of
either atom!
2. The range of 2θ used is always the same – 10 to 10 deg
3. The wavelength of X-rays is in the range 0.80 ˚A–1.40 ˚A
4. The background is always ≥ 0 for all 2θ
5. Crystallite sizes are typically ≤ 20 nm but are also often subject to quite big errors.
• The template gives the expected units of each of the quantities – although the checking
code will try to pick up errors here, it is not always perfect! Common errors include getting
confused when to use radians and when to use degrees, returning lengths in m and
not nm, returning composition in % and not as a fraction.
• Do not leave this until the last couple of weeks. This is a substantial task and
you should make a strart straightaway – remember that there are 10% of the
marks riding on completing weekly reports for each week until the hand-in deadline!
12
Downloaded Assessment Tasksheet.pdf for None p.y.1.8.r Zheng from 86.2.66.201 on 6th February 2020 20:56
PHYS 2320 None p.y.1.8.r Zheng [py18rz] – Assessment Tasksheet.pdf : 86.2.66.201 6th February 2020 20:56 M2AD-2JKO-7BXS-SUEP