Archive for Python

Essays and (Computational) Physics

Posted in Biographical, Education, Maynooth with tags , , , , , on March 14, 2023 by telescoper

There have been more news stories about ChatGPT and assessment in universities going around. There’s one here from The Journal and another here from The Conversation to give just two examples.

I wrote about this myself a couple of months ago in a post that included this:

I have to admit that I’ve never really understood the obsession in some parts of academia with “the student Essay” as a form of assessment. I agree that writing skills are extremely important but they’re not the only skills it is important for students to acquire during the course of a degree. Of course I’m biased because I work in Theoretical Physics, an area in which student essays play a negligible role in assessment. Our students do have to write project reports, etc, but writing about something you yourself have done seems to me to be different from writing about what other people have done. While forms of assessment in science subjects have evolved considerably over the last 50 years, other domains still seem to concentrate almost exclusively on “The Essay”.

Whatever you think about the intrinsic value of The Essay (or lack thereof) it is clear that if it is not done in isolation (and under supervision) it is extremely vulnerable to cheating.

A few people have retorted that communication skills are very important in higher education. I agree with that wholeheartedly, but it seems to me that (a) there are other ways of communicating than via formal essays and (b) there are, should be, more to academic study than  writing about things.

That said, I do think we could be doing more in some disciplines, including my own, to cultivate communication skills in general and writing skills in particular. In Theoretical Physics we certainly don’t do this as much as we should. I do have a project report in my 3rd Year computational physics module, but that is a relatively short document and the report itself counts only one-third of the marks (and the project is only 40% of the module mark).

These thoughts somehow reminded me of this. You can click on it to make it bigger if it’s difficult to read. It was the first paper (called colloquially Paper Zero) of my finals examination at the University of Cambridge way back in 1985, getting on for 40 years ago:

wpid-wp-1425648226410.jpeg

As you can probably infer from the little circle around number 4, I decided to write an Essay about topic 4. I’ve always been interested in detective stories so this was an easy choice for me, but I have absolutely no idea what I wrote about for three hours. Nor do I recall actually ever getting a mark for the essay, so I never really knew whether it really counted for anything. I do remember, however, that I had another 3-hour examination in the afternoon of the same day, two three-hour examinations the following day, and would have had two the day after that had I not elected to do a theory project which let me off one paper at the end and for which I got a good mark.

Anyway, to get back to the essay paper, we certainly don’t set essay examinations like that here in the the Department of Theoretical Physics at Maynooth University and I suspect they no longer do so in the Department of Physics at Cambridge either. At the time I didn’t really see the point of making students write such things under examination conditions but then we didn’t have ChatGPT way back then. No doubt it could generate a reasonable essay on any of the topics given.

I am skeptical about whether any of my 3rd year computational physicists would use ChatGPT to write their reports, but they might. But ChatGPT can write Python code too. Am I worried about that? Not greatly. I’ve asked it to write scripts for the various class exercises I’ve set so far and the code it has produced has usually failed. It will get better though….

New Publication at the Open Journal of Astrophysics

Posted in The Universe and Stuff, Open Access, OJAp Papers with tags , , , , on March 10, 2023 by telescoper

It’s time to announce yet another new paper at the Open Journal of Astrophysics.

The latest paper is the 9th paper in Volume 6 (2023) and the 74th in all. This one is another one for the folder marked Instrumentation and Methods for Astrophysics. The title is “panco2: a Python library to measure intracluster medium pressure profiles from Sunyaev-Zeldovich observations”. The code described in the paper The Python code is available on GitHub and there isextensive technical documentation to complement this paper.

The authors are Florian Kéruzoré (Argonne National Laboratory, USA, and the University of University of Grenoble, France), Frédéric Mayet, Emmanuel Artis, Juan-Francisco Macías-Pérez, Miren Muñoz-Echeverría and Laurence Perotto (all of the University of Grenoble, France) and Florian Ruppin (of the University of Lyon, also in France).

Here is a screen grab of the overlay which includes the  abstract:

 

 

You can click on the image of the overlay to make it larger should you wish to do so. You can find the officially accepted version of the paper on the arXiv here.

On Astropy

Posted in The Universe and Stuff with tags , , on July 3, 2022 by telescoper

