Author Topic: Python used for calculators/converters.  (Read 1240 times)

0 Members and 1 Guest are viewing this topic.

Online mendip_discoveryTopic starter

  • Frequent Contributor
  • **
  • Posts: 940
  • Country: gb
Python used for calculators/converters.
« on: July 07, 2023, 05:24:32 pm »
<coat="flameproof">

I have never been a coder as such. More of a tinkerer, as I can work out some code and mod it for my use. I just don't have a coding brain, some argue I am brain free. I also like maths though I never really learnt much of it at school and didn't do any at college my understanding is limited at times.

Anyway, I am messing around with Python and Jupyter. I would like to use it for doing some maths. I know you can get a lot of these sites that will do the calculation for you but I always have an edge case that means I end up using Excel for it. Before I go faffing about making these up are there any published gits or sites for it?

For example PT100 and K-type maths. But I also need to do stuff for sine bars, water ml in g etc.
Motorcyclist, Nerd, and I work in a Calibration Lab :-)
--
So everyone is clear, Calibration = Taking Measurement against a known source, Verification = Checking Calibration against Specification, Adjustment = Adjusting the unit to be within specifications.
 

Online RAPo

  • Frequent Contributor
  • **
  • Posts: 696
  • Country: nl
Re: Python used for calculators/converters.
« Reply #1 on: July 07, 2023, 05:33:25 pm »
It is even the standard Python distrib.
For k-type, look here.
 

Online mendip_discoveryTopic starter

  • Frequent Contributor
  • **
  • Posts: 940
  • Country: gb
Re: Python used for calculators/converters.
« Reply #2 on: July 07, 2023, 05:43:24 pm »
It is even the standard Python distrib.
For k-type, look here.

The PT100 one looks to only be a table lookup but that was just a cursory scan of the code.

The thermocouple one looks nice.
Motorcyclist, Nerd, and I work in a Calibration Lab :-)
--
So everyone is clear, Calibration = Taking Measurement against a known source, Verification = Checking Calibration against Specification, Adjustment = Adjusting the unit to be within specifications.
 

Offline radiogeek381

  • Regular Contributor
  • *
  • Posts: 125
  • Country: us
    • SoDaRadio
Re: Python used for calculators/converters.
« Reply #3 on: July 16, 2023, 05:57:48 pm »
Python has become my general-purpose desktop calculator. If I know I'll be in a session for a while, or if the calculations involve vectors or data files, I'll fire up a Jupyter session.

And mendip_discovery's comment about the availability of libraries illustrates an important point: no matter how weird your requirement is, there is a good chance someone has written a python library for it. Some are pretty good, others passable, and some are awful. But it is still better than starting with a flat rock.
 

Online mendip_discoveryTopic starter

  • Frequent Contributor
  • **
  • Posts: 940
  • Country: gb
Re: Python used for calculators/converters.
« Reply #4 on: July 16, 2023, 07:36:04 pm »
I use online calculators and I also do a fair bit in excel. But it's hard to show how I worked it out and the formula it came from.

I am teaching myself LaTEX for the formulas.

For work I have had to do maths for measuring thread pitch diameters using cyclinders, and also taking into account for rake and compression. That put my in maths meltdown for a while. In excel it's ok but would be nice to use it as a function.

Last week I had to convert a pressure gauge that measures in tons to psi knowing the piston size is 75mm. All doable online but I always fear the online stuff will disappear the next time I need it. Plus many of them fail to explain how they get there so I cant be sure the numbers are correct.

I will go ahead with my plans. I just will put them on github for the next person who has to do the same maths. Hopefully it will help the next idiot who has to workout stuff.
Motorcyclist, Nerd, and I work in a Calibration Lab :-)
--
So everyone is clear, Calibration = Taking Measurement against a known source, Verification = Checking Calibration against Specification, Adjustment = Adjusting the unit to be within specifications.
 

Offline eugene

  • Frequent Contributor
  • **
  • Posts: 496
  • Country: us
Re: Python used for calculators/converters.
« Reply #5 on: July 17, 2023, 02:02:03 pm »
There are lots of ways to do what it seems like you want to do. I tend to use Octave for a lot of things, because no matter how hard I try, I just can't grow fond of Python. But that's just me. I know several PhD'ed researchers that use Python for almost everything, and others that accomplish heroic feats in Excel. It all depends on where you feel comfortable.
90% of quoted statistics are fictional
 

Online RoGeorge

  • Super Contributor
  • ***
  • Posts: 6522
  • Country: ro
Re: Python used for calculators/converters.
« Reply #6 on: July 17, 2023, 02:51:39 pm »
LaTEX for the formulas

My understanding is TeX is the typesetting language, while LaTeX is the language together with some predefined things, like it would be C plus the standard libraries.  For formulas only, it is not needed to learn TeX.  There are online helpers that can tell you the syntax, help you to find a certain symbol, and so on.

This post has a link with more examples than needed for formulas:  https://www.eevblog.com/forum/beginners/how-does-posting-math-notation-work/msg3994178/#msg3994178

EEVblog forum supports MathJax, a LaTeX like syntax but not the full TeX language.



