Ask Your Question

v_2e's profile - activity

2022-07-23 15:05:48 +0200 received badge  Famous Question (source)
2021-05-29 10:19:48 +0200 received badge  Civic Duty (source)
2020-06-17 15:19:19 +0200 received badge  Famous Question (source)
2020-05-24 07:18:15 +0200 received badge  Famous Question (source)
2020-04-18 20:44:43 +0200 received badge  Notable Question (source)
2020-01-13 22:52:40 +0200 received badge  Notable Question (source)
2019-03-23 14:00:22 +0200 received badge  Famous Question (source)
2018-10-23 10:52:48 +0200 received badge  Famous Question (source)
2018-08-26 19:25:51 +0200 received badge  Popular Question (source)
2018-04-01 22:09:50 +0200 commented answer Moving my Sage install (on Linux)

This does not seem to work any more. At least, for the 8.1 version it does not. And the documentation now says "...once you have built Sage, you will not be able to move or rename its directory without likely breaking Sage."

2018-04-01 22:06:46 +0200 received badge  Popular Question (source)
2018-03-03 12:47:12 +0200 received badge  Notable Question (source)
2018-03-03 12:47:12 +0200 received badge  Famous Question (source)
2017-10-27 15:59:02 +0200 received badge  Notable Question (source)
2017-10-27 15:59:02 +0200 received badge  Popular Question (source)
2017-10-27 15:59:02 +0200 received badge  Famous Question (source)
2017-09-10 00:27:41 +0200 received badge  Famous Question (source)
2017-06-27 19:27:29 +0200 received badge  Famous Question (source)
2017-04-17 02:01:29 +0200 received badge  Famous Question (source)
2017-02-03 00:32:45 +0200 received badge  Famous Question (source)
2017-01-10 07:38:51 +0200 received badge  Famous Question (source)
2016-07-20 09:14:04 +0200 received badge  Popular Question (source)
2016-06-24 21:38:09 +0200 received badge  Famous Question (source)
2016-06-20 03:28:25 +0200 received badge  Popular Question (source)
2016-06-20 03:28:25 +0200 received badge  Notable Question (source)
2016-02-18 23:06:58 +0200 received badge  Notable Question (source)
2016-02-02 13:37:32 +0200 asked a question Insert image into Graphics object

