Skip to content

Commit

Permalink
pointcalc headless fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrolexa committed Feb 10, 2025
1 parent 9ad4920 commit 38926e8
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 54 deletions.
2 changes: 1 addition & 1 deletion pypsbuilder/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"get_tcapi",
)

__version__ = "2.6.1"
__version__ = "2.6.2"
__author__ = "Ondrej Lexa"
__copyright__ = "© Ondrej Lexa 2016-2025"
__email__ = "[email protected]"
5 changes: 1 addition & 4 deletions pypsbuilder/psclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
# author: Ondrej Lexa
# website: https://github.com/ondrolexa/pypsbuilder

try:
import cPickle as pickle
except ImportError:
import pickle
import pickle
import gzip
import numpy as np
import matplotlib.pyplot as plt
Expand Down
103 changes: 54 additions & 49 deletions pypsbuilder/psexplorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1220,55 +1220,6 @@ def glabel(self, label=False, skiplabels=0, labelfs=6):
f'{ix + 1}: {" ".join(sorted([self.abbr.get(sa, sa) for sa in self.identify(x, y)]))}'
)

def pointcalc(self, label=False, skiplabels=0, labelfs=6):
fig, ax = plt.subplots()
ax.autoscale_view()
self.add_overlay(ax, label=label, skiplabels=skiplabels, fontsize=labelfs)
ax.set_xlim(self.xrange)
ax.set_ylim(self.yrange)
ax.format_coord = self.format_coord
x, y = plt.ginput(1)[0]
plt.close(fig)
k = self.identify(x, y)
if k is not None:
last_inv = 0
for ix, ps in self.sections.items():
# update guesses from closest inv point
dst = sys.float_info.max
for id_inv, inv in ps.invpoints.items():
d2 = (inv._x - x) ** 2 + (inv._y - y) ** 2
if d2 < dst:
dst = d2
id_close = id_inv
if id_close != last_inv and not ps.invpoints[id_close].manual:
self.tc.update_scriptfile(guesses=ps.invpoints[id_close].ptguess())
last_inv = id_close
tcout, ans = self.tc.calc_assemblage(k.difference(self.tc.excess), y, x)
status, res, output = self.tc.parse_logfile()
if res is None:
for ix, ps in self.sections.items():
# update guesses from closest uni line point
dst = sys.float_info.max
for id_uni in self.unilists[ix][k]:
uni = ps.unilines[id_uni]
if not uni.manual:
for vix in list(range(len(uni._x))[uni.used]):
d2 = (uni._x[vix] - x) ** 2 + (uni._y[vix] - y) ** 2
if d2 < dst:
dst = d2
id_close = id_uni
vix_close = vix
self.tc.update_scriptfile(
guesses=ps.unilines[id_close].ptguess(idx=vix_close)
)
tcout, ans = self.tc.calc_assemblage(k.difference(self.tc.excess), y, x)
status, res, output = self.tc.parse_logfile()
if res is None:
print("Calculation failed")
else:
print(output)
return res[0]

def remove_grid_data(self, key, phase, expr):
"""Remove calculated data from grid and mark as failed
Expand Down Expand Up @@ -2769,6 +2720,60 @@ def show_path_modes(self, ptpath, exclude=[], cmap="tab20"):
)
plt.show()

def pointcalc(self, t=None, p=None, label=False, skiplabels=0, labelfs=6, show_output=False):
if t is None or p is None:
fig, ax = plt.subplots()
ax.autoscale_view()
self.add_overlay(ax, label=label, skiplabels=skiplabels, fontsize=labelfs)
ax.set_xlim(self.xrange)
ax.set_ylim(self.yrange)
ax.format_coord = self.format_coord
t, p = plt.ginput(1)[0]
plt.close(fig)
k = self.identify(t, p)
if k is not None:
last_inv = 0
id_close = 0
for ix, ps in self.sections.items():
# update guesses from closest inv point
dst = sys.float_info.max
for id_inv, inv in ps.invpoints.items():
d2 = (inv._x - t) ** 2 + (inv._y - p) ** 2
if d2 < dst:
dst = d2
id_close = id_inv
if id_close != last_inv and not ps.invpoints[id_close].manual:
self.tc.update_scriptfile(guesses=ps.invpoints[id_close].ptguess())
last_inv = id_close
tcout, ans = self.tc.calc_assemblage(k.difference(self.tc.excess), p, t)
status, res, output = self.tc.parse_logfile()
if res is None:
for ix, ps in self.sections.items():
# update guesses from closest uni line point
dst = sys.float_info.max
for id_uni in self.unilists[ix][k]:
uni = ps.unilines[id_uni]
if not uni.manual:
for vix in list(range(len(uni._x))[uni.used]):
d2 = (uni._x[vix] - t) ** 2 + (uni._y[vix] - p) ** 2
if d2 < dst:
dst = d2
id_close = id_uni
vix_close = vix
self.tc.update_scriptfile(
guesses=ps.unilines[id_close].ptguess(idx=vix_close)
)
tcout, ans = self.tc.calc_assemblage(k.difference(self.tc.excess), p, t)
status, res, output = self.tc.parse_logfile()
if res is None:
print("Calculation failed")
else:
if show_output:
print(output)
return res[0]
else:
print(f"No assembplage found at T={t}, p-{p}")


class TXPS(PS):
"""Class to postprocess txbuilder project"""
Expand Down

0 comments on commit 38926e8

Please sign in to comment.