Skip to content

Commit

Permalink
Merge pull request #92 from ess-dmsc-dram/fix-typos
Browse files Browse the repository at this point in the history
Fix typos and run checks in CI
  • Loading branch information
jl-wynen authored Sep 10, 2024
2 parents 96cab4a + 789c8ac commit cb37ab0
Show file tree
Hide file tree
Showing 46 changed files with 846 additions and 825 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/deploy-book.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,22 @@ on:

# This job installs dependencies, builds the book, and pushes it to `gh-pages`
jobs:
formatting:
name: Formatting and static analysis
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'
- uses: pre-commit/[email protected]
with:
extra_args: --all-files
- uses: pre-commit-ci/[email protected]
if: always()
with:
msg: Apply automatic formatting

deploy-book:
runs-on: ubuntu-latest
timeout-minutes: 45
Expand Down
18 changes: 18 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-added-large-files
- id: check-json
- id: check-merge-conflict
- id: check-toml
- id: check-yaml
- id: detect-private-key
- id: end-of-file-fixer
exclude: '\.idea/'
- id: trailing-whitespace
args: [ --markdown-linebreak-ext=md ]
- repo: https://github.com/crate-ci/typos
rev: v1.24.5
hooks:
- id: typos
4 changes: 2 additions & 2 deletions 1-python/python_basics/basic_language_principles.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
"metadata": {},
"source": [
"**Exercise (3)** <br>\n",
"Using the variable assigment code shown above, first initialize a variable to `2` and then increment it by 2.\n",
"Using the variable assignment code shown above, first initialize a variable to `2` and then increment it by 2.\n",
"Then assign to the variable x the string value `\"my string\"`."
]
},
Expand Down Expand Up @@ -161,7 +161,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"You are most likely seeing the error similar to one bellow:\n",
"You are most likely seeing the error similar to one below:\n",
"\n",
"```python\n",
"---------------------------------------------------------------------------\n",
Expand Down
2 changes: 1 addition & 1 deletion 1-python/using_external_libraries/matplotlib.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1434,7 +1434,7 @@
"source": [
"### Interactive linked scatter and histogram\n",
"\n",
"In this example, we use the `RectangleSelector` to select points in a 2D scatter plots that represent the x and y coordinates of some data points. The points also have a 3rd dimension/property, e.g., temperature. The temperature of all the points is histogrammed in the right-hand side panel. The histogram for only the selected points is overlayed with a red color and updated every time the selector is moved/resized."
"In this example, we use the `RectangleSelector` to select points in a 2D scatter plots that represent the x and y coordinates of some data points. The points also have a 3rd dimension/property, e.g., temperature. The temperature of all the points is histogrammed in the right-hand side panel. The histogram for only the selected points is overlaid with a red color and updated every time the selector is moved/resized."
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion 1-python/using_external_libraries/numpy.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
"### Data types\n",
"\n",
"Numpy arrays support a variety of data-types (`dtype`).\n",
"The most commonly used ones are integers and floating-point numbers in either double-precison or single-precision.\n",
"The most commonly used ones are integers and floating-point numbers in either double-precision or single-precision.\n",
"By default `dtype` is inferred from the values used for initialization.\n",
"To control it, many functions support a `dtype` keyword argument.\n",
"For explicit conversion `astype()` can be used:"
Expand Down
2 changes: 1 addition & 1 deletion 1-python/using_external_libraries/pandas.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1667,7 +1667,7 @@
"\n",
"- Dealing with missing values \n",
"```\n",
"df_to_write_to_file.to_csv('simple_file.csv', na_rep='Unkown') # missing value saved as 'Unknown'\n",
"df_to_write_to_file.to_csv('simple_file.csv', na_rep='Unknown') # missing value saved as 'Unknown'\n",
"```\n",
"\n",
"- Specifying the precision of the data written to file\n",
Expand Down
2 changes: 1 addition & 1 deletion 1-python/using_external_libraries/unit_testing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@
"As an example, we are going to look at the Zeeman effect.\n",
"Let us start by reminding ourselves of the formula.\n",
"\n",
"The coupling of the spin and orbital angular momentum of an electron to an external magentic field $B$ shifts the energy level of that electron by\n",
"The coupling of the spin and orbital angular momentum of an electron to an external magnetic field $B$ shifts the energy level of that electron by\n",
"\n",
"$$\n",
"\\Delta E = \\mu_B g_j m_j B ,\n",
Expand Down
2 changes: 1 addition & 1 deletion 3-mcstas/Simulation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"### Programming language\n",
"The McStas core and components are all written using the C programming language, though the user interface for assembling the instrument is a meta-language built upon C. This means C code is allowed in parts the file, but it also has a section for adding these components with their parameters and physical positions / rotations with a simple syntax. There also exists a McStas python API called McStasScript, this is what will be used during this course.\n",
"\n",
"### Coordiante system\n",
"### Coordinate system\n",
"To use McStas effectively it is important to understand the coordinate system. The beam direction is generally along the z direction, y points upwards against gravity and x to the left when looking in the beam direction. Furthermore each component will have its own coordinate system, and components can be placed relative to one another. The McStas core handles this complexity so each component can work in a simple local coordinate system.\n",
"\n",
"### Units\n",
Expand Down
2 changes: 1 addition & 1 deletion 3-mcstas/Talk.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@
"tags": []
},
"source": [
"### Coordiante system\n",
"### Coordinate system\n",
"- x: left, looking in the beam direction\n",
"- y: upwards, against gravity\n",
"- z: beam direction "
Expand Down
2 changes: 1 addition & 1 deletion 3-mcstas/make_SANS_instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def mu_gas(sigma, bars, temperature_C):
ref.set_AT([0, 0.5*casing.yheight, 0], RELATIVE=detector_position)
"""

# Parmeters for time of flight limits
# Parameters for time of flight limits
instrument.add_declare_var("double", "t_min")
instrument.add_declare_var("double", "t_max")
instrument.add_declare_var("double", "t_max_pulses")
Expand Down
4 changes: 2 additions & 2 deletions 3-mcstas/mcstas-qens.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,7 @@
"The next task is to specify the physical location of the component, this is done using the `set_AT` method on the component object.\n",
"This method takes a list of 3 numbers, corresponding to the `x`, `y` and `z` coordinates of the component.\n",
"\n",
"One can also specify in what coordinate system one wants to work, which can be that of any preceeding component.\n",
"One can also specify in what coordinate system one wants to work, which can be that of any preceding component.\n",
"Use the `RELATIVE` keyword to work in the `source` coordinate system.\n",
"The position of the chopper is needed for calculating phase, so it is available as a variable in the instrument, use this variable to set the position."
]
Expand Down Expand Up @@ -1072,7 +1072,7 @@
"### Time resolution\n",
"Using the plotted data above its possible to get a estimate of the time resolution of the instrument.\n",
"\n",
"Use the curser to zoom and read of values for the time resolution of the instrument (FWHM). Insert the found time in the question below as a value in seconds."
"Use the cursor to zoom and read of values for the time resolution of the instrument (FWHM). Insert the found time in the question below as a value in seconds."
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion 3-mcstas/mcstas-sans.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,7 @@
"source": [
"## Run improved instrument\n",
"\n",
"Its time to run the improved instrument. We will use the same parameters as earlier, but now also set `integration_time` to $5\\times 10^4$, corresponding to 13.8 hours. This is suposed to emulate a long measurement of the instrument background only done rarely. We use the integration time in the continued workflow to estimate the error on the measured signal.\n",
"Its time to run the improved instrument. We will use the same parameters as earlier, but now also set `integration_time` to $5\\times 10^4$, corresponding to 13.8 hours. This is supposed to emulate a long measurement of the instrument background only done rarely. We use the integration time in the continued workflow to estimate the error on the measured signal.\n",
"\n",
"Store the returned data in a variable called `background_data`. Name the generated data folder \"SANS_without_sample_1_pulse\" using the *output_path* argument in the `settings` method of the instrument."
]
Expand Down
40 changes: 20 additions & 20 deletions 3-mcstas/monte_carlo.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,47 +7,47 @@
def plot_points(square_side_length, circle_radius,n=100):
global points_inside_circle, total_points, estimates, estimate
global points_x_inside, points_y_inside, points_x_outside, points_y_outside

for _ in range(n):
x, y = np.random.rand(2)*square_side_length # Random points x, y between 0 and 1
distance = np.sqrt((x-0.5*square_side_length)**2 + (y-0.5*square_side_length)**2)

total_points += 1

if distance <= circle_radius:
points_inside_circle += 1
points_x_inside.append(x)
points_y_inside.append(y)
else:
points_x_outside.append(x)
points_y_outside.append(y)

# area of circle = pi*circle_radius**2
# area of box = side_length**2
# estimate =

estimate = square_side_length**2/circle_radius**2 * points_inside_circle / total_points
estimates.append(estimate)

# Update scatter plots
scatter_inside.set_offsets(np.c_[points_x_inside, points_y_inside])
scatter_outside.set_offsets(np.c_[points_x_outside, points_y_outside])

# Update line plot
line.set_data(range(len(estimates)), estimates)
if len(estimates) == 0:
line_pi.set_data([0, 1], [np.pi, np.pi])
else:
line_pi.set_data([0, len(estimates)], [np.pi, np.pi])

ax[1].relim()
ax[1].autoscale_view()


ax[1].set_title(f'Estimate of Pi: {estimate}')
ax[1].set_xlabel('Number of Points')
ax[1].set_ylabel('Estimate Value')

# Update the figure
fig.canvas.draw()

Expand Down Expand Up @@ -87,7 +87,7 @@ def example(points=100, square_side_length=1, circle_diameter=1):
# Initial Plot
plot_points(square_side_length, circle_radius, 100)


plt.tight_layout()


Expand Down Expand Up @@ -126,44 +126,44 @@ def example_interactive(square_side_length=1, circle_diameter=1):
def plot_points(n=1):
global points_inside_circle, total_points, estimates, estimate
global points_x_inside, points_y_inside, points_x_outside, points_y_outside, scatter_inside, scatter_outside

for _ in range(n):
x, y = np.random.rand(2)*square_side_length # Random points x, y between 0 and 1
distance = np.sqrt((x-0.5*square_side_length)**2 + (y-0.5*square_side_length)**2)

total_points += 1

if distance <= circle_radius:
points_inside_circle += 1
points_x_inside.append(x)
points_y_inside.append(y)
else:
points_x_outside.append(x)
points_y_outside.append(y)

# area of circle = pi*circle_radius**2
# area of box = side_length**2
# estimate =

estimate = square_side_length**2/circle_radius**2 * points_inside_circle / total_points
estimates.append(estimate)

# Update scatter plots
scatter_inside.set_offsets(np.c_[points_x_inside, points_y_inside])
scatter_outside.set_offsets(np.c_[points_x_outside, points_y_outside])

# Update line plot
line.set_data(range(len(estimates)), estimates)
if len(estimates) == 0:
line_pi.set_data([0, 1], [np.pi, np.pi])
else:
line_pi.set_data([0, len(estimates)], [np.pi, np.pi])

ax[1].relim()
ax[1].autoscale_view()
ax[1].set_xlabel('Number of Points')
ax[1].set_ylabel('Estimate Value')

# Update the figure
fig.canvas.draw()

Expand Down
8 changes: 4 additions & 4 deletions 3-mcstas/quizlib/QENS_quiz.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def question_8(self, answer=None):
which is done using the *set_AT* component. This method takes a list
of 3 numbers, corresponding to the *x*, *y* and *z* coordinates of
the component. One can also specify in what coordinate system one
wants to work, which can be that of any preceeding component. Use
wants to work, which can be that of any preceding component. Use
the *RELATIVE* keyword to work in the *source* coordinate system.
The position of the chopper is needed for calculating phase, so it
is available as a variable in the instrument, use this variable to
Expand Down Expand Up @@ -259,7 +259,7 @@ def question_9(self, answer=None):
self.insert_value(answer, 0.000246,
feedback_correct=success_msg,
feedback_below=below_msg, feedback_above=above_msg,
tollerance_factor=0.2)
tolerance_factor=0.2)

def question_10(self, answer=None):
"""
Expand All @@ -275,7 +275,7 @@ def question_10(self, answer=None):
self.insert_value(answer, 0.00126,
feedback_correct=success_msg,
feedback_below=below_msg, feedback_above=above_msg,
tollerance_factor=0.25)
tolerance_factor=0.25)

