Author Topic: Help needed to get this snake to behave.  (Read 330 times)

0 Members and 1 Guest are viewing this topic.

Offline mendip_discoveryTopic starter

  • Frequent Contributor
  • **
  • Posts: 933
  • Country: gb
Help needed to get this snake to behave.
« on: July 03, 2024, 08:21:40 pm »
Using python I am calling a class from another .py file to do some maths. But its adding a V at the end of it. I would like to remove the V. I have tried replace but I keep getting an error,

Code: [Select]
AttributeError                            Traceback (most recent call last)
Cell In[11], line 8
      5 #results.report.expanded(k=2)
      6 #results.expanded(0.9545)
      7 UoM = results.expand(k=2)
----> 8 UoM_sig_digits = Number(UoM, n=2, fmt='decimal').replace('V', '')
      9 UoM_value = UoM_sig_digits
     10 #print(UoM_sig_digits)

AttributeError: 'Number' object has no attribute 'replace'

This is the code I am trying to run,

Code: [Select]
import matplotlib.pyplot as plt
import numpy as np
import suncal
from suncal.common.report import Number

model = suncal.Model('f = V')
model.var('V').measure([10.000070, 10.000069, 10.000069, 10.000069, 10.000069, 10.000069, 10.000069], units='volts').typeb(name='Resolution',dist='uniform', unc=0.5, units='microvolts').typeb(name='Thermal EMF', dist='uniform', unc=0.3*2, units='microvolts').typeb(name='Spec % of reading', unc='0.0035%', k=2, units='volt').typeb(name='Spec % of range', unc='0.0005 %range(10)', k=2, units='volt')
model.calculate_gum()
results = model.calculate_gum()
UoM = results.expand(k=2)
UoM_sig_digits = Number(UoM, n=2, fmt='decimal').replace('V', '')
print(UoM_sig_digits)

I can get it to spit out 0.00035 V but as soon as I try a replace it gets funny. The Number is a class.
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 ledtester

  • Super Contributor
  • ***
  • Posts: 3133
  • Country: us
Re: Help needed to get this snake to behave.
« Reply #1 on: July 03, 2024, 09:43:59 pm »
Quote
AttributeError: 'Number' object has no attribute 'replace'

I would try first converting the Number object to a string and then using the .replace method.

Using the str() function might work, e.g.:

Code: [Select]
UoM_sig_digits = str(Number(UoM, n=2, fmt='decimal')).replace('V', '')

However, I am suspicious of having to convert UoM to a Number in the first place -- what do you get if you convert UoM to a string?

What do you get if you print the type of UoM?

Code: [Select]
    print(type(UoM))

Using the built-in float() function might convert UoM to a float:

Code: [Select]
   print("%.2f" % float(UoM))

Also - it would be very helpful to have the documentation for the suncal module.
« Last Edit: July 03, 2024, 09:48:21 pm by ledtester »
 
The following users thanked this post: mendip_discovery

Offline mendip_discoveryTopic starter

  • Frequent Contributor
  • **
  • Posts: 933
  • Country: gb
Re: Help needed to get this snake to behave.
« Reply #2 on: July 04, 2024, 06:30:05 pm »
So converting to a string was the solution.

UoM type was <class 'pint.Quantity'>
 the other was <class 'suncal.common.report.Number'>

Suncal is from Sandia Labs PSL,
https://github.com/sandialabs/suncal/
which is a handy program for solving Uncertainty and other things.

I got it to work by turning it into a string.

I plan to calculate UoM on the readings I do on the 34401A as I do them on the fly. I Just realised once I know the temp I can also calculate thermal EMF on the fly as well.

Thank you for your help.

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.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf