PyGamLab 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
PyGamLab/Convertos.py ADDED
@@ -0,0 +1,1728 @@
1
+
2
+ '''
3
+ Convertors.py :
4
+
5
+ This module provides converter functions for transforming values between different units of measurement.
6
+
7
+ '''
8
+
9
+ #" IN GOD WE TRUST, ALL OTHERS MUST BRING DATA"
10
+ # -W. Edwards Deming
11
+ #------------------------------------------------------------------------------
12
+ # Copyright 2023 The Gamlab Authors. All Rights Reserved.
13
+ # Licensed under the Apache License, Version 2.0 (the "License");
14
+ # you may not use this file except in compliance with the License.
15
+ # You may obtain a copy of the License at
16
+ # http://www.apache.org/licenses/LICENSE-2.0
17
+ # Unless required by applicable law or agreed to in writing, software
18
+ # distributed under the License is distributed on an "AS IS" BASIS,
19
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
+ # See the License for the specific language governing permissions and
21
+ # limitations under the License.
22
+ #------------------------------------------------------------------------------
23
+
24
+ '''
25
+ The Scientific experimental simulation library
26
+ -------------------------------------------------------------------------------
27
+ Graphen & Advanced Material Laboratory
28
+
29
+ it aimes to provide new scientist to use data,simlation, prepared data
30
+ and Artificial intelligence models.
31
+
32
+ See http://gamlab.aut.ac.ir for complete documentation.
33
+ '''
34
+ __doc__='''
35
+
36
+ @author: Ali Pilehvar Meibody (Alipilehvar1999@gmail.com)
37
+
38
+ 888 888
39
+ .d8888b .d88b. 88888b.d88b. 888 .d88b. 888
40
+ d88P" d88""88b 888 "888 "88b 888 d88""88b 88888PP
41
+ 888 8888 888 888 888 888 888 888 888 888 888 888
42
+ Y88b. 88 Y88..88PP. 888 888 888 888...... Y88..88PP. 888 888
43
+ "Y8888P8 "Y88P8888 888 888 888 888888888 "Y88P8888 88888888
44
+
45
+
46
+ @Director of Gamlab: Professor M. Naderi (Mnaderi@aut.ac.ir)
47
+
48
+ @Graphene Advanced Material Laboratory: https://www.GamLab.Aut.ac.ir
49
+
50
+
51
+ @Co-authors:
52
+ '''
53
+
54
+
55
+
56
+ #baraxesh nis
57
+ def Celsius_To_Kelvin(t):
58
+ T=t+273
59
+ return T
60
+
61
+
62
+
63
+
64
+
65
+ def Square_Meter_To_Square_Cm(b):
66
+
67
+ '''
68
+ Parameters
69
+ ----------
70
+ b: int
71
+ Square_meter
72
+ -------
73
+ c : int
74
+ Square_Cm
75
+ '''
76
+ c =b*10000
77
+ return c
78
+
79
+ def Square_Cm_To_Square_meter(a):
80
+
81
+ '''
82
+ Parameters
83
+ ----------
84
+ a : int
85
+ Square_Cm
86
+ -------
87
+ c : int
88
+ Square_Meter
89
+ '''
90
+ c=a/10000
91
+ return c
92
+
93
+
94
+
95
+ def Meter_To_MilliMeter(meter):
96
+ '''
97
+
98
+
99
+ Parameters
100
+ ----------
101
+ meter : int
102
+ enter the length in meter.
103
+
104
+ Returns
105
+ -------
106
+ milimeter : int
107
+ This function converts meter into milimeter.
108
+
109
+ '''
110
+ milimeter=meter*1000
111
+ return milimeter
112
+
113
+
114
+
115
+ def MilliMeter_To_Meter (milimeter):
116
+ '''
117
+
118
+
119
+ Parameters
120
+ ----------
121
+ milimeter : int
122
+ enter the length in milimeter.
123
+
124
+ Returns
125
+ -------
126
+ meter : int
127
+ This function converts milimeter into meter.
128
+
129
+ '''
130
+ meter=milimeter/1000
131
+ return meter
132
+
133
+
134
+
135
+ def Cubic_Meter_To_Liter(number_in_Cubic_Meter):
136
+ '''
137
+ This function converts cubic meters to liters.
138
+
139
+ Parameters
140
+ ----------
141
+ number_in_Cubic_Meter : int or float
142
+ Number per cubic meter unit.
143
+ Liter : int or float
144
+ Number per liter unit.
145
+
146
+ '''
147
+ Liter= number_in_Cubic_Meter*1000
148
+ return Liter
149
+
150
+
151
+ def Liter_To_Cubic_Meter(number_in_Liter):
152
+ '''
153
+ This function converts liters to cubic meters.
154
+
155
+ Parameters
156
+ ----------
157
+ number_in_Liter : int or float
158
+ Number per liter unit.
159
+ Cubic_Meter : int or float
160
+ Number per cubic meter unit.
161
+
162
+ '''
163
+ Cubic_Meter= number_in_Liter/1000
164
+ return (Cubic_Meter)
165
+
166
+
167
+ # Celcius_To_Kelvin
168
+ def Celcius_To_Kelvin (Celcius):
169
+
170
+
171
+ '''
172
+ This function is used to convert celcius to kelvin
173
+ The tempreture in celcius is different from the tempreture in kelvin by 273.15
174
+
175
+ '''
176
+ Kelvin = Celcius + 273.15
177
+ return Kelvin
178
+
179
+
180
+
181
+
182
+ #Kelvin_to_celcius
183
+ def Kelvin_to_Celcius (Kelvin):
184
+ '''
185
+ This function is used to convert kelvin to celcius
186
+ The tempreture in celcius is different from the tempreture in kelvin by 273.15
187
+
188
+ '''
189
+ Celcius = Kelvin - 273.15
190
+ return Celcius
191
+
192
+
193
+
194
+
195
+ def Foot_Pound_To_Newton(Foot_Pounds):
196
+ '''
197
+ # This Conventor convert ft-lbs to Nm
198
+
199
+
200
+ Parameters
201
+ ----------
202
+ Foot_Pound : a unit of torque equal to the force of 1 lb acting perpendicularly to
203
+ an axis of rotation at a distance of 1 foot.(ft-lbs)
204
+
205
+ Returns
206
+ -------
207
+ Newton_Meters : The newton-metre is the unit of torque.(Nm)
208
+
209
+
210
+ '''
211
+
212
+
213
+ global Newton_Meters
214
+ Newton_Meters=Foot_Pounds*1.3558
215
+ return Newton_Meters
216
+
217
+ def Newton_To_Foot_Pound(Newton_Meters):
218
+ '''
219
+ # This Conventor convert Nm to ft-lbs
220
+
221
+ Parameters
222
+ ----------
223
+ Newton_Meters : The newton-metre is the unit of torque.(Nm)
224
+
225
+ Returns
226
+ -------
227
+ Foot_Pound : a unit of torque equal to the force of 1 lb acting perpendicularly to
228
+ an axis of rotation at a distance of 1 foot.(ft-lbs)
229
+
230
+ '''
231
+
232
+ global Foot_Pound
233
+ Foot_Pound=Newton_Meters*0.7376
234
+ return Foot_Pound
235
+
236
+
237
+ def Fabric_GSM_to_GLM(Fabric_Weight,Fabric_Width):
238
+ '''
239
+ This function converts fabric weight in GSM unit to GLM unit.
240
+
241
+ Parameters
242
+ ----------
243
+ Fabric_Weight : int or float
244
+ fabric weight per GSM.
245
+ Fabric_Width : int or float
246
+ width of fabric per inches.
247
+ Fabric_GLM : int or float
248
+ Result.
249
+
250
+ '''
251
+ Fabric_GLM=(Fabric_Weight*Fabric_Width)/39.37
252
+ return Fabric_GLM
253
+
254
+
255
+
256
+ def Kilogeram_Per_Cubic_Meter_To_Pounds_Per_Cubic_Inch(KgPerCubicMeter):
257
+ L=KgPerCubicMeter*0.0000361273
258
+ return L
259
+ def Pounds_Per_Cubic_Inch_To_Kilogeram_Per_Cubic_Meter(LbPerCubicInch):
260
+ Kg=LbPerCubicInch*27679.9
261
+ return Kg
262
+
263
+
264
+
265
+
266
+ def KiloMeter_To_LightYear(km):
267
+ ly = km / 9460730472801.1
268
+ return ly
269
+
270
+
271
+
272
+ def LightYear_To_KiloMeter(ly):
273
+ km = ly * 9460730472801.1
274
+ return km
275
+
276
+
277
+
278
+ def Micrometer_To_Nanometer(micrometer=1):
279
+ """
280
+ converting micrometer to nanometer
281
+
282
+ Parameters
283
+ ----------
284
+ micrometer : float,dimension
285
+ DESCRIPTION. The default is 1.
286
+
287
+ Returns
288
+ -------
289
+ Nanometer : float,dimension
290
+ unit(nm)
291
+
292
+ """
293
+ Micrometer=float(input ('how many Micrometer?'))
294
+ Nanometer=Micrometer*1000
295
+ print(Micrometer,'Micrometer=',Nanometer,'Nanometer.')
296
+ return Nanometer
297
+
298
+
299
+ def Nanometer_To_Micrometer(nanometer=1):
300
+ """
301
+ converting nanometer to micrometer
302
+
303
+ Parameters
304
+ ----------
305
+ nanometer : float,dimension
306
+ unit (nm)
307
+ DESCRIPTION. The default is 1.
308
+
309
+ Returns
310
+ -------
311
+ Micrometer : float,dimension
312
+
313
+
314
+ """
315
+ Nanometer=float(input ('how many nanometer?'))
316
+ Micrometer=Nanometer/1000
317
+ print(Nanometer,'nanometer=',Micrometer,'micrometer.')
318
+ return Micrometer
319
+
320
+ #PART.2.6
321
+
322
+ def Minute_To_Second (Minute):
323
+ '''
324
+ This function converts minutes to seconds
325
+
326
+ Parameters
327
+ ----------
328
+ Minute : int
329
+ units of time in minute
330
+
331
+ Returns
332
+
333
+ int
334
+ Minute_to_Second
335
+
336
+ '''
337
+
338
+
339
+ return (Minute*60)
340
+
341
+
342
+ def Second_To_Minute (Second):
343
+ '''
344
+ This function converts seconds to minutes
345
+ Parameters
346
+ ----------
347
+ Second : int
348
+ units of time in seconds
349
+
350
+ Returns
351
+ int
352
+
353
+ Second_to_Minute
354
+ '''
355
+
356
+
357
+ return (Second/60)
358
+
359
+
360
+
361
+ def Megapascal_To_Pascal(Megapascal):
362
+ '''
363
+ #This Conventor Convert Megapascal to Pascal
364
+
365
+ Parameters
366
+ ----------
367
+ Megapascal : 1 Megapascal equals 1,000,000 Pascals.
368
+
369
+
370
+ Returns
371
+ -------
372
+ Pascal : the unit of pressure or stress in SI.
373
+ '''
374
+
375
+ Pascal=Megapascal/1000000
376
+ return Pascal
377
+
378
+ def Pascal_To_Megapascal(Pascal):
379
+ '''
380
+ # This Conventor Convert Pascal to Megapascal
381
+
382
+ Parameters
383
+ ----------
384
+ Pascal : the unit of pressure or stress in SI.
385
+
386
+ Returns
387
+ -------
388
+ Megapascal : 1 Megapascal equals 1,000,000 Pascals.
389
+
390
+ '''
391
+
392
+ Megapascal=1000000*Pascal
393
+ return Megapascal
394
+
395
+
396
+
397
+ def Newton_TO_Pound_Force(Newton):
398
+ # 1 Pound_Force = 4.448221619 New
399
+
400
+
401
+ Pound_Force = Newton / 4.448221619
402
+ '''
403
+ #It converts the Force from Newton to Pound_Force.
404
+
405
+ Parameters:
406
+ ----------
407
+
408
+ Newton : float
409
+ Unit musst be newton(N).
410
+
411
+ '''
412
+ return Pound_Force
413
+
414
+
415
+ def Pound_Force_To_Newton(Pound_Force):
416
+
417
+ Newton = Pound_Force * 4.448221619
418
+ '''
419
+ It converts the Force from Pound_Force to Newton.
420
+
421
+ Parameters:
422
+ ----------
423
+
424
+ Pound_Force : float
425
+ Unit musst be lb.
426
+
427
+ '''
428
+
429
+ return Newton
430
+
431
+
432
+
433
+
434
+
435
+
436
+ def Yarn_Count_Converter(Yarn_Count, Current_System='tex', Desired_System='den'):
437
+ '''
438
+ This function converts yarn count values in different systems.
439
+
440
+ Parameters
441
+ ----------
442
+ Yarn_Count : int or float
443
+ Number of yarn count.
444
+ Current_System : str, optional
445
+ Current yarn count system. The default is 'tex'.
446
+ Desired_System : str, optional
447
+ Expected yarn count system. The default is 'den'.
448
+ Yarn_Count : int or float
449
+ Result.
450
+
451
+ '''
452
+ sys1=str(Current_System).lower()
453
+ sys2=str(Desired_System).lower()
454
+
455
+ if sys1=='tex' and sys2=='dtex':
456
+ Yarn_Count=Yarn_Count*10
457
+ return Yarn_Count
458
+
459
+ elif sys1=='tex' and sys2=='den':
460
+ Yarn_Count=Yarn_Count*9
461
+ return Yarn_Count
462
+
463
+ elif sys1=='tex' and sys2=='nm':
464
+ Yarn_Count=1000/Yarn_Count
465
+ return Yarn_Count
466
+
467
+ elif sys1=='tex' and sys2=='ne':
468
+ Yarn_Count=590.5/Yarn_Count
469
+ return Yarn_Count
470
+
471
+ elif sys1=='tex' and sys2=='nw':
472
+ Yarn_Count=885.8/Yarn_Count
473
+ return Yarn_Count
474
+
475
+ elif sys1=='dtex' and sys2=='tex':
476
+ Yarn_Count=Yarn_Count*0.1
477
+ return Yarn_Count
478
+
479
+ elif sys1=='dtex' and sys2=='den':
480
+ Yarn_Count=Yarn_Count*0.9
481
+ return Yarn_Count
482
+
483
+ elif sys1=='dtex' and sys2=='ne':
484
+ Yarn_Count=5905.4/Yarn_Count
485
+ return Yarn_Count
486
+
487
+ elif sys1=='dtex' and sys2=='nw':
488
+ Yarn_Count=8858/Yarn_Count
489
+ return Yarn_Count
490
+
491
+ elif sys1=='dtex' and sys2=='nm':
492
+ Yarn_Count=10000/Yarn_Count
493
+ return Yarn_Count
494
+
495
+ elif sys1=='den' and sys2=='tex':
496
+ Yarn_Count=Yarn_Count/9
497
+ return Yarn_Count
498
+
499
+ elif sys1=='den' and sys2=='dtex':
500
+ Yarn_Count=Yarn_Count/0.9
501
+ return Yarn_Count
502
+
503
+ elif sys1=='den' and sys2=='nm':
504
+ Yarn_Count=9000/Yarn_Count
505
+ return Yarn_Count
506
+
507
+ elif sys1=='den' and sys2=='ne':
508
+ Yarn_Count=5314.9/Yarn_Count
509
+ return Yarn_Count
510
+
511
+ elif sys1=='den' and sys2=='nw':
512
+ Yarn_Count=7972/Yarn_Count
513
+ return Yarn_Count
514
+
515
+ elif sys1=='ne' and sys2=='tex':
516
+ Yarn_Count=590.6/Yarn_Count
517
+ return Yarn_Count
518
+
519
+ elif sys1=='ne' and sys2=='dtex':
520
+ Yarn_Count=5906/Yarn_Count
521
+ return Yarn_Count
522
+
523
+ elif sys1=='ne' and sys2=='den':
524
+ Yarn_Count=5315/Yarn_Count
525
+ return Yarn_Count
526
+
527
+ elif sys1=='ne' and sys2=='nm':
528
+ Yarn_Count=1.693*Yarn_Count
529
+ return Yarn_Count
530
+
531
+ elif sys1=='ne' and sys2=='nw':
532
+ Yarn_Count=1.5*Yarn_Count
533
+ return Yarn_Count
534
+
535
+ elif sys1=='nm' and sys2=='tex':
536
+ Yarn_Count=1000/Yarn_Count
537
+ return Yarn_Count
538
+
539
+ elif sys1=='nm' and sys2=='dtex':
540
+ Yarn_Count=10000/Yarn_Count
541
+ return Yarn_Count
542
+
543
+ elif sys1=='nm' and sys2=='den':
544
+ Yarn_Count=9000/Yarn_Count
545
+ return Yarn_Count
546
+
547
+ elif sys1=='nm' and sys2=='ne':
548
+ Yarn_Count=0.59*Yarn_Count
549
+ return Yarn_Count
550
+
551
+ elif sys1=='nm' and sys2=='nw':
552
+ Yarn_Count=0.89*Yarn_Count
553
+ return Yarn_Count
554
+
555
+ elif sys1=='nw' and sys2=='tex':
556
+ Yarn_Count=885.8/Yarn_Count
557
+ return Yarn_Count
558
+
559
+ elif sys1=='nw' and sys2=='dtex':
560
+ Yarn_Count=8858/Yarn_Count
561
+ return Yarn_Count
562
+
563
+ elif sys1=='nw' and sys2=='den':
564
+ Yarn_Count=7972/Yarn_Count
565
+ return Yarn_Count
566
+
567
+ elif sys1=='nw' and sys2=='nm':
568
+ Yarn_Count=1.129*Yarn_Count
569
+ return Yarn_Count
570
+
571
+ elif sys1=='nw' and sys2=='ne':
572
+ Yarn_Count=(2/3)*Yarn_Count
573
+ return Yarn_Count
574
+
575
+ else:
576
+
577
+ print("Your inputs are invalid!")
578
+
579
+
580
+
581
+
582
+ def Coulomb_To_Electron_volt( coulomb):
583
+ electron_volt = coulomb * 6.24e18
584
+ return electron_volt
585
+
586
+ def Electron_volt_To_Coulomb( electron_volt):
587
+ coulomb = electron_volt / 6.24e18
588
+ return coulomb
589
+
590
+
591
+
592
+
593
+ def Atmosphere_To_Pascal (atm):
594
+ Pa= float(atm * 101325)
595
+ return Pa
596
+
597
+
598
+ #vice versa___________________
599
+
600
+ def Pascal_To_Atmosphere (Pa):
601
+ atm = float(Pa / 101325)
602
+ return atm
603
+
604
+
605
+
606
+
607
+ def Percentages_To_Moles(total, percentages):
608
+ # Define the molecular weight of the composite mixture
609
+ molar_weight = {'TEGDMA': 156.27, 'BIS_GMA': 512.67, 'UDMA': 398.48,
610
+ 'Silica dioxide': 60.08, 'Barium silicate': 233.39, 'Zirconium dioxide': 123.22
611
+ }
612
+
613
+ # Calculate the moles of each material
614
+ moles = {}
615
+ for material, percent in percentages.items():
616
+ moles[material] = (percent / 100) * (total / molar_weight[material])
617
+
618
+ return moles
619
+
620
+
621
+
622
+
623
+ def Moles_To_Percentages(total, moles):
624
+ # Define the molecular weight of the composite mixture
625
+ molar_weight = {'TEGDMA': 156.27, 'BIS_GMA': 512.67, 'UDMA': 398.48,
626
+ 'Silica dioxide': 60.08, 'Barium silicate': 233.39, 'Zirconium dioxide': 123.22
627
+ }
628
+
629
+ # Calculate the percentages of each material
630
+ percentages = {}
631
+ for material, mole in moles.items():
632
+ percentages[material] = (mole * molar_weight[material] / total) * 100
633
+
634
+ return percentages
635
+
636
+
637
+
638
+ #convertor1
639
+ def Radians_To_Degrees (num):
640
+ '''
641
+
642
+ This function is used for convert radians to degree
643
+ '''
644
+ degree=num*180/math.pi
645
+ return degree
646
+
647
+ #convertor2
648
+ def Weightpercent_To_ppm (num):
649
+ '''
650
+
651
+ This function is used for convert weight percent to ppm
652
+ '''
653
+ ppm= num*10000
654
+ return ppm
655
+
656
+
657
+
658
+
659
+ def Fahrenheit_To_Centigrade(F):
660
+ '''
661
+ This function is usef for convert Fahrenheit_to_Centigrade
662
+ '''
663
+ C=F-32/18
664
+ return C
665
+
666
+
667
+
668
+ def Centigrade_To_Fahrenheit(C):
669
+ '''
670
+ This function is usef for Centigrade_to_Fahrenheit
671
+ '''
672
+ F=C*1.8+32
673
+ return F
674
+
675
+
676
+
677
+
678
+
679
+ def Pascal_to_mmHg(p):
680
+ '''
681
+ This function convert pascal to mmHg
682
+
683
+ Parameters
684
+ ----------
685
+ p : float
686
+ pressure (Pa).
687
+
688
+ Returns
689
+ -------
690
+ None.
691
+
692
+ '''
693
+ mmHg=p/2
694
+ return mmHg
695
+
696
+
697
+ def Kmph_To_Mps(V1):
698
+ """
699
+ This function is uesd to convert Kilometer per hour to meter per second
700
+ """
701
+
702
+ V2=V1/3.6
703
+ return V2
704
+
705
+
706
+ def Mps_To_Kmph(V1):
707
+ """
708
+ This function is used to convert meter per second to kilometer per hour
709
+ """
710
+ V2=V1*3.6
711
+ return V2
712
+
713
+
714
+ def Pascal_To_CmHg(P1):
715
+ """
716
+ This function is used to convert Pascal to centimeter mercury
717
+ """
718
+ P2=P1/1333.22
719
+ return P2
720
+
721
+
722
+ def CmHg_To_Pascal(P1):
723
+ """
724
+ This function is used to convert mercury centimeter to Pascal
725
+ """
726
+ P2=P1*1333.22
727
+ return P2
728
+
729
+
730
+ def Sec_To_Hour(t):
731
+ t=t/3600
732
+ return t
733
+
734
+ def Hour_To_Sec(t):
735
+ t=t*3600
736
+ return t
737
+
738
+
739
+
740
+
741
+ def Electronvolt_To_Joule(e_v):
742
+ Joule=e_v*1.6022e-19
743
+ return Joule
744
+
745
+
746
+ def Degree_To_Radian(deg):
747
+ '''
748
+ This function converts values of angle from degree to radian.
749
+ '''
750
+ rad=deg*3.141592653589793/180
751
+ return rad
752
+
753
+
754
+
755
+
756
+ def Centigrade_to_kelvin(value):
757
+ return value + 237
758
+
759
+
760
+
761
+
762
+
763
+ def Foot_To_Mile (ft):
764
+
765
+ mi=0.000189393939*ft
766
+
767
+ return mi
768
+
769
+ def Mile_To_Foot (mi):
770
+
771
+ ft=5280*mi
772
+
773
+ return ft
774
+
775
+
776
+ def Byte_To_Kilobyte (b):
777
+
778
+ kb=0.0009765625*b
779
+
780
+ return kb
781
+
782
+ def Kilobyte_To_Byte (kb):
783
+
784
+ b=1024*kb
785
+
786
+ return b
787
+
788
+
789
+
790
+ def Celesius_To_Farenheit(a):##a= temperature in celsius
791
+ b=(1.8*a)+32##b=temperature in farenheit
792
+ return b
793
+
794
+ def Farenheit_To_Celsius(a):##a=temperature in farenheit
795
+ b=(a-32)/1.8##b=temperature in celsius
796
+ return b
797
+
798
+
799
+ def Ppm_To_Percent(a):##a=ion concentration in ppm in brine
800
+ b=a/10000##b=ion percent in brine
801
+ return b
802
+
803
+
804
+ def Percent_To_Ppm(a):##a=ion percent in brine
805
+ b=a*10000##b=ion concentration in ppm in brine
806
+ return b
807
+
808
+
809
+
810
+ def Viscosity_To_Poise(pa_s):
811
+ '''Pa_s=(float) the viscosity in Pa.S
812
+
813
+
814
+ Return:
815
+ float: Viscosity in poise
816
+ '''
817
+
818
+
819
+ poise=pa_s*10
820
+ return poise
821
+
822
+
823
+ def Viscosity_To_Pas(poise):
824
+ '''poise=(float) the viscosity in poise
825
+
826
+
827
+ Return:
828
+ float: Viscosity in pas
829
+ '''
830
+
831
+
832
+ pa_s=poise/10
833
+ return pa_s
834
+
835
+
836
+
837
+
838
+
839
+ def Meter_To_inch(m):
840
+ In=m*0.0254
841
+ return In
842
+
843
+
844
+ def Inch_To_Meter(In):
845
+ m=In/0.0254
846
+ return m
847
+
848
+
849
+
850
+ def Joules_To_Calories(Joules):
851
+ Calories=Joules/4.2
852
+ return Calories
853
+
854
+ def Calories_To_Joules(Calories):
855
+ Joules=Calories*4.2
856
+ return Joules
857
+
858
+
859
+
860
+ def Torr_To_Pascal(torr):
861
+
862
+ '''
863
+ this function converts torr to pascal
864
+ '''
865
+
866
+
867
+ pa = (torr*760)/101325
868
+
869
+ return pa
870
+
871
+ def Pascal_To_Torr(pa):
872
+
873
+ '''
874
+ this function converts pascal to torr
875
+ '''
876
+
877
+ torr = (pa*101325)/760
878
+
879
+ return torr
880
+
881
+
882
+
883
+ def Miller_To_Millerbrove(u,v,w):
884
+
885
+ '''
886
+ this function converts miller index to miller_brove index
887
+
888
+ parameters: (miller indexes)
889
+ ---------------------------
890
+ 1. u: int
891
+ Intersection with axis a1
892
+
893
+ 2. v: int
894
+ Intersection with axis a2
895
+
896
+ 3. w: int
897
+ Intersection with axis z
898
+
899
+ Returns --> (miller_brove indexes)
900
+
901
+ 1. l: int
902
+ Intersection with axis a1
903
+
904
+ 2. m: int
905
+ Intersection with axis a2
906
+
907
+ 3. n: int
908
+ Intersection with axis a3
909
+
910
+ 4. o: int
911
+ Intersection with axis z
912
+
913
+ '''
914
+
915
+ l = ((2*u)-v)/3
916
+ m = ((2*v)-u)/3
917
+ n = (-1)*(l+m)
918
+ o = w
919
+
920
+ return l,m,n,o
921
+
922
+
923
+ def Millerbrove_To_Miller(l,m,n,o):
924
+
925
+ '''
926
+ this function converts miller_brove index to miller index
927
+
928
+ Parameters: (miller_brove indexes)
929
+ -----------------------------------
930
+ 1. l: int
931
+ Intersection with axis a1
932
+
933
+ 2. m: int
934
+ Intersection with axis a2
935
+
936
+ 3. n: int
937
+ Intersection with axis a3
938
+
939
+ 4. o: int
940
+ Intersection with axis z
941
+
942
+ Returns --> (miller indexes)
943
+
944
+ 1. u: int
945
+ Intersection with axis a1
946
+
947
+ 2. v: int
948
+ Intersection with axis a2
949
+
950
+ 3. w: int
951
+ Intersection with axis z
952
+ '''
953
+ u = (2*m) + l
954
+ v = (2*l) + m
955
+ w = o
956
+
957
+
958
+ return u,v,w
959
+
960
+
961
+
962
+
963
+ def Calories_To_Joules(cal):
964
+ """
965
+
966
+ Parameters
967
+ ----------
968
+ cal : float
969
+ Calories.
970
+
971
+ Returns
972
+ -------
973
+ J : float
974
+ Converts calories to joules.
975
+
976
+ """
977
+
978
+ J=4.184*cal
979
+ return J
980
+
981
+ def Joules_To_Calories(J):
982
+ """
983
+
984
+ Parameters
985
+ ----------
986
+ J : float
987
+ Joules.
988
+
989
+ Returns
990
+ -------
991
+ cal : float
992
+ Converts joules to calories.
993
+
994
+ """
995
+
996
+ cal=J/4.184
997
+ return cal
998
+
999
+ def Bar_To_Pascal(bar):
1000
+ """
1001
+
1002
+ Parameters
1003
+ ----------
1004
+ bar : float
1005
+ bar.
1006
+
1007
+ Returns
1008
+ -------
1009
+ Pa : float
1010
+ Converts bar to pascal.
1011
+
1012
+ """
1013
+
1014
+ Pa=bar*(10**(-5))
1015
+ return Pa
1016
+
1017
+ def Pascal_To_Bar(Pa):
1018
+ """
1019
+
1020
+ Parameters
1021
+ ----------
1022
+ Pa : float
1023
+ Pascal.
1024
+
1025
+ Returns
1026
+ -------
1027
+ bar : float
1028
+ Converts pascal to bar.
1029
+
1030
+ """
1031
+
1032
+ bar=Pa*(10**5)
1033
+ return bar
1034
+
1035
+
1036
+ import math
1037
+
1038
+
1039
+
1040
+
1041
+ def Meter_To_Angstrom(m):
1042
+ return m*1e10
1043
+
1044
+ def Angstrom_To_Meter(A):
1045
+ return A*1e-10
1046
+
1047
+ def Milimeter_To_Angstrom(mm):
1048
+ return mm*1e7
1049
+
1050
+ def Angstrom_To_Milimeter(A):
1051
+ return A*1e-7
1052
+
1053
+ def Nanometer_To_Angstrom(nm):
1054
+ return nm*10
1055
+
1056
+ def Angstrom_To_Nanometer(A):
1057
+ return A/10
1058
+
1059
+ def Micrometer_To_Angstrom(um):
1060
+ return um*10000
1061
+
1062
+ def Angstrom_To_Micrometer(A):
1063
+ return A/10000
1064
+
1065
+
1066
+
1067
+
1068
+ def Kilometer_Per_Hour_To_Meter_Per_Second(kph):
1069
+ '''
1070
+ Parameters
1071
+ ----------
1072
+ kph: float
1073
+ number in kilometer per hour
1074
+ mps: float
1075
+ number in meter per second
1076
+ '''
1077
+ mps=kph*3.6
1078
+ return mps
1079
+
1080
+
1081
+
1082
+
1083
+
1084
+ def Meter_Per_Second_To_Kilometer_Per_Hour(mps):
1085
+ '''
1086
+ Parameters
1087
+ ----------
1088
+ mps: float
1089
+ number in meter per second
1090
+ kph: float
1091
+ number in kilometer per hour
1092
+ '''
1093
+ kph=mps/3.6
1094
+ return kph
1095
+
1096
+
1097
+ def Kg_To_Ton(Kg):
1098
+ Ton=1000*Kg
1099
+ return Ton
1100
+
1101
+
1102
+
1103
+
1104
+
1105
+
1106
+
1107
+ def Joules_Per_Minute_To_Kilowatt(Joules_Per_Minute):
1108
+ '''
1109
+
1110
+ Parameters
1111
+ ----------
1112
+ Joules_Per_Minute : float
1113
+ number per Joules unit.
1114
+
1115
+ Returns
1116
+ -------
1117
+ Kilowatt : float
1118
+ number per Kilowatt unit.
1119
+
1120
+ '''
1121
+ Kilowatt=(Joules_Per_Minute)/60000
1122
+ return Kilowatt
1123
+
1124
+
1125
+
1126
+ def Inch_To_Centimeter(Inch):
1127
+ '''
1128
+ Parameters
1129
+ ----------
1130
+ Inch : float or int
1131
+ ne inch is equal to 2.54 centimeters.
1132
+ number per Inch unit.
1133
+
1134
+ Returns
1135
+ -------
1136
+ Centimeter : float
1137
+ number per Centimeter unit.
1138
+
1139
+ '''
1140
+ Centimeter=2.54*Inch
1141
+ return Centimeter
1142
+
1143
+
1144
+ def Gram_To_Mole(g,MW):
1145
+ '''
1146
+ This function calaculates the eqivalent amount of substance of a compound in mole(s) base on mass in gram(s).
1147
+
1148
+ Parameters
1149
+ ----------
1150
+ g : float
1151
+ g is the mass of a compound in gram(s).
1152
+ MW : float
1153
+ MW is the Molecular weight of a compound (gram/mol).
1154
+
1155
+ Returns
1156
+ -------
1157
+ Mole : float
1158
+ Mole is the eqivalent amount of substance of a compound in mole(s).
1159
+
1160
+ '''
1161
+ Mole = g / MW
1162
+ return Mole
1163
+
1164
+
1165
+
1166
+ def Mole_To_Gram(mol,MW):
1167
+ '''
1168
+ This function calaculates the eqivalent mass of a compound in gram(s) base on amount of substance in mole(s).
1169
+
1170
+ Parameters
1171
+ ----------
1172
+ mol : float
1173
+ mol is the eqivalent amount of substance of a compound in mole(s).
1174
+ MW : float
1175
+ MW is the Molecular weight of a compound (gram/mole).
1176
+
1177
+ Returns
1178
+ -------
1179
+ g : float
1180
+ g is the eqivalent mass in of a compound in in gram(s).
1181
+
1182
+ '''
1183
+ g = mol * MW
1184
+ return g
1185
+
1186
+
1187
+ def Hertz_To_Rpm(a,/):
1188
+ '''
1189
+ A converter machine to convert frequency in Hertz(Hz) to frequency in rpm.
1190
+ Parameters
1191
+ ----------
1192
+ a : int or float
1193
+ frequency, Hertz(Hz).
1194
+
1195
+ Returns
1196
+ b : int or float
1197
+ frequency, revolution per minute (rpm)
1198
+ '''
1199
+ b=a*60
1200
+ return b
1201
+
1202
+
1203
+
1204
+ def Rpm_To_Hertz(b,/):
1205
+ '''
1206
+ A converter machine to convert frequency in rpm to frequency in Herta(Hz).
1207
+ Parameters
1208
+ ----------
1209
+ b : int or float
1210
+ frequency, revolution per minute (rpm).
1211
+
1212
+ Returns
1213
+ a, frequency, Hertz(Hz)
1214
+
1215
+ '''
1216
+ a=b/60
1217
+ return a
1218
+
1219
+
1220
+
1221
+
1222
+ def Annual_To_Monthly_Loss(annual_loss):
1223
+ '''
1224
+
1225
+
1226
+ Parameters
1227
+ ----------
1228
+ annual_loss : int
1229
+ the annual loss of an Economic enterprise.
1230
+
1231
+ Returns
1232
+ -------
1233
+
1234
+ the monthly loss of an Economic enterprise.
1235
+
1236
+ '''
1237
+ if not str(annual_loss).isdigit():
1238
+ print ('error! bad parameter!')
1239
+ return int(annual_loss/12)
1240
+
1241
+
1242
+
1243
+
1244
+
1245
+
1246
+
1247
+
1248
+
1249
+ def Molarity_To_Normality(Molarity,n):
1250
+ '''
1251
+
1252
+
1253
+ Parameters
1254
+ ----------
1255
+ Molarity : float
1256
+ n : int
1257
+ Number of moles.
1258
+
1259
+ Returns
1260
+ -------
1261
+ Normality.
1262
+
1263
+ '''
1264
+ Normality=Molarity*n
1265
+ return(Normality)
1266
+
1267
+
1268
+ def Normality_To_Molarity(Normality,n):
1269
+ '''
1270
+
1271
+
1272
+ Parameters
1273
+ ----------
1274
+ Normality : float
1275
+ n : int
1276
+ Number of moles.
1277
+
1278
+ Returns
1279
+ -------
1280
+ Molarity.
1281
+
1282
+ '''
1283
+ Molarity=Normality/n
1284
+ return(Molarity)
1285
+
1286
+
1287
+
1288
+ def Mass_To_Mole(Mass,Molar_Mass):
1289
+ '''
1290
+
1291
+
1292
+ Parameters
1293
+ ----------
1294
+ Mass : float
1295
+ The mass of substance(g).
1296
+ Molar_Mass : float
1297
+ The mass of one mole of substance (g/mol).
1298
+
1299
+ Returns
1300
+ -------
1301
+ Mole: int
1302
+
1303
+ '''
1304
+ Mole=Mass/Molar_Mass
1305
+ return(Mole)
1306
+
1307
+
1308
+
1309
+ def Mole_To_Mass(Mole,Molar_Mass):
1310
+ '''
1311
+
1312
+
1313
+ Parameters
1314
+ ----------
1315
+ Mole : int
1316
+
1317
+ Molar_Mass : float
1318
+ The mass of one mole of substance (g/mol).
1319
+
1320
+ Returns
1321
+ -------
1322
+ Mass (g) : Float.
1323
+
1324
+ '''
1325
+ Mass=Mole*Molar_Mass
1326
+ return(Mass)
1327
+
1328
+
1329
+
1330
+ def Kg_To_Lbm(Kg):
1331
+ Lbm=0.4535*Kg
1332
+ return Lbm
1333
+
1334
+
1335
+ def Lbm_To_Kg(Lbm):
1336
+ Kg=2.20462*Lbm
1337
+ return Kg
1338
+
1339
+
1340
+ def Psi_To_Mpa(Num_Psi,/):
1341
+ '''
1342
+
1343
+
1344
+ Parameters
1345
+ ----------
1346
+
1347
+ Num_Psi : float
1348
+ Psi = Pounds force per square inch
1349
+
1350
+ Returns
1351
+ -------
1352
+ Mpa : float
1353
+ Megapascals=Newton per square millimetre
1354
+
1355
+ '''
1356
+ Mpa=Num_Psi*(1/145)
1357
+ return Mpa
1358
+
1359
+
1360
+
1361
+ def Mpa_To_Psi(Num_Mpa,/):
1362
+ '''
1363
+
1364
+
1365
+ Parameters
1366
+ ----------
1367
+
1368
+ Num_Mpa : float
1369
+ Megapascals=Newton per square millimetre
1370
+
1371
+ Returns
1372
+ -------
1373
+ Psi : float
1374
+ Psi=Pounds force per square inch
1375
+
1376
+ '''
1377
+ Psi=Num_Mpa*145
1378
+ return Psi
1379
+
1380
+
1381
+ def Decimal_To_Binary(Num_dec):
1382
+ Bin=0
1383
+ i=0
1384
+ while Num_dec!=0:
1385
+ r=Num_dec%2
1386
+ Bin=Bin+(r*(10**i))
1387
+ Num_dec=Num_dec//2
1388
+ i=i+1
1389
+ return Bin
1390
+
1391
+
1392
+
1393
+ def Pound_To_Kilogram(number_in_pound):
1394
+ '''
1395
+ This function converts the desired number from pounds to kilograms.
1396
+
1397
+ Parameters
1398
+ ----------
1399
+ number_in_pound : int
1400
+ Number per pound.
1401
+
1402
+ Returns
1403
+ -------
1404
+ kilogram : int
1405
+ Number per kilogram.
1406
+
1407
+ '''
1408
+ kilogram=number_in_pound/2.2046
1409
+ return kilogram
1410
+
1411
+ def Kilogram_To_Pound(number_in_kilogram):
1412
+ '''
1413
+ This function converts the desired number from kilograms to pounds.
1414
+
1415
+ Parameters
1416
+ ----------
1417
+ number_in_kilogram : int
1418
+ Number per kilogram.
1419
+
1420
+ Returns
1421
+ -------
1422
+ pound : int
1423
+ Number per pound.
1424
+
1425
+ '''
1426
+ pound=number_in_kilogram*2.2046
1427
+ return pound
1428
+
1429
+
1430
+
1431
+
1432
+ def Centimeter_per_Minute_To_Meter_per_Hour_Welding_Speed_Converter(Centimeter_per_Minute):
1433
+ '''
1434
+ This function converts the Welding Speed from Centimeter per Minute to Meter per Hour.
1435
+
1436
+ Parameters
1437
+ ----------
1438
+ Centimeter_per_Minute : float
1439
+ Centimeter_per_Minute is a unit for welding speed.
1440
+
1441
+ Returns
1442
+ -------
1443
+ Meter_per_Hour is a unit for welding speed.
1444
+
1445
+ '''
1446
+
1447
+ Meter_per_Hour=Centimeter_per_Minute/1.7
1448
+ return Meter_per_Hour
1449
+
1450
+
1451
+ def Meter_per_Hour_To_Centimeter_per_Minute_Welding_Speed_Converter(Meter_per_Hour):
1452
+ '''
1453
+ This function converts the Welding Speed from Meter per Hour to Centimeter per Minute.
1454
+
1455
+ Parameters
1456
+ ----------
1457
+ Meter_per_Hour : float
1458
+ Meter_per_Hour is a unit for welding speed.
1459
+
1460
+ Returns
1461
+ -------
1462
+ Centimeter_per_Minute is a unit for welding speed.
1463
+
1464
+ '''
1465
+
1466
+ Centimeter_per_Minute=Meter_per_Hour*1.7
1467
+ return Centimeter_per_Minute
1468
+
1469
+
1470
+ def Liter_per_Minute_To_CC_per_Second_Welding_Gas_Flow_Rate_Converter(Liter_per_Minute):
1471
+ '''
1472
+ This function converts the Welding Gas Flow Rate from Liter per Minute to CC per Second.
1473
+
1474
+ Parameters
1475
+ ----------
1476
+ Liter_per_Minute : float
1477
+ Liter_per_Minute is a unit for gas flow rate in welding.
1478
+
1479
+ Returns
1480
+ -------
1481
+ CC_per_Second is a unit for gas flow rate in welding.
1482
+
1483
+ '''
1484
+
1485
+ CC_per_Second=Liter_per_Minute*16.67
1486
+ return CC_per_Second
1487
+
1488
+
1489
+
1490
+ def CC_per_Second_To_Liter_per_Minute_Welding_Gas_Flow_Rate_Converter(CC_per_Second):
1491
+ '''
1492
+ This function converts the Welding Gas Flow Rate from CC per Second to Liter per Minute.
1493
+
1494
+ Parameters
1495
+ ----------
1496
+ CC_per_Second : float
1497
+ CC_per_Second is a unit for gas flow rate in welding.
1498
+
1499
+ Returns
1500
+ -------
1501
+ Liter_per_Minute is a unit for gas flow rate in welding.
1502
+
1503
+ '''
1504
+
1505
+ Liter_per_Minute=CC_per_Second/16.67
1506
+ return Liter_per_Minute
1507
+
1508
+
1509
+ def Mm_year_To_Mils_year(milpy):
1510
+ """
1511
+ 1mm/yr=39.37mpy
1512
+ Crossion rate
1513
+ """
1514
+ mpy=39.37*milpy
1515
+ return mpy
1516
+
1517
+ def Mils_year_To_Mm_year(mpy):
1518
+ """
1519
+ 1mm/yr=39.37mpy
1520
+ Crossion rate
1521
+ """
1522
+ Mm_year=mpy/39.37
1523
+ return Mm_year
1524
+
1525
+
1526
+
1527
+ def Rockwell_To_Brinell(hrb):
1528
+ '''
1529
+ convert Rockwell hardness (HRB) to Brinell hardness (HB).
1530
+
1531
+ Parameters
1532
+
1533
+ hrb : float
1534
+ hardness in Rochwell scale.
1535
+
1536
+ Returns float: Hardness in Brinell scale.
1537
+
1538
+
1539
+ '''
1540
+ hb = (hrb * 5.0) + 50
1541
+ return hb
1542
+
1543
+
1544
+
1545
+ def Brinell_To_Rockwell(hb):
1546
+ '''
1547
+ convert Brinell hardness (HB) to Rockwell hardness (HRB)
1548
+
1549
+ Parameters
1550
+ ----------
1551
+ hb : float
1552
+ hardness in Brinell scale.
1553
+
1554
+ Returns float: Hardness in Rochwell scale.
1555
+
1556
+
1557
+ '''
1558
+
1559
+ hrb = (hb - 50) / 5.0
1560
+ return hrb
1561
+
1562
+
1563
+
1564
+ def Horsepower_To_Watt (Horsepower):
1565
+ '''
1566
+
1567
+
1568
+ Parameters
1569
+ ----------
1570
+ Horsepower : float
1571
+ give number in horsepower.
1572
+
1573
+ Returns
1574
+ -------
1575
+ watt : float
1576
+ return your number in watt.
1577
+
1578
+ '''
1579
+ Watt = "{:e}".format(Horsepower * 745.7)
1580
+ return Watt
1581
+
1582
+
1583
+
1584
+ def Watt_To_Horsepower (Watt) :
1585
+ '''
1586
+
1587
+
1588
+ Parameters
1589
+ ----------
1590
+ Watt : float
1591
+ give number in Watt.
1592
+
1593
+ Returns
1594
+ -------
1595
+ Horsepower : float
1596
+ return number in Horsepower.
1597
+
1598
+ '''
1599
+ Horsepower = "{:e}".format(Watt / 745.7)
1600
+ return Horsepower
1601
+
1602
+
1603
+
1604
+ def Force_CGS_To_SI (Force_in_CGS):
1605
+ '''
1606
+
1607
+
1608
+ Parameters
1609
+ ----------
1610
+ Force_In_CGS : float
1611
+ give your force value in CGS system.
1612
+
1613
+ Returns
1614
+ -------
1615
+ SI : float
1616
+ return your force value in SI system.
1617
+
1618
+ '''
1619
+
1620
+ SI = "{:e}".format(Force_in_CGS * 1e-5)
1621
+ return SI
1622
+
1623
+ def Force_SI_To_CGS (Force_in_SI) :
1624
+ '''
1625
+
1626
+
1627
+ Parameters
1628
+ ----------
1629
+ Force_in_SI : float
1630
+ give your force value in SI system.
1631
+
1632
+ Returns
1633
+ -------
1634
+ CGS : float
1635
+ return your force value in CGS system.
1636
+
1637
+ '''
1638
+
1639
+ CGS = "{:e}".format(Force_in_SI * 1e+5)
1640
+ return CGS
1641
+
1642
+
1643
+ def Nanometer_To_Angstrom(Nanometer_value):
1644
+
1645
+ '''
1646
+ This function converts Nanometers to Angstroms.
1647
+ 1 Nanometer(nm)= 10 Angstroms(Å)
1648
+
1649
+ Parameters
1650
+ ----------
1651
+ Nanometer_value: int or float
1652
+ Value in Nanometers(nm).
1653
+
1654
+ Returns
1655
+ -------
1656
+ Angstrom_value: int or float
1657
+ Equivalent value in Angstroms(Å).
1658
+
1659
+ '''
1660
+ Angstrom_value= Nanometer_value*10
1661
+ return Angstrom_value
1662
+
1663
+ def Angstrom_To_Nanometer(Angstrom_value):
1664
+
1665
+ '''
1666
+ This function converts Angstroms to Nanometers.
1667
+
1668
+ Parameters
1669
+ ----------
1670
+ Angstrom_value: int or Float
1671
+ Value in angstroms (Å).
1672
+
1673
+ Returns
1674
+ -------
1675
+ Nanometer_value: int or Float
1676
+ Equivalent value in Nanometers (nm).
1677
+
1678
+ '''
1679
+ Nanometer_value= Angstrom_value/10
1680
+ return Nanometer_value
1681
+
1682
+
1683
+ def Current_density_To_mpy(Current_density,density,masschange,valency):
1684
+ """
1685
+
1686
+
1687
+ Parameters
1688
+ ----------
1689
+ Current_density : float
1690
+ Current density .(microA/cm2)
1691
+ density : float
1692
+ Material Density (g/cm3).
1693
+ masschange : float
1694
+ amount of matter already corroded (g)
1695
+ valency : intiger
1696
+ How positive is the charge of the Material
1697
+
1698
+ Returns
1699
+ -------
1700
+ corrosion rate in mpy
1701
+
1702
+
1703
+ """
1704
+ corrosion_rate_mpy=Current_density*1e-6*31536000*(1/density)*masschange*400*(1/(valency*96500))
1705
+ return corrosion_rate_mpy
1706
+
1707
+ def Mpy_To_current_density(mpy,density,masschange,valency):
1708
+ """
1709
+
1710
+
1711
+ Parameters
1712
+ ----------
1713
+ mpy : float
1714
+ corrosion rate in mpy
1715
+ density : float
1716
+ materails density
1717
+ masschange : float
1718
+ amount of mass corroded
1719
+ valency : int
1720
+ how positive is the charge
1721
+
1722
+ Returns
1723
+ -------
1724
+ Current density
1725
+
1726
+ """
1727
+ Current_density=(mpy*1e6*density*2.5*valency*96500)/(31536000*masschange*1000)
1728
+ return Current_density