Just a quick post to draw your attention to an important paper on arXiv about the Astropy Project, which is community effort to develop a common core package for Astronomy in Python and foster an ecosystem of interoperable astronomy packages. The abstract of the paper is:

The Astropy Project supports and fosters the development of open-source and openly-developed Python packages that provide commonly needed functionality to the astronomical community. A key element of the Astropy Project is the core package astropy, which serves as the foundation for more specialized projects and packages. In this article, we summarize key features in the core package as of the recent major release, version 5.0, and provide major updates for the Project. We then discuss supporting a broader ecosystem of interoperable packages, including connections with several astronomical observatories and missions. We also revisit the future outlook of the Astropy Project and the current status of Learn Astropy. We conclude by raising and discussing the current and future challenges facing the Project.

One of the great advantages of using Python for scientific programming in general and for applications to astrophysics in particular is the existence of extensive software libraries of which Astropy is a prominent example. This is one reason why Python is now the state-of-the-art language in many fields, as exemplified by the following graphic (Figure 1 from the paper) showing the frequency of mentions of various languages in the astronomical literature.

This is on a logarithmic scale so Python is really way out in front.

Most people I know use Python for their scientific programming, and most undergraduate physics courses also use it (including mine at Maynooth). I’m a big fan of the astropy project but it faces many challenges, including funding and management issues. I can’t do much about those but I can encourage users of astropy at least to ensure they acknowledge and cite it properly in their papers, following the instructions here.

Elliptical Discussions

Posted in Cute Problems, Education, Maynooth, The Universe and Stuff with tags , , on April 7, 2022 by telescoper

It’s the ninth week of Semester 2 and I’m coming to the end of lectures and laboratory sessions for my Computational Physics module; for the remaining three weeks (plus the Easter vacation) the students in this class will be mainly concentrating on the mini-projects that form part of the assessment.

This afternoon, though we had a session on how to transform higher-order differential equations into sets of coupled first-order ODEs suitable for vectorization and consequent solution using standard techniques. The problem we focussed on today was the simple problem of orbital motion of a test particle under the gravitational force in plane-polar coordinates, which can be prepared for physical solution thusly:

This sort of thing reminds me of my undergraduate theory project at Cambridge, where I did a similar thing to solve the equations governing the action of a four-level laser, though that was in Fortran rather than Python. In my own solution I used Python’s off-the-shelf solver odeint.

I like the orbital motion problem a lot because it’s a bit more than a coding exercise: students have to think about how to choose initial data, how to test the their code and interpret the results. Even before that there’s the issue of what units to use; SI units are a bit daft for astronomical problems. For solar system calculations it makes sense to use Astronomical Units for distances and years for time; in such a system it’s easy to work out that GM is just 4π2, which avoids having to deal with ridiculously large or ridiculously small numbers.

Anyway, the fun thing about this lab was that once everyone had got their code working they could try setting initial data to get a circular orbit as a special case, explore how the shape of elliptical orbits depends on the input data, how to make an unbound orbit, and so on. It’s important to understand the output of a numerical calculation in terms of basic physical principles. All that led to a discussion in class of solar system exploration, transfer orbits, what would happen if the mass of the Sun suddenly changed, or if G was a function of time, and lots of other things.

I find sessions like this that encourage students to explore problems themselves very rewarding and I think they add a valuable extra dimension to standard teaching formats. I hope the projects that they’ll be doing from now on – involving topics in areas ranging from atomic physics, cosmology, particle physics and climate science, and done in groups – will provoke even more discussion of this type.

Scientific Computing Then and Now

Posted in Biographical, mathematics with tags , , , on February 10, 2022 by telescoper

This afternoon I was in charge of another Computational Physics laboratory session. This one went better than last week, when we had a lot of teething problems, and I’m glad to say that the students are already writing bits of Python code and getting output – some of it was even correct!

After this afternoon’s session I came back to my office and noticed this little book on my shelf:

Despite the exorbitant cost, I bought it when I was an undergraduate back in the 1980s, though it was first published in 1966. It’s an interesting little book, notable for the fact that it doesn’t cover any computer programming at all. It focusses instead on the analysis of accuracy and stability of various methods of doing various things.

This is the jacket blurb:

