cancel
Showing results for
Did you mean:

Solved!
Go to solution

## ChnMapLinCalc function

Hi,

I am new to this forum and hopefully this thread is compiled with the rules.

I used ChnMapLinCalc function to interpolate a curve in DIAdem like this.

Set MeanCellCapacity = ChnMapLinCalc("[1]/Temp", "[1]/Capacity", "[1]/AveragedTemp", "[1]/TempCapacity", True, "const. value", NOVALUE, "analogue", 0)

When I ran the function on DIAdem, it threw me an error saying "[1]/AveragedTemp" channel is not monotonic increasing from line 330 onwards.

What I would like to do is to create the resultant channel ("[1]/TempCapacity") based on the input temperature ("[1]/AveragedTemp") via the interpolation from the curves ("[1]/Temp" & "[1]/Capacity").  Not sure if this is the only way to do, but currently being stuck at that.

Just wondering if anyone has ideas to workaround or come across this issue?  Many thanks in advance.

Message 1 of 10
(1,231 Views)

## Re: ChnMapLinCalc function

If you mean linear interpolation you could do

`ChnRegrXYCalc("[1]/Temp", "[1]/Capacity", "/RegressionX", "/RegressionY", "linear", "Partition complete area", 100, 1)`

Then use "RegressionX" to find the closest "AveragedTemp" value and the corresponding "RegressionY" would be your "TempCapacity"

It will also have the mx+b values in the "RegressionY" properties along with precision

Message 2 of 10
(1,208 Views)

## Re: ChnMapLinCalc function

Thanks for the quick reply and contribution to my issue gsklyr.

Could you elaborate a bit more how to use your method to achieve my goal?

Let me explain a bit more about what I am trying to do by using the screenshot below.

I have the averaged temperature channel called "AveragedTemp" which goes up and down in values.  I have got a table that converts the temperature to capacity and the table is loaded on to Data Portal as two channels, "Temp" and "Capacity".  So I would like to use the conversion table to obtain the interpolated capacity, which will be generated as a new curve so that I can plot the curve on "VIEW", according to the averaged temperature as shown in the screenshot.

Just wondering if your method above is able to do it or I need another approach?  Please let me know and many thanks in advance.

Message 3 of 10
(1,163 Views)

## Re: ChnMapLinCalc function

These are the value I got using linear regression:

However, your data is not linear

The green line is the one that gave me the interpolated capacity values but looks like the blue one fits better (that's a 4th order polynomial).

The blue curve gave me better values

But still not quite like your so I am not sure how you do it manually

Message 4 of 10
(1,149 Views)

## Re: ChnMapLinCalc function

I actually get it now sorry for confusing.  You do not need to make a model, you can just do your interpolation.  Simply go to channel functions in analysis tab and use 'sort channel values' to sort you averaged temp channel.  You can then proceed with the in terpolation function with the desired results.

Message 5 of 10
(1,143 Views)

## Re: ChnMapLinCalc function

Specifically, run:

``ChnMultipleSortExt("[1]/AveragedTemp", "", "Up", "UpperCase", True)``

(The 'True' in the end is to avoid creating additional channels and will sort 'AveragedTemp' in place)

and then

``Set MeanCellCapacity = ChnMapLinCalc("[1]/Temp", "[1]/Capacity", "[1]/AveragedTemp", "[1]/TempCapacity", True, "const. value", NOVALUE, "analogue", 0)``

Message 6 of 10
(1,124 Views)

## Re: ChnMapLinCalc function

Hi gsklyr,

My task needs the averaged temperature (AveragedTemp) and interpolated capacity (TempCapacity) plotted out on VIEW.  Not sure if I follow your suggestion correctly.  Do you mean that I firstly sorted AveragedTemp in an ascending order by ChnMultipleSortExt, then do the interpolation by using ChnMapLinCalc to get the interpolated capacity values, then use a reverse functional (not sure what function it will be) to convert ascended AveragedTemp back to the original curve?

Sorry I am still new to DIAdem so not sure of my understanding is correct.  Thanks for your advice and patience.

Message 7 of 10
(1,093 Views)

## Re: ChnMapLinCalc function

Yes, to sort, interpolate, then sort back, this will do the job:

``````Dim temp_length: temp_length = Data.Root.ChannelGroups(1).Channels("AveragedTemp").Properties("length").Value
Call ChnLinGen("/LinearGenerated", 1, temp_length, temp_length, "")
Call ChnMultipleSortExt("[1]/AveragedTemp", "[1]/LinearGenerated", "Up", "UpperCase", True)
Call ChnMapLinCalc("[1]/Temp", "[1]/Capacity", "[1]/AveragedTemp", "[1]/TempCapacity", True, "const. value", NOVALUE, "analogue", 0)
Call ChnMultipleSortExt("[1]/LinearGenerated", "[1]/AveragedTemp", "Up", "UpperCase", True)
Call Data.Root.ChannelGroups(1).Channels.Remove("LinearGenerated")``````
Message 8 of 10
(1,076 Views)
Solution
Accepted by Kane_Lok

## Re: ChnMapLinCalc function

I forgot to add the resulting capacity channel to be sorted back.  Here is the full script:

``````Dim temp_length: temp_length = Data.Root.ChannelGroups(1).Channels("AveragedTemp").Properties("length").Value
Call ChnLinGen("[1]/LinearGenerated", 1, temp_length, temp_length, "")
Call ChnMultipleSortExt("[1]/AveragedTemp", "[1]/LinearGenerated", "Up", "UpperCase", True)
Call ChnMapLinCalc("[1]/Temp", "[1]/Capacity", "[1]/AveragedTemp", "[1]/TempCapacity", True, "const. value", NOVALUE, "analogue", 0)
Call ChnMultipleSortExt("[1]/LinearGenerated", "'[1]/AveragedTemp','[1]/TempCapacity'", "Up", "UpperCase", True)
Call Data.Root.ChannelGroups(1).Channels.Remove("LinearGenerated")``````
Message 9 of 10
(1,068 Views)

## Re: ChnMapLinCalc function

It works perfectly in my application.  Many thanks gsklyr.

Message 10 of 10
(938 Views)