Smooth function question [message #89419] |
Wed, 15 October 2014 06:11  |
zolile mtumela
Messages: 50 Registered: September 2011
|
Member |
|
|
Dear all,
I got a 3D data. I applied a SMOOTH function like smooth(a,3), the plots look fine and when I print the number of elements on the screen are equal as the original data. But when wrote to a file I found that there is a missing element or number is not corresponding with original data. I checked using excel. I am a bit confused, I need some help. Any suggestion is very welcome,
Thanks
Zolile
|
|
|
Re: Smooth function question [message #89420 is a reply to message #89419] |
Wed, 15 October 2014 06:29   |
Helder Marchetto
Messages: 520 Registered: November 2011
|
Senior Member |
|
|
On Wednesday, October 15, 2014 3:11:05 PM UTC+2, zolile...@gmail.com wrote:
> Dear all,
>
> I got a 3D data. I applied a SMOOTH function like smooth(a,3), the plots look fine and when I print the number of elements on the screen are equal as the original data. But when wrote to a file I found that there is a missing element or number is not corresponding with original data. I checked using excel. I am a bit confused, I need some help. Any suggestion is very welcome,
>
> Thanks
>
> Zolile
Yes, smooth is not your problem.
IDL> a = randomu(s,100,100,100)
IDL> help, a
A FLOAT = Array[100, 100, 100]
IDL> help, smooth(a,3)
<Expression> FLOAT = Array[100, 100, 100]
Your problem is writing the data and/or reading the data. Without some code to look at, it's difficult to say.
Whatever, smooth() does not change the number of elements. At the edges "strange" things might happen, but no element is lost.
cheers, Helder
|
|
|
Re: Smooth function question [message #89421 is a reply to message #89419] |
Wed, 15 October 2014 06:37   |
zolile mtumela
Messages: 50 Registered: September 2011
|
Member |
|
|
On Wednesday, October 15, 2014 3:11:05 PM UTC+2, zolile...@gmail.com wrote:
> Dear all,
>
> I got a 3D data. I applied a SMOOTH function like smooth(a,3), the plots look fine and when I print the number of elements on the screen are equal as the original data. But when wrote to a file I found that there is a missing element or number is not corresponding with original data. I checked using excel. I am a bit confused, I need some help. Any suggestion is very welcome,
>
> Thanks
>
> Zolile
openR, Lun, File,/Get_Lun
readf, Lun, str
while~eof(lun) do begin
readf,lun,date,time,Bx,By,Bz
print,date,time,Bx,By,Bz
Bx_array = [Bx_array, Bx]
By_array = [By_array, By]
Bz_array = [Bz_array, Bz]
endwhile
free_lun,lun
Bx_array=Bx_array[1:*]
By_array=By_array[1:*]
Bz_array=Bz_array[1:*]
Nx = n_elements(Bx_array)
time = findgen(Nx)
time = time/225.
Ny = n_elements(By_array)
time = findgen(Ny)
time = time/225.
Nz = n_elements(Bz_array)
time = findgen(Nz)
time = time/225.
Smoothed1 = smooth(Bx_array,3)
Smoothed2 = smooth(By_array,3)
Smoothed3 = smooth(Bz_array,3)
NN1=n_elements(smoothed1)
NN2=n_elements(smoothed2)
NN3=n_elements(smoothed3)
print, smoothed1
print, NN1,NN2,NN3
openw,1,'dataxx.txt'
printf,1,transpose(smoothed1)
close,1
|
|
|
Re: Smooth function question [message #89424 is a reply to message #89421] |
Wed, 15 October 2014 07:56   |
Helder Marchetto
Messages: 520 Registered: November 2011
|
Senior Member |
|
|
On Wednesday, October 15, 2014 3:37:14 PM UTC+2, zolile...@gmail.com wrote:
> On Wednesday, October 15, 2014 3:11:05 PM UTC+2, zolile...@gmail.com wrote:
>
>> Dear all,
>
>>
>
>> I got a 3D data. I applied a SMOOTH function like smooth(a,3), the plots look fine and when I print the number of elements on the screen are equal as the original data. But when wrote to a file I found that there is a missing element or number is not corresponding with original data. I checked using excel. I am a bit confused, I need some help. Any suggestion is very welcome,
>
>>
>
>> Thanks
>
>>
>
>> Zolile
>
>
>
> openR, Lun, File,/Get_Lun
>
> readf, Lun, str
>
> while~eof(lun) do begin
>
>
>
> readf,lun,date,time,Bx,By,Bz
>
> print,date,time,Bx,By,Bz
>
> Bx_array = [Bx_array, Bx]
>
> By_array = [By_array, By]
>
> Bz_array = [Bz_array, Bz]
>
> endwhile
>
> free_lun,lun
>
> Bx_array=Bx_array[1:*]
>
> By_array=By_array[1:*]
>
> Bz_array=Bz_array[1:*]
>
>
>
>
>
> Nx = n_elements(Bx_array)
>
> time = findgen(Nx)
>
> time = time/225.
>
>
>
> Ny = n_elements(By_array)
>
> time = findgen(Ny)
>
> time = time/225.
>
>
>
> Nz = n_elements(Bz_array)
>
> time = findgen(Nz)
>
> time = time/225.
>
>
>
> Smoothed1 = smooth(Bx_array,3)
>
> Smoothed2 = smooth(By_array,3)
>
> Smoothed3 = smooth(Bz_array,3)
>
>
>
> NN1=n_elements(smoothed1)
>
> NN2=n_elements(smoothed2)
>
> NN3=n_elements(smoothed3)
>
> print, smoothed1
>
>
>
> print, NN1,NN2,NN3
>
>
>
> openw,1,'dataxx.txt'
>
> printf,1,transpose(smoothed1)
>
> close,1
According to your post from before, the number of elements by the print command (monitor output) do not match with those of the text file produced.
I tried replicating your last lines:
IDL> openw,1,'dataxx.txt'
IDL> smoothed = findgen(100)
IDL> printf,1,transpose(smoothed)
IDL> close,1
IDL> print, FILE_LINES('dataxx.txt')
100
So I get 100 lines in the text file. Something like this:
0.000000
1.00000
2.00000
3.00000
4.00000
5.00000
...
95.0000
96.0000
97.0000
98.0000
99.0000
This is the same as if I did
IDL> print, smoothed
So I think there is something missing part in your code or you're mixing up files when checking what has been done.
Maybe try putting a time stamp... something like
IDL> start_t = systime()
IDL> print, 'start : '+start_t
IDL> printf,1,start_t
IDL> printf,1,transpose(smoothed)
IDL> end_t = systime()
IDL> print, 'end : '+end_t
IDL> printf,1,end_t
IDL> close,1
Do the values in the file and on the screen match?
If they match, then you have to have a file with a number of lines equal to the number of elements of smoothed + 2 (for the time stamps!)
Cheers, Helder
|
|
|
Re: Smooth function question [message #89436 is a reply to message #89419] |
Thu, 16 October 2014 00:14  |
zolile mtumela
Messages: 50 Registered: September 2011
|
Member |
|
|
On Wednesday, October 15, 2014 3:11:05 PM UTC+2, zolile...@gmail.com wrote:
> Dear all,
>
> I got a 3D data. I applied a SMOOTH function like smooth(a,3), the plots look fine and when I print the number of elements on the screen are equal as the original data. But when wrote to a file I found that there is a missing element or number is not corresponding with original data. I checked using excel. I am a bit confused, I need some help. Any suggestion is very welcome,
>
> Thanks
>
> Zolile
23-03-2002 16:11:33.000 1.57100 -8.41400 -4.89800
23-03-2002 16:11:49.000 1.57200 -8.60200 -4.59500
23-03-2002 16:12:05.000 1.00100 -8.48400 -5.06300
23-03-2002 16:12:21.000 0.806000 -8.38700 -5.26600
Date_array = 0
time_array = 0
Bx_array = 0
By_array = 0
Bz_array = 0
Thanks Helder
I think my problem is on time array, Bcz I would also like to print time as it is/similar, I am having hard time to do so!! And I would like to print all these time Bx, By and Bz in one file.
Many thanks
Zolile
|
|
|