This short book sets out the principles of the methods commonly employed in obtaining numerical solutions to mathematical equations and shows how they are applied in solving particular types of equations. Now that computing facilities are available to most universities, scientific and engineering laboratories and design shops, an introduction to numerical method is an essential part of the training of scientists and engineers. A course on the lines of Professor Wilkes’s book is given to graduate or undergraduate students of mathematics, the physical sciences and engineering at many universities and the number will increase. By concentrating on the essentials of his subject and giving it a modern slant, Professor Wilkes has written a book that is both concise and that covers the needs of a great many users of digital computers; it will serve also as a sound introduction for those who need to consult more detailed works.

Like any book that describes itself as having “a modern slant” is almost bound to date very quickly, and so this did, but its virtue is that it does complement current “modern” books which don’t include as much about the issues covered by Wilkes because one is nowadays far less constrained by memory and speed than was the case decades ago (and which circumstances I recall very well).

The Course Module I’m teaching covers numerical differentiation, numerical integration, root-finding and the solution of ordinary differential equations. All these topics are covered by Wilkes but I was intrigued to discover when I looked that he does numerical integration before numerical differentiation, whereas I do it the other way round. I put it first because I think it’s easier, and I wanted the students do do actually coding as quickly as possible, but I seem to remember doing e.g. Simpson’s Rule at school but don’t recall ever being taught about derivatives as finite differences.

Looking up the start of numerical differentiation in Wilkes I found:

This is a far less satisfactory method than numerical integration, as the following considerations show.

The following considerations indeed talk about the effect of rounding errors on calculations of finite differences (e.g. the forward difference Δf = [f(x+δ)-f(x)]/δ or backward difference Δf = [f(x)-f(x-δ)]/δ) with relatively large step size δ. Even with a modest modern machine one can use step sizes small enough to make the errors negligible for many purposes. Nevertheless I think it is important to see how the errors behave for those cases where it might be difficult to choose a very small δ. Indeed it seemed to surprise the students that using a symmetric difference Δf=[f(x+δ)-f(x-δ)]/2δ is significantly better than a forward or backward difference. Do a Taylor series expansion and you’ll understand why!

This example with δ=0.1 shows how the symmetric difference recovers the correct derivative of sin(x) far more accurately than the forward or backward derivative:

A Day of Computing

Posted in Biographical, Education, Maynooth, The Universe and Stuff with tags , , , , , , on February 3, 2022 by telescoper

Last Semester, Thursday was what I optimistically called a “Research Day” (on the basis that I had no teaching on it). This Semester it’s one of my busiest teaching days, with lecturing in the morning and a lab session in the afternoon, both for Computational Physics.

For most of the last two years I’ve been delivering the lectures and running the lab remotely, but now that we’re back teaching face-to-face I gave the lecture in person and was in the lab with the class for this afternoon’s session. I’ve got about twice as many students this year as last year swill be running two lab sessions (one next Tuesday repeating the material from the Thursday one, and so on throughout the term).

Running the lab remotely worked reasonably well because Python is available to download for free and works on a standard Windows-based PC. In the lab however we use a Linux (Ubuntu) system, which gives the students the chance to try a different operating system (and one which is for many purposes better than Windows).

It’s good to be back running the computing laboratory class in person but I was a bit nervous this morning because since I last did it that way the machines we have in our laboratory have all been upgraded to a new operating system and have a new (and very different) version of Python (3.9 versus the now obsolete 2.7). I’ve been around long enough to realize that things can go wrong in such situations, so I warned the class during this morning’s lecture that there might be teething troubles. Sure enough we had quite a few technical glitches but, to be honest, it it could have been a lot worse. Next Tuesday’s lab should be a bit less stressful as we’ve fixed a few of the things that went wrong.

So, by no means a disaster, but a busy and quite stressful day. Time to go home and relax.

Language Lessons

Posted in History, Irish Language, Maynooth with tags , , , , , , , , , , on February 4, 2021 by telescoper

Thursday is Computational Physics Day this term so this morning I delivered the first Panopto lecture of that module and in the afternoon we had our first laboratory session. The students are all at home of course so we had to run the lab with them using their own laptops rather than the dedicated Linux cluster we have in the Department and interacting via Microsoft Teams.  The first lab is very introductory so it was really just me presenting and them following on their machines without too much interaction. The ability to share a screen is actually very useful though and I imagine using it quite a lot to share Spyder. It went fairly well, I think, with all the students getting started out on the business of learning Python.