def question_11(self, answer=None):
"""
Expand All @@ -289,4 +289,4 @@ def question_11(self, answer=None):
self.insert_value(answer, 8.238,
feedback_correct=success_msg,
feedback_below=below_msg, feedback_above=above_msg,
tollerance_factor=0.20)
tolerance_factor=0.20)
41 changes: 12 additions & 29 deletions 3-mcstas/quizlib/quiz.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def multiple_choice(self, answer, correct_answer, feedback):
correct = answer in correct_answer
else:
correct = answer == correct_answer

if answer not in feedback:
message = "This multiple choice question did not contain that option!"
valid = False
Expand All @@ -67,26 +67,26 @@ def multiple_choice(self, answer, correct_answer, feedback):

def insert_value(self, answer, correct_answer,
feedback_correct="", feedback_below="", feedback_above="",
tollerance_factor=None, tollerance_interval=None):
tolerance_factor=None, tolerance_interval=None):

if answer is None:
print("Insert your answer in the question above.")
return

if tollerance_interval is not None and tollerance_factor is not None:
print("Question bug, use only tollerance_factor or tollerance_interval!")
if tolerance_interval is not None and tolerance_factor is not None:
print("Question bug, use only tolerance_factor or tolerance_interval!")

lower_limit = correct_answer
if tollerance_factor is not None:
lower_limit *= 1 - tollerance_factor
if tollerance_interval is not None:
lower_limit -= 0.5*tollerance_interval
if tolerance_factor is not None:
lower_limit *= 1 - tolerance_factor
if tolerance_interval is not None:
lower_limit -= 0.5*tolerance_interval

upper_limit = correct_answer
if tollerance_factor is not None:
upper_limit *= 1 + tollerance_factor
if tollerance_interval is not None:
upper_limit += 0.5*tollerance_interval
if tolerance_factor is not None:
upper_limit *= 1 + tolerance_factor
if tolerance_interval is not None:
upper_limit += 0.5*tolerance_interval

if not isinstance(answer, (float, int)):
message = "This question needs a value as the answer"
Expand Down Expand Up @@ -269,20 +269,3 @@ def last_component_in_instr_check(self, answer, comp_type_str, required_pars=Non
print_box(success_msg, True)

return True

















1 change: 0 additions & 1 deletion 3-mcstas/ray_tracer_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,3 @@ def large():


return sim

Loading

0 comments on commit cb37ab0

Please sign in to comment.