Scilab Basics

Before everything, I would like to express how I feel about this activity. Before I enrolled the course Applied Physics 186, I already took programming subjects like App Physics 155 and App Physics 156. There we learned a programming language called Python. At first, it was so difficult learning the language as if I don’t know anything.

python
Me getting devoured by Python

But then with some hard work, I was able to master the basics of Python which lead me to do great in my Computational Physics subjects (yey me!!). I finally know how to code in Python.

python2
Me taking control of Python

Anyway, the point is that I felt the same way to Scilab.

notagain
Yes this is the first time I used Scilab

It was so difficult to learn with only just a small limited time to do so. But the story ended with a good ending and that I am now beginning to understand Scilab. With a few more practice, I might eventually master this programming language too.

thatstwoIn this activity, we were asked to produce seven outputs: a centered square, sinusoid along the x-direction (corrugated roof), grating along the x-direction, annulus, circular aperture with graded transparency (Gaussian transparency), ellipse and a cross. To produce these outputs, we needed to use the newly learned programming language, Scilab.

Basing solely on the given example (and some friends who helped me), I was able to produce the required outputs. The example given produces an output of a centered circle. First, I generated a grid 100 x 100 and assigned A as the value of the grid’s every point and is equal to zero. The grid also spans from -1 to 1 in both x- and y-axis. By finding the values of (x²+y²)<0.7 on the grid. That same spot, the values of A will be changed to 1. Thus when plotting the grid, A will serve as the value of the color of the grid on that point (black for 0 and white for 1). The figure below does not look like a circle because the width of the x-axis is wider then the width of the y-axis.

centeredcircle
Figure 1. Centered circle

For the centered square, I created an 800 x 800 grid but still ranging from -1 to 1 in both x- and y-axis. The initial value of A will be zero and by only selecting the center of the grid, we let the value of A on that center to be 1.

Figure 2. Centered Square
Figure 2. Centered Square

Again, the image looked like a rectangle due to the width bias. Also, notice that the square now looks better or has a better quality as compared to the circle. This is because I increased the size of the grid from 100 x 100 to 800 x 800. This will also affect the quality of the image.

For the sinusoid along the x-direction, again, I created an 800 x 800 grid. The range of values for the x- and y-axis now spans from -10 to 10. I made it like this because a full period of a sinusoid is 2π. To show at least two good sinusoids, I made the range of values to be greater than 4π. The values of the variable A in this case will be equal to sin(X) that is why the sinusoid is along the x-direction. To make a sinusoid along the y-direction, just change X to Y to make A=sin(Y).

Figure 3. Sinusoid along the x-direction
Figure 3. Sinusoid along the x-direction
Figure 4. Sinusoid along the y-direction
Figure 4. Sinusoid along the y-direction

For the grating along the x-direction, a 500 x 500 grid is genereated which spans from -20 to 20 in both x- and y-axis. I used a variable r = sin(X) which will be used later to filter the values of A. The initial values of A is 0 for all points on the grid. By selecting the r values which are less than 0 on the grid, I made the value of A on those points be equal to 1. Since there are equal number of points where sin(X) is greater than 0 and sin(X) is less than 0, the grating would be equally spaced where the width of the black is equal to the width of the white.

grating
Figure 5. Grating along the x-direction.

Creating an annulus would do almost the exact same thing in creating a centered circle. An annulus is like a ring-shaped object. To create the annulus, I generated an 800 x 800 grid which spand from -1 to 1 in both x- and y-axis. The initial values of A will be zero for all. I will then change the value of A to zero for all points inside the centered circle of radius 0.7 and outside the centered circle of radius 0.5.

annulus
Figure 6. Centered annulus