In between lecturing the morning and running the laboratory session this afternoon I had the chance to study another kind of language. Soon after I first arrived in Maynooth I got an email from Maynooth University about Irish language classes. Feeling a bit ashamed about not having learned Welsh in all my time in Cardiff, I thought I’d sign up for the Beginners class and fill in a Doodle Poll to help the organizers schedule it. Unfortunately, when the result was announced  it was at a time that I couldn’t make owing to teaching, so I couldn’t do it. That  happened a couple of times, in fact. This year however I’ve managed to register at a time I can make, though obviously the sessions are online.

I’m not sure how wise it is for me to try learning a new language during a term as busy as this, but I have to say I enjoyed the first session enormously. It was all very introductory, but I’ve learnt a few things about pronunciation – unsurprisingly the Irish word for pronunciation fuaimniú is unsurprisingly quite difficult to pronounce – and the difference between slender and broad vowels. I also learnt that to construct a verbal noun, instead of putting -ing on the end as you would in English, in Irish you use the word ag in front of the verb.

That’s not to say I had no problems. I’m still not sure I can say  Dia duit (hello) properly. The second “d” is hardly pronounced. 

Irish isn’t much like Welsh, which I failed to learn previously.  Although Irish and Welsh are both Celtic languages they are from two distinct groups: the Goidelic group that comprises Irish, Manx and Scottish Gaelic; and the Brythonic group that comprises Welsh, Cornish and Breton. These are sometimes referred to as q-Celtic and p-Celtic, respectively, although not everyone agrees that is a useful categorization. Incidentally, Scottish Gaelic is not the language spoken by the Celtic people who lived in Scotland at the time of the Romans, the Picts, which is lost. Scottish Gaelic is actually descended from Middle Irish. Also incidentally, Breton was taken to Brittany by a mass migration of people from South-West Britain fleeing the Anglo-Saxons which peaked somewhere around 500 AD. I guess that was the first Brexodus.

Welsh and Irish don’t sound at all similar to me, which is not surprising really. It is thought that the Brythonic languages evolved from a language  brought to Britain by people from somewhere in Gaul (probably Northern France), whereas the people whose language led to the Goidelic tongues were probably from somewhere in the Iberia (modern-day Spain or Portugal). The modern versions of Irish and Welsh do contain words borrowed from Latin, French and English so there are similarities there too.

Only a diacritic mark appears in Irish, the síneadh fada (`long accent’), sometimes called the fada for short, which looks the same as the acute accent in, e.g., French. There’s actually one in síneadh if you look hard enough. It just means the vowel is pronounced long (i.e. the first syllable of síneadh is pronounced SHEEN). The word sean (meaning old) is pronounced like “shan” whereas Seán the name is pronounced “Shawn”.

One does find quite a few texts (especially online) where the fada is carelessly omitted, but it really is quite important. For example Cáca is the Irish word for `cake’, while the unaccented Caca means `excrement’…

I took the above text in Irish and English from the front cover of an old examination paper. You can see the accents as well as another feature of Irish which is slightly similar to Welsh, the mysterious lower-case h in front of Éireann. This is a consequence of an initial mutation, in which the initial character of word changes in various situations according to syntax or morphology (i.e. following certain words changing the case of a noun or following certain sounds). This specific case is an an example of h-prothesis (of an initial vowel).

In Welsh, mutations involve the substitution of one character for another. For example, `Wales’ is Cymru but if you cross the border into Wales you may see a sign saying Croeso i Gymru, the `C’ having mutated. The Irish language is a bit friendlier to the learner than Welsh, however, as the mutated character (h in the example above) is inserted in front of the unmutated character. Seeing both the mutated and unmutated character helps a person with limited vocabulary (such as myself) figure out what’s going on.

Mutations of consonants also occur in Irish. These can involve lenition (literally `weakening’, also known as aspiration) or eclipsis (nasalisation). In the case of eclipsis the unmutated consonant is preceded by another denoting the actual sound, e.g. b becomes m in terms of pronunciation, but what is written is mb. On the other hand, lenition is denoted by an following the unmutated consonant. In older forms of Irish the overdot (ponc séimhithe) -another diacritic – was used to denote lenition.

