xarray-graph 0.2.3__tar.gz → 0.2.4__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: xarray-graph
3
- Version: 0.2.3
3
+ Version: 0.2.4
4
4
  Summary: PyQt/PySide UI for graphing (x,y) slices of Xarray datasets.
5
5
  Keywords: PyQt,PySide,xarray,graph
6
6
  Home-page: https://github.com/marcel-goldschen-ohm/xarray-graph
@@ -35,7 +35,7 @@ classifiers = [
35
35
  "Programming Language :: Python :: 3.12",
36
36
  "Programming Language :: Python :: 3.13",
37
37
  ]
38
- version = "0.2.3"
38
+ version = "0.2.4"
39
39
 
40
40
  [project.license]
41
41
  text = "MIT"
@@ -153,7 +153,7 @@ class XarrayGraph(QMainWindow):
153
153
  self._notes_edit.setPlainText(self.attrs.get('notes', ''))
154
154
 
155
155
  # populate array math selections
156
- # self._update_array_math_comboboxes()
156
+ self._update_array_math_comboboxes()
157
157
 
158
158
  @property
159
159
  def dims(self) -> list[str]:
@@ -1191,7 +1191,7 @@ class XarrayGraph(QMainWindow):
1191
1191
  self._math_operator_combobox.setSizePolicy(QSizePolicy.Policy.Minimum, QSizePolicy.Policy.Preferred)
1192
1192
 
1193
1193
  self._math_eval_button = QPushButton('Evaluate')
1194
- # self._math_eval_button.clicked.connect(self.eval_array_math)
1194
+ self._math_eval_button.pressed.connect(self.eval_array_math)
1195
1195
 
1196
1196
  math_group = QGroupBox('Array math')
1197
1197
  grid = QGridLayout(math_group)
@@ -1512,13 +1512,6 @@ class XarrayGraph(QMainWindow):
1512
1512
 
1513
1513
  self._control_panel.addWidget(scroll_area)
1514
1514
 
1515
- # def _show_region_context_menu(self, pos: QPoint) -> None:
1516
- # if not hasattr(self, '_region_button_menu'):
1517
- # self._region_button_menu = QMenu()
1518
- # menu = QMenu()
1519
- # menu.addAction('Draw X-axis regions until unchecked', self.clear_regions)
1520
- # menu.exec(self.sender().mapToGlobal(pos))
1521
-
1522
1515
  def _set_region_drawing_mode(self, draw: bool | None = None) -> None:
1523
1516
  if draw is None:
1524
1517
  draw = self._region_button.isChecked()
@@ -1667,57 +1660,48 @@ class XarrayGraph(QMainWindow):
1667
1660
  if isinstance(item, XAxisRegion):
1668
1661
  item.setFontSize(self._textitem_fontsize_spinbox.value())
1669
1662
 
1670
- # def _update_array_math_comboboxes(self) -> None:
1671
- # var_items = []
1672
- # item = self._data_treeview.model().root
1673
- # while item is not None:
1674
- # if item.is_var():
1675
- # var_items += [item.name_from_path(maxchar=100)]
1676
- # item = item.next_depth_first()
1677
- # self._math_lhs_combobox.clear()
1678
- # self._math_rhs_combobox.clear()
1679
- # self._math_lhs_combobox.addItems(var_items)
1680
- # self._math_rhs_combobox.addItems(var_items)
1663
+ def _update_array_math_comboboxes(self) -> None:
1664
+ var_paths = [item.path for item in self._data_treeview.model().root().depth_first() if item.is_var()]
1665
+ for i in range(len(var_paths)):
1666
+ if len(var_paths[i]) > 100:
1667
+ var_paths[i] = '...' + var_paths[i][-97:]
1668
+ self._math_lhs_combobox.clear()
1669
+ self._math_rhs_combobox.clear()
1670
+ self._math_lhs_combobox.addItems(var_paths)
1671
+ self._math_rhs_combobox.addItems(var_paths)
1681
1672
 