The next image is an aperture with Gaussian transparency. I created an 800 x 800 grid with a span of -1 to 1 in both x-and y-axis. Using the equation of a Gaussian (or Normal) distribution, I created first a whole grid with values of A equal to a Gaussian distribution (1 on the center and exponentially decreasing as it moves radially outward. Since it should be an aperture, I created a centered circle with the values of A less than 0.3 be equal to 0. These values can only be found on the outer part of the circle so a good aperture will be produced.

Figure 7.
Figure 7. Aperture with Gaussian transparency

An ellipse is to be produced on the next image. To produce the image, I just followed the general equation of an ellipse. I also used an 800 x 800 grid spanning from -10 to 10 for both x- and y-axis. The value of A will be zero outside the ellipse and 1 inside it. To make sure that the generated image is an ellipse, I made sure that the edge of the major axis is not equal to the edge of the minor axis (which can be observed on the image). To make things better, I created an ellipse that tilted about 45°.

ellipse
Figure 8. Ellipse
Figure 9. Tilted Ellipse
Figure 9. Tilted Ellipse

Lastly, a cross is to be produced. Using an 800 x 800 grid spanning from -1 to 1, a cross was created. Initially, the values of A was set to 0 then the boundary -0.2<X<0.2 and -0.2<Y<0.2 was set to 1. Note that the two boundaries are not really connected by the AND operator. If they were connected by the AND operator, only a square would form so both those conditions will be set to 1 separately to form a cross.

Figure 10. Cross
Figure 10. Cross

I can also create a cross that forms an X.

Figure 11. Cross that forms an X
Figure 11. Cross that forms an X

All Scilab codes used can be found here.

Review:

For those who helped me in my struggles in Scilab, I would like to thank you from the bottom of my heart. I would like to name a few who went the extra mile and stayed until I understood how to use Scilab: Jesli Santiago and Ralph Aguinaldo. Also, I would like to thank my sources for the GIFs and images that I used in this report.thanks3For my self evaluation, I understood how to use Scilab to produce the required outputs. I also did all the expected outputs and even went beyond and tried a few extra graphs to test my newly acquired knowledge in Scilab. Because of this, I would give myself a 12 for my self evaluation grade.

12

Use of Ratio and Proportion in Digital Scanning

Digital scanning is a method used by many people to recover images and be able to reconstruct it for digital use. Artists use this method to make digital copies of their artworks so they can enhance it through the computer. Some people use digital scanning to revive old books because digital scanning is a better method as compared to retyping the whole book.

For the case of plots or graphs, it is hard to recover the values on the image due to the inaccuracy of the measuring tool and most of the time, these values may be needed to study the graph deeper. One of the known methods to extract these values is through the use of ratio and proportion. To have better results, it is better for the plot or graph to have tick marks with fixed intervals. The tick marks will be used later on as the basis for the ratio.

The figure below shows the plot that I have chosen to use for digital reconstruction. It is Figure 11 of the 1993 undergraduate thesis of Richell Taberdo Martinez entitled “Spectroscopic Analysis of the National Institute of Physics Plasma Experimental Rig II Modified.

H profile: Retrieved from: Figure 11, Spectroscopic Analysis of the National Institute of Physics Plasma Experimental Rig II Modified
Figure 1. Plot to be reconstructed for this activity.

It can be observed that the figure above has tick marks for the x- and y-axis. The x-axis shows 1 angstrom increment per tick while the y-axis shows 0.02 increment in relative intensity. These values are used in getting the pixel ratio of the image. Using Microsoft Paint, a value was extracted for the number of pixels per increment. For the x-axis, it is estimated to be 7 pixels per increment and the y-axis also yielding 7 pixels per increment. The ratio for both axes will then be estimated to be 0.14 angstrom per pixel and 0.003 relative intensity per pixel for the x- and y-axis, respectively.

After getting the ratios, several important points (peaks, corner points, etc) on the image will be gathered and using Microsoft Paint, their pixel locations (relative to the x- and y-axis, not the edge of the image) can be extracted. Multiplying the pixel values with the ratio, the respective values of the gathered points can be estimated. And because of the ratio, the value of the plot at any point can now be estimated.

The reconstructed image was plotted using Microsoft Excel. I gathered 20 points on the plot and converted it to their respective estimated values. The figure below shows the reconstructed plot for the Hγ profile.

ReconstructedPlot
Figure 2. Reconstructed plot with the original plot on the background.

The original plot was set as the background of the graph. I chose red dashed line for the reconstructed plot so that it will not totally cover the original plot on its background. Based on the plot, I can conclude that the use of ratio of proportion in reconstructing plots from images is very effective as it returns a relatively accurate (depending on the resolution of the image) value for the plot.

Review:

I give credit to the owner of the undergraduate thesis (R.T. Martinez) for the usage of her plot in my report. I also give credit to Microsoft Paint for giving me very good pixel locations and to Microsoft Excel for reconstructing my plot. Also, I give credits to my classmate Ron Aves in helping me find this plot. Also, I would like to thank my sources for the GIFs and images that I used in this report.

thanks

Anyway, the activity was fairly easy (meaning I enjoyed this activity) and I understood every part of it clearly. I noticed that an image with a higher resolution can give more accurate values. This is because an image with better quality can remove the doubt of the researcher on what pixel is the right pixel like the figure below.

con1
Figure 3. First observed limitation of the results.

The figure above shows the x- and y-axis of my chosen plot. The lines is too wide (the width of the line is about 3 pixels). Because of this, it is hard to be consistent therefore it will become a limitation to the acquired results.

Figure 4. Second observed limitation of the results.
Figure 4. Second observed limitation of the results.

Another thing is that in choosing points, some plots may have these kinds of points so consistency can really be the problem. The size of the point on the figure above is about 5 pixels in diameter.

But for me, I tried my best to become consistent with my chosen points and because of the effort I made, I was able to reconstruct the plot accurately. The grade that I will be giving to myself is 11 because I somewhat tested the limitations of the ratio and proportion method.

11