Anyway, I’ve seen Dia duit written Dia dhuit which might explain why the d sounds so weak. We live and learn. If I keep at it long enough I might eventually be able to understand the TG4 commentary on the hurling..

The Start of Spring Semester

Posted in Biographical, Education, Maynooth with tags , , , , , , , on February 1, 2021 by telescoper

It’s February 1st 2021, which means that today is Imbolc, a Gaelic festival marking the point halfway between the winter solstice and vernal equinox, i.e. it’s a Cross-Quarter Day. To be pedantic, Imbolc is actually the period between this evening and tomorrow evening as in the Celtic calendar days were counted from sunset to sunset.

The first Day of February is also the Feast day of St Brigid of Kildare (c. 451-525), one of Ireland’s patron saints along with Saints Patrick and Colm Cille. One of her miraculous powers was the ability to change water into ale, which perhaps explains her enduring popularity among the Irish.

In Ireland this day is sometimes regarded as the first day of spring, as it is roughly the time when the first spring lambs are born. It corresponds to the Welsh Gŵyl Fair y Canhwyllau and is also known as the `Cross Quarter Day’ or (my favourite) `The Quickening of the Year’. According to legend it is also the day on which jackdaws mate. Given how many of them there are around Maynooth there should be a lot of action today.

Today is, appropriately enough in the light of all this, the start of the Spring Semester of teaching at Maynooth University, the fourth Spring Semester I will have experienced here although this is obviously not like the others in that we’ll be teaching online at least for the first half and probably for the entirety. I was planning to stay at home today but I realised I’d left some things I need in the office on campus so will have to go to collect them. That’s why I’m up early. That and the need to shake myself out of the lockdown torpor that has afflicted me since New Year. It’s time to get my act together, pull my finger out, put my best foot forward, etc.

This Semester I am teaching Engineering Mathematics II, Computational Physics I and Advanced Electromagnetism. The former, what you would probably call a `service course’, covers a mixture of things, mainly Linear Algebra but with some other bits thrown in for fun, such as Laplace transforms. Interestingly I find the Mathematical Physics students do not encounter Laplace Transforms in the first year, but perhaps engineers use them more often than physicists do? I think I’ve written only one paper that made use of a Laplace transform. Anyway, I have to start with this topic as the students need some knowledge of it for some other module they’re taking this semester. I reckon six lectures will be enough to give them what they need. That’s two weeks of lectures, there being three lectures a week for this module.

Once again my teaching timetable for this module is quite nice. I have lectures on Monday, Tuesday and Wednesday and then the students have a choice of tutorial (on either Thursday or Friday). That means I can get through a decent amount of material each week before each tutorial. I don’t do the tutorials, by the way: that’s left to one of our PhD students, who gets paid for doing that and correcting the weekly coursework. There are about 50 students on this module, divided into two courses: Electronic Engineering and Robotics and Intelligent Devices. We don’t have Civil or Mechanical or Chemical Engineering, etc, at Maynooth, in case you were wondering. Lectures will be done as webcasts using Panopto but also recorded for later viewing.

My first Computational Physics lecture, which I will do from home, is on Thursday, after which there is a lab session which we will do via Microsoft Teams. That’s the way we did it after lockdown last year and it worked OK. Students attend one two-hour lab session in addition to the lecture, on either Thursday or Tuesday. The first lecture being on Thursday the first lab session will be Thursday afternoon, with the same material being covered the following Tuesday. Fortunately, Python is free to download and easy to install so it’s quite straightforward to run the labs remotely. Teams has a screen sharing facility so it’s quite easy for myself or my demonstrator to see what is wrong in the same way we would do in a laboratory class.

The Advanced Electromagnetism module is a new one for me but I’m quite looking forward to it. Being a final-year module its content is less prescriptive than others and I’ll be adding a few things that I find interesting. Both lectures for that one are on Wednesdays and again will be given as webcasts with recordings available later.

Today is a particularly busy day because in addition to my first lecture (at 2pm) I have a meeting of Academic Council (3pm via Teams), a Euclid telecon (via Zoom) and a meeting with my PhD student via Teams. I have also been trying to sort out tutors and tutorials for the forthcoming Semester: these don’t start until next week so there’s time, but it has been quite a challenge to get everyone sorted. Fortunately I think that’s now done.

Oh, and another thing. I signed up for Irish language lessons (Beginners Level) and will be having classes once a week from now on.

It’s going to be a very busy term but I reckon being busy is probably going to be a good way to get through the next few months.

Spring Semester Starts

Posted in Biographical, Education, Maynooth with tags , , , , , , on February 3, 2020 by telescoper

It’s February 3rd 2020, which means that today is two days after Imbolc, a Gaelic festival marking the point halfway between the winter solstice and vernal equinox. The 1st Day of February is also the Feast day of St Brigid of Kildare (c. 451-525), one of Ireland’s patron saints along with Saints Patrick and Colm Cille. One of her miraculous powers was the ability to change water into ale, which perhaps explains her enduring popularity among the Irish.

In Ireland this day is sometimes regarded as the first day of spring, as it is roughly the time when the first spring lambs are born. It corresponds to the Welsh Gŵyl Fair y Canhwyllau and is also known as the `Cross Quarter Day’ or (my favourite) `The Quickening of the Year’.

Today is, appropriately enough in the light of all this, the start of the Spring Semester of teaching at Maynooth University, the third Spring Semester I will have experienced here. The weather has even played along; it has definitely been spring-like. The Campus, whicgh has beenhas been very quiet for the last week or so since the examinations finished, is full of students again.

This Semester, as was the case last year, I am teaching Engineering Mathematics II and Computational Physics I. The former, what you would probably call a `service course’, covers a mixture of things, mainly Linear Algebra but with some other bits thrown in for fun, such as Laplace transforms. Interestingly I find the Mathematical Physics students do not encounter Laplace Transforms in the first year, but perhaps engineers use them more often than physicists do? I think I’ve written only one paper that made use of a Laplace transform. Anyway, I have to start with this topic as the students need some knowledge of it for some other module they’re taking this semester. I reckon six lectures will be enough to give them what they need. That’s two weeks of lectures, there being three lectures a week for this module.

