Skip to content

Commit

Permalink
Merge pull request #37 from tevorbl/master
Browse files Browse the repository at this point in the history
fixed failure on python 3.11 & other changes
  • Loading branch information
lefakkomies authored Sep 22, 2024
2 parents b1f7aea + e61e4dc commit 4007821
Show file tree
Hide file tree
Showing 30 changed files with 784 additions and 230 deletions.
5 changes: 4 additions & 1 deletion examples/ex_amortized_loan.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
NOTE: currently this example is broken (Sep 2024)
"""
import sys
import numpy as np
Expand All @@ -25,6 +27,7 @@
from pynomo.nomographer import Nomographer
from pynomo.nomo_wrapper import Nomo_Block_Type_5

#np.seterr(all='raise')

# Type 5 contour
def f1(x, u):
Expand Down Expand Up @@ -104,7 +107,7 @@ def f1(x, u):
}

main_params = {
'filename': 'amortized_loan.pdf',
'filename': 'ex_amortized_loan.pdf',
'paper_height': 20.0,
'paper_width': 20.0,
'block_params': [block_1_params, block_2_params],
Expand Down
Empty file modified examples/ex_type5_nomo_1.py
100644 → 100755
Empty file.
11 changes: 5 additions & 6 deletions examples/genus1.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def fw(u,v):
'f': lambda u: 0, # x coordinate
'g': lambda u: offset_u + scale_u*u, # y coordinate
'h': lambda u: 1, # constant
'title': r'$u$',
'title': r'u',
'scale_type': 'linear smart',
'tick_levels': 5,
'tick_text_levels': 3,
Expand All @@ -95,7 +95,7 @@ def fw(u,v):
'f': lambda v: 1,
'g': lambda v: offset_v + scale_v*v,
'h': lambda v: 1,
'title': r'$v$',
'title': r'v',
'scale_type': 'linear smart',
'tick_levels': 5,
'tick_text_levels': 3,
Expand All @@ -109,7 +109,7 @@ def fw(u,v):
'g': lambda w: ( offset_u*scale_v + scale_u*offset_v*w \
- scale_u*scale_v*w**3 ) / (scale_u*w+scale_v),
'h': lambda w: 1,
'title': r'$w$',
'title': r'w',
'title_x_shift': 10,
'scale_type': 'linear smart',
'tick_levels': 5,
Expand Down Expand Up @@ -141,7 +141,7 @@ def fw(u,v):
'function_x': lambda u: middle_axis['f'](u/alt_per_orig),
'function_y': lambda u: middle_axis['g'](u/alt_per_orig),
'align_func': lambda u: u / alt_per_orig,
'title': r'$9w$',
'title': r'9w',
'title_x_shift': 7,
'title_y_shift': -3,
'scale_type': 'linear smart',
Expand All @@ -159,7 +159,7 @@ def fw(u,v):


main_params = {
'filename': 'LC_filter.pdf',
'filename': 'genus1.pdf',

# a4 page, with margins approx 2cm
'paper_height': 25, # units are cm
Expand All @@ -180,7 +180,6 @@ def fw(u,v):

}

main_params['filename'] += '.pdf'
print("printing ", main_params['filename'], " ...")
Nomographer(main_params)

Expand Down
15 changes: 13 additions & 2 deletions nomogen/AJh.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,24 @@

import sys

import inspect
import os

sys.path.insert(0, "..")

import math

from nomogen import Nomogen
from pynomo.nomographer import Nomographer

# get current file name
myfile = os.path.basename(inspect.stack()[0][1]).replace(".py", "")

# alternative with no external dependencies - it works most of the time
# myfile = __name__ == "__main__" and (__file__.endswith(".py") and __file__.replace(".py", "") or "nomogen")
# or __name__,



########################################
#
Expand Down Expand Up @@ -103,13 +114,13 @@ def AJh(L, p):
}

main_params = {
'filename': 'AJH',
'filename': myfile,
'paper_height': 15, # units are cm
'paper_width': 10,
'title_x': 4.5,
'title_y': 1.5,
'title_box_width': 8.0,
'title_str': r'\scriptsize $(1+L)h^2 - Lh(1+p) - {1 \over 3} (1-L)(1+2p) = 0$',
'title_str': r'$ \scriptsize (1+L)h^2 - Lh(1+p) - {1 \over 3} (1-L)(1+2p) = 0$',
'block_params': [block_params0],
'transformations': [('scale paper',)],
'npoints': NN
Expand Down
31 changes: 21 additions & 10 deletions nomogen/AJp.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,25 @@
# nomogen example program

import sys
import math

import inspect
import os

sys.path.insert(0, "..")

from math import *
sys.path.insert(0, "..")

from nomogen import Nomogen
from pynomo.nomographer import Nomographer

# get current file name
myfile = os.path.basename(inspect.stack()[0][1]).replace(".py", "")

# alternative with no external dependencies - it works most of the time
# myfile = __name__ == "__main__" and (__file__.endswith(".py") and __file__.replace(".py", "") or "nomogen")
# or __name__,



########################################
#
Expand Down Expand Up @@ -38,18 +49,18 @@ def AJcheck(L, h, p):
def AJp(L, h):
p = ((1 + L) * h ** 2 - L * h - (1 - L) / 3) / (L * h + 2 * (1 - L) / 3)
# print("result is ", (1+L)*h**2 - L*h*(1+p) - (1-L)*(1+2*p)/3)
if not isclose(AJcheck(L, h, p), 0, abs_tol=1e-10):
if not math.isclose(AJcheck(L, h, p), 0, abs_tol=1e-10):
print("AJp equation failed")
sys.exit("quitting")
return p


Lmin = 0.5;
Lmax = 1.0;
hmin = 0.75;
hmax = 1.0;
pmin = AJp(Lmax, hmin); # <-- this clips the p scale, alternatively pmin = AJp(Lmin, hmin);
pmax = AJp(Lmin, hmax);
Lmin = 0.5
Lmax = 1.0
hmin = 0.75
hmax = 1.0
pmin = AJp(Lmax, hmin) # <-- this clips the p scale, alternatively pmin = AJp(Lmin, hmin)
pmax = AJp(Lmin, hmax)

# print('pmin is ', pmin, ', pmax is ', pmax);

Expand Down Expand Up @@ -106,7 +117,7 @@ def AJp(L, h):
}

main_params = {
'filename': 'AJp',
'filename': myfile,
'paper_height': 10, # units are cm
'paper_width': 10,
'title_x': 5,
Expand Down
69 changes: 52 additions & 17 deletions nomogen/GENERATE_EXAMPLES.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#!/usr/bin/env python3

"""
GENERATE_ALL.py
GENERATE_EXAMPLES.py
Generates example nomographs. Used for testing that software package works.
Copyright (C) 20124 Leif Roschier
Copyright (C) 2024 Leif Roschier
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -19,9 +21,16 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import os
import re
import time
import sys
import subprocess

showPdf = False
for a in sys.argv[1:]:
#print( "arg is ", a )
if a == '-d':
showPdf = True


sys.path.append('../pynomo')
sys.path.append('../pynomo/pynomo')
Expand All @@ -32,21 +41,47 @@
if root == '.':
filelist = files

filelist.remove('GENERATE_EXAMPLES.py')
if 'GENERATE_EXAMPLES.py' in filelist: filelist.remove('GENERATE_EXAMPLES.py')
if 'nomogen.py' in filelist: filelist.remove('nomogen.py')

nr_fails = 0
tic_orig = time.time()
# print filelist

for filename in filelist:
if re.compile(".py").search(filename, 1) is not None:
tic = time.time()
print("************************************")
print("executing %s" % filename)
with open(filename) as f:
code = compile(f.read(), filename, 'exec')
exec(code)
# execfile(filename)
toc = time.time()
print('Took %3.1f s for %s to execute.' % (toc - tic, filename))
print("------------------------------------")
if filename.endswith( ".py" ):
print("\n************************************")
#print( filename )
text = open(filename).read()
if 'Nomographer' in text:
print("executing %s" % filename)
code = compile(text, filename, 'exec')
tic = time.time()
# recover if this test fails
try:
exec(code)
except BaseException as e:
print( "test", filename, "failed -", repr(e) )
nr_fails = nr_fails + 1
toc = time.time()
print('Took %3.1f s for %s to execute.' % (toc - tic, filename))
# execfile(filename)
pdffilename = filename.replace("py", "pdf" )

if showPdf:
import platform
if platform.system() == 'Darwin': # macOS
subprocess.call(('open', pdffilename))
elif platform.system() == 'Windows': # Windows
os.startfile(pdffilename)
else: # linux variants
subprocess.call(('xdg-open', pdffilename))
else:
print( 'file {} is not a nomogram file'.format(filename) )


toc_orig = time.time()
print('%3.1f s has elapsed overall' % (toc_orig - tic_orig))
print( "\nall tests passed" if nr_fails == 0 else
"1 failed test" if nr_fails == 1 else
"{} failed tests".format(nr_fails) )
print('%3.1f s has elapsed overall' % (toc_orig - tic_orig))

27 changes: 19 additions & 8 deletions nomogen/air.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,24 @@

import sys

import inspect
import os

sys.path.insert(0, "..")

import math

from nomogen import Nomogen
from pynomo.nomographer import Nomographer

# get current file name
myfile = os.path.basename(inspect.stack()[0][1]).replace(".py", "")

# alternative with no external dependencies - it works most of the time
# myfile = __name__ == "__main__" and (__file__.endswith(".py") and __file__.replace(".py", "") or "nomogen")
# or __name__,



########################################
#
Expand All @@ -32,15 +43,15 @@ def Q(d, v):
return d * d * v * math.pi / 4


dmin = 0.1;
dmax = 0.3; # metres
vmin = 0.3;
vmax = 4.5; # meters/sec
dmin = 0.1
dmax = 0.3 # metres
vmin = 0.3
vmax = 4.5 # meters/sec

Qmin = Q(dmin, vmin)
Qmax = Q(dmax, vmax)

print('Qmin is ', Qmin, ', Qmax is ', Qmax);
print('Qmin is ', Qmin, ', Qmax is ', Qmax)
###############################################################
#
# nr Chebyshev nodes needed to define the scales
Expand Down Expand Up @@ -94,17 +105,17 @@ def Q(d, v):
}

main_params = {
'filename': 'air',
'filename': myfile,
'paper_height': 10, # units are cm
'paper_width': 10,
'title_x': 2,
'title_y': 9.0,
'title_box_width': 8.0,
'title_str': r'\small $ Q = {\pi \over 4} d^2 v $',
'title_str': r'$ \small Q = {\pi \over 4} d^2 v $',
'extra_texts': [
{'x': 3,
'y': 10,
'text': r'$Air \thinspace flow \thinspace through \thinspace a \thinspace circular \thinspace duct $',
'text': r'Air flow through a circular duct',
'width': 7,
}],
'block_params': [block_params0],
Expand Down
Loading

0 comments on commit 4007821

Please sign in to comment.