Is it possible to insert an image (let's say, a PNG file) into a Graphics object containing some plots?

I need to create a raster inset into a figure with the list_plot'ted curves.

2015-07-03 21:08:35 +0200 edited answer Spectral density of a signal

A self-answer:

The power spectral density (PSD) may be defined as

$ S(\omega) = \lim \limits_{T \to +\infty} \frac{\left \vert F_T(\omega) \right \vert ^2}{T} $,

where $ F_T (\omega)$ is the Fourier transform defined as follows:

$ {F}_T(\omega) = \int \limits_0^T f(t) \exp(-i\omega t) ~ dt$

def PSD(time_series):
    import scipy

    signal_length = n(len(time_series)*(time_series[1][0]-time_series[0][0]))
    signal_fft = scipy.fft(zip(*time_series)[1])

    spectrum = []
    for i in range(len(signal_fft)//2):
        spectrum.append((i/signal_length,abs(signal_fft[i])**2/len(time_series)))
    return spectrum

The accepted data set format is:

data = [(t1,y1),(t2,y2),...,(tn,yn)]

Calling

PSD(data)

for such signal will return the Power Spectral Density of a signal.


Sometimes it is useful to apply some kind of window function to a signal prior to calculating the PSD, since the sharp start and end of the data record may produce some spurious spectral components.

Here is an example of the popular Hanning Window application for the time series:

def hanning_window(time_series):
    ''' Applies Hanning window to the time series.
    Accepted data format is a list of tuples [(x1,y1),(x2,y2),...]'''

    series_length = n(len(time_series))
    processed_signal=[]
    for i in range(len(time_series)):
        processed_signal.append((time_series[i][0], n(time_series[i][1] * \
                                 (0.5*(1 - cos(2*pi*i/(series_length-1)))))))

    return processed_signal

The result of its application looks like this: The result of Hanning window function influcence on the signal

One can simply call

PSD(hanning_window(data))

to get the power spectral density for a data set with Hanning window function applied.

You can compare the results of spectral density calculation for the initial time series and "windowed" time series: image description

2015-07-03 15:51:45 +0200 received badge  Famous Question (source)
2015-06-15 20:29:19 +0200 commented answer Two Y-axes

@Jorge Why do you call this "mimic"? You are trying to use the Sage wrappers around Matplotlib functions, while I used those functions directly instead. That was the whole purpose of building such a long algorithm instead of the short one like yours.

2015-06-15 20:19:58 +0200 received badge  Notable Question (source)
2015-05-11 21:18:28 +0200 received badge  Notable Question (source)
2015-03-27 04:12:17 +0200 marked best answer Markers in list_plot

Hello! I discovered today that one cannot use the marker property with list_plot(). So I would like to know if this hasn't been implemented yet (but planned) or there is another way to be used?

Thanks!

Edit: I tried to use

list_plot(DATA_LIST, plotjoined=True, linestyle="", marker='v')

and it indeed let me use different form of markers, but in the case when DATA_LIST consists of only one element, the point placed incorrectly on the resulting plot.

Edit 2: I remembered that there were some problems associated with the logarithmic scales on the axes. That is why I re-read this thread and realized that I have to add an axes_pad=0 parameter in order to get the correctly placed points. So the resuling work-around for a loglog scale would look like this:

list_plot(DATA_LIST, plotjoined=True, linestyle="", marker='v', scale='loglog', axes_pad=0)
2015-03-27 04:11:55 +0200 marked best answer Plot a list of 3D data

Hello! I have a task to plot a list of 3D data of the following form:

 x  y  z
(1, 1, 1)
(1, 5, 7)
(8.8, 0, 3)
(7.5, 1.91, 11.8)
(0, 0, 0)

It looks like with "list_plot3d()" I can only get a surface, while I need just the dots with the appropriate coordinates (x, y, z). How can I do that?

2015-03-27 04:11:52 +0200 marked best answer Easy way to get repeatable random number sequences.

Hello!
Tell me please, if there is a simple and easy way to get the same random number sequence multiple times in Sage?
For example, in Python one can use the random.seed() function to set the random seed and then get a random nuber sequence with random.random() function. After that it is easy and obvious to set the random.seed() to the same seed as the first time and get the very same random sequence again.
But how to get such sequences in Sage?

Thanks.

2015-03-27 04:09:53 +0200 marked best answer Two Y-axes

Hello! Could somebody please point me to a way of plotting two curves associated with different y-axes? I need to plot two curves with different scale over the y-axis to compare their form. What I was thinking of is having two separate y-axes on both sides of a plot and associating one of the curves with the left axis and the other one - with the right axis. Is that possible?

Thank you.

2015-03-27 04:09:12 +0200 marked best answer Cyrillic text on the plot

Is it possible to add the Cyrillic text to the plot in Sage Notebook?

Currently I am trying to do somethink of this kind:

total_plot = plot(sin(x),-10,10)
total_plot += text("????????", (5,0.5))
total_plot.show(figsize=(4,3))

Sage gives the error message:

ValueError: matplotlib display text must have all code points < 128
or use Unicode strings

If I add the 'u' symbol before the string

total_plot += text(u"????????", (5,0.5))

I can only see the empty rectangles instead of the letters.

P.S. I saw this question, however, I am more interested in not using Matplotlib directly if possible.

2015-03-27 04:08:43 +0200 marked best answer Dealing with 'NaN' values in lists

Hello!

Maybe somebody here has an experience on working with 'NaN' values in Sage.

My situation is the following: I need to load some experimentally measured data into a list of float values. But unfortunately, the experimental data set is not "solid" - it has 'NaN' values somewhere inside.

What I currently need to perform first of all is to calculate the average value of a list slice. Preferably, simply using 'mean()' if it is possible.

So could somebody please give me an advice how to work with such arrays correctly?

Thank you.

2015-03-27 04:08:37 +0200 marked best answer Gauss distribution fit

Hello! I have a problem with fitting my data set with a Gauss (Normal) distribution.

data = [[90.00, 2.0], [97.40, 5.0], [104.8, 14.0], [112.2, 12.0], [119.6, 11.0], \
        [127.0, 6.0], [134.4, 3.0], [141.8, 1.0], [149.2, 2.0], [156.6, 1.0]]

var('sigma mu max x')
model(x) = max*(1/sqrt(2*pi*sigma**2))*exp(-(x-mu)**2/(2*sigma**2))

find_fit(data, model)

gives a result:

[sigma == 1.0, mu == 1.0, max == 1.0]

I tried to use a Python function instead of the symbolic one:

var('sigma mu max x')
def model(x,sigma,mu,max):
    return max*(1/(sigma*sqrt(2*pi)))*exp(-(x-mu)**2/(2*sigma**2))

find_fit(data, model, parameters=[sigma, mu, max], variables = [x])

and obtained the very same result:

[sigma == 1.0, mu == 1.0, max == 1.0]

Why does it give me this (obviously, incorrect) result? And what is a way to do it right?

Thanks.

2015-03-27 04:08:14 +0200 marked best answer tseriesChaos package for R from Sage Notebook

Hello! I need some nonlinear time series analysis functionality, which, as I've learnt from Internet, is provided by the 'tseriesChaos' package for R. I tried to use it from inside the Sage Notebook (one of the public servers) like this:

r.library('tseriesChaos')

and got the following error message:

Traceback (click to the left of this block for traceback)
...
  there is no package called 'tseriesChaos'

This variant:

%r
library(tseriesChaos)

gave almost the same:

Error in library(tseriesChaos) : 
  there is no package called 'tseriesChaos'

So it looks like there is no 'tseriesChaos' package in a default Sage installation. So, how is it possible to use it? And how is it probable for the 'tseriesChaos' package to be included into Sage by default?

Thanks.

2015-03-27 04:07:35 +0200 marked best answer 3d plots without Java

Hello! Is it possible to get a "static" plot of 3D-data? For example, if I state the fixed angles of view and want to get simply a PNG file. Maybe something like the command

gnuplot -e 'set terminal png; set view 80,30; splot "output.txt"'

gives.

If it isn't implemented in Sage right now, is it planned? Thanks.

2015-03-27 04:07:31 +0200 marked best answer Does HTTP login to Sage Notebook send plaintex password?

Does my web-browser send the login and password in plaintext when I login to Sage Notebook via HTTP protocol?

2015-03-27 04:07:07 +0200 marked best answer interpolated 2D plot

Hello! Is there a way to create a plot from a list of data using some kind of non-linear interpolation (e.g. splines) between the data points?

Thanks.

2015-03-14 18:49:34 +0200 marked best answer Spectral density of a signal

Hello!

Could somebody please help me find a way to build the spectral density function for a given signal in Sage?

Thank you!

2015-03-14 18:47:46 +0200 received badge  Notable Question (source)
2015-03-02 20:00:53 +0200 received badge  Notable Question (source)