Once again my teaching timetable for this module is quite nice. I have lectures on Monday, Tuesday and Wednesday and then the students have a choice of tutorial (on either Thursday or Friday). That means I can get through a decent amount of material each week before each tutorial. I don’t do the tutorials, by the way: that’s left to one of our PhD students, who gets paid for doing that and correcting the weekly coursework. There are about 50 students on this module, divided into two courses: Electronic Engineering and Robotics and Intelligent Devices. We don’t have Civil or Mechanical or Chemical Engineering, etc at Maynooth, in case you were wondering.

Anyway, my first lecture was this afternoon at 2pm and had a good turnout. It was so sunny outside that we had to close all the blinds. That’s quite an unusual event for a February lecture!

My first Computational Physics lecture is on Thursday, after which it will be back to the Department for some frantic behind-the-scenes activity ahead of the afternoon lab session, which is in a computer room near my office. Students attend one two-hour lab session in addition to the lecture, on either Thursday or Tuesday. The first lecture being on Thursday the first lab session will be Thursday afternoon, with the same material being covered the following Tuesday.

While my teaching duties are the same this year as they were in the corresponding semester last year, there is a significant difference this year in that I am now also Head of Department. Either side of my first lecture I had to attend a meeting of the Faculty Executive for Science & Engineering, a meeting on `Project LEGO’ (which, sadly, did not involve any actual Lego but was instead about the proposed redesign of the University’s website) and a meeting of Academic Council. I have also been trying to sort out tutors and tutorials for the forthcoming Semester: these don’t start until next week so there’s time, but it’s quite a challenge to get everyone sorted out. A few timetable clashes have also come to light. So, in summary, I’m a bit worn out after today and will shortly go home to vegetate.

At least I didn’t have to find time for the regular Monday afternoon Euclid telecon in which I usually participate. There wasn’t one today because the working group of which I am part is actually meeting in person for a few days… in Paris! I couldn’t go because of all the above!

Most Popular Programming Languages 1965-2019

Posted in The Universe and Stuff with tags , , , on October 21, 2019 by telescoper

I find this absolutely fascinating. I’ve programmed in Fortran, Pascal, Basic, Assembler, C, C++, Javascript and Python lived long enough to see quite the fashion for most of these languages come and go on a relatively short timescale. Perhaps it provides a salutary lesson for those who think their current Python codes will always be useful?