MapInfo Pro

 View Only
Expand all | Collapse all

Calculating Log

  • 1.  Calculating Log

    Posted 10-01-2021 00:23
    Edited by Mike Woodbury 10-01-2021 00:24

    Hi,

    Can anyone please help with Log calc in MIP (Or Discover) from Native/X file

    I have looked under Table | SQL; Table | Update Column and Home | Tool Manger | SQL, plus a quick search on the internet

    I did try Home | Tool Manger | SQL however, was unable to sort out scripting. I did find the Log function however, I didn't structure the script correct (attached)

    In the end, I have to work out side of MIP, and calc in ioGAS, SPSS, Excel or R (prefer to keep inside MIP if at all possible). 

     

    Cheers, Mike



    ------------------------------
    Mike Woodbury
    Knowledge Community Shared Account
    ------------------------------


  • 2.  RE: Calculating Log

    Employee
    Posted 10-01-2021 01:40
    Hi Mike

    Move your Log expression up and replace the * with the expression:

    Select Au_ppb, Log(Au_ppb)
    From MYTABLE
    Into Selection

    You can add additional columns in the projection list to get these returned with the query too.
    Or write MYTABLE.*, Log(Au_ppb) to get all the columns and the log value.

    ------------------------------
    Peter Horsbøll Møller
    Principal Presales Consultant | Distinguished Engineer
    Precisely | Trust in Data
    ------------------------------



  • 3.  RE: Calculating Log

    Posted 10-01-2021 02:06

    Hi Peter,

     

    Perfect, it worked. Thank you Peter

     

    Is there a way to write the LogAu, back to the original table, placing the Log(Au_ppb) at the end of the original table?

     

    I take it you could also apply logs to all e.g. elements in the table, in 1 step?

     

    Cheers, Mike

     

     

     






  • 4.  RE: Calculating Log

    Employee
    Posted 10-01-2021 02:17
    Hi Mike

    You can add a new column anywhere through the Table Structure dialog (right-click on a table in the Table List or find it on the Table tab).
    Then use the Update Column dialog to update the new column with your Log expression.

    ------------------------------
    Peter Horsbøll Møller
    Principal Presales Consultant | Distinguished Engineer
    Precisely | Trust in Data
    ------------------------------



  • 5.  RE: Calculating Log

    Posted 10-01-2021 05:24

    Hi Peter,

     

    The results don't look correct? These look to be LN, not log 10 (x). I checked a couple on my calculator and the results in MIP are not Log 10 (x)

     

    Results I'm getting are different to what I'm expecting Peter. My mistake if I didn't specify Log 10 (x) = Log

     

    Cheers, Mike

     






  • 6.  RE: Calculating Log

    Employee
    Posted 10-01-2021 10:07
    I assume this can be helpful (from the MapBasic help):

    You can calculate logarithmic values in other bases (for example, base 10) using the natural logarithm. To obtain the base-10 logarithm of the number n, divide the natural log of n ( Log( n ) ) by the natural logarithm of 10 ( Log( 10 ) ).

    I guess this means you can do your calculation using this expression: Log(Au_ppb)/Log(10)


    ------------------------------
    Peter Horsbøll Møller
    Principal Presales Consultant | Distinguished Engineer
    Precisely | Trust in Data
    ------------------------------



  • 7.  RE: Calculating Log

    Posted 10-01-2021 13:02
    Hi Peter,

    Thank you. I understand now, much appreciated. I will run your script on my file in the morning and achieve the desired outcome I'm after. Perfect! 

    I did try and use your suggested 'update column', which worked, and populated the calc'ed value into the table. Perfect!! 

    Mapinfo + discover have some pretty cool stuff!! Was exploring the Discover | surface | kriging tool yesterday, but ran into an issue with MIP, which assigns a 0 to nulls in the file (eg in my Au ppb field). I usually log the Au ppb before kriging. I got around the issue in MIP, using a query to select Au ppb > 0 before log, and Datamine | surface | kriging

    I originally compared the output without excluding the nulls = 0, in Discover (as I forgot MIP assigns 0's to nulls), and a bunch of anomalies disappeared. Didn't agree with the log Au / Z_Au ioGAS image (ioGAS ignores Null's). 

    Do you know if there is any way of preventing MIP to assign a zero to Null values? Would save a couple steps.

    Cheers, Mike 

    Sent from Mike W iPhone





  • 8.  RE: Calculating Log

    Posted 10-03-2021 00:33

    Hi Peter,

     

    Thank you, yes it worked (great) and the update column (intersects) also worked.

     

    I will advise the Discover Support who stated on Friday that the Log (10) cannot be calculated in MapInfo.

     

    Appreciate your help once again!

     

    Stay safe!

     

    Rgs

    Mike Woodbury – SensOre

     

     

     






  • 9.  RE: Calculating Log

    Posted 10-04-2021 00:05

    Hi Peter,

     

    As mentioned, your suggestion for calc the log base 10 of my Au ppb works using; Au_ppb, Log(Au_ppb)/Log(10)

     

    I'm just confused, as the equations implies the division by Log (10) [Log (10) = 1], so I was unsure how MIP is calculating the correct value = Ln/1

     

    Cheers, Mike

     






  • 10.  RE: Calculating Log

    Employee
    Posted 10-04-2021 01:30
    Hi Mike

    Log(10) is 2.30259.
    I guess you refer to base-10 logarithm of 10 (Log10(10)) which in MapInfo syntax would be Log(10)/Log(10) and so result in 1.

    ------------------------------
    Peter Horsbøll Møller
    Principal Presales Consultant | Distinguished Engineer
    Precisely | Trust in Data
    ------------------------------



  • 11.  RE: Calculating Log

    Posted 10-04-2021 02:28

    Hi Peter,

     

    Yes, Log Base-10. I have included some examples of Au ppb column and the MIP syntax from Friday

     

    The calc/results in MIP are correct;

     

    (Au_ppb)/Log(10) = 2.70805/ 2.3026 (log of 10) = 1.17609 [Log-10 (15)

     

    If MIP could please add in functionality for Log-10 this would be v. helpful

     

    Thank you for your help Peter!

     

    Cheers

     

     

     






  • 12.  RE: Calculating Log

    Employee
    Posted 10-04-2021 03:49
    Hi Mike

    You can already calculate the Log10 for a value using the expression I showed earlier: Log(Au_ppb) / Log(10)

    Do you want us to add a dedicated Log10(Au_ppb) function? Or a Log function where you can specify the base as a second parameter Log(Au_ppb, 10)?

    Thanks


    ------------------------------
    Peter Horsbøll Møller
    Principal Presales Consultant | Distinguished Engineer
    Precisely | Trust in Data
    ------------------------------



  • 13.  RE: Calculating Log

    Posted 10-04-2021 05:05

    Hi Peter,

     

    Yes please!! Please add a function that we can specify the base as a second parameter, perhaps into one of the functions in the query setup.

     

    Appreciated.

     

    Cheers

     






  • 14.  RE: Calculating Log

    Employee
    Posted 10-05-2021 02:54
    I added an idea to the Precisely Ideas portal: Add a LogBase() function to MapBasic

    Feel to vote and comment on it

    ------------------------------
    Peter Horsbøll Møller
    Principal Presales Consultant | Distinguished Engineer
    Precisely | Trust in Data
    ------------------------------



  • 15.  RE: Calculating Log

    Posted 10-01-2021 11:31

    Hello Mike,

     

    The MapBasic log() function is for natural (base e) logs. You can confirm this by taking the log of e itself, which should yield 1.

    print log(2.718281828459)

    outputs: 1

     

    To find the log of another base, such as 10, simply divide the natural log of your number by the natural log of the desired base.

    print log(2.718281828459)/log(10)

    outputs: 0.434294

     

    Hopefully these match both your calculator and your expectations!

     

    In you're working in Python, the math module has log2(x), log10(x) and log(x, base) functions.

     

    Regards,

    Warren Vick

     






  • 16.  RE: Calculating Log

    Posted 10-01-2021 12:35
    Hello Warren,

    Thank you for the reply!

    Your explanation looks spot on! I'm going to try it in the morning, as I don't have my calc available or my pc open right now. 

    Can I please ask how you would write an expression to calculate the log base 10 for my Au ppb in Mapinfo please? I'm only using the SQL window to do this?

    Cheers, Mike 

    Sent from Mike W iPhone