1682
- # def eval_array_math(self) -> None:
1683
- # var_items = []
1684
- # item = self._data_treeview.model().root
1685
- # while item is not None:
1686
- # if item.is_var():
1687
- # var_items += [item]
1688
- # item = item.next_depth_first()
1689
- # lhs_item = var_items[self._math_lhs_combobox.currentIndex()]
1690
- # rhs_item = var_items[self._math_rhs_combobox.currentIndex()]
1691
- # lhs: xr.DataArray = lhs_item.node.inherited_data(lhs_item.key)
1692
- # rhs: xr.DataArray = rhs_item.node.inherited_data(rhs_item.key)
1693
- # op = self._math_operator_combobox.currentText()
1694
- # # TODO: limit vars to the intersection of their coords
1695
- # if op == '+':
1696
- # result = lhs + rhs
1697
- # elif op == '-':
1698
- # result = lhs - rhs
1699
- # elif op == '*':
1700
- # result = lhs * rhs
1701
- # elif op == '/':
1702
- # result = lhs / rhs
1703
- # # append result as child of lhs_item
1704
- # # TODO: handle result name collisions
1705
- # result_name = self._math_result_name_edit.text().strip()
1706
- # ds = xr.Dataset(data_vars={result.name: result})
1707
- # result_node = XarrayTreeNode(name=result_name, dataset=ds, parent=lhs_item.node)
1673
+ def eval_array_math(self) -> None:
1674
+ var_items = [item for item in self._data_treeview.model().root().depth_first() if item.is_var()]
1675
+ lhs_item = var_items[self._math_lhs_combobox.currentIndex()]
1676
+ rhs_item = var_items[self._math_rhs_combobox.currentIndex()]
1677
+ lhs: xr.DataArray = lhs_item.node[lhs_item.key]
1678
+ rhs: xr.DataArray = rhs_item.node[rhs_item.key]
1679
+ op = self._math_operator_combobox.currentText()
1680
+ if op == '+':
1681
+ result = lhs + rhs
1682
+ elif op == '-':
1683
+ result = lhs - rhs
1684
+ elif op == '*':
1685
+ result = lhs * rhs
1686
+ elif op == '/':
1687
+ result = lhs / rhs
1688
+ # append result as child of lhs_item
1689
+ result_name = self._math_result_name_edit.text().strip()
1690
+ if result_name == '':
1691
+ result_name = self._math_result_name_edit.placeholderText()
1692
+ result_ds = xr.Dataset(data_vars={result.name: result})
1693
+ result_node = DataTree(name=result_name, data=result_ds, parent=lhs_item.node)
1708
1694
 
1709
- # # update data tree
1710
- # self.data = self.data
1711
-
1712
- # # make sure newly added node is selected and expanded
1713
- # model: XarrayTreeModel = self._data_treeview.model()
1714
- # item: XarrayTreeItem = model.root
1715
- # while item is not None:
1716
- # if item.node is result_node and item.is_var():
1717
- # index: QModelIndex = model.createIndex(item.row(), 0, item)
1718
- # self._data_treeview.selectionModel().select(index, QItemSelectionModel.SelectionFlag.Select | QItemSelectionModel.SelectionFlag.Rows)
1719
- # self._data_treeview.setExpanded(model.parent(index), True)
1720
- # item = item.next_depth_first()
1695
+ # update data tree
1696
+ self.data = self.data
1697
+
1698
+ # make sure newly added fit nodes are selected and expanded
1699
+ model: XarrayTreeModel = self._data_treeview.model()
1700
+ for item in model.root().depth_first():
1701
+ if item.node is result_node and item.is_var():
1702
+ index: QModelIndex = model.createIndex(item.sibling_index, 0, item)
1703
+ self._data_treeview.selectionModel().select(index, QItemSelectionModel.SelectionFlag.Select | QItemSelectionModel.SelectionFlag.Rows)
1704
+ self._data_treeview.setExpanded(model.parent(index), True)
1721
1705
 
1722
1706
  # # @Slot()
1723
1707
  # # def on_axes_item_changed(self):
File without changes
File without changes