- #1
warhammer
- 159
- 31
Hi,
I have a Computer Science exam (course contains Unix, C & Python) coming up which is part of my Astrophysics Masters degree. In the exam, I am allowed to carry all kinds of resources including PDFs of books, except connect to the Internet or use ChatGPT etc.
I wanted to ask if anybody had suggestions or recommendations for books that have solved astrophysics problems in C or Python as "cheatsheet" for the upcoming exam.
Below I'm also sharing one of the questions from a previous year exam for greater clarity~
In this exercise, we will use real exoplanet data from the extrasolar system Encyclopedia accessible at https://exoplanet.eu. The data you will use initially are in the file named exoplanets.csv. Files in the csv (comma-separated values) format use commas to separate successive values. When you open the data file, you will notice that there are many columns in it, the first ones being the name of the planet [name], the status of the planet [planet_status] (confirmed or candidate) and the planet mass [mass], where the labels shown in between the square brackets are the names of the columns in the data file. A few columns later, the radii of the exoplanets are given in the column labelled [radius], which will be relevant later on.
Have a look at the .csv file and try to read it with the techniques we learned in the python course. Treat missing values as NaNs ("Not A Number"). You may encounter difficulties. If you do, describe what you have tried and why you think it does not work.
Create a file called new_exoplanets.txt including only the 3 columns of interest that have the following labels: planet_status, mass, radius (see above for what they represent). In the rest of the text, the planet masses will be labelled Mpla and their radii Rpla.
Create a python code that: (a) computes the number of confirmed and candidate planets and writes it to the screen
(b) plots log10(Rpla/R⊕) (y-axis) Vs log10(Mpla/M⊕) (x-axis) for confirmed exoplanets keeping only planets that have both a mass and a radius (use green dot symbols). Note that the data for masses and radii are in Jupiter units initially. Use the following conversion factors: RJ=11.2 R⊕ and MJ=317.8 M⊕.
(c) We want to fit a power law through the data points using the least-squares method. We will only fit the part that does not look flat, i.e. we will exclude planets with masses greater than 120 M⊕. We recall that if we have a series of data points and want to fit a line such that y = ax + b (here with y=log10(Rpla/R⊕) and x=log10(Mpla/M⊕)), the best fitting values for a and b are given by a and b. Find a and b and print them to the screen (hint: you may use numpy functions if needed).
(d) Plot your fit to the data as a red continuous line on the previous figure. Add labels to the axes and save the figure.
This is the Python section of the Exam. I request any guidance & help on sharing resources/books that cover such problems.
I have a Computer Science exam (course contains Unix, C & Python) coming up which is part of my Astrophysics Masters degree. In the exam, I am allowed to carry all kinds of resources including PDFs of books, except connect to the Internet or use ChatGPT etc.
I wanted to ask if anybody had suggestions or recommendations for books that have solved astrophysics problems in C or Python as "cheatsheet" for the upcoming exam.
Below I'm also sharing one of the questions from a previous year exam for greater clarity~
In this exercise, we will use real exoplanet data from the extrasolar system Encyclopedia accessible at https://exoplanet.eu. The data you will use initially are in the file named exoplanets.csv. Files in the csv (comma-separated values) format use commas to separate successive values. When you open the data file, you will notice that there are many columns in it, the first ones being the name of the planet [name], the status of the planet [planet_status] (confirmed or candidate) and the planet mass [mass], where the labels shown in between the square brackets are the names of the columns in the data file. A few columns later, the radii of the exoplanets are given in the column labelled [radius], which will be relevant later on.
Have a look at the .csv file and try to read it with the techniques we learned in the python course. Treat missing values as NaNs ("Not A Number"). You may encounter difficulties. If you do, describe what you have tried and why you think it does not work.
Create a file called new_exoplanets.txt including only the 3 columns of interest that have the following labels: planet_status, mass, radius (see above for what they represent). In the rest of the text, the planet masses will be labelled Mpla and their radii Rpla.
Create a python code that: (a) computes the number of confirmed and candidate planets and writes it to the screen
(b) plots log10(Rpla/R⊕) (y-axis) Vs log10(Mpla/M⊕) (x-axis) for confirmed exoplanets keeping only planets that have both a mass and a radius (use green dot symbols). Note that the data for masses and radii are in Jupiter units initially. Use the following conversion factors: RJ=11.2 R⊕ and MJ=317.8 M⊕.
(c) We want to fit a power law through the data points using the least-squares method. We will only fit the part that does not look flat, i.e. we will exclude planets with masses greater than 120 M⊕. We recall that if we have a series of data points and want to fit a line such that y = ax + b (here with y=log10(Rpla/R⊕) and x=log10(Mpla/M⊕)), the best fitting values for a and b are given by a and b. Find a and b and print them to the screen (hint: you may use numpy functions if needed).
(d) Plot your fit to the data as a red continuous line on the previous figure. Add labels to the axes and save the figure.
This is the Python section of the Exam. I request any guidance & help on sharing resources/books that cover such problems.