About Python vs a spreadsheet like Excel or Calc (Calc is the spreadsheet application from the free office package LibreOffice, compatible with Excel), or spreadsheet vs Matlab (Octave is the free Matlab, also compatible) use whatever comes natural to you.

A spreadsheet would be easier to draft some calculations for a one go, Python or Octave will be more powerful but will require more effort.

The spreadsheet wins for draft calculations, because you can see the result "live".  You type the input number in a cell, hit enter, and in another cell you see the result instantly, all under your eyes and at known positions on the screen, easy to comment about them in a nearby cell, to color them, plot a chart with a couple of mouse clicks, to save all for later, and so on.

When it comes to more elaborated data analysis, then Python (or Octave) is the right tool.

Offline abeyer

  • Frequent Contributor
  • **
  • Posts: 330
  • Country: us
Re: Python used for calculators/converters.
« Reply #7 on: July 17, 2023, 09:07:10 pm »
If you're using python for the calculations, you can also generate the LaTeX for an annotated function w/ google's latexify: https://github.com/google/latexify_py
 

Offline bpiphany

  • Regular Contributor
  • *
  • Posts: 132
  • Country: se
Re: Python used for calculators/converters.
« Reply #8 on: July 18, 2023, 08:24:47 am »
For those with an affinity for python and spreadsheets, try python and spreadsheets. I haven't tried it myself, but I have a friend who keeps raving about it.

https://en.wikipedia.org/wiki/Pyspread
 

Online RAPo

  • Frequent Contributor
  • **
  • Posts: 696
  • Country: nl
Re: Python used for calculators/converters.
« Reply #9 on: July 18, 2023, 09:23:49 am »
Don't tell them a disaster waiting to happen.

For those with an affinity for python and spreadsheets, try python and spreadsheets. I haven't tried it myself, but I have a friend who keeps raving about it.

https://en.wikipedia.org/wiki/Pyspread
 

Online RoGeorge

  • Super Contributor
  • ***
  • Posts: 6522
  • Country: ro
Re: Python used for calculators/converters.
« Reply #10 on: July 18, 2023, 09:50:53 am »
Behind any office software package, there is a backend programming language already, usually accessible to the end user (without installing anything extra, and for free even in Excel) with all the classes that were used by developers, which means it can easily handle object from a spreadsheet, like cells or values, etc.

Usually it's as easy as hitting ALT+F11 in a spreadsheet, to open a code editor and start writing your own programs.

For Microsoft Office products (including Excel) the programming language is VBA (Visual Basic for Applications).  It is not unusual to see a spreadsheet as a GUI for one's own programs.  That's an unexpectedly powerful technique (for those fluent in VBA), just look at this 3 minutes demo:

Excel Magic
EngineeringFun


 8)

Though, would be nice to have a spreadsheet with Python as the backend language.  ::)
Or at least to evaluate Python code in each cell, instead of just a spreadsheet formula.
« Last Edit: July 18, 2023, 10:03:20 am by RoGeorge »
 

Offline abeyer

  • Frequent Contributor
  • **
  • Posts: 330
  • Country: us
Re: Python used for calculators/converters.
« Reply #11 on: July 18, 2023, 07:49:54 pm »
Though, would be nice to have a spreadsheet with Python as the backend language.  ::)
Or at least to evaluate Python code in each cell, instead of just a spreadsheet formula.

https://www.xlwings.org/
 

Online RoGeorge

  • Super Contributor
  • ***
  • Posts: 6522
  • Country: ro
Re: Python used for calculators/converters.
« Reply #12 on: July 19, 2023, 05:40:27 am »
Something like that, from their demo videos xlwings looks very promising.
Would have give it a try, unfortunately I don't use Excel, nor Google Sheets.

Offline bpiphany

  • Regular Contributor
  • *
  • Posts: 132
  • Country: se
Re: Python used for calculators/converters.
« Reply #13 on: July 19, 2023, 12:05:15 pm »
Though, would be nice to have a spreadsheet with Python as the backend language.  ::)
Or at least to evaluate Python code in each cell, instead of just a spreadsheet formula.

Quote from: https://pyspread.gitlab.io/manual/basic_concepts.html
Everything is accessible
All parts of pyspread are written in Python, therefore all objects can be accessed from within each cell. This is also the case for external modules.


Don't tell them a disaster waiting to happen.

Quote from: https://pyspread.gitlab.io/manual/basic_concepts.html
Security
Since Python expressions are evaluated in pyspread, a pyspread spreadsheet is as powerful as any program. It could harm the system or even send confidential data to third persons over the Internet.
The risk is the the same that all office applications poese, which is why many provide precautions. The concept in pyspread is that you - the user - are trustworthy and no-one else.


Basic Concepts | pyspread
 
The following users thanked this post: eugene

Offline eugene

  • Frequent Contributor
  • **
  • Posts: 496
  • Country: us
Re: Python used for calculators/converters.
« Reply #14 on: July 19, 2023, 08:33:36 pm »
Everyone should know enough not to run an Excel sheet with macros unless written by someone you know and trust. The same would be true of sheets written for pyspread.
90% of quoted statistics are fictional
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf