comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Newbie's question
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Newbie's question [message #45924] Wed, 19 October 2005 15:06 Go to next message
ChiChiRuiz@gmail.com is currently offline  ChiChiRuiz@gmail.com
Messages: 32
Registered: October 2005
Member
Hi there,

I have a scatter plot which has the shape of a parabola, like y=x^2.
I want to find the best curve fit to the scatter plot, so I used the
function "curvefit" with no weights and with initial guesses (1.0, 2.0)
i.e. y = 1.*x^(2.). So, here's the problem...when I use only the right
half of the data points (i.e. x and y values are positive), I get the
curvefit returns parameter (0.5, 1.5), which means, the best fit curse
is y=.5*x^(1.75). I know the fit should be symmetric, so the same curve
SHOULD fit the other half. Now unto the left half side of the data
set, curvefit does not work anymore, and here's why, x^(1.5)=x^(3/2)
and when x is a negative number, IDL returns "NaN" because it can't
take the square root of a negative number, hence the entire procedure
will not work. I ended up having to throw away half of my data points,
and I'm not very comfortable with that. Any idea how to go around it
or suggest another function to do the same thing?

Besides, I've thought about using "polyfit", but if I remember
correctly, polyfit only takes in one x value vs. one y value. Scatter
plot has one x value vs. several y values. I don't think it'll
work in my case, but I may be wrong...

TIA (thanks in advance)

Angie
Re: Newbie's question [message #45976 is a reply to message #45924] Fri, 21 October 2005 15:06 Go to previous messageGo to next message
James Kuyper is currently offline  James Kuyper
Messages: 425
Registered: March 2000
Senior Member
ChiChiRuiz@gmail.com wrote:
> Hi James,
>
> The x values are air temperatures in comparison to the ground, ie. if
> the air is cooler than the ground (a shadow or shade), then the value
> is negative; if the air is hotter than the ground, it's a positive
> number. Over a strip of image, the value varies from negative to
> positive. So, I'm interested how, over a ROI, the temp changes over
> some location.

OK, and now what are the y values, and why do you expect them to be the
square of the x values?
Re: Newbie's question [message #45980 is a reply to message #45924] Fri, 21 October 2005 11:22 Go to previous messageGo to next message
ChiChiRuiz@gmail.com is currently offline  ChiChiRuiz@gmail.com
Messages: 32
Registered: October 2005
Member
Hi James,

The x values are air temperatures in comparison to the ground, ie. if
the air is cooler than the ground (a shadow or shade), then the value
is negative; if the air is hotter than the ground, it's a positive
number. Over a strip of image, the value varies from negative to
positive. So, I'm interested how, over a ROI, the temp changes over
some location.

Angie
Re: Newbie's question [message #45984 is a reply to message #45924] Fri, 21 October 2005 10:29 Go to previous messageGo to next message
James Kuyper is currently offline  James Kuyper
Messages: 425
Registered: March 2000
Senior Member
JD Smith wrote:
> On Fri, 21 Oct 2005 05:55:53 -0700, James Kuyper wrote:
>
>>> Fitting to a single power law is a time honored tradition in many of the
>>> precision-limited fields of physics (e.g. astronomy).
>>
>> True, but following that tradition is only appropriate when there's a
>> specific reason to expect a power law of some kind.
>
> You'd be surprised how many different motivations are invoked in the
> cult of log-log.

No I wouldn't. By training, I'm a theoretical cosmologist. I've seen a
lot of badly motivated log-log "analysis" by astronomers.
Re: Newbie's question [message #45985 is a reply to message #45924] Fri, 21 October 2005 10:19 Go to previous messageGo to next message
James Kuyper is currently offline  James Kuyper
Messages: 425
Registered: March 2000
Senior Member
ChiChiRuiz@gmail.com wrote:
> I agreed that it's more a scientific problem, rather than a numerical
> one. It'd just never crossed my mind that it would be this
> complicated. The x, y arrays are values from different images over the
> same pixel location, because of the stats analysis to produce these
> values, they "SHOULD" have a y=x^2 relationship, but due to large
> analytical errors, I know it's not exactly y=x^2. I just want to get a
> general idea for the scatter plot.

I still think that it's likely that you're doing the wrong kind of
analysis. However, I can't be sure, and I can't suggest an alternative,
unless I know a little bit more about what these numbers actually mean.

When you say "images", I tend to think of something which, at the
fundamental level, is incapable of having negative values. Background
subtraction can produce negative values, and dealing with that in a
fashion that doesn't bias your statistics is a tricky issue. However, I
got the impression from your comments that the negative values were
pretty common, and of a magnitude similar to that of your positive
values.

It also would help if we knew what you were planning to do with this
number once you've calculated it. The right number to calculate, and
the best way to calculate it, often depends upon how you plan to use
that number.
Re: Newbie's question [message #45987 is a reply to message #45924] Fri, 21 October 2005 09:35 Go to previous messageGo to next message
JD Smith is currently offline  JD Smith
Messages: 850
Registered: December 1999
Senior Member
On Fri, 21 Oct 2005 05:55:53 -0700, James Kuyper wrote:

>> Fitting to a single power law is a time honored tradition in many of the
>> precision-limited fields of physics (e.g. astronomy).
>
> True, but following that tradition is only appropriate when there's a
> specific reason to expect a power law of some kind.

You'd be surprised how many different motivations are invoked in the
cult of log-log.

JD
Re: newbie's question [message #53404 is a reply to message #45924] Sat, 14 April 2007 11:08 Go to previous message
geonline714 is currently offline  geonline714
Messages: 7
Registered: April 2007
Junior Member
Dear David,

Thank you for your detailed explanation. Now it works. :)

Have a great weekend!

Sincerely,
Qi
On Apr 14, 10:04 am, David Fanning <n...@dfanning.com> wrote:
> geonline...@gmail.com writes:
>> I tried to run a script like this (stored in test.pro):
>
>> array = ['one', 'two', 'three']
>> print, array
>> n = N_ELEMENTS(array)
>> print, n
>> FOR i=0,n-1 DO BEGIN
>> PRINT, array[i]
>> ENDFOR
>
>> However, I got error message as follows:
>
>> IDL> @test
>> one two three
>> 3
>> Attempt to subscript ARRAY with I is out of range.
>> Execution halted at: $MAIN$
>
>> ENDFOR
>> ^
>> Syntax error.
>> At: E:\temp\test.pro, Line 7
>
>> This is an example from IDL. Do you have any idea about what is going
>> on?
>
> The @ sign attempts to read the instructions in the file
> as if you were typing them at the IDL command line. That
> is, one after the other. But, it is VERY difficult to
> write multiple line commands, such as in your FOR loop,
> at the IDL command line. You will need line continuation
> and line concatenation symbols to do so. NO ONE WANTS TO
> DO THAT!
>
> So, what you want to do is compile this bunch of commands
> you have FIRST, then execute that. BUT, in order to make
> these command compilable, there has to be an END statement
> at the end of the commands, so the compiler knows where
> to stop. That is what is missing in your code (and is
> probably what you have left out of the example).
>
> What you want to do with this code is add an END statement.
> Then compile the commands:
>
> IDL> .compile test
>
> Then run this main-level program:
>
> IDL> .go
>
> Cheers,
>
> David
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: newbie's question [message #53406 is a reply to message #45924] Sat, 14 April 2007 10:04 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
geonline714@gmail.com writes:

> I tried to run a script like this (stored in test.pro):
>
> array = ['one', 'two', 'three']
> print, array
> n = N_ELEMENTS(array)
> print, n
> FOR i=0,n-1 DO BEGIN
> PRINT, array[i]
> ENDFOR
>
>
> However, I got error message as follows:
>
> IDL> @test
> one two three
> 3
> Attempt to subscript ARRAY with I is out of range.
> Execution halted at: $MAIN$
>
> ENDFOR
> ^
> Syntax error.
> At: E:\temp\test.pro, Line 7
>
>
> This is an example from IDL. Do you have any idea about what is going
> on?

The @ sign attempts to read the instructions in the file
as if you were typing them at the IDL command line. That
is, one after the other. But, it is VERY difficult to
write multiple line commands, such as in your FOR loop,
at the IDL command line. You will need line continuation
and line concatenation symbols to do so. NO ONE WANTS TO
DO THAT!

So, what you want to do is compile this bunch of commands
you have FIRST, then execute that. BUT, in order to make
these command compilable, there has to be an END statement
at the end of the commands, so the compiler knows where
to stop. That is what is missing in your code (and is
probably what you have left out of the example).

What you want to do with this code is add an END statement.
Then compile the commands:

IDL> .compile test

Then run this main-level program:

IDL> .go

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: newbie's question
Next Topic: Re: FIX FOR FC5 SEG FAULTS

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 19:05:43 PDT 2025

Total time taken to generate the page: 0.00678 seconds