scitex 2.5.0__py3-none-any.whl → 2.7.3__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.
- scitex/__init__.py +25 -10
- scitex/__main__.py +2 -1
- scitex/__version__.py +1 -1
- scitex/_optional_deps.py +13 -20
- scitex/ai/__init__.py +5 -0
- scitex/ai/_gen_ai/_Anthropic.py +3 -1
- scitex/ai/_gen_ai/_BaseGenAI.py +3 -2
- scitex/ai/_gen_ai/_DeepSeek.py +1 -1
- scitex/ai/_gen_ai/_Google.py +3 -2
- scitex/ai/_gen_ai/_Llama.py +4 -2
- scitex/ai/_gen_ai/_OpenAI.py +3 -1
- scitex/ai/_gen_ai/_PARAMS.py +1 -0
- scitex/ai/_gen_ai/_Perplexity.py +3 -1
- scitex/ai/_gen_ai/__init__.py +1 -0
- scitex/ai/_gen_ai/_format_output_func.py +3 -1
- scitex/ai/classification/CrossValidationExperiment.py +8 -14
- scitex/ai/classification/examples/timeseries_cv_demo.py +128 -112
- scitex/ai/classification/reporters/_BaseClassificationReporter.py +2 -0
- scitex/ai/classification/reporters/_ClassificationReporter.py +30 -45
- scitex/ai/classification/reporters/_MultiClassificationReporter.py +8 -11
- scitex/ai/classification/reporters/_SingleClassificationReporter.py +126 -182
- scitex/ai/classification/reporters/__init__.py +1 -1
- scitex/ai/classification/reporters/reporter_utils/_Plotter.py +213 -119
- scitex/ai/classification/reporters/reporter_utils/__init__.py +28 -36
- scitex/ai/classification/reporters/reporter_utils/aggregation.py +125 -143
- scitex/ai/classification/reporters/reporter_utils/data_models.py +128 -120
- scitex/ai/classification/reporters/reporter_utils/reporting.py +507 -340
- scitex/ai/classification/reporters/reporter_utils/storage.py +4 -1
- scitex/ai/classification/reporters/reporter_utils/validation.py +141 -154
- scitex/ai/classification/timeseries/_TimeSeriesBlockingSplit.py +204 -129
- scitex/ai/classification/timeseries/_TimeSeriesCalendarSplit.py +215 -171
- scitex/ai/classification/timeseries/_TimeSeriesMetadata.py +17 -17
- scitex/ai/classification/timeseries/_TimeSeriesSlidingWindowSplit.py +67 -143
- scitex/ai/classification/timeseries/_TimeSeriesSlidingWindowSplit_v01-not-using-n_splits.py +67 -143
- scitex/ai/classification/timeseries/_TimeSeriesStrategy.py +12 -13
- scitex/ai/classification/timeseries/_TimeSeriesStratifiedSplit.py +231 -144
- scitex/ai/classification/timeseries/__init__.py +2 -4
- scitex/ai/classification/timeseries/_normalize_timestamp.py +3 -0
- scitex/ai/clustering/_pca.py +0 -1
- scitex/ai/clustering/_umap.py +1 -2
- scitex/ai/feature_extraction/__init__.py +10 -8
- scitex/ai/feature_extraction/vit.py +0 -1
- scitex/ai/feature_selection/feature_selection.py +3 -8
- scitex/ai/metrics/_calc_conf_mat.py +2 -0
- scitex/ai/metrics/_calc_feature_importance.py +3 -7
- scitex/ai/metrics/_calc_pre_rec_auc.py +5 -5
- scitex/ai/metrics/_calc_roc_auc.py +4 -2
- scitex/ai/metrics/_calc_seizure_prediction_metrics.py +35 -20
- scitex/ai/metrics/_calc_silhouette_score.py +1 -3
- scitex/ai/optim/Ranger_Deep_Learning_Optimizer/ranger/ranger.py +0 -3
- scitex/ai/optim/Ranger_Deep_Learning_Optimizer/ranger/ranger2020.py +0 -3
- scitex/ai/optim/Ranger_Deep_Learning_Optimizer/ranger/ranger913A.py +0 -3
- scitex/ai/optim/_optimizers.py +1 -1
- scitex/ai/plt/__init__.py +6 -1
- scitex/ai/plt/_plot_feature_importance.py +1 -3
- scitex/ai/plt/_plot_learning_curve.py +9 -24
- scitex/ai/plt/_plot_optuna_study.py +4 -3
- scitex/ai/plt/_plot_pre_rec_curve.py +9 -15
- scitex/ai/plt/_plot_roc_curve.py +6 -8
- scitex/ai/plt/_stx_conf_mat.py +121 -122
- scitex/ai/sampling/undersample.py +3 -2
- scitex/ai/sklearn/__init__.py +2 -2
- scitex/ai/training/_LearningCurveLogger.py +23 -10
- scitex/ai/utils/_check_params.py +0 -1
- scitex/audio/README.md +52 -0
- scitex/audio/__init__.py +384 -0
- scitex/audio/__main__.py +129 -0
- scitex/audio/_tts.py +334 -0
- scitex/audio/engines/__init__.py +44 -0
- scitex/audio/engines/base.py +275 -0
- scitex/audio/engines/elevenlabs_engine.py +143 -0
- scitex/audio/engines/gtts_engine.py +162 -0
- scitex/audio/engines/pyttsx3_engine.py +131 -0
- scitex/audio/mcp_server.py +757 -0
- scitex/benchmark/__init__.py +15 -25
- scitex/benchmark/benchmark.py +124 -117
- scitex/benchmark/monitor.py +117 -107
- scitex/benchmark/profiler.py +61 -58
- scitex/bridge/__init__.py +110 -0
- scitex/bridge/_helpers.py +149 -0
- scitex/bridge/_plt_vis.py +529 -0
- scitex/bridge/_protocol.py +283 -0
- scitex/bridge/_stats_plt.py +261 -0
- scitex/bridge/_stats_vis.py +265 -0
- scitex/browser/__init__.py +0 -2
- scitex/browser/auth/__init__.py +0 -0
- scitex/browser/auth/google.py +16 -11
- scitex/browser/automation/CookieHandler.py +2 -3
- scitex/browser/collaboration/__init__.py +3 -0
- scitex/browser/collaboration/auth_helpers.py +3 -1
- scitex/browser/collaboration/collaborative_agent.py +2 -0
- scitex/browser/collaboration/interactive_panel.py +2 -2
- scitex/browser/collaboration/shared_session.py +20 -11
- scitex/browser/collaboration/standard_interactions.py +1 -0
- scitex/browser/core/BrowserMixin.py +12 -30
- scitex/browser/core/ChromeProfileManager.py +9 -24
- scitex/browser/debugging/_browser_logger.py +15 -25
- scitex/browser/debugging/_failure_capture.py +9 -2
- scitex/browser/debugging/_highlight_element.py +15 -6
- scitex/browser/debugging/_show_grid.py +5 -6
- scitex/browser/debugging/_sync_session.py +4 -3
- scitex/browser/debugging/_test_monitor.py +14 -5
- scitex/browser/debugging/_visual_cursor.py +46 -35
- scitex/browser/interaction/click_center.py +4 -3
- scitex/browser/interaction/click_with_fallbacks.py +7 -10
- scitex/browser/interaction/close_popups.py +79 -66
- scitex/browser/interaction/fill_with_fallbacks.py +8 -8
- scitex/browser/pdf/__init__.py +3 -1
- scitex/browser/pdf/click_download_for_chrome_pdf_viewer.py +11 -10
- scitex/browser/pdf/detect_chrome_pdf_viewer.py +3 -6
- scitex/browser/remote/CaptchaHandler.py +109 -96
- scitex/browser/remote/ZenRowsAPIClient.py +91 -97
- scitex/browser/remote/ZenRowsBrowserManager.py +138 -112
- scitex/browser/stealth/HumanBehavior.py +4 -9
- scitex/browser/stealth/StealthManager.py +11 -26
- scitex/capture/__init__.py +17 -17
- scitex/capture/__main__.py +2 -3
- scitex/capture/capture.py +23 -51
- scitex/capture/cli.py +14 -39
- scitex/capture/gif.py +5 -9
- scitex/capture/mcp_server.py +7 -20
- scitex/capture/session.py +4 -3
- scitex/capture/utils.py +18 -53
- scitex/cli/__init__.py +1 -1
- scitex/cli/cloud.py +158 -116
- scitex/cli/config.py +224 -0
- scitex/cli/main.py +41 -40
- scitex/cli/scholar.py +60 -27
- scitex/cli/security.py +14 -20
- scitex/cli/web.py +87 -90
- scitex/cli/writer.py +51 -45
- scitex/cloud/__init__.py +14 -11
- scitex/cloud/_matplotlib_hook.py +6 -6
- scitex/config/README.md +313 -0
- scitex/config/{PriorityConfig.py → _PriorityConfig.py} +114 -17
- scitex/config/_ScitexConfig.py +319 -0
- scitex/config/__init__.py +41 -9
- scitex/config/_paths.py +325 -0
- scitex/config/default.yaml +81 -0
- scitex/context/_suppress_output.py +2 -3
- scitex/db/_BaseMixins/_BaseBackupMixin.py +3 -1
- scitex/db/_BaseMixins/_BaseBatchMixin.py +3 -1
- scitex/db/_BaseMixins/_BaseBlobMixin.py +3 -1
- scitex/db/_BaseMixins/_BaseImportExportMixin.py +1 -3
- scitex/db/_BaseMixins/_BaseIndexMixin.py +3 -1
- scitex/db/_BaseMixins/_BaseMaintenanceMixin.py +1 -3
- scitex/db/_BaseMixins/_BaseQueryMixin.py +3 -1
- scitex/db/_BaseMixins/_BaseRowMixin.py +3 -1
- scitex/db/_BaseMixins/_BaseTableMixin.py +3 -1
- scitex/db/_BaseMixins/_BaseTransactionMixin.py +1 -3
- scitex/db/_BaseMixins/__init__.py +1 -1
- scitex/db/__init__.py +9 -1
- scitex/db/__main__.py +8 -21
- scitex/db/_check_health.py +15 -31
- scitex/db/_delete_duplicates.py +7 -4
- scitex/db/_inspect.py +22 -38
- scitex/db/_inspect_optimized.py +89 -85
- scitex/db/_postgresql/_PostgreSQL.py +0 -1
- scitex/db/_postgresql/_PostgreSQLMixins/_BlobMixin.py +3 -1
- scitex/db/_postgresql/_PostgreSQLMixins/_ConnectionMixin.py +1 -3
- scitex/db/_postgresql/_PostgreSQLMixins/_ImportExportMixin.py +1 -3
- scitex/db/_postgresql/_PostgreSQLMixins/_MaintenanceMixin.py +1 -4
- scitex/db/_postgresql/_PostgreSQLMixins/_QueryMixin.py +3 -3
- scitex/db/_postgresql/_PostgreSQLMixins/_RowMixin.py +3 -1
- scitex/db/_postgresql/_PostgreSQLMixins/_TransactionMixin.py +1 -3
- scitex/db/_postgresql/__init__.py +1 -1
- scitex/db/_sqlite3/_SQLite3.py +2 -4
- scitex/db/_sqlite3/_SQLite3Mixins/_ArrayMixin.py +11 -12
- scitex/db/_sqlite3/_SQLite3Mixins/_ArrayMixin_v01-need-_hash-col.py +19 -14
- scitex/db/_sqlite3/_SQLite3Mixins/_BatchMixin.py +3 -1
- scitex/db/_sqlite3/_SQLite3Mixins/_BlobMixin.py +7 -7
- scitex/db/_sqlite3/_SQLite3Mixins/_ColumnMixin.py +118 -111
- scitex/db/_sqlite3/_SQLite3Mixins/_ConnectionMixin.py +8 -10
- scitex/db/_sqlite3/_SQLite3Mixins/_GitMixin.py +17 -45
- scitex/db/_sqlite3/_SQLite3Mixins/_ImportExportMixin.py +1 -3
- scitex/db/_sqlite3/_SQLite3Mixins/_IndexMixin.py +3 -1
- scitex/db/_sqlite3/_SQLite3Mixins/_QueryMixin.py +3 -4
- scitex/db/_sqlite3/_SQLite3Mixins/_RowMixin.py +9 -9
- scitex/db/_sqlite3/_SQLite3Mixins/_TableMixin.py +18 -11
- scitex/db/_sqlite3/_SQLite3Mixins/__init__.py +1 -0
- scitex/db/_sqlite3/__init__.py +1 -1
- scitex/db/_sqlite3/_delete_duplicates.py +13 -11
- scitex/decorators/__init__.py +29 -4
- scitex/decorators/_auto_order.py +43 -43
- scitex/decorators/_batch_fn.py +12 -6
- scitex/decorators/_cache_disk.py +8 -9
- scitex/decorators/_cache_disk_async.py +8 -7
- scitex/decorators/_combined.py +19 -13
- scitex/decorators/_converters.py +16 -3
- scitex/decorators/_deprecated.py +32 -22
- scitex/decorators/_numpy_fn.py +18 -4
- scitex/decorators/_pandas_fn.py +17 -5
- scitex/decorators/_signal_fn.py +17 -3
- scitex/decorators/_torch_fn.py +32 -15
- scitex/decorators/_xarray_fn.py +23 -9
- scitex/dev/_analyze_code_flow.py +0 -2
- scitex/dev/plt/__init__.py +272 -0
- scitex/dev/plt/plot_mpl_axhline.py +28 -0
- scitex/dev/plt/plot_mpl_axhspan.py +28 -0
- scitex/dev/plt/plot_mpl_axvline.py +28 -0
- scitex/dev/plt/plot_mpl_axvspan.py +28 -0
- scitex/dev/plt/plot_mpl_bar.py +29 -0
- scitex/dev/plt/plot_mpl_barh.py +29 -0
- scitex/dev/plt/plot_mpl_boxplot.py +28 -0
- scitex/dev/plt/plot_mpl_contour.py +31 -0
- scitex/dev/plt/plot_mpl_contourf.py +31 -0
- scitex/dev/plt/plot_mpl_errorbar.py +30 -0
- scitex/dev/plt/plot_mpl_eventplot.py +28 -0
- scitex/dev/plt/plot_mpl_fill.py +30 -0
- scitex/dev/plt/plot_mpl_fill_between.py +31 -0
- scitex/dev/plt/plot_mpl_hexbin.py +28 -0
- scitex/dev/plt/plot_mpl_hist.py +28 -0
- scitex/dev/plt/plot_mpl_hist2d.py +28 -0
- scitex/dev/plt/plot_mpl_imshow.py +29 -0
- scitex/dev/plt/plot_mpl_pcolormesh.py +31 -0
- scitex/dev/plt/plot_mpl_pie.py +29 -0
- scitex/dev/plt/plot_mpl_plot.py +29 -0
- scitex/dev/plt/plot_mpl_quiver.py +31 -0
- scitex/dev/plt/plot_mpl_scatter.py +28 -0
- scitex/dev/plt/plot_mpl_stackplot.py +31 -0
- scitex/dev/plt/plot_mpl_stem.py +29 -0
- scitex/dev/plt/plot_mpl_step.py +29 -0
- scitex/dev/plt/plot_mpl_violinplot.py +28 -0
- scitex/dev/plt/plot_sns_barplot.py +29 -0
- scitex/dev/plt/plot_sns_boxplot.py +29 -0
- scitex/dev/plt/plot_sns_heatmap.py +28 -0
- scitex/dev/plt/plot_sns_histplot.py +29 -0
- scitex/dev/plt/plot_sns_kdeplot.py +29 -0
- scitex/dev/plt/plot_sns_lineplot.py +31 -0
- scitex/dev/plt/plot_sns_scatterplot.py +29 -0
- scitex/dev/plt/plot_sns_stripplot.py +29 -0
- scitex/dev/plt/plot_sns_swarmplot.py +29 -0
- scitex/dev/plt/plot_sns_violinplot.py +29 -0
- scitex/dev/plt/plot_stx_bar.py +29 -0
- scitex/dev/plt/plot_stx_barh.py +29 -0
- scitex/dev/plt/plot_stx_box.py +28 -0
- scitex/dev/plt/plot_stx_boxplot.py +28 -0
- scitex/dev/plt/plot_stx_conf_mat.py +28 -0
- scitex/dev/plt/plot_stx_contour.py +31 -0
- scitex/dev/plt/plot_stx_ecdf.py +28 -0
- scitex/dev/plt/plot_stx_errorbar.py +30 -0
- scitex/dev/plt/plot_stx_fill_between.py +31 -0
- scitex/dev/plt/plot_stx_fillv.py +28 -0
- scitex/dev/plt/plot_stx_heatmap.py +28 -0
- scitex/dev/plt/plot_stx_image.py +28 -0
- scitex/dev/plt/plot_stx_imshow.py +28 -0
- scitex/dev/plt/plot_stx_joyplot.py +28 -0
- scitex/dev/plt/plot_stx_kde.py +28 -0
- scitex/dev/plt/plot_stx_line.py +28 -0
- scitex/dev/plt/plot_stx_mean_ci.py +28 -0
- scitex/dev/plt/plot_stx_mean_std.py +28 -0
- scitex/dev/plt/plot_stx_median_iqr.py +28 -0
- scitex/dev/plt/plot_stx_raster.py +28 -0
- scitex/dev/plt/plot_stx_rectangle.py +28 -0
- scitex/dev/plt/plot_stx_scatter.py +29 -0
- scitex/dev/plt/plot_stx_shaded_line.py +29 -0
- scitex/dev/plt/plot_stx_violin.py +28 -0
- scitex/dev/plt/plot_stx_violinplot.py +28 -0
- scitex/dict/_DotDict.py +15 -19
- scitex/dict/_flatten.py +1 -0
- scitex/dict/_listed_dict.py +1 -0
- scitex/dict/_pop_keys.py +1 -0
- scitex/dict/_replace.py +1 -0
- scitex/dict/_safe_merge.py +1 -0
- scitex/dict/_to_str.py +2 -3
- scitex/dsp/__init__.py +13 -4
- scitex/dsp/_crop.py +3 -1
- scitex/dsp/_detect_ripples.py +3 -1
- scitex/dsp/_modulation_index.py +3 -1
- scitex/dsp/_time.py +3 -1
- scitex/dsp/_wavelet.py +0 -1
- scitex/dsp/example.py +0 -5
- scitex/dsp/filt.py +4 -0
- scitex/dsp/utils/__init__.py +4 -1
- scitex/dsp/utils/pac.py +3 -3
- scitex/dt/_normalize_timestamp.py +4 -1
- scitex/errors.py +3 -6
- scitex/etc/__init__.py +1 -1
- scitex/fig/__init__.py +352 -0
- scitex/{vis → fig}/backend/__init__.py +3 -3
- scitex/{vis/backend/export.py → fig/backend/_export.py} +1 -1
- scitex/{vis/backend/parser.py → fig/backend/_parser.py} +2 -4
- scitex/{vis/backend/render.py → fig/backend/_render.py} +1 -1
- scitex/{vis → fig}/canvas.py +16 -4
- scitex/{vis → fig}/editor/__init__.py +0 -0
- scitex/{vis → fig}/editor/_dearpygui_editor.py +450 -304
- scitex/fig/editor/_defaults.py +300 -0
- scitex/fig/editor/_edit.py +751 -0
- scitex/{vis → fig}/editor/_flask_editor.py +8 -8
- scitex/{vis → fig}/editor/_mpl_editor.py +63 -48
- scitex/{vis → fig}/editor/_qt_editor.py +391 -160
- scitex/{vis → fig}/editor/_tkinter_editor.py +146 -89
- scitex/fig/editor/flask_editor/__init__.py +21 -0
- scitex/fig/editor/flask_editor/_bbox.py +1276 -0
- scitex/fig/editor/flask_editor/_core.py +624 -0
- scitex/fig/editor/flask_editor/_plotter.py +601 -0
- scitex/fig/editor/flask_editor/_renderer.py +739 -0
- scitex/{vis/editor/flask_editor/utils.py → fig/editor/flask_editor/_utils.py} +13 -14
- scitex/{vis → fig}/editor/flask_editor/templates/__init__.py +6 -6
- scitex/fig/editor/flask_editor/templates/_html.py +834 -0
- scitex/fig/editor/flask_editor/templates/_scripts.py +3136 -0
- scitex/fig/editor/flask_editor/templates/_styles.py +1346 -0
- scitex/{vis → fig}/io/__init__.py +18 -6
- scitex/fig/io/_bundle.py +973 -0
- scitex/{vis/io/canvas.py → fig/io/_canvas.py} +9 -5
- scitex/{vis/io/data.py → fig/io/_data.py} +14 -10
- scitex/{vis/io/directory.py → fig/io/_directory.py} +7 -4
- scitex/{vis/io/export.py → fig/io/_export.py} +16 -13
- scitex/{vis/io/load.py → fig/io/_load.py} +2 -2
- scitex/{vis/io/panel.py → fig/io/_panel.py} +22 -14
- scitex/{vis/io/save.py → fig/io/_save.py} +1 -1
- scitex/{vis → fig}/model/__init__.py +8 -8
- scitex/{vis/model/annotations.py → fig/model/_annotations.py} +3 -5
- scitex/{vis/model/axes.py → fig/model/_axes.py} +2 -2
- scitex/{vis/model/figure.py → fig/model/_figure.py} +1 -1
- scitex/{vis/model/guides.py → fig/model/_guides.py} +2 -2
- scitex/{vis/model/plot.py → fig/model/_plot.py} +3 -5
- scitex/{vis/model/plot_types.py → fig/model/_plot_types.py} +0 -0
- scitex/{vis/model/styles.py → fig/model/_styles.py} +1 -1
- scitex/{vis → fig}/utils/__init__.py +3 -3
- scitex/{vis/utils/defaults.py → fig/utils/_defaults.py} +1 -2
- scitex/{vis/utils/validate.py → fig/utils/_validate.py} +3 -9
- scitex/gen/_DimHandler.py +6 -6
- scitex/gen/__init__.py +5 -1
- scitex/gen/_deprecated_close.py +1 -0
- scitex/gen/_deprecated_start.py +5 -3
- scitex/gen/_detect_environment.py +44 -41
- scitex/gen/_detect_notebook_path.py +51 -47
- scitex/gen/_embed.py +1 -1
- scitex/gen/_get_notebook_path.py +81 -62
- scitex/gen/_inspect_module.py +0 -1
- scitex/gen/_norm.py +16 -7
- scitex/gen/_norm_cache.py +78 -65
- scitex/gen/_print_config.py +0 -3
- scitex/gen/_src.py +2 -3
- scitex/gen/_title_case.py +3 -2
- scitex/gen/_to_even.py +8 -8
- scitex/gen/_transpose.py +3 -3
- scitex/gen/misc.py +0 -3
- scitex/gists/_SigMacro_processFigure_S.py +2 -2
- scitex/gists/_SigMacro_toBlue.py +2 -2
- scitex/gists/__init__.py +4 -1
- scitex/git/_branch.py +19 -11
- scitex/git/_clone.py +23 -15
- scitex/git/_commit.py +10 -12
- scitex/git/_init.py +15 -38
- scitex/git/_remote.py +9 -3
- scitex/git/_result.py +3 -0
- scitex/git/_retry.py +2 -5
- scitex/git/_types.py +4 -0
- scitex/git/_validation.py +8 -8
- scitex/git/_workflow.py +4 -4
- scitex/io/__init__.py +12 -27
- scitex/io/_bundle.py +434 -0
- scitex/io/_flush.py +5 -2
- scitex/io/_glob.py +2 -2
- scitex/io/_json2md.py +3 -3
- scitex/io/_load.py +104 -8
- scitex/io/_load_cache.py +71 -71
- scitex/io/_load_configs.py +2 -3
- scitex/io/_load_modules/_H5Explorer.py +11 -14
- scitex/io/_load_modules/_ZarrExplorer.py +3 -3
- scitex/io/_load_modules/_bibtex.py +62 -63
- scitex/io/_load_modules/_canvas.py +6 -11
- scitex/io/_load_modules/_catboost.py +7 -2
- scitex/io/_load_modules/_hdf5.py +2 -0
- scitex/io/_load_modules/_image.py +7 -4
- scitex/io/_load_modules/_matlab.py +3 -1
- scitex/io/_load_modules/_optuna.py +0 -1
- scitex/io/_load_modules/_pdf.py +38 -29
- scitex/io/_load_modules/_sqlite3.py +1 -0
- scitex/io/_load_modules/_txt.py +6 -2
- scitex/io/_load_modules/_xml.py +9 -9
- scitex/io/_load_modules/_zarr.py +12 -10
- scitex/io/_metadata.py +34 -285
- scitex/io/_metadata_modules/__init__.py +46 -0
- scitex/io/_metadata_modules/_embed.py +70 -0
- scitex/io/_metadata_modules/_read.py +64 -0
- scitex/io/_metadata_modules/_utils.py +79 -0
- scitex/io/_metadata_modules/embed_metadata_jpeg.py +74 -0
- scitex/io/_metadata_modules/embed_metadata_pdf.py +53 -0
- scitex/io/_metadata_modules/embed_metadata_png.py +26 -0
- scitex/io/_metadata_modules/embed_metadata_svg.py +62 -0
- scitex/io/_metadata_modules/read_metadata_jpeg.py +57 -0
- scitex/io/_metadata_modules/read_metadata_pdf.py +51 -0
- scitex/io/_metadata_modules/read_metadata_png.py +39 -0
- scitex/io/_metadata_modules/read_metadata_svg.py +44 -0
- scitex/io/_qr_utils.py +21 -14
- scitex/io/_save.py +755 -80
- scitex/io/_save_modules/__init__.py +7 -2
- scitex/io/_save_modules/_bibtex.py +66 -61
- scitex/io/_save_modules/_canvas.py +8 -9
- scitex/io/_save_modules/_catboost.py +2 -2
- scitex/io/_save_modules/_csv.py +4 -4
- scitex/io/_save_modules/_excel.py +5 -9
- scitex/io/_save_modules/_hdf5.py +9 -21
- scitex/io/_save_modules/_html.py +5 -5
- scitex/io/_save_modules/_image.py +107 -14
- scitex/io/_save_modules/_joblib.py +2 -2
- scitex/io/_save_modules/_json.py +51 -6
- scitex/io/_save_modules/_listed_dfs_as_csv.py +2 -1
- scitex/io/_save_modules/_listed_scalars_as_csv.py +2 -1
- scitex/io/_save_modules/_matlab.py +2 -2
- scitex/io/_save_modules/_numpy.py +6 -8
- scitex/io/_save_modules/_pickle.py +4 -4
- scitex/io/_save_modules/_plotly.py +3 -3
- scitex/io/_save_modules/_tex.py +30 -29
- scitex/io/_save_modules/_text.py +2 -2
- scitex/io/_save_modules/_yaml.py +9 -9
- scitex/io/_save_modules/_zarr.py +15 -15
- scitex/io/utils/__init__.py +2 -1
- scitex/io/utils/h5_to_zarr.py +183 -163
- scitex/linalg/__init__.py +1 -1
- scitex/linalg/_geometric_median.py +4 -3
- scitex/logging/_Tee.py +5 -7
- scitex/logging/__init__.py +18 -19
- scitex/logging/_config.py +4 -1
- scitex/logging/_context.py +6 -5
- scitex/logging/_formatters.py +2 -3
- scitex/logging/_handlers.py +19 -20
- scitex/logging/_levels.py +9 -17
- scitex/logging/_logger.py +74 -15
- scitex/logging/_print_capture.py +17 -17
- scitex/msword/__init__.py +255 -0
- scitex/msword/profiles.py +357 -0
- scitex/msword/reader.py +753 -0
- scitex/msword/utils.py +289 -0
- scitex/msword/writer.py +362 -0
- scitex/nn/_BNet.py +1 -3
- scitex/nn/_Filters.py +6 -2
- scitex/nn/_ModulationIndex.py +3 -1
- scitex/nn/_PAC.py +3 -2
- scitex/nn/_PSD.py +0 -1
- scitex/nn/__init__.py +16 -3
- scitex/path/_clean.py +10 -8
- scitex/path/_find.py +1 -1
- scitex/path/_get_spath.py +1 -2
- scitex/path/_mk_spath.py +1 -1
- scitex/path/_symlink.py +5 -10
- scitex/pd/__init__.py +4 -1
- scitex/pd/_force_df.py +24 -24
- scitex/pd/_get_unique.py +1 -0
- scitex/pd/_merge_columns.py +1 -1
- scitex/pd/_round.py +11 -7
- scitex/pd/_to_xy.py +0 -1
- scitex/plt/__init__.py +190 -89
- scitex/plt/_subplots/_AxesWrapper.py +28 -12
- scitex/plt/_subplots/_AxisWrapper.py +114 -47
- scitex/plt/_subplots/_AxisWrapperMixins/_AdjustmentMixin/__init__.py +36 -0
- scitex/plt/_subplots/_AxisWrapperMixins/_AdjustmentMixin/_labels.py +264 -0
- scitex/plt/_subplots/_AxisWrapperMixins/_AdjustmentMixin/_metadata.py +213 -0
- scitex/plt/_subplots/_AxisWrapperMixins/_AdjustmentMixin/_visual.py +128 -0
- scitex/plt/_subplots/_AxisWrapperMixins/_MatplotlibPlotMixin/__init__.py +59 -0
- scitex/plt/_subplots/_AxisWrapperMixins/_MatplotlibPlotMixin/_base.py +34 -0
- scitex/plt/_subplots/_AxisWrapperMixins/_MatplotlibPlotMixin/_scientific.py +593 -0
- scitex/plt/_subplots/_AxisWrapperMixins/_MatplotlibPlotMixin/_statistical.py +654 -0
- scitex/plt/_subplots/_AxisWrapperMixins/_MatplotlibPlotMixin/_stx_aliases.py +527 -0
- scitex/plt/_subplots/_AxisWrapperMixins/_RawMatplotlibMixin.py +321 -0
- scitex/plt/_subplots/_AxisWrapperMixins/_SeabornMixin/__init__.py +33 -0
- scitex/plt/_subplots/_AxisWrapperMixins/_SeabornMixin/_base.py +152 -0
- scitex/plt/_subplots/_AxisWrapperMixins/_SeabornMixin/_wrappers.py +600 -0
- scitex/plt/_subplots/_AxisWrapperMixins/_TrackingMixin.py +26 -14
- scitex/plt/_subplots/_AxisWrapperMixins/_UnitAwareMixin.py +80 -73
- scitex/plt/_subplots/_AxisWrapperMixins/__init__.py +79 -5
- scitex/plt/_subplots/_FigWrapper.py +97 -64
- scitex/plt/_subplots/_SubplotsWrapper.py +161 -84
- scitex/plt/_subplots/__init__.py +10 -0
- scitex/plt/_subplots/_export_as_csv.py +124 -52
- scitex/plt/_subplots/_export_as_csv_formatters/__init__.py +9 -0
- scitex/plt/_subplots/_export_as_csv_formatters/_format_annotate.py +14 -23
- scitex/plt/_subplots/_export_as_csv_formatters/_format_bar.py +88 -38
- scitex/plt/_subplots/_export_as_csv_formatters/_format_barh.py +25 -31
- scitex/plt/_subplots/_export_as_csv_formatters/_format_boxplot.py +53 -23
- scitex/plt/_subplots/_export_as_csv_formatters/_format_contour.py +38 -25
- scitex/plt/_subplots/_export_as_csv_formatters/_format_contourf.py +17 -9
- scitex/plt/_subplots/_export_as_csv_formatters/_format_errorbar.py +70 -124
- scitex/plt/_subplots/_export_as_csv_formatters/_format_eventplot.py +30 -17
- scitex/plt/_subplots/_export_as_csv_formatters/_format_fill.py +31 -17
- scitex/plt/_subplots/_export_as_csv_formatters/_format_fill_between.py +33 -21
- scitex/plt/_subplots/_export_as_csv_formatters/_format_hexbin.py +14 -4
- scitex/plt/_subplots/_export_as_csv_formatters/_format_hist.py +43 -29
- scitex/plt/_subplots/_export_as_csv_formatters/_format_hist2d.py +14 -4
- scitex/plt/_subplots/_export_as_csv_formatters/_format_imshow.py +27 -11
- scitex/plt/_subplots/_export_as_csv_formatters/_format_imshow2d.py +34 -16
- scitex/plt/_subplots/_export_as_csv_formatters/_format_matshow.py +16 -8
- scitex/plt/_subplots/_export_as_csv_formatters/_format_pie.py +15 -6
- scitex/plt/_subplots/_export_as_csv_formatters/_format_plot.py +85 -46
- scitex/plt/_subplots/_export_as_csv_formatters/_format_plot_box.py +52 -27
- scitex/plt/_subplots/_export_as_csv_formatters/_format_plot_imshow.py +14 -1
- scitex/plt/_subplots/_export_as_csv_formatters/_format_plot_kde.py +27 -18
- scitex/plt/_subplots/_export_as_csv_formatters/_format_plot_scatter.py +14 -5
- scitex/plt/_subplots/_export_as_csv_formatters/_format_quiver.py +16 -8
- scitex/plt/_subplots/_export_as_csv_formatters/_format_scatter.py +17 -6
- scitex/plt/_subplots/_export_as_csv_formatters/_format_sns_barplot.py +43 -26
- scitex/plt/_subplots/_export_as_csv_formatters/_format_sns_boxplot.py +68 -47
- scitex/plt/_subplots/_export_as_csv_formatters/_format_sns_heatmap.py +52 -64
- scitex/plt/_subplots/_export_as_csv_formatters/_format_sns_histplot.py +55 -50
- scitex/plt/_subplots/_export_as_csv_formatters/_format_sns_jointplot.py +23 -10
- scitex/plt/_subplots/_export_as_csv_formatters/_format_sns_kdeplot.py +63 -29
- scitex/plt/_subplots/_export_as_csv_formatters/_format_sns_lineplot.py +48 -40
- scitex/plt/_subplots/_export_as_csv_formatters/_format_sns_pairplot.py +20 -6
- scitex/plt/_subplots/_export_as_csv_formatters/_format_sns_scatterplot.py +44 -40
- scitex/plt/_subplots/_export_as_csv_formatters/_format_sns_stripplot.py +46 -39
- scitex/plt/_subplots/_export_as_csv_formatters/_format_sns_swarmplot.py +46 -39
- scitex/plt/_subplots/_export_as_csv_formatters/_format_sns_violinplot.py +75 -94
- scitex/plt/_subplots/_export_as_csv_formatters/_format_stem.py +12 -3
- scitex/plt/_subplots/_export_as_csv_formatters/_format_step.py +12 -3
- scitex/plt/_subplots/_export_as_csv_formatters/_format_streamplot.py +17 -9
- scitex/plt/_subplots/_export_as_csv_formatters/_format_stx_bar.py +84 -0
- scitex/plt/_subplots/_export_as_csv_formatters/_format_stx_barh.py +85 -0
- scitex/plt/_subplots/_export_as_csv_formatters/_format_stx_conf_mat.py +31 -18
- scitex/plt/_subplots/_export_as_csv_formatters/_format_stx_contour.py +54 -0
- scitex/plt/_subplots/_export_as_csv_formatters/_format_stx_ecdf.py +24 -11
- scitex/plt/_subplots/_export_as_csv_formatters/_format_stx_errorbar.py +120 -0
- scitex/plt/_subplots/_export_as_csv_formatters/_format_stx_fillv.py +35 -31
- scitex/plt/_subplots/_export_as_csv_formatters/_format_stx_heatmap.py +33 -23
- scitex/plt/_subplots/_export_as_csv_formatters/_format_stx_image.py +44 -28
- scitex/plt/_subplots/_export_as_csv_formatters/_format_stx_imshow.py +63 -0
- scitex/plt/_subplots/_export_as_csv_formatters/_format_stx_joyplot.py +31 -12
- scitex/plt/_subplots/_export_as_csv_formatters/_format_stx_line.py +34 -23
- scitex/plt/_subplots/_export_as_csv_formatters/_format_stx_mean_ci.py +32 -26
- scitex/plt/_subplots/_export_as_csv_formatters/_format_stx_mean_std.py +29 -23
- scitex/plt/_subplots/_export_as_csv_formatters/_format_stx_median_iqr.py +32 -26
- scitex/plt/_subplots/_export_as_csv_formatters/_format_stx_raster.py +21 -11
- scitex/plt/_subplots/_export_as_csv_formatters/_format_stx_rectangle.py +84 -56
- scitex/plt/_subplots/_export_as_csv_formatters/_format_stx_scatter.py +51 -0
- scitex/plt/_subplots/_export_as_csv_formatters/_format_stx_scatter_hist.py +46 -34
- scitex/plt/_subplots/_export_as_csv_formatters/_format_stx_shaded_line.py +46 -30
- scitex/plt/_subplots/_export_as_csv_formatters/_format_stx_violin.py +51 -51
- scitex/plt/_subplots/_export_as_csv_formatters/_format_text.py +32 -31
- scitex/plt/_subplots/_export_as_csv_formatters/_format_violin.py +34 -31
- scitex/plt/_subplots/_export_as_csv_formatters/_format_violinplot.py +44 -37
- scitex/plt/_subplots/_export_as_csv_formatters/verify_formatters.py +91 -74
- scitex/plt/_tpl.py +6 -5
- scitex/plt/ax/_plot/__init__.py +24 -0
- scitex/plt/ax/_plot/_add_fitted_line.py +12 -11
- scitex/plt/ax/_plot/_plot_circular_hist.py +3 -1
- scitex/plt/ax/_plot/_plot_statistical_shaded_line.py +25 -19
- scitex/plt/ax/_plot/_stx_conf_mat.py +6 -3
- scitex/plt/ax/_plot/_stx_ecdf.py +9 -5
- scitex/plt/ax/_plot/_stx_fillv.py +4 -2
- scitex/plt/ax/_plot/_stx_heatmap.py +7 -4
- scitex/plt/ax/_plot/_stx_image.py +7 -5
- scitex/plt/ax/_plot/_stx_joyplot.py +32 -10
- scitex/plt/ax/_plot/_stx_raster.py +26 -11
- scitex/plt/ax/_plot/_stx_rectangle.py +2 -2
- scitex/plt/ax/_plot/_stx_shaded_line.py +15 -11
- scitex/plt/ax/_plot/_stx_violin.py +3 -1
- scitex/plt/ax/_style/_add_marginal_ax.py +6 -4
- scitex/plt/ax/_style/_auto_scale_axis.py +14 -10
- scitex/plt/ax/_style/_extend.py +3 -1
- scitex/plt/ax/_style/_force_aspect.py +5 -3
- scitex/plt/ax/_style/_format_units.py +2 -2
- scitex/plt/ax/_style/_hide_spines.py +5 -1
- scitex/plt/ax/_style/_map_ticks.py +5 -3
- scitex/plt/ax/_style/_rotate_labels.py +5 -4
- scitex/plt/ax/_style/_rotate_labels_v01.py +73 -63
- scitex/plt/ax/_style/_set_log_scale.py +120 -85
- scitex/plt/ax/_style/_set_meta.py +99 -76
- scitex/plt/ax/_style/_set_supxyt.py +33 -16
- scitex/plt/ax/_style/_set_xyt.py +27 -18
- scitex/plt/ax/_style/_share_axes.py +15 -5
- scitex/plt/ax/_style/_show_spines.py +58 -57
- scitex/plt/ax/_style/_style_barplot.py +1 -1
- scitex/plt/ax/_style/_style_boxplot.py +25 -14
- scitex/plt/ax/_style/_style_errorbar.py +0 -0
- scitex/plt/ax/_style/_style_scatter.py +1 -1
- scitex/plt/ax/_style/_style_suptitles.py +3 -3
- scitex/plt/ax/_style/_style_violinplot.py +8 -2
- scitex/plt/color/__init__.py +34 -2
- scitex/plt/color/_add_hue_col.py +1 -0
- scitex/plt/color/_colors.py +0 -1
- scitex/plt/color/_get_colors_from_conf_matap.py +3 -1
- scitex/plt/color/_vizualize_colors.py +0 -1
- scitex/plt/docs/FIGURE_ARCHITECTURE.md +155 -97
- scitex/plt/gallery/README.md +75 -0
- scitex/plt/gallery/__init__.py +29 -0
- scitex/plt/gallery/_generate.py +560 -0
- scitex/plt/gallery/_plots.py +594 -0
- scitex/plt/gallery/_registry.py +153 -0
- scitex/plt/io/__init__.py +53 -0
- scitex/plt/io/_bundle.py +490 -0
- scitex/plt/io/_layered_bundle.py +1343 -0
- scitex/plt/styles/SCITEX_STYLE.yaml +26 -0
- scitex/plt/styles/__init__.py +23 -9
- scitex/plt/styles/_plot_defaults.py +62 -61
- scitex/plt/styles/_plot_postprocess.py +126 -77
- scitex/plt/styles/_style_loader.py +0 -0
- scitex/plt/styles/presets.py +121 -18
- scitex/plt/utils/__init__.py +42 -3
- scitex/plt/utils/_close.py +8 -3
- scitex/plt/utils/_collect_figure_metadata.py +3033 -271
- scitex/plt/utils/_colorbar.py +15 -17
- scitex/plt/utils/_configure_mpl.py +26 -30
- scitex/plt/utils/_crop.py +87 -36
- scitex/plt/utils/_csv_column_naming.py +177 -72
- scitex/plt/utils/_dimension_viewer.py +7 -19
- scitex/plt/utils/_figure_from_axes_mm.py +70 -16
- scitex/plt/utils/_figure_mm.py +119 -3
- scitex/plt/utils/_get_actual_font.py +5 -4
- scitex/plt/utils/_histogram_utils.py +52 -48
- scitex/plt/utils/_hitmap.py +1643 -0
- scitex/plt/utils/_is_valid_axis.py +19 -13
- scitex/plt/utils/_mk_colorbar.py +3 -3
- scitex/plt/utils/_scientific_captions.py +202 -139
- scitex/plt/utils/_scitex_config.py +98 -98
- scitex/plt/utils/_units.py +0 -0
- scitex/plt/utils/metadata/__init__.py +61 -0
- scitex/plt/utils/metadata/_artist_extraction.py +119 -0
- scitex/plt/utils/metadata/_axes_metadata.py +93 -0
- scitex/plt/utils/metadata/_collection_artists.py +292 -0
- scitex/plt/utils/metadata/_core.py +207 -0
- scitex/plt/utils/metadata/_csv_column_extraction.py +186 -0
- scitex/plt/utils/metadata/_csv_hash.py +115 -0
- scitex/plt/utils/metadata/_csv_verification.py +95 -0
- scitex/plt/utils/metadata/_data_linkage.py +263 -0
- scitex/plt/utils/metadata/_dimensions.py +242 -0
- scitex/plt/utils/metadata/_editable_export.py +405 -0
- scitex/plt/utils/metadata/_figure_metadata.py +58 -0
- scitex/plt/utils/metadata/_geometry_extraction.py +570 -0
- scitex/plt/utils/metadata/_image_text_artists.py +168 -0
- scitex/plt/utils/metadata/_label_parsing.py +82 -0
- scitex/plt/utils/metadata/_legend_extraction.py +120 -0
- scitex/plt/utils/metadata/_line_artists.py +367 -0
- scitex/plt/utils/metadata/_line_semantic_handling.py +173 -0
- scitex/plt/utils/metadata/_patch_artists.py +211 -0
- scitex/plt/utils/metadata/_plot_content.py +26 -0
- scitex/plt/utils/metadata/_plot_type_detection.py +184 -0
- scitex/plt/utils/metadata/_precision.py +134 -0
- scitex/plt/utils/metadata/_precision_config.py +68 -0
- scitex/plt/utils/metadata/_precision_sections.py +211 -0
- scitex/plt/utils/metadata/_recipe_extraction.py +267 -0
- scitex/plt/utils/metadata/_style_parsing.py +174 -0
- scitex/repro/_RandomStateManager.py +33 -38
- scitex/repro/__init__.py +16 -7
- scitex/repro/_gen_ID.py +7 -9
- scitex/repro/_gen_timestamp.py +7 -6
- scitex/repro/_hash_array.py +8 -12
- scitex/reproduce/__init__.py +1 -1
- scitex/resource/_get_processor_usages.py +3 -1
- scitex/resource/_log_processor_usages.py +3 -1
- scitex/rng/__init__.py +1 -1
- scitex/schema/README.md +178 -0
- scitex/schema/__init__.py +237 -0
- scitex/schema/_canvas.py +444 -0
- scitex/schema/_plot.py +1015 -0
- scitex/schema/_stats.py +762 -0
- scitex/schema/_validation.py +590 -0
- scitex/scholar/.legacy/Scholar.py +5 -12
- scitex/scholar/.legacy/_Scholar.py +66 -99
- scitex/scholar/.legacy/_ScholarAPI.py +75 -66
- scitex/scholar/.legacy/_tmp/search_engine/_BaseSearchEngine.py +3 -3
- scitex/scholar/.legacy/_tmp/search_engine/_UnifiedSearcher.py +4 -9
- scitex/scholar/.legacy/_tmp/search_engine/__init__.py +14 -21
- scitex/scholar/.legacy/_tmp/search_engine/local/_LocalSearchEngine.py +40 -37
- scitex/scholar/.legacy/_tmp/search_engine/local/_VectorSearchEngine.py +31 -28
- scitex/scholar/.legacy/_tmp/search_engine/web/_ArxivSearchEngine.py +74 -65
- scitex/scholar/.legacy/_tmp/search_engine/web/_CrossRefSearchEngine.py +122 -116
- scitex/scholar/.legacy/_tmp/search_engine/web/_GoogleScholarSearchEngine.py +65 -59
- scitex/scholar/.legacy/_tmp/search_engine/web/_PubMedSearchEngine.py +121 -107
- scitex/scholar/.legacy/_tmp/search_engine/web/_SemanticScholarSearchEngine.py +5 -12
- scitex/scholar/.legacy/database/_DatabaseEntry.py +49 -45
- scitex/scholar/.legacy/database/_DatabaseIndex.py +131 -94
- scitex/scholar/.legacy/database/_LibraryManager.py +65 -63
- scitex/scholar/.legacy/database/_PaperDatabase.py +138 -124
- scitex/scholar/.legacy/database/_ScholarDatabaseIntegration.py +14 -36
- scitex/scholar/.legacy/database/_StorageIntegratedDB.py +192 -156
- scitex/scholar/.legacy/database/_ZoteroCompatibleDB.py +300 -237
- scitex/scholar/.legacy/database/__init__.py +2 -1
- scitex/scholar/.legacy/database/manage.py +92 -84
- scitex/scholar/.legacy/lookup/_LookupIndex.py +157 -101
- scitex/scholar/.legacy/lookup/__init__.py +2 -1
- scitex/scholar/.legacy/metadata/doi/batch/_MetadataHandlerForBatchDOIResolution.py +4 -9
- scitex/scholar/.legacy/metadata/doi/batch/_ProgressManagerForBatchDOIResolution.py +10 -23
- scitex/scholar/.legacy/metadata/doi/batch/_SourceStatsManagerForBatchDOIResolution.py +4 -9
- scitex/scholar/.legacy/metadata/doi/batch/__init__.py +3 -1
- scitex/scholar/.legacy/metadata/doi/resolvers/_BatchDOIResolver.py +10 -25
- scitex/scholar/.legacy/metadata/doi/resolvers/_BibTeXDOIResolver.py +19 -49
- scitex/scholar/.legacy/metadata/doi/resolvers/_DOIResolver.py +1 -0
- scitex/scholar/.legacy/metadata/doi/resolvers/_SingleDOIResolver.py +8 -20
- scitex/scholar/.legacy/metadata/doi/sources/.combined-SemanticScholarSource/_SemanticScholarSource.py +37 -35
- scitex/scholar/.legacy/metadata/doi/sources/.combined-SemanticScholarSource/_SemanticScholarSourceEnhanced.py +49 -37
- scitex/scholar/.legacy/metadata/doi/sources/_ArXivSource.py +11 -30
- scitex/scholar/.legacy/metadata/doi/sources/_BaseDOISource.py +19 -47
- scitex/scholar/.legacy/metadata/doi/sources/_CrossRefLocalSource.py +1 -0
- scitex/scholar/.legacy/metadata/doi/sources/_CrossRefSource.py +12 -33
- scitex/scholar/.legacy/metadata/doi/sources/_OpenAlexSource.py +8 -20
- scitex/scholar/.legacy/metadata/doi/sources/_PubMedSource.py +10 -27
- scitex/scholar/.legacy/metadata/doi/sources/_SemanticScholarSource.py +11 -29
- scitex/scholar/.legacy/metadata/doi/sources/_SourceManager.py +8 -21
- scitex/scholar/.legacy/metadata/doi/sources/_SourceResolutionStrategy.py +24 -55
- scitex/scholar/.legacy/metadata/doi/sources/_SourceRotationManager.py +8 -21
- scitex/scholar/.legacy/metadata/doi/sources/_URLDOISource.py +9 -16
- scitex/scholar/.legacy/metadata/doi/sources/_UnifiedSource.py +8 -22
- scitex/scholar/.legacy/metadata/doi/sources/__init__.py +1 -0
- scitex/scholar/.legacy/metadata/doi/utils/_PubMedConverter.py +4 -8
- scitex/scholar/.legacy/metadata/doi/utils/_RateLimitHandler.py +17 -43
- scitex/scholar/.legacy/metadata/doi/utils/_TextNormalizer.py +8 -18
- scitex/scholar/.legacy/metadata/doi/utils/_URLDOIExtractor.py +4 -8
- scitex/scholar/.legacy/metadata/doi/utils/__init__.py +1 -0
- scitex/scholar/.legacy/metadata/doi/utils/_to_complete_metadata_structure.py +1 -0
- scitex/scholar/.legacy/metadata/enrichment/_LibraryEnricher.py +2 -3
- scitex/scholar/.legacy/metadata/enrichment/enrichers/_ImpactFactorEnricher.py +6 -12
- scitex/scholar/.legacy/metadata/enrichment/enrichers/_SmartEnricher.py +5 -10
- scitex/scholar/.legacy/metadata/enrichment/sources/_UnifiedMetadataSource.py +4 -5
- scitex/scholar/.legacy/metadata/query_to_full_meta_json.py +8 -12
- scitex/scholar/.legacy/metadata/urls/_URLMetadataHandler.py +3 -3
- scitex/scholar/.legacy/metadata/urls/_ZoteroTranslatorRunner.py +15 -21
- scitex/scholar/.legacy/metadata/urls/__init__.py +3 -3
- scitex/scholar/.legacy/metadata/urls/_finder.py +4 -6
- scitex/scholar/.legacy/metadata/urls/_handler.py +7 -15
- scitex/scholar/.legacy/metadata/urls/_resolver.py +6 -12
- scitex/scholar/.legacy/search/_Embedder.py +74 -69
- scitex/scholar/.legacy/search/_SemanticSearch.py +91 -90
- scitex/scholar/.legacy/search/_SemanticSearchEngine.py +104 -109
- scitex/scholar/.legacy/search/_UnifiedSearcher.py +530 -471
- scitex/scholar/.legacy/search/_VectorDatabase.py +111 -92
- scitex/scholar/.legacy/search/__init__.py +1 -0
- scitex/scholar/.legacy/storage/_EnhancedStorageManager.py +182 -154
- scitex/scholar/.legacy/storage/__init__.py +2 -1
- scitex/scholar/__init__.py +0 -2
- scitex/scholar/__main__.py +1 -3
- scitex/scholar/auth/ScholarAuthManager.py +13 -36
- scitex/scholar/auth/core/AuthenticationGateway.py +15 -29
- scitex/scholar/auth/core/BrowserAuthenticator.py +22 -57
- scitex/scholar/auth/core/StrategyResolver.py +10 -27
- scitex/scholar/auth/core/__init__.py +5 -1
- scitex/scholar/auth/gateway/_OpenURLLinkFinder.py +11 -21
- scitex/scholar/auth/gateway/_OpenURLResolver.py +10 -18
- scitex/scholar/auth/gateway/_resolve_functions.py +3 -3
- scitex/scholar/auth/providers/BaseAuthenticator.py +1 -0
- scitex/scholar/auth/providers/EZProxyAuthenticator.py +7 -14
- scitex/scholar/auth/providers/OpenAthensAuthenticator.py +29 -57
- scitex/scholar/auth/providers/ShibbolethAuthenticator.py +87 -73
- scitex/scholar/auth/session/AuthCacheManager.py +12 -22
- scitex/scholar/auth/session/SessionManager.py +4 -6
- scitex/scholar/auth/sso/BaseSSOAutomator.py +13 -19
- scitex/scholar/auth/sso/OpenAthensSSOAutomator.py +16 -45
- scitex/scholar/auth/sso/SSOAutomator.py +8 -15
- scitex/scholar/auth/sso/UniversityOfMelbourneSSOAutomator.py +13 -23
- scitex/scholar/browser/ScholarBrowserManager.py +31 -56
- scitex/scholar/browser/__init__.py +1 -0
- scitex/scholar/browser/utils/click_and_wait.py +3 -4
- scitex/scholar/browser/utils/close_unwanted_pages.py +4 -7
- scitex/scholar/browser/utils/wait_redirects.py +15 -40
- scitex/scholar/citation_graph/__init__.py +0 -0
- scitex/scholar/citation_graph/builder.py +3 -7
- scitex/scholar/citation_graph/database.py +4 -11
- scitex/scholar/citation_graph/example.py +5 -10
- scitex/scholar/citation_graph/models.py +0 -0
- scitex/scholar/cli/_url_utils.py +1 -1
- scitex/scholar/cli/chrome.py +5 -3
- scitex/scholar/cli/download_pdf.py +13 -14
- scitex/scholar/cli/handlers/bibtex_handler.py +4 -12
- scitex/scholar/cli/handlers/doi_handler.py +1 -3
- scitex/scholar/cli/handlers/project_handler.py +6 -20
- scitex/scholar/cli/open_browser.py +41 -39
- scitex/scholar/cli/open_browser_auto.py +31 -39
- scitex/scholar/cli/open_browser_monitored.py +27 -24
- scitex/scholar/config/ScholarConfig.py +5 -8
- scitex/scholar/config/__init__.py +1 -0
- scitex/scholar/config/core/_CascadeConfig.py +3 -3
- scitex/scholar/config/core/_PathManager.py +16 -28
- scitex/scholar/core/Paper.py +79 -78
- scitex/scholar/core/Papers.py +16 -27
- scitex/scholar/core/Scholar.py +98 -229
- scitex/scholar/core/journal_normalizer.py +52 -49
- scitex/scholar/core/oa_cache.py +27 -23
- scitex/scholar/core/open_access.py +17 -8
- scitex/scholar/docs/template.py +4 -3
- scitex/scholar/docs/to_claude/examples/example-python-project-scitex/scripts/mnist/clf_svm.py +0 -0
- scitex/scholar/docs/to_claude/examples/example-python-project-scitex/scripts/mnist/download.py +0 -0
- scitex/scholar/docs/to_claude/examples/example-python-project-scitex/scripts/mnist/plot_conf_mat.py +0 -0
- scitex/scholar/docs/to_claude/examples/example-python-project-scitex/scripts/mnist/plot_digits.py +0 -0
- scitex/scholar/docs/to_claude/examples/example-python-project-scitex/scripts/mnist/plot_umap_space.py +0 -0
- scitex/scholar/examples/00_config.py +10 -9
- scitex/scholar/examples/01_auth.py +3 -0
- scitex/scholar/examples/02_browser.py +14 -10
- scitex/scholar/examples/03_01-engine.py +3 -0
- scitex/scholar/examples/03_02-engine-for-bibtex.py +4 -3
- scitex/scholar/examples/04_01-url.py +9 -9
- scitex/scholar/examples/04_02-url-for-bibtex.py +7 -3
- scitex/scholar/examples/04_02-url-for-dois.py +87 -97
- scitex/scholar/examples/05_download_pdf.py +10 -4
- scitex/scholar/examples/06_find_and_download.py +6 -6
- scitex/scholar/examples/06_parse_bibtex.py +17 -17
- scitex/scholar/examples/07_storage_integration.py +6 -9
- scitex/scholar/examples/99_fullpipeline-for-bibtex.py +14 -15
- scitex/scholar/examples/99_fullpipeline-for-one-entry.py +31 -23
- scitex/scholar/examples/99_maintenance.py +3 -0
- scitex/scholar/examples/dev.py +2 -3
- scitex/scholar/examples/zotero_integration.py +11 -18
- scitex/scholar/impact_factor/ImpactFactorEngine.py +7 -9
- scitex/scholar/impact_factor/estimation/__init__.py +4 -4
- scitex/scholar/impact_factor/estimation/core/__init__.py +3 -7
- scitex/scholar/impact_factor/estimation/core/cache_manager.py +223 -211
- scitex/scholar/impact_factor/estimation/core/calculator.py +165 -131
- scitex/scholar/impact_factor/estimation/core/journal_matcher.py +217 -172
- scitex/scholar/impact_factor/jcr/ImpactFactorJCREngine.py +6 -14
- scitex/scholar/impact_factor/jcr/build_database.py +4 -3
- scitex/scholar/integration/base.py +9 -17
- scitex/scholar/integration/mendeley/exporter.py +2 -4
- scitex/scholar/integration/mendeley/importer.py +3 -3
- scitex/scholar/integration/mendeley/linker.py +3 -3
- scitex/scholar/integration/mendeley/mapper.py +9 -6
- scitex/scholar/integration/zotero/__main__.py +26 -43
- scitex/scholar/integration/zotero/exporter.py +15 -11
- scitex/scholar/integration/zotero/importer.py +12 -10
- scitex/scholar/integration/zotero/linker.py +8 -12
- scitex/scholar/integration/zotero/mapper.py +17 -12
- scitex/scholar/metadata_engines/.combined-SemanticScholarSource/_SemanticScholarSource.py +37 -35
- scitex/scholar/metadata_engines/.combined-SemanticScholarSource/_SemanticScholarSourceEnhanced.py +47 -35
- scitex/scholar/metadata_engines/ScholarEngine.py +21 -43
- scitex/scholar/metadata_engines/__init__.py +1 -0
- scitex/scholar/metadata_engines/individual/ArXivEngine.py +15 -37
- scitex/scholar/metadata_engines/individual/CrossRefEngine.py +15 -42
- scitex/scholar/metadata_engines/individual/CrossRefLocalEngine.py +24 -45
- scitex/scholar/metadata_engines/individual/OpenAlexEngine.py +11 -21
- scitex/scholar/metadata_engines/individual/PubMedEngine.py +10 -27
- scitex/scholar/metadata_engines/individual/SemanticScholarEngine.py +28 -35
- scitex/scholar/metadata_engines/individual/URLDOIEngine.py +11 -22
- scitex/scholar/metadata_engines/individual/_BaseDOIEngine.py +20 -49
- scitex/scholar/metadata_engines/utils/_PubMedConverter.py +4 -8
- scitex/scholar/metadata_engines/utils/_URLDOIExtractor.py +5 -10
- scitex/scholar/metadata_engines/utils/__init__.py +2 -0
- scitex/scholar/metadata_engines/utils/_metadata2bibtex.py +3 -0
- scitex/scholar/metadata_engines/utils/_standardize_metadata.py +2 -3
- scitex/scholar/pdf_download/ScholarPDFDownloader.py +25 -37
- scitex/scholar/pdf_download/strategies/chrome_pdf_viewer.py +11 -19
- scitex/scholar/pdf_download/strategies/direct_download.py +5 -9
- scitex/scholar/pdf_download/strategies/manual_download_fallback.py +3 -3
- scitex/scholar/pdf_download/strategies/manual_download_utils.py +6 -13
- scitex/scholar/pdf_download/strategies/open_access_download.py +49 -31
- scitex/scholar/pdf_download/strategies/response_body.py +8 -19
- scitex/scholar/pipelines/ScholarPipelineBibTeX.py +9 -18
- scitex/scholar/pipelines/ScholarPipelineMetadataParallel.py +25 -26
- scitex/scholar/pipelines/ScholarPipelineMetadataSingle.py +62 -23
- scitex/scholar/pipelines/ScholarPipelineParallel.py +13 -30
- scitex/scholar/pipelines/ScholarPipelineSearchParallel.py +299 -220
- scitex/scholar/pipelines/ScholarPipelineSearchSingle.py +202 -165
- scitex/scholar/pipelines/ScholarPipelineSingle.py +25 -51
- scitex/scholar/pipelines/SearchQueryParser.py +55 -55
- scitex/scholar/search_engines/ScholarSearchEngine.py +31 -27
- scitex/scholar/search_engines/_BaseSearchEngine.py +20 -23
- scitex/scholar/search_engines/individual/ArXivSearchEngine.py +53 -35
- scitex/scholar/search_engines/individual/CrossRefSearchEngine.py +47 -40
- scitex/scholar/search_engines/individual/OpenAlexSearchEngine.py +55 -50
- scitex/scholar/search_engines/individual/PubMedSearchEngine.py +8 -10
- scitex/scholar/search_engines/individual/SemanticScholarSearchEngine.py +55 -49
- scitex/scholar/storage/BibTeXHandler.py +150 -95
- scitex/scholar/storage/PaperIO.py +3 -6
- scitex/scholar/storage/ScholarLibrary.py +70 -49
- scitex/scholar/storage/_DeduplicationManager.py +52 -25
- scitex/scholar/storage/_LibraryCacheManager.py +19 -46
- scitex/scholar/storage/_LibraryManager.py +65 -175
- scitex/scholar/url_finder/ScholarURLFinder.py +9 -25
- scitex/scholar/url_finder/strategies/find_pdf_urls_by_direct_links.py +1 -1
- scitex/scholar/url_finder/strategies/find_pdf_urls_by_href.py +6 -10
- scitex/scholar/url_finder/strategies/find_pdf_urls_by_navigation.py +4 -6
- scitex/scholar/url_finder/strategies/find_pdf_urls_by_publisher_patterns.py +8 -15
- scitex/scholar/url_finder/strategies/find_pdf_urls_by_zotero_translators.py +3 -3
- scitex/scholar/url_finder/strategies/find_supplementary_urls_by_href.py +3 -3
- scitex/scholar/url_finder/translators/core/patterns.py +6 -4
- scitex/scholar/url_finder/translators/core/registry.py +6 -9
- scitex/scholar/url_finder/translators/individual/BOFiP_Impots.py +60 -52
- scitex/scholar/url_finder/translators/individual/Baidu_Scholar.py +54 -62
- scitex/scholar/url_finder/translators/individual/Bangkok_Post.py +38 -44
- scitex/scholar/url_finder/translators/individual/Baruch_Foundation.py +43 -47
- scitex/scholar/url_finder/translators/individual/Beobachter.py +46 -50
- scitex/scholar/url_finder/translators/individual/Bezneng_Gajit.py +37 -41
- scitex/scholar/url_finder/translators/individual/BibLaTeX.py +59 -52
- scitex/scholar/url_finder/translators/individual/BibTeX.py +83 -79
- scitex/scholar/url_finder/translators/individual/Biblio_com.py +48 -51
- scitex/scholar/url_finder/translators/individual/Bibliontology_RDF.py +58 -56
- scitex/scholar/url_finder/translators/individual/Camara_Brasileira_do_Livro_ISBN.py +102 -99
- scitex/scholar/url_finder/translators/individual/CanLII.py +49 -43
- scitex/scholar/url_finder/translators/individual/Canada_com.py +36 -40
- scitex/scholar/url_finder/translators/individual/Canadian_Letters_and_Images.py +43 -43
- scitex/scholar/url_finder/translators/individual/Canadiana_ca.py +77 -66
- scitex/scholar/url_finder/translators/individual/Cascadilla_Proceedings_Project.py +68 -62
- scitex/scholar/url_finder/translators/individual/Central_and_Eastern_European_Online_Library_Journals.py +60 -60
- scitex/scholar/url_finder/translators/individual/Champlain_Society_Collection.py +63 -61
- scitex/scholar/url_finder/translators/individual/Chicago_Journal_of_Theoretical_Computer_Science.py +74 -58
- scitex/scholar/url_finder/translators/individual/Christian_Science_Monitor.py +32 -38
- scitex/scholar/url_finder/translators/individual/Columbia_University_Press.py +51 -47
- scitex/scholar/url_finder/translators/individual/Common_Place.py +66 -57
- scitex/scholar/url_finder/translators/individual/Cornell_LII.py +66 -62
- scitex/scholar/url_finder/translators/individual/Cornell_University_Press.py +38 -45
- scitex/scholar/url_finder/translators/individual/CourtListener.py +52 -56
- scitex/scholar/url_finder/translators/individual/DAI_Zenon.py +53 -54
- scitex/scholar/url_finder/translators/individual/access_medicine.py +27 -33
- scitex/scholar/url_finder/translators/individual/acm.py +1 -1
- scitex/scholar/url_finder/translators/individual/acm_digital_library.py +93 -63
- scitex/scholar/url_finder/translators/individual/airiti.py +3 -1
- scitex/scholar/url_finder/translators/individual/aosic.py +3 -1
- scitex/scholar/url_finder/translators/individual/archive_ouverte_aosic.py +3 -1
- scitex/scholar/url_finder/translators/individual/archive_ouverte_en_sciences_de_l_information_et_de_la_communication___aosic_.py +6 -2
- scitex/scholar/url_finder/translators/individual/artforum.py +35 -27
- scitex/scholar/url_finder/translators/individual/arxiv.py +1 -1
- scitex/scholar/url_finder/translators/individual/arxiv_org.py +8 -4
- scitex/scholar/url_finder/translators/individual/atlanta_journal_constitution.py +22 -18
- scitex/scholar/url_finder/translators/individual/atypon_journals.py +19 -11
- scitex/scholar/url_finder/translators/individual/austlii_and_nzlii.py +48 -44
- scitex/scholar/url_finder/translators/individual/australian_dictionary_of_biography.py +21 -17
- scitex/scholar/url_finder/translators/individual/bailii.py +22 -19
- scitex/scholar/url_finder/translators/individual/bbc.py +46 -42
- scitex/scholar/url_finder/translators/individual/bbc_genome.py +37 -25
- scitex/scholar/url_finder/translators/individual/biblioteca_nacional_de_maestros.py +24 -20
- scitex/scholar/url_finder/translators/individual/bibliotheque_archives_nationale_quebec_pistard.py +42 -43
- scitex/scholar/url_finder/translators/individual/bibliotheque_archives_nationales_quebec.py +87 -81
- scitex/scholar/url_finder/translators/individual/bibliotheque_nationale_france.py +39 -37
- scitex/scholar/url_finder/translators/individual/bibsys.py +32 -28
- scitex/scholar/url_finder/translators/individual/bioconductor.py +58 -52
- scitex/scholar/url_finder/translators/individual/biomed_central.py +23 -15
- scitex/scholar/url_finder/translators/individual/biorxiv.py +26 -13
- scitex/scholar/url_finder/translators/individual/blogger.py +39 -43
- scitex/scholar/url_finder/translators/individual/bloomberg.py +48 -52
- scitex/scholar/url_finder/translators/individual/bloomsbury_food_library.py +37 -37
- scitex/scholar/url_finder/translators/individual/bluesky.py +30 -28
- scitex/scholar/url_finder/translators/individual/bnf_isbn.py +1 -1
- scitex/scholar/url_finder/translators/individual/bocc.py +66 -60
- scitex/scholar/url_finder/translators/individual/boe.py +52 -52
- scitex/scholar/url_finder/translators/individual/brill.py +3 -1
- scitex/scholar/url_finder/translators/individual/business_standard.py +36 -38
- scitex/scholar/url_finder/translators/individual/cabi_cab_abstracts.py +39 -41
- scitex/scholar/url_finder/translators/individual/cambridge.py +3 -1
- scitex/scholar/url_finder/translators/individual/cambridge_core.py +30 -24
- scitex/scholar/url_finder/translators/individual/caod.py +50 -46
- scitex/scholar/url_finder/translators/individual/cbc.py +91 -67
- scitex/scholar/url_finder/translators/individual/ccfr_bnf.py +49 -53
- scitex/scholar/url_finder/translators/individual/cia_world_factbook.py +43 -33
- scitex/scholar/url_finder/translators/individual/crossref_rest.py +208 -174
- scitex/scholar/url_finder/translators/individual/current_affairs.py +29 -35
- scitex/scholar/url_finder/translators/individual/dabi.py +70 -66
- scitex/scholar/url_finder/translators/individual/dagens_nyheter.py +3 -1
- scitex/scholar/url_finder/translators/individual/dagstuhl.py +10 -15
- scitex/scholar/url_finder/translators/individual/dar_almandumah.py +13 -9
- scitex/scholar/url_finder/translators/individual/dart_europe.py +19 -22
- scitex/scholar/url_finder/translators/individual/data_gov.py +2 -2
- scitex/scholar/url_finder/translators/individual/databrary.py +27 -28
- scitex/scholar/url_finder/translators/individual/datacite_json.py +152 -137
- scitex/scholar/url_finder/translators/individual/dataverse.py +68 -64
- scitex/scholar/url_finder/translators/individual/daum_news.py +38 -38
- scitex/scholar/url_finder/translators/individual/dblp.py +4 -8
- scitex/scholar/url_finder/translators/individual/dblp_computer_science_bibliography.py +8 -3
- scitex/scholar/url_finder/translators/individual/dbpia.py +5 -3
- scitex/scholar/url_finder/translators/individual/defense_technical_information_center.py +30 -28
- scitex/scholar/url_finder/translators/individual/delpher.py +102 -79
- scitex/scholar/url_finder/translators/individual/demographic_research.py +35 -31
- scitex/scholar/url_finder/translators/individual/denik_cz.py +58 -54
- scitex/scholar/url_finder/translators/individual/depatisnet.py +7 -10
- scitex/scholar/url_finder/translators/individual/der_freitag.py +81 -66
- scitex/scholar/url_finder/translators/individual/der_spiegel.py +56 -54
- scitex/scholar/url_finder/translators/individual/digibib_net.py +3 -1
- scitex/scholar/url_finder/translators/individual/digizeitschriften.py +3 -1
- scitex/scholar/url_finder/translators/individual/dpla.py +13 -14
- scitex/scholar/url_finder/translators/individual/dspace.py +2 -2
- scitex/scholar/url_finder/translators/individual/ebrary.py +3 -1
- scitex/scholar/url_finder/translators/individual/ebscohost.py +3 -1
- scitex/scholar/url_finder/translators/individual/electronic_colloquium_on_computational_complexity.py +3 -1
- scitex/scholar/url_finder/translators/individual/elife.py +3 -1
- scitex/scholar/url_finder/translators/individual/elsevier_health_journals.py +3 -1
- scitex/scholar/url_finder/translators/individual/emerald.py +3 -1
- scitex/scholar/url_finder/translators/individual/emerald_insight.py +3 -1
- scitex/scholar/url_finder/translators/individual/epicurious.py +3 -1
- scitex/scholar/url_finder/translators/individual/eurogamerusgamer.py +3 -1
- scitex/scholar/url_finder/translators/individual/fachportal_padagogik.py +3 -1
- scitex/scholar/url_finder/translators/individual/frontiers.py +1 -1
- scitex/scholar/url_finder/translators/individual/gale_databases.py +3 -1
- scitex/scholar/url_finder/translators/individual/gms_german_medical_science.py +6 -2
- scitex/scholar/url_finder/translators/individual/ieee_computer_society.py +6 -2
- scitex/scholar/url_finder/translators/individual/ieee_xplore.py +41 -35
- scitex/scholar/url_finder/translators/individual/inter_research_science_center.py +6 -2
- scitex/scholar/url_finder/translators/individual/jisc_historical_texts.py +3 -1
- scitex/scholar/url_finder/translators/individual/jstor.py +14 -12
- scitex/scholar/url_finder/translators/individual/korean_national_library.py +3 -1
- scitex/scholar/url_finder/translators/individual/la_times.py +3 -1
- scitex/scholar/url_finder/translators/individual/landesbibliographie_baden_wurttemberg.py +3 -1
- scitex/scholar/url_finder/translators/individual/legislative_insight.py +3 -1
- scitex/scholar/url_finder/translators/individual/libraries_tasmania.py +3 -1
- scitex/scholar/url_finder/translators/individual/library_catalog__koha_.py +3 -1
- scitex/scholar/url_finder/translators/individual/lingbuzz.py +2 -2
- scitex/scholar/url_finder/translators/individual/max_planck_institute_for_the_history_of_science_virtual_laboratory_library.py +3 -1
- scitex/scholar/url_finder/translators/individual/mdpi.py +12 -6
- scitex/scholar/url_finder/translators/individual/microbiology_society_journals.py +3 -1
- scitex/scholar/url_finder/translators/individual/midas_journals.py +3 -1
- scitex/scholar/url_finder/translators/individual/nagoya_university_opac.py +3 -1
- scitex/scholar/url_finder/translators/individual/nature_publishing_group.py +32 -19
- scitex/scholar/url_finder/translators/individual/ntsb_accident_reports.py +3 -1
- scitex/scholar/url_finder/translators/individual/openedition_journals.py +8 -4
- scitex/scholar/url_finder/translators/individual/orcid.py +16 -15
- scitex/scholar/url_finder/translators/individual/oxford.py +25 -19
- scitex/scholar/url_finder/translators/individual/oxford_dictionaries_premium.py +3 -1
- scitex/scholar/url_finder/translators/individual/ozon_ru.py +3 -1
- scitex/scholar/url_finder/translators/individual/plos.py +9 -12
- scitex/scholar/url_finder/translators/individual/polygon.py +3 -1
- scitex/scholar/url_finder/translators/individual/primo.py +3 -1
- scitex/scholar/url_finder/translators/individual/project_muse.py +3 -1
- scitex/scholar/url_finder/translators/individual/pubfactory_journals.py +3 -1
- scitex/scholar/url_finder/translators/individual/pubmed.py +71 -65
- scitex/scholar/url_finder/translators/individual/pubmed_central.py +8 -6
- scitex/scholar/url_finder/translators/individual/rechtspraak_nl.py +3 -1
- scitex/scholar/url_finder/translators/individual/sage_journals.py +25 -17
- scitex/scholar/url_finder/translators/individual/sciencedirect.py +36 -17
- scitex/scholar/url_finder/translators/individual/semantics_visual_library.py +3 -1
- scitex/scholar/url_finder/translators/individual/silverchair.py +70 -52
- scitex/scholar/url_finder/translators/individual/sora.py +3 -1
- scitex/scholar/url_finder/translators/individual/springer.py +15 -11
- scitex/scholar/url_finder/translators/individual/ssrn.py +3 -3
- scitex/scholar/url_finder/translators/individual/stanford_encyclopedia_of_philosophy.py +3 -1
- scitex/scholar/url_finder/translators/individual/superlib.py +3 -1
- scitex/scholar/url_finder/translators/individual/treesearch.py +3 -1
- scitex/scholar/url_finder/translators/individual/university_of_chicago_press_books.py +3 -1
- scitex/scholar/url_finder/translators/individual/vlex.py +3 -1
- scitex/scholar/url_finder/translators/individual/web_of_science.py +3 -1
- scitex/scholar/url_finder/translators/individual/web_of_science_nextgen.py +3 -1
- scitex/scholar/url_finder/translators/individual/wiley.py +31 -25
- scitex/scholar/url_finder/translators/individual/wilson_center_digital_archive.py +3 -1
- scitex/scholar/utils/bibtex/_parse_bibtex.py +3 -3
- scitex/scholar/utils/cleanup/_cleanup_scholar_processes.py +5 -9
- scitex/scholar/utils/text/_TextNormalizer.py +249 -176
- scitex/scholar/utils/validation/DOIValidator.py +31 -28
- scitex/scholar/utils/validation/__init__.py +0 -0
- scitex/scholar/utils/validation/validate_library_dois.py +61 -57
- scitex/scholar/zotero/__init__.py +1 -1
- scitex/security/cli.py +7 -20
- scitex/security/github.py +45 -32
- scitex/session/__init__.py +8 -9
- scitex/session/_decorator.py +49 -42
- scitex/session/_lifecycle.py +39 -39
- scitex/session/_manager.py +24 -20
- scitex/sh/__init__.py +4 -3
- scitex/sh/_execute.py +10 -7
- scitex/sh/_security.py +3 -3
- scitex/sh/_types.py +2 -3
- scitex/stats/__init__.py +174 -6
- scitex/stats/_schema.py +42 -569
- scitex/stats/auto/__init__.py +188 -0
- scitex/stats/auto/_context.py +331 -0
- scitex/stats/auto/_formatting.py +679 -0
- scitex/stats/auto/_rules.py +901 -0
- scitex/stats/auto/_selector.py +554 -0
- scitex/stats/auto/_styles.py +721 -0
- scitex/stats/correct/__init__.py +4 -4
- scitex/stats/correct/_correct_bonferroni.py +43 -34
- scitex/stats/correct/_correct_fdr.py +14 -40
- scitex/stats/correct/_correct_fdr_.py +39 -46
- scitex/stats/correct/_correct_holm.py +14 -32
- scitex/stats/correct/_correct_sidak.py +36 -21
- scitex/stats/descriptive/_circular.py +20 -21
- scitex/stats/descriptive/_describe.py +19 -5
- scitex/stats/descriptive/_nan.py +5 -7
- scitex/stats/descriptive/_real.py +4 -3
- scitex/stats/effect_sizes/__init__.py +10 -11
- scitex/stats/effect_sizes/_cliffs_delta.py +35 -32
- scitex/stats/effect_sizes/_cohens_d.py +30 -31
- scitex/stats/effect_sizes/_epsilon_squared.py +19 -22
- scitex/stats/effect_sizes/_eta_squared.py +23 -27
- scitex/stats/effect_sizes/_prob_superiority.py +18 -21
- scitex/stats/io/__init__.py +29 -0
- scitex/stats/io/_bundle.py +156 -0
- scitex/stats/posthoc/__init__.py +3 -3
- scitex/stats/posthoc/_dunnett.py +75 -55
- scitex/stats/posthoc/_games_howell.py +61 -43
- scitex/stats/posthoc/_tukey_hsd.py +42 -34
- scitex/stats/power/__init__.py +2 -2
- scitex/stats/power/_power.py +56 -56
- scitex/stats/tests/__init__.py +1 -1
- scitex/stats/tests/correlation/__init__.py +1 -1
- scitex/stats/tests/correlation/_test_pearson.py +28 -38
- scitex/stats/utils/__init__.py +14 -17
- scitex/stats/utils/_effect_size.py +85 -78
- scitex/stats/utils/_formatters.py +49 -43
- scitex/stats/utils/_normalizers.py +7 -14
- scitex/stats/utils/_power.py +56 -56
- scitex/str/__init__.py +1 -0
- scitex/str/_clean_path.py +3 -3
- scitex/str/_factor_out_digits.py +86 -58
- scitex/str/_format_plot_text.py +180 -111
- scitex/str/_latex.py +19 -19
- scitex/str/_latex_fallback.py +9 -10
- scitex/str/_parse.py +3 -6
- scitex/str/_print_debug.py +13 -13
- scitex/str/_printc.py +2 -0
- scitex/str/_search.py +3 -3
- scitex/template/.legacy/_clone_project.py +9 -13
- scitex/template/__init__.py +10 -2
- scitex/template/_clone_project.py +7 -2
- scitex/template/_copy.py +1 -0
- scitex/template/_customize.py +3 -6
- scitex/template/_git_strategy.py +2 -3
- scitex/template/_rename.py +1 -0
- scitex/template/clone_pip_project.py +6 -7
- scitex/template/clone_research.py +7 -10
- scitex/template/clone_singularity.py +6 -7
- scitex/template/clone_writer_directory.py +6 -7
- scitex/tex/__init__.py +4 -0
- scitex/tex/_export.py +890 -0
- scitex/tex/_preview.py +26 -11
- scitex/tex/_to_vec.py +10 -7
- scitex/torch/__init__.py +11 -1
- scitex/types/_ArrayLike.py +2 -0
- scitex/types/_is_listed_X.py +3 -3
- scitex/units.py +110 -77
- scitex/utils/_compress_hdf5.py +3 -3
- scitex/utils/_email.py +8 -4
- scitex/utils/_notify.py +14 -8
- scitex/utils/_search.py +6 -6
- scitex/utils/_verify_scitex_format.py +17 -42
- scitex/utils/_verify_scitex_format_v01.py +12 -34
- scitex/utils/template.py +4 -3
- scitex/web/__init__.py +7 -1
- scitex/web/_scraping.py +54 -38
- scitex/web/_search_pubmed.py +30 -14
- scitex/writer/.legacy/Writer_v01-refactored.py +4 -4
- scitex/writer/.legacy/_compile.py +18 -28
- scitex/writer/Writer.py +8 -21
- scitex/writer/__init__.py +11 -11
- scitex/writer/_clone_writer_project.py +2 -6
- scitex/writer/_compile/__init__.py +1 -0
- scitex/writer/_compile/_parser.py +1 -0
- scitex/writer/_compile/_runner.py +35 -38
- scitex/writer/_compile/_validator.py +1 -0
- scitex/writer/_compile/manuscript.py +1 -0
- scitex/writer/_compile/revision.py +1 -0
- scitex/writer/_compile/supplementary.py +1 -0
- scitex/writer/_compile_async.py +5 -12
- scitex/writer/_project/__init__.py +1 -0
- scitex/writer/_project/_create.py +10 -25
- scitex/writer/_project/_trees.py +4 -9
- scitex/writer/_project/_validate.py +2 -3
- scitex/writer/_validate_tree_structures.py +7 -18
- scitex/writer/dataclasses/__init__.py +8 -10
- scitex/writer/dataclasses/config/_CONSTANTS.py +2 -3
- scitex/writer/dataclasses/config/_WriterConfig.py +4 -9
- scitex/writer/dataclasses/contents/_ManuscriptContents.py +14 -25
- scitex/writer/dataclasses/contents/_RevisionContents.py +21 -16
- scitex/writer/dataclasses/contents/_SupplementaryContents.py +21 -24
- scitex/writer/dataclasses/core/_Document.py +2 -3
- scitex/writer/dataclasses/core/_DocumentSection.py +8 -23
- scitex/writer/dataclasses/results/_CompilationResult.py +2 -3
- scitex/writer/dataclasses/results/_LaTeXIssue.py +3 -6
- scitex/writer/dataclasses/results/_SaveSectionsResponse.py +20 -9
- scitex/writer/dataclasses/results/_SectionReadResponse.py +24 -10
- scitex/writer/dataclasses/tree/_ConfigTree.py +7 -4
- scitex/writer/dataclasses/tree/_ManuscriptTree.py +10 -13
- scitex/writer/dataclasses/tree/_RevisionTree.py +16 -17
- scitex/writer/dataclasses/tree/_ScriptsTree.py +10 -5
- scitex/writer/dataclasses/tree/_SharedTree.py +10 -13
- scitex/writer/dataclasses/tree/_SupplementaryTree.py +15 -14
- scitex/writer/utils/.legacy_git_retry.py +3 -8
- scitex/writer/utils/_parse_latex_logs.py +2 -3
- scitex/writer/utils/_parse_script_args.py +20 -23
- scitex/writer/utils/_watch.py +5 -5
- {scitex-2.5.0.dist-info → scitex-2.7.3.dist-info}/METADATA +14 -10
- {scitex-2.5.0.dist-info → scitex-2.7.3.dist-info}/RECORD +1149 -985
- scitex/db/_sqlite3/_SQLite3Mixins/_ColumnMixin_v01-indentation-issues.py +0 -583
- scitex/io/memo.md +0 -2827
- scitex/plt/_subplots/TODO.md +0 -53
- scitex/plt/_subplots/_AxisWrapperMixins/_AdjustmentMixin.py +0 -537
- scitex/plt/_subplots/_AxisWrapperMixins/_MatplotlibPlotMixin.py +0 -1499
- scitex/plt/_subplots/_AxisWrapperMixins/_SeabornMixin.py +0 -431
- scitex/plt/_subplots/_export_as_csv_formatters.py +0 -112
- scitex/vis/__init__.py +0 -177
- scitex/vis/editor/_defaults.py +0 -244
- scitex/vis/editor/_edit.py +0 -378
- scitex/vis/editor/flask_editor/__init__.py +0 -21
- scitex/vis/editor/flask_editor/bbox.py +0 -216
- scitex/vis/editor/flask_editor/core.py +0 -152
- scitex/vis/editor/flask_editor/plotter.py +0 -130
- scitex/vis/editor/flask_editor/renderer.py +0 -184
- scitex/vis/editor/flask_editor/templates/html.py +0 -295
- scitex/vis/editor/flask_editor/templates/scripts.py +0 -614
- scitex/vis/editor/flask_editor/templates/styles.py +0 -549
- /scitex/{vis → fig}/README.md +0 -0
- /scitex/{vis → fig}/docs/CANVAS_ARCHITECTURE.md +0 -0
- {scitex-2.5.0.dist-info → scitex-2.7.3.dist-info}/WHEEL +0 -0
- {scitex-2.5.0.dist-info → scitex-2.7.3.dist-info}/entry_points.txt +0 -0
- {scitex-2.5.0.dist-info → scitex-2.7.3.dist-info}/licenses/LICENSE +0 -0
|
@@ -0,0 +1,1276 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
# File: ./src/scitex/vis/editor/flask_editor/bbox.py
|
|
4
|
+
"""Bounding box extraction for figure elements.
|
|
5
|
+
|
|
6
|
+
Updated to integrate Schema v0.3 geometry extraction for shape-based hit testing.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from typing import Dict, Any
|
|
10
|
+
|
|
11
|
+
# Try to import schema v0.3 geometry extraction
|
|
12
|
+
try:
|
|
13
|
+
from scitex.plt.utils.metadata._geometry_extraction import (
|
|
14
|
+
extract_axes_bbox_px,
|
|
15
|
+
extract_line_geometry,
|
|
16
|
+
extract_scatter_geometry,
|
|
17
|
+
extract_polygon_geometry,
|
|
18
|
+
extract_bar_group_geometry,
|
|
19
|
+
)
|
|
20
|
+
GEOMETRY_V03_AVAILABLE = True
|
|
21
|
+
except ImportError:
|
|
22
|
+
GEOMETRY_V03_AVAILABLE = False
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def extract_bboxes(
|
|
26
|
+
fig, ax, renderer, img_width: int, img_height: int
|
|
27
|
+
) -> Dict[str, Any]:
|
|
28
|
+
"""Extract bounding boxes for all figure elements (single-axis)."""
|
|
29
|
+
from matplotlib.transforms import Bbox
|
|
30
|
+
|
|
31
|
+
# Get figure tight bbox in inches
|
|
32
|
+
fig_bbox = fig.get_tightbbox(renderer)
|
|
33
|
+
tight_x0 = fig_bbox.x0
|
|
34
|
+
tight_y0 = fig_bbox.y0
|
|
35
|
+
tight_width = fig_bbox.width
|
|
36
|
+
tight_height = fig_bbox.height
|
|
37
|
+
|
|
38
|
+
# bbox_inches='tight' adds pad_inches (default 0.1) around the tight bbox
|
|
39
|
+
pad_inches = 0.1
|
|
40
|
+
saved_width_inches = tight_width + 2 * pad_inches
|
|
41
|
+
saved_height_inches = tight_height + 2 * pad_inches
|
|
42
|
+
|
|
43
|
+
# Scale factors for converting inches to pixels
|
|
44
|
+
scale_x = img_width / saved_width_inches
|
|
45
|
+
scale_y = img_height / saved_height_inches
|
|
46
|
+
|
|
47
|
+
bboxes = {}
|
|
48
|
+
|
|
49
|
+
def get_element_bbox(element, name):
|
|
50
|
+
"""Get element bbox in image pixel coordinates."""
|
|
51
|
+
try:
|
|
52
|
+
bbox = element.get_window_extent(renderer)
|
|
53
|
+
|
|
54
|
+
elem_x0_inches = bbox.x0 / fig.dpi
|
|
55
|
+
elem_x1_inches = bbox.x1 / fig.dpi
|
|
56
|
+
elem_y0_inches = bbox.y0 / fig.dpi
|
|
57
|
+
elem_y1_inches = bbox.y1 / fig.dpi
|
|
58
|
+
|
|
59
|
+
x0_rel = elem_x0_inches - tight_x0 + pad_inches
|
|
60
|
+
x1_rel = elem_x1_inches - tight_x0 + pad_inches
|
|
61
|
+
y0_rel = saved_height_inches - (elem_y1_inches - tight_y0 + pad_inches)
|
|
62
|
+
y1_rel = saved_height_inches - (elem_y0_inches - tight_y0 + pad_inches)
|
|
63
|
+
|
|
64
|
+
bboxes[name] = {
|
|
65
|
+
"x0": max(0, int(x0_rel * scale_x)),
|
|
66
|
+
"y0": max(0, int(y0_rel * scale_y)),
|
|
67
|
+
"x1": min(img_width, int(x1_rel * scale_x)),
|
|
68
|
+
"y1": min(img_height, int(y1_rel * scale_y)),
|
|
69
|
+
"label": name.replace("_", " ").title(),
|
|
70
|
+
}
|
|
71
|
+
except Exception as e:
|
|
72
|
+
print(f"Error getting bbox for {name}: {e}")
|
|
73
|
+
|
|
74
|
+
def bbox_to_img_coords(bbox):
|
|
75
|
+
"""Convert matplotlib bbox to image pixel coordinates."""
|
|
76
|
+
x0_inches = bbox.x0 / fig.dpi
|
|
77
|
+
y0_inches = bbox.y0 / fig.dpi
|
|
78
|
+
x1_inches = bbox.x1 / fig.dpi
|
|
79
|
+
y1_inches = bbox.y1 / fig.dpi
|
|
80
|
+
x0_rel = x0_inches - tight_x0 + pad_inches
|
|
81
|
+
y0_rel = y0_inches - tight_y0 + pad_inches
|
|
82
|
+
x1_rel = x1_inches - tight_x0 + pad_inches
|
|
83
|
+
y1_rel = y1_inches - tight_y0 + pad_inches
|
|
84
|
+
return {
|
|
85
|
+
"x0": int(x0_rel * scale_x),
|
|
86
|
+
"y0": int((saved_height_inches - y1_rel) * scale_y),
|
|
87
|
+
"x1": int(x1_rel * scale_x),
|
|
88
|
+
"y1": int((saved_height_inches - y0_rel) * scale_y),
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
# Get bboxes for title, labels
|
|
92
|
+
# Use ax_00_ prefix for consistency with geometry_px.json format
|
|
93
|
+
ax_prefix = "ax_00_"
|
|
94
|
+
if ax.title.get_text():
|
|
95
|
+
get_element_bbox(ax.title, f"{ax_prefix}title")
|
|
96
|
+
if ax.xaxis.label.get_text():
|
|
97
|
+
get_element_bbox(ax.xaxis.label, f"{ax_prefix}xlabel")
|
|
98
|
+
if ax.yaxis.label.get_text():
|
|
99
|
+
get_element_bbox(ax.yaxis.label, f"{ax_prefix}ylabel")
|
|
100
|
+
|
|
101
|
+
# Get axis bboxes
|
|
102
|
+
_extract_axis_bboxes(ax, renderer, bboxes, bbox_to_img_coords, Bbox, ax_prefix)
|
|
103
|
+
|
|
104
|
+
# Get legend bbox
|
|
105
|
+
legend = ax.get_legend()
|
|
106
|
+
if legend:
|
|
107
|
+
get_element_bbox(legend, f"{ax_prefix}legend")
|
|
108
|
+
|
|
109
|
+
# Get caption bbox (figure-level text)
|
|
110
|
+
for text_artist in fig.texts:
|
|
111
|
+
# Check if this is a caption (positioned below figure)
|
|
112
|
+
text_content = text_artist.get_text()
|
|
113
|
+
if text_content:
|
|
114
|
+
pos = text_artist.get_position()
|
|
115
|
+
# Caption is typically centered horizontally (x ~= 0.5) and below figure (y < 0.1)
|
|
116
|
+
if pos[1] < 0.1:
|
|
117
|
+
get_element_bbox(text_artist, f"{ax_prefix}caption")
|
|
118
|
+
break # Only one caption expected
|
|
119
|
+
|
|
120
|
+
# Get trace (line) bboxes
|
|
121
|
+
_extract_trace_bboxes(
|
|
122
|
+
ax,
|
|
123
|
+
fig,
|
|
124
|
+
renderer,
|
|
125
|
+
bboxes,
|
|
126
|
+
get_element_bbox,
|
|
127
|
+
tight_x0,
|
|
128
|
+
tight_y0,
|
|
129
|
+
saved_height_inches,
|
|
130
|
+
scale_x,
|
|
131
|
+
scale_y,
|
|
132
|
+
pad_inches,
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
# Add schema v0.3 metadata if available
|
|
136
|
+
if GEOMETRY_V03_AVAILABLE:
|
|
137
|
+
axes_bbox = extract_axes_bbox_px(ax, fig)
|
|
138
|
+
bboxes["_meta"] = {
|
|
139
|
+
"schema_version": "0.3.0",
|
|
140
|
+
"axes_bbox_px": axes_bbox,
|
|
141
|
+
"geometry_available": True,
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return bboxes
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def extract_bboxes_multi(
|
|
148
|
+
fig, axes_map: Dict[str, Any], renderer, img_width: int, img_height: int
|
|
149
|
+
) -> Dict[str, Any]:
|
|
150
|
+
"""Extract bounding boxes for all elements in a multi-axis figure.
|
|
151
|
+
|
|
152
|
+
Args:
|
|
153
|
+
fig: Matplotlib figure
|
|
154
|
+
axes_map: Dict mapping axis IDs (e.g., 'ax_00') to matplotlib Axes objects
|
|
155
|
+
renderer: Matplotlib renderer
|
|
156
|
+
img_width: Image width in pixels
|
|
157
|
+
img_height: Image height in pixels
|
|
158
|
+
|
|
159
|
+
Returns:
|
|
160
|
+
Dict with bboxes keyed by "{ax_id}_{element_type}" (e.g., "ax_00_xlabel")
|
|
161
|
+
"""
|
|
162
|
+
from matplotlib.transforms import Bbox
|
|
163
|
+
|
|
164
|
+
# Get figure tight bbox in inches
|
|
165
|
+
fig_bbox = fig.get_tightbbox(renderer)
|
|
166
|
+
tight_x0 = fig_bbox.x0
|
|
167
|
+
tight_y0 = fig_bbox.y0
|
|
168
|
+
tight_width = fig_bbox.width
|
|
169
|
+
tight_height = fig_bbox.height
|
|
170
|
+
|
|
171
|
+
# bbox_inches='tight' adds pad_inches (default 0.1) around the tight bbox
|
|
172
|
+
pad_inches = 0.1
|
|
173
|
+
saved_width_inches = tight_width + 2 * pad_inches
|
|
174
|
+
saved_height_inches = tight_height + 2 * pad_inches
|
|
175
|
+
|
|
176
|
+
# Scale factors for converting inches to pixels
|
|
177
|
+
scale_x = img_width / saved_width_inches
|
|
178
|
+
scale_y = img_height / saved_height_inches
|
|
179
|
+
|
|
180
|
+
bboxes = {}
|
|
181
|
+
|
|
182
|
+
def get_element_bbox(element, name, ax_id, current_ax=None):
|
|
183
|
+
"""Get element bbox in image pixel coordinates."""
|
|
184
|
+
import numpy as np
|
|
185
|
+
full_name = f"{ax_id}_{name}"
|
|
186
|
+
try:
|
|
187
|
+
bbox = element.get_window_extent(renderer)
|
|
188
|
+
|
|
189
|
+
# Check for invalid bbox (infinity or NaN)
|
|
190
|
+
if not (np.isfinite(bbox.x0) and np.isfinite(bbox.x1) and
|
|
191
|
+
np.isfinite(bbox.y0) and np.isfinite(bbox.y1)):
|
|
192
|
+
# Try to get bbox from data for scatter/collection elements
|
|
193
|
+
if hasattr(element, 'get_offsets') and current_ax is not None:
|
|
194
|
+
offsets = element.get_offsets()
|
|
195
|
+
if len(offsets) > 0 and np.isfinite(offsets).all():
|
|
196
|
+
# Use axis transform to get display coordinates
|
|
197
|
+
display_coords = current_ax.transData.transform(offsets)
|
|
198
|
+
x0 = display_coords[:, 0].min()
|
|
199
|
+
x1 = display_coords[:, 0].max()
|
|
200
|
+
y0 = display_coords[:, 1].min()
|
|
201
|
+
y1 = display_coords[:, 1].max()
|
|
202
|
+
if np.isfinite([x0, x1, y0, y1]).all():
|
|
203
|
+
from matplotlib.transforms import Bbox
|
|
204
|
+
bbox = Bbox.from_extents(x0, y0, x1, y1)
|
|
205
|
+
else:
|
|
206
|
+
return # Skip this element
|
|
207
|
+
else:
|
|
208
|
+
return # Skip this element
|
|
209
|
+
else:
|
|
210
|
+
return # Skip this element
|
|
211
|
+
|
|
212
|
+
elem_x0_inches = bbox.x0 / fig.dpi
|
|
213
|
+
elem_x1_inches = bbox.x1 / fig.dpi
|
|
214
|
+
elem_y0_inches = bbox.y0 / fig.dpi
|
|
215
|
+
elem_y1_inches = bbox.y1 / fig.dpi
|
|
216
|
+
|
|
217
|
+
x0_rel = elem_x0_inches - tight_x0 + pad_inches
|
|
218
|
+
x1_rel = elem_x1_inches - tight_x0 + pad_inches
|
|
219
|
+
y0_rel = saved_height_inches - (elem_y1_inches - tight_y0 + pad_inches)
|
|
220
|
+
y1_rel = saved_height_inches - (elem_y0_inches - tight_y0 + pad_inches)
|
|
221
|
+
|
|
222
|
+
# Clamp values to avoid overflow
|
|
223
|
+
x0_px = max(0, min(img_width, int(x0_rel * scale_x)))
|
|
224
|
+
y0_px = max(0, min(img_height, int(y0_rel * scale_y)))
|
|
225
|
+
x1_px = max(0, min(img_width, int(x1_rel * scale_x)))
|
|
226
|
+
y1_px = max(0, min(img_height, int(y1_rel * scale_y)))
|
|
227
|
+
|
|
228
|
+
bboxes[full_name] = {
|
|
229
|
+
"x0": x0_px,
|
|
230
|
+
"y0": y0_px,
|
|
231
|
+
"x1": x1_px,
|
|
232
|
+
"y1": y1_px,
|
|
233
|
+
"label": f"{ax_id}: {name.replace('_', ' ').title()}",
|
|
234
|
+
"ax_id": ax_id,
|
|
235
|
+
}
|
|
236
|
+
except Exception as e:
|
|
237
|
+
print(f"Error getting bbox for {full_name}: {e}")
|
|
238
|
+
|
|
239
|
+
def bbox_to_img_coords(bbox):
|
|
240
|
+
"""Convert matplotlib bbox to image pixel coordinates."""
|
|
241
|
+
x0_inches = bbox.x0 / fig.dpi
|
|
242
|
+
y0_inches = bbox.y0 / fig.dpi
|
|
243
|
+
x1_inches = bbox.x1 / fig.dpi
|
|
244
|
+
y1_inches = bbox.y1 / fig.dpi
|
|
245
|
+
x0_rel = x0_inches - tight_x0 + pad_inches
|
|
246
|
+
y0_rel = y0_inches - tight_y0 + pad_inches
|
|
247
|
+
x1_rel = x1_inches - tight_x0 + pad_inches
|
|
248
|
+
y1_rel = y1_inches - tight_y0 + pad_inches
|
|
249
|
+
return {
|
|
250
|
+
"x0": int(x0_rel * scale_x),
|
|
251
|
+
"y0": int((saved_height_inches - y1_rel) * scale_y),
|
|
252
|
+
"x1": int(x1_rel * scale_x),
|
|
253
|
+
"y1": int((saved_height_inches - y0_rel) * scale_y),
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
# Extract bboxes for each axis
|
|
257
|
+
for ax_id, ax in axes_map.items():
|
|
258
|
+
# Get axes bounding box (the entire panel area)
|
|
259
|
+
try:
|
|
260
|
+
ax_bbox = ax.get_window_extent(renderer)
|
|
261
|
+
coords = bbox_to_img_coords(ax_bbox)
|
|
262
|
+
# Extract actual title/labels from the axes
|
|
263
|
+
title_text = ax.title.get_text() if ax.title else ""
|
|
264
|
+
xlabel_text = ax.xaxis.label.get_text() if ax.xaxis.label else ""
|
|
265
|
+
ylabel_text = ax.yaxis.label.get_text() if ax.yaxis.label else ""
|
|
266
|
+
bboxes[f"{ax_id}_panel"] = {
|
|
267
|
+
**coords,
|
|
268
|
+
"label": f"Panel {ax_id}",
|
|
269
|
+
"ax_id": ax_id,
|
|
270
|
+
"is_panel": True,
|
|
271
|
+
"title": title_text,
|
|
272
|
+
"xlabel": xlabel_text,
|
|
273
|
+
"ylabel": ylabel_text,
|
|
274
|
+
}
|
|
275
|
+
except Exception as e:
|
|
276
|
+
print(f"Error getting panel bbox for {ax_id}: {e}")
|
|
277
|
+
|
|
278
|
+
# Get bboxes for title, labels
|
|
279
|
+
if ax.title.get_text():
|
|
280
|
+
get_element_bbox(ax.title, "title", ax_id, ax)
|
|
281
|
+
if ax.xaxis.label.get_text():
|
|
282
|
+
get_element_bbox(ax.xaxis.label, "xlabel", ax_id, ax)
|
|
283
|
+
if ax.yaxis.label.get_text():
|
|
284
|
+
get_element_bbox(ax.yaxis.label, "ylabel", ax_id, ax)
|
|
285
|
+
|
|
286
|
+
# Get X-axis bbox (spine + ticks + ticklabels)
|
|
287
|
+
_extract_axis_bboxes_for_axis(ax, ax_id, renderer, bboxes, bbox_to_img_coords, Bbox)
|
|
288
|
+
|
|
289
|
+
# Get legend bbox
|
|
290
|
+
legend = ax.get_legend()
|
|
291
|
+
if legend:
|
|
292
|
+
get_element_bbox(legend, "legend", ax_id, ax)
|
|
293
|
+
|
|
294
|
+
# Get trace (line) bboxes
|
|
295
|
+
_extract_trace_bboxes_for_axis(
|
|
296
|
+
ax,
|
|
297
|
+
ax_id,
|
|
298
|
+
fig,
|
|
299
|
+
renderer,
|
|
300
|
+
bboxes,
|
|
301
|
+
get_element_bbox,
|
|
302
|
+
tight_x0,
|
|
303
|
+
tight_y0,
|
|
304
|
+
saved_height_inches,
|
|
305
|
+
scale_x,
|
|
306
|
+
scale_y,
|
|
307
|
+
pad_inches,
|
|
308
|
+
)
|
|
309
|
+
|
|
310
|
+
# Get caption bbox (figure-level text)
|
|
311
|
+
# This is outside the per-axis loop since caption is a figure-level element
|
|
312
|
+
for text_artist in fig.texts:
|
|
313
|
+
text_content = text_artist.get_text()
|
|
314
|
+
if text_content:
|
|
315
|
+
pos = text_artist.get_position()
|
|
316
|
+
# Caption is typically centered horizontally (x ~= 0.5) and below figure (y < 0.1)
|
|
317
|
+
if pos[1] < 0.1:
|
|
318
|
+
try:
|
|
319
|
+
bbox = text_artist.get_window_extent(renderer)
|
|
320
|
+
x0_inches = bbox.x0 / fig.dpi
|
|
321
|
+
x1_inches = bbox.x1 / fig.dpi
|
|
322
|
+
y0_inches = bbox.y0 / fig.dpi
|
|
323
|
+
y1_inches = bbox.y1 / fig.dpi
|
|
324
|
+
x0_rel = x0_inches - tight_x0 + pad_inches
|
|
325
|
+
x1_rel = x1_inches - tight_x0 + pad_inches
|
|
326
|
+
y0_rel = saved_height_inches - (y1_inches - tight_y0 + pad_inches)
|
|
327
|
+
y1_rel = saved_height_inches - (y0_inches - tight_y0 + pad_inches)
|
|
328
|
+
bboxes["caption"] = {
|
|
329
|
+
"x0": max(0, int(x0_rel * scale_x)),
|
|
330
|
+
"y0": max(0, int(y0_rel * scale_y)),
|
|
331
|
+
"x1": min(img_width, int(x1_rel * scale_x)),
|
|
332
|
+
"y1": min(img_height, int(y1_rel * scale_y)),
|
|
333
|
+
"label": "Caption",
|
|
334
|
+
}
|
|
335
|
+
except Exception as e:
|
|
336
|
+
print(f"Error getting caption bbox: {e}")
|
|
337
|
+
break # Only one caption expected
|
|
338
|
+
|
|
339
|
+
# Add schema v0.3 metadata if available
|
|
340
|
+
if GEOMETRY_V03_AVAILABLE:
|
|
341
|
+
axes_bboxes = {}
|
|
342
|
+
for ax_id, ax in axes_map.items():
|
|
343
|
+
axes_bboxes[ax_id] = extract_axes_bbox_px(ax, fig)
|
|
344
|
+
bboxes["_meta"] = {
|
|
345
|
+
"schema_version": "0.3.0",
|
|
346
|
+
"axes": axes_bboxes,
|
|
347
|
+
"geometry_available": True,
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
return bboxes
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
def _extract_trace_bboxes_for_axis(
|
|
354
|
+
ax,
|
|
355
|
+
ax_id,
|
|
356
|
+
fig,
|
|
357
|
+
renderer,
|
|
358
|
+
bboxes,
|
|
359
|
+
get_element_bbox,
|
|
360
|
+
tight_x0,
|
|
361
|
+
tight_y0,
|
|
362
|
+
saved_height_inches,
|
|
363
|
+
scale_x,
|
|
364
|
+
scale_y,
|
|
365
|
+
pad_inches,
|
|
366
|
+
):
|
|
367
|
+
"""Extract bboxes for all data elements in a specific axis.
|
|
368
|
+
|
|
369
|
+
Handles:
|
|
370
|
+
- Lines (plot, errorbar lines)
|
|
371
|
+
- Scatter points (PathCollection)
|
|
372
|
+
- Fill areas (PolyCollection from fill_between)
|
|
373
|
+
- Bars (Rectangle patches)
|
|
374
|
+
"""
|
|
375
|
+
import numpy as np
|
|
376
|
+
|
|
377
|
+
def coords_to_img_points(data_coords):
|
|
378
|
+
"""Convert data coordinates to image pixel coordinates."""
|
|
379
|
+
if len(data_coords) == 0:
|
|
380
|
+
return []
|
|
381
|
+
transform = ax.transData
|
|
382
|
+
points_display = transform.transform(data_coords)
|
|
383
|
+
points_img = []
|
|
384
|
+
for px, py in points_display:
|
|
385
|
+
# Skip invalid points (NaN, infinity)
|
|
386
|
+
if not np.isfinite(px) or not np.isfinite(py):
|
|
387
|
+
continue
|
|
388
|
+
px_inches = px / fig.dpi
|
|
389
|
+
py_inches = py / fig.dpi
|
|
390
|
+
x_rel = px_inches - tight_x0 + pad_inches
|
|
391
|
+
y_rel = saved_height_inches - (py_inches - tight_y0 + pad_inches)
|
|
392
|
+
# Clamp to reasonable bounds to avoid overflow
|
|
393
|
+
x_img = max(-10000, min(10000, int(x_rel * scale_x)))
|
|
394
|
+
y_img = max(-10000, min(10000, int(y_rel * scale_y)))
|
|
395
|
+
points_img.append([x_img, y_img])
|
|
396
|
+
# Downsample if too many
|
|
397
|
+
if len(points_img) > 100:
|
|
398
|
+
step = len(points_img) // 100
|
|
399
|
+
points_img = points_img[::step]
|
|
400
|
+
return points_img
|
|
401
|
+
|
|
402
|
+
# 1. Extract lines (plot, errorbar lines, etc.)
|
|
403
|
+
line_idx = 0
|
|
404
|
+
for line in ax.get_lines():
|
|
405
|
+
try:
|
|
406
|
+
label = line.get_label()
|
|
407
|
+
# Include unlabeled lines but mark them appropriately
|
|
408
|
+
if label is None or label.startswith("_"):
|
|
409
|
+
label = None # Will use generic name
|
|
410
|
+
|
|
411
|
+
trace_name = f"trace_{line_idx}"
|
|
412
|
+
full_name = f"{ax_id}_{trace_name}"
|
|
413
|
+
get_element_bbox(line, trace_name, ax_id, ax)
|
|
414
|
+
|
|
415
|
+
if full_name in bboxes:
|
|
416
|
+
bboxes[full_name]["label"] = f"{ax_id}: {label or f'Line {line_idx}'}"
|
|
417
|
+
bboxes[full_name]["trace_idx"] = line_idx
|
|
418
|
+
bboxes[full_name]["element_type"] = "line"
|
|
419
|
+
|
|
420
|
+
xdata, ydata = line.get_xdata(), line.get_ydata()
|
|
421
|
+
if len(xdata) > 0:
|
|
422
|
+
bboxes[full_name]["points"] = coords_to_img_points(
|
|
423
|
+
list(zip(xdata, ydata))
|
|
424
|
+
)
|
|
425
|
+
|
|
426
|
+
# Add schema v0.3 geometry_px if available
|
|
427
|
+
if GEOMETRY_V03_AVAILABLE:
|
|
428
|
+
try:
|
|
429
|
+
geom = extract_line_geometry(line, ax, fig)
|
|
430
|
+
bboxes[full_name]["geometry_px"] = geom
|
|
431
|
+
except Exception:
|
|
432
|
+
pass # Fall back to legacy points
|
|
433
|
+
|
|
434
|
+
line_idx += 1
|
|
435
|
+
except Exception as e:
|
|
436
|
+
print(f"Error getting line bbox for {ax_id}: {e}")
|
|
437
|
+
|
|
438
|
+
# 2. Extract collections (scatter, fill_between, etc.)
|
|
439
|
+
coll_idx = 0
|
|
440
|
+
for coll in ax.collections:
|
|
441
|
+
try:
|
|
442
|
+
label = coll.get_label()
|
|
443
|
+
if label is None or label.startswith("_"):
|
|
444
|
+
# Still extract unlabeled collections but with generic name
|
|
445
|
+
label = None
|
|
446
|
+
|
|
447
|
+
coll_type = type(coll).__name__
|
|
448
|
+
if coll_type == "PathCollection":
|
|
449
|
+
# Scatter points
|
|
450
|
+
element_name = f"scatter_{coll_idx}"
|
|
451
|
+
full_name = f"{ax_id}_{element_name}"
|
|
452
|
+
get_element_bbox(coll, element_name, ax_id, ax)
|
|
453
|
+
|
|
454
|
+
if full_name in bboxes:
|
|
455
|
+
bboxes[full_name]["label"] = f"{ax_id}: {label or f'Scatter {coll_idx}'}"
|
|
456
|
+
bboxes[full_name]["element_type"] = "scatter"
|
|
457
|
+
|
|
458
|
+
# Get scatter point positions
|
|
459
|
+
offsets = coll.get_offsets()
|
|
460
|
+
if len(offsets) > 0:
|
|
461
|
+
bboxes[full_name]["points"] = coords_to_img_points(offsets)
|
|
462
|
+
|
|
463
|
+
# Add schema v0.3 geometry_px if available
|
|
464
|
+
if GEOMETRY_V03_AVAILABLE:
|
|
465
|
+
try:
|
|
466
|
+
geom = extract_scatter_geometry(coll, ax, fig)
|
|
467
|
+
bboxes[full_name]["geometry_px"] = geom
|
|
468
|
+
except Exception:
|
|
469
|
+
pass # Fall back to legacy points
|
|
470
|
+
|
|
471
|
+
elif coll_type in ("PolyCollection", "FillBetweenPolyCollection"):
|
|
472
|
+
# Fill areas (fill_between, etc.)
|
|
473
|
+
element_name = f"fill_{coll_idx}"
|
|
474
|
+
full_name = f"{ax_id}_{element_name}"
|
|
475
|
+
get_element_bbox(coll, element_name, ax_id, ax)
|
|
476
|
+
|
|
477
|
+
if full_name in bboxes:
|
|
478
|
+
bboxes[full_name]["label"] = f"{ax_id}: {label or f'Fill {coll_idx}'}"
|
|
479
|
+
bboxes[full_name]["element_type"] = "fill"
|
|
480
|
+
|
|
481
|
+
# Add schema v0.3 geometry_px if available
|
|
482
|
+
if GEOMETRY_V03_AVAILABLE:
|
|
483
|
+
try:
|
|
484
|
+
geom = extract_polygon_geometry(coll, ax, fig)
|
|
485
|
+
bboxes[full_name]["geometry_px"] = geom
|
|
486
|
+
except Exception:
|
|
487
|
+
pass
|
|
488
|
+
|
|
489
|
+
coll_idx += 1
|
|
490
|
+
except Exception as e:
|
|
491
|
+
print(f"Error getting collection bbox for {ax_id}: {e}")
|
|
492
|
+
|
|
493
|
+
# 3. Extract patches (bars, rectangles, etc.)
|
|
494
|
+
patch_idx = 0
|
|
495
|
+
for patch in ax.patches:
|
|
496
|
+
try:
|
|
497
|
+
label = patch.get_label()
|
|
498
|
+
patch_type = type(patch).__name__
|
|
499
|
+
|
|
500
|
+
if patch_type == "Rectangle":
|
|
501
|
+
# Bar chart bars
|
|
502
|
+
element_name = f"bar_{patch_idx}"
|
|
503
|
+
full_name = f"{ax_id}_{element_name}"
|
|
504
|
+
get_element_bbox(patch, element_name, ax_id, ax)
|
|
505
|
+
|
|
506
|
+
if full_name in bboxes:
|
|
507
|
+
bboxes[full_name]["label"] = f"{ax_id}: {label or f'Bar {patch_idx}'}"
|
|
508
|
+
bboxes[full_name]["element_type"] = "bar"
|
|
509
|
+
|
|
510
|
+
patch_idx += 1
|
|
511
|
+
except Exception as e:
|
|
512
|
+
print(f"Error getting patch bbox for {ax_id}: {e}")
|
|
513
|
+
|
|
514
|
+
|
|
515
|
+
def _extract_axis_bboxes_for_axis(ax, ax_id, renderer, bboxes, bbox_to_img_coords, Bbox):
|
|
516
|
+
"""Extract X and Y axis bboxes for a specific axis (multi-axis version)."""
|
|
517
|
+
try:
|
|
518
|
+
# X-axis: combine spine and tick labels into one bbox
|
|
519
|
+
x_axis_bboxes = []
|
|
520
|
+
for ticklabel in ax.xaxis.get_ticklabels():
|
|
521
|
+
if ticklabel.get_visible():
|
|
522
|
+
try:
|
|
523
|
+
tb = ticklabel.get_window_extent(renderer)
|
|
524
|
+
if tb.width > 0:
|
|
525
|
+
x_axis_bboxes.append(tb)
|
|
526
|
+
except Exception:
|
|
527
|
+
pass
|
|
528
|
+
for tick in ax.xaxis.get_major_ticks():
|
|
529
|
+
if tick.tick1line.get_visible():
|
|
530
|
+
try:
|
|
531
|
+
tb = tick.tick1line.get_window_extent(renderer)
|
|
532
|
+
if tb.width > 0 or tb.height > 0:
|
|
533
|
+
x_axis_bboxes.append(tb)
|
|
534
|
+
except Exception:
|
|
535
|
+
pass
|
|
536
|
+
spine_bbox = ax.spines["bottom"].get_window_extent(renderer)
|
|
537
|
+
if spine_bbox.width > 0:
|
|
538
|
+
if x_axis_bboxes:
|
|
539
|
+
tick_union = Bbox.union(x_axis_bboxes)
|
|
540
|
+
constrained_spine = Bbox.from_extents(
|
|
541
|
+
tick_union.x0, spine_bbox.y0, tick_union.x1, spine_bbox.y1
|
|
542
|
+
)
|
|
543
|
+
x_axis_bboxes.append(constrained_spine)
|
|
544
|
+
else:
|
|
545
|
+
x_axis_bboxes.append(spine_bbox)
|
|
546
|
+
if x_axis_bboxes:
|
|
547
|
+
combined = Bbox.union(x_axis_bboxes)
|
|
548
|
+
bboxes[f"{ax_id}_xaxis"] = bbox_to_img_coords(combined)
|
|
549
|
+
bboxes[f"{ax_id}_xaxis"]["label"] = f"{ax_id}: X Axis"
|
|
550
|
+
bboxes[f"{ax_id}_xaxis"]["ax_id"] = ax_id
|
|
551
|
+
bboxes[f"{ax_id}_xaxis"]["element_type"] = "xaxis"
|
|
552
|
+
|
|
553
|
+
# Y-axis: combine spine and tick labels into one bbox
|
|
554
|
+
y_axis_bboxes = []
|
|
555
|
+
for ticklabel in ax.yaxis.get_ticklabels():
|
|
556
|
+
if ticklabel.get_visible():
|
|
557
|
+
try:
|
|
558
|
+
tb = ticklabel.get_window_extent(renderer)
|
|
559
|
+
if tb.width > 0:
|
|
560
|
+
y_axis_bboxes.append(tb)
|
|
561
|
+
except Exception:
|
|
562
|
+
pass
|
|
563
|
+
for tick in ax.yaxis.get_major_ticks():
|
|
564
|
+
if tick.tick1line.get_visible():
|
|
565
|
+
try:
|
|
566
|
+
tb = tick.tick1line.get_window_extent(renderer)
|
|
567
|
+
if tb.width > 0 or tb.height > 0:
|
|
568
|
+
y_axis_bboxes.append(tb)
|
|
569
|
+
except Exception:
|
|
570
|
+
pass
|
|
571
|
+
spine_bbox = ax.spines["left"].get_window_extent(renderer)
|
|
572
|
+
if spine_bbox.height > 0:
|
|
573
|
+
if y_axis_bboxes:
|
|
574
|
+
tick_union = Bbox.union(y_axis_bboxes)
|
|
575
|
+
constrained_spine = Bbox.from_extents(
|
|
576
|
+
spine_bbox.x0, tick_union.y0, spine_bbox.x1, tick_union.y1
|
|
577
|
+
)
|
|
578
|
+
y_axis_bboxes.append(constrained_spine)
|
|
579
|
+
else:
|
|
580
|
+
y_axis_bboxes.append(spine_bbox)
|
|
581
|
+
if y_axis_bboxes:
|
|
582
|
+
combined = Bbox.union(y_axis_bboxes)
|
|
583
|
+
padded = Bbox.from_extents(
|
|
584
|
+
combined.x0 - 10, combined.y0 - 5, combined.x1 + 5, combined.y1 + 5
|
|
585
|
+
)
|
|
586
|
+
bboxes[f"{ax_id}_yaxis"] = bbox_to_img_coords(padded)
|
|
587
|
+
bboxes[f"{ax_id}_yaxis"]["label"] = f"{ax_id}: Y Axis"
|
|
588
|
+
bboxes[f"{ax_id}_yaxis"]["ax_id"] = ax_id
|
|
589
|
+
bboxes[f"{ax_id}_yaxis"]["element_type"] = "yaxis"
|
|
590
|
+
|
|
591
|
+
except Exception as e:
|
|
592
|
+
print(f"Error getting axis bboxes for {ax_id}: {e}")
|
|
593
|
+
|
|
594
|
+
|
|
595
|
+
def _extract_axis_bboxes(ax, renderer, bboxes, bbox_to_img_coords, Bbox, ax_prefix=""):
|
|
596
|
+
"""Extract bboxes for X and Y axis elements.
|
|
597
|
+
|
|
598
|
+
Args:
|
|
599
|
+
ax: Matplotlib axis.
|
|
600
|
+
renderer: Figure renderer.
|
|
601
|
+
bboxes: Dict to store bboxes.
|
|
602
|
+
bbox_to_img_coords: Coordinate conversion function.
|
|
603
|
+
Bbox: Matplotlib Bbox class.
|
|
604
|
+
ax_prefix: Prefix for bbox names (e.g., "ax_00_").
|
|
605
|
+
"""
|
|
606
|
+
try:
|
|
607
|
+
# X-axis: combine spine and tick labels into one bbox
|
|
608
|
+
x_axis_bboxes = []
|
|
609
|
+
for ticklabel in ax.xaxis.get_ticklabels():
|
|
610
|
+
if ticklabel.get_visible():
|
|
611
|
+
try:
|
|
612
|
+
tb = ticklabel.get_window_extent(renderer)
|
|
613
|
+
if tb.width > 0:
|
|
614
|
+
x_axis_bboxes.append(tb)
|
|
615
|
+
except Exception:
|
|
616
|
+
pass
|
|
617
|
+
for tick in ax.xaxis.get_major_ticks():
|
|
618
|
+
if tick.tick1line.get_visible():
|
|
619
|
+
try:
|
|
620
|
+
tb = tick.tick1line.get_window_extent(renderer)
|
|
621
|
+
if tb.width > 0 or tb.height > 0:
|
|
622
|
+
x_axis_bboxes.append(tb)
|
|
623
|
+
except Exception:
|
|
624
|
+
pass
|
|
625
|
+
spine_bbox = ax.spines["bottom"].get_window_extent(renderer)
|
|
626
|
+
if spine_bbox.width > 0:
|
|
627
|
+
if x_axis_bboxes:
|
|
628
|
+
tick_union = Bbox.union(x_axis_bboxes)
|
|
629
|
+
constrained_spine = Bbox.from_extents(
|
|
630
|
+
tick_union.x0, spine_bbox.y0, tick_union.x1, spine_bbox.y1
|
|
631
|
+
)
|
|
632
|
+
x_axis_bboxes.append(constrained_spine)
|
|
633
|
+
else:
|
|
634
|
+
x_axis_bboxes.append(spine_bbox)
|
|
635
|
+
if x_axis_bboxes:
|
|
636
|
+
combined = Bbox.union(x_axis_bboxes)
|
|
637
|
+
bboxes[f"{ax_prefix}xaxis_spine"] = bbox_to_img_coords(combined)
|
|
638
|
+
bboxes[f"{ax_prefix}xaxis_spine"]["label"] = "X Spine & Ticks"
|
|
639
|
+
|
|
640
|
+
# Y-axis: combine spine and tick labels into one bbox
|
|
641
|
+
y_axis_bboxes = []
|
|
642
|
+
for ticklabel in ax.yaxis.get_ticklabels():
|
|
643
|
+
if ticklabel.get_visible():
|
|
644
|
+
try:
|
|
645
|
+
tb = ticklabel.get_window_extent(renderer)
|
|
646
|
+
if tb.width > 0:
|
|
647
|
+
y_axis_bboxes.append(tb)
|
|
648
|
+
except Exception:
|
|
649
|
+
pass
|
|
650
|
+
for tick in ax.yaxis.get_major_ticks():
|
|
651
|
+
if tick.tick1line.get_visible():
|
|
652
|
+
try:
|
|
653
|
+
tb = tick.tick1line.get_window_extent(renderer)
|
|
654
|
+
if tb.width > 0 or tb.height > 0:
|
|
655
|
+
y_axis_bboxes.append(tb)
|
|
656
|
+
except Exception:
|
|
657
|
+
pass
|
|
658
|
+
spine_bbox = ax.spines["left"].get_window_extent(renderer)
|
|
659
|
+
if spine_bbox.height > 0:
|
|
660
|
+
if y_axis_bboxes:
|
|
661
|
+
tick_union = Bbox.union(y_axis_bboxes)
|
|
662
|
+
constrained_spine = Bbox.from_extents(
|
|
663
|
+
spine_bbox.x0, tick_union.y0, spine_bbox.x1, tick_union.y1
|
|
664
|
+
)
|
|
665
|
+
y_axis_bboxes.append(constrained_spine)
|
|
666
|
+
else:
|
|
667
|
+
y_axis_bboxes.append(spine_bbox)
|
|
668
|
+
if y_axis_bboxes:
|
|
669
|
+
combined = Bbox.union(y_axis_bboxes)
|
|
670
|
+
padded = Bbox.from_extents(
|
|
671
|
+
combined.x0 - 10, combined.y0 - 5, combined.x1 + 5, combined.y1 + 5
|
|
672
|
+
)
|
|
673
|
+
bboxes[f"{ax_prefix}yaxis_spine"] = bbox_to_img_coords(padded)
|
|
674
|
+
bboxes[f"{ax_prefix}yaxis_spine"]["label"] = "Y Spine & Ticks"
|
|
675
|
+
|
|
676
|
+
except Exception as e:
|
|
677
|
+
print(f"Error getting axis bboxes: {e}")
|
|
678
|
+
|
|
679
|
+
|
|
680
|
+
def _extract_trace_bboxes(
|
|
681
|
+
ax,
|
|
682
|
+
fig,
|
|
683
|
+
renderer,
|
|
684
|
+
bboxes,
|
|
685
|
+
get_element_bbox,
|
|
686
|
+
tight_x0,
|
|
687
|
+
tight_y0,
|
|
688
|
+
saved_height_inches,
|
|
689
|
+
scale_x,
|
|
690
|
+
scale_y,
|
|
691
|
+
pad_inches,
|
|
692
|
+
):
|
|
693
|
+
"""Extract bboxes for all data elements (lines, scatter, fill) with proximity detection."""
|
|
694
|
+
import numpy as np
|
|
695
|
+
|
|
696
|
+
def coords_to_img_points(data_coords):
|
|
697
|
+
"""Convert data coordinates to image pixel coordinates."""
|
|
698
|
+
if len(data_coords) == 0:
|
|
699
|
+
return []
|
|
700
|
+
transform = ax.transData
|
|
701
|
+
points_display = transform.transform(data_coords)
|
|
702
|
+
points_img = []
|
|
703
|
+
for px, py in points_display:
|
|
704
|
+
if not np.isfinite(px) or not np.isfinite(py):
|
|
705
|
+
continue
|
|
706
|
+
px_inches = px / fig.dpi
|
|
707
|
+
py_inches = py / fig.dpi
|
|
708
|
+
x_rel = px_inches - tight_x0 + pad_inches
|
|
709
|
+
y_rel = saved_height_inches - (py_inches - tight_y0 + pad_inches)
|
|
710
|
+
x_img = max(-10000, min(10000, int(x_rel * scale_x)))
|
|
711
|
+
y_img = max(-10000, min(10000, int(y_rel * scale_y)))
|
|
712
|
+
points_img.append([x_img, y_img])
|
|
713
|
+
if len(points_img) > 100:
|
|
714
|
+
step = len(points_img) // 100
|
|
715
|
+
points_img = points_img[::step]
|
|
716
|
+
return points_img
|
|
717
|
+
|
|
718
|
+
# 1. Extract lines
|
|
719
|
+
for idx, line in enumerate(ax.get_lines()):
|
|
720
|
+
try:
|
|
721
|
+
label = line.get_label()
|
|
722
|
+
# Include unlabeled lines but mark them appropriately
|
|
723
|
+
if label is None or label.startswith("_"):
|
|
724
|
+
label = None # Will use generic name
|
|
725
|
+
get_element_bbox(line, f"trace_{idx}")
|
|
726
|
+
if f"trace_{idx}" in bboxes:
|
|
727
|
+
bboxes[f"trace_{idx}"]["label"] = label or f"Trace {idx}"
|
|
728
|
+
bboxes[f"trace_{idx}"]["trace_idx"] = idx
|
|
729
|
+
bboxes[f"trace_{idx}"]["element_type"] = "line"
|
|
730
|
+
|
|
731
|
+
xdata, ydata = line.get_xdata(), line.get_ydata()
|
|
732
|
+
if len(xdata) > 0:
|
|
733
|
+
bboxes[f"trace_{idx}"]["points"] = coords_to_img_points(
|
|
734
|
+
list(zip(xdata, ydata))
|
|
735
|
+
)
|
|
736
|
+
|
|
737
|
+
# Add schema v0.3 geometry_px if available
|
|
738
|
+
if GEOMETRY_V03_AVAILABLE:
|
|
739
|
+
try:
|
|
740
|
+
geom = extract_line_geometry(line, ax, fig)
|
|
741
|
+
bboxes[f"trace_{idx}"]["geometry_px"] = geom
|
|
742
|
+
except Exception:
|
|
743
|
+
pass
|
|
744
|
+
except Exception as e:
|
|
745
|
+
print(f"Error getting trace bbox: {e}")
|
|
746
|
+
|
|
747
|
+
# 2. Extract collections (scatter, fill_between)
|
|
748
|
+
coll_idx = 0
|
|
749
|
+
for coll in ax.collections:
|
|
750
|
+
try:
|
|
751
|
+
label = coll.get_label()
|
|
752
|
+
if label is None or label.startswith("_"):
|
|
753
|
+
label = None
|
|
754
|
+
|
|
755
|
+
coll_type = type(coll).__name__
|
|
756
|
+
if coll_type == "PathCollection":
|
|
757
|
+
# Scatter points
|
|
758
|
+
elem_key = f"scatter_{coll_idx}"
|
|
759
|
+
get_element_bbox(coll, elem_key)
|
|
760
|
+
|
|
761
|
+
# Initialize entry if bbox extraction failed but we have data
|
|
762
|
+
offsets = coll.get_offsets()
|
|
763
|
+
if elem_key not in bboxes and len(offsets) > 0:
|
|
764
|
+
# Create bbox from data coordinates as fallback
|
|
765
|
+
points_img = coords_to_img_points(offsets)
|
|
766
|
+
if points_img:
|
|
767
|
+
xs = [p[0] for p in points_img]
|
|
768
|
+
ys = [p[1] for p in points_img]
|
|
769
|
+
bboxes[elem_key] = {
|
|
770
|
+
"x0": min(xs) - 10,
|
|
771
|
+
"y0": min(ys) - 10,
|
|
772
|
+
"x1": max(xs) + 10,
|
|
773
|
+
"y1": max(ys) + 10,
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
if elem_key in bboxes:
|
|
777
|
+
bboxes[elem_key]["label"] = label or f"Scatter {coll_idx}"
|
|
778
|
+
bboxes[elem_key]["element_type"] = "scatter"
|
|
779
|
+
|
|
780
|
+
if len(offsets) > 0:
|
|
781
|
+
bboxes[elem_key]["points"] = coords_to_img_points(offsets)
|
|
782
|
+
|
|
783
|
+
# Add schema v0.3 geometry_px if available
|
|
784
|
+
if GEOMETRY_V03_AVAILABLE:
|
|
785
|
+
try:
|
|
786
|
+
geom = extract_scatter_geometry(coll, ax, fig)
|
|
787
|
+
bboxes[elem_key]["geometry_px"] = geom
|
|
788
|
+
except Exception:
|
|
789
|
+
pass
|
|
790
|
+
|
|
791
|
+
elif coll_type in ("PolyCollection", "FillBetweenPolyCollection"):
|
|
792
|
+
# Fill areas
|
|
793
|
+
get_element_bbox(coll, f"fill_{coll_idx}")
|
|
794
|
+
if f"fill_{coll_idx}" in bboxes:
|
|
795
|
+
bboxes[f"fill_{coll_idx}"]["label"] = label or f"Fill {coll_idx}"
|
|
796
|
+
bboxes[f"fill_{coll_idx}"]["element_type"] = "fill"
|
|
797
|
+
|
|
798
|
+
# Add schema v0.3 geometry_px if available
|
|
799
|
+
if GEOMETRY_V03_AVAILABLE:
|
|
800
|
+
try:
|
|
801
|
+
geom = extract_polygon_geometry(coll, ax, fig)
|
|
802
|
+
bboxes[f"fill_{coll_idx}"]["geometry_px"] = geom
|
|
803
|
+
except Exception:
|
|
804
|
+
pass
|
|
805
|
+
|
|
806
|
+
coll_idx += 1
|
|
807
|
+
except Exception as e:
|
|
808
|
+
print(f"Error getting collection bbox: {e}")
|
|
809
|
+
|
|
810
|
+
|
|
811
|
+
def extract_bboxes_from_metadata(
|
|
812
|
+
metadata: Dict[str, Any],
|
|
813
|
+
img_width: int,
|
|
814
|
+
img_height: int,
|
|
815
|
+
) -> Dict[str, Any]:
|
|
816
|
+
"""Extract bounding boxes from pre-computed metadata (without re-rendering).
|
|
817
|
+
|
|
818
|
+
This is used when loading actual PNGs from bundles instead of re-rendering.
|
|
819
|
+
Extracts bbox info from:
|
|
820
|
+
- hit_regions (if available from v0.3 schema)
|
|
821
|
+
- elements dict
|
|
822
|
+
- axes positions
|
|
823
|
+
|
|
824
|
+
Args:
|
|
825
|
+
metadata: JSON metadata from spec.json or panel JSON
|
|
826
|
+
img_width: Image width in pixels
|
|
827
|
+
img_height: Image height in pixels
|
|
828
|
+
|
|
829
|
+
Returns:
|
|
830
|
+
Dict with bboxes keyed by element name
|
|
831
|
+
"""
|
|
832
|
+
bboxes = {}
|
|
833
|
+
|
|
834
|
+
# Check for pre-computed hit_regions (v0.3 schema)
|
|
835
|
+
hit_regions = metadata.get("hit_regions", {})
|
|
836
|
+
if hit_regions:
|
|
837
|
+
color_map = hit_regions.get("color_map", {})
|
|
838
|
+
for element_name, color in color_map.items():
|
|
839
|
+
# We don't have exact coords from color map, but we can create placeholder
|
|
840
|
+
bboxes[element_name] = {
|
|
841
|
+
"label": element_name.replace("_", " ").title(),
|
|
842
|
+
"element_type": _guess_element_type(element_name),
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
# Check for geometry_px in cache (v0.3 layered bundle)
|
|
846
|
+
geometry_px = metadata.get("geometry_px", {})
|
|
847
|
+
if geometry_px:
|
|
848
|
+
for element_name, geom in geometry_px.items():
|
|
849
|
+
if isinstance(geom, dict) and "bbox" in geom:
|
|
850
|
+
bbox = geom["bbox"]
|
|
851
|
+
bboxes[element_name] = {
|
|
852
|
+
"x0": bbox.get("x0", 0),
|
|
853
|
+
"y0": bbox.get("y0", 0),
|
|
854
|
+
"x1": bbox.get("x1", img_width),
|
|
855
|
+
"y1": bbox.get("y1", img_height),
|
|
856
|
+
"label": element_name.replace("_", " ").title(),
|
|
857
|
+
"element_type": _guess_element_type(element_name),
|
|
858
|
+
}
|
|
859
|
+
if "points" in geom:
|
|
860
|
+
bboxes[element_name]["points"] = geom["points"]
|
|
861
|
+
|
|
862
|
+
# Extract from elements dict if present
|
|
863
|
+
elements = metadata.get("elements", {})
|
|
864
|
+
if not isinstance(elements, dict):
|
|
865
|
+
elements = {}
|
|
866
|
+
for element_name, element_info in elements.items():
|
|
867
|
+
if not isinstance(element_info, dict):
|
|
868
|
+
continue
|
|
869
|
+
if element_name not in bboxes:
|
|
870
|
+
bboxes[element_name] = {
|
|
871
|
+
"label": element_info.get("label", element_name.replace("_", " ").title()),
|
|
872
|
+
"element_type": element_info.get("type", _guess_element_type(element_name)),
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
# Extract from axes (handle both dict and list formats)
|
|
876
|
+
axes = metadata.get("axes", [])
|
|
877
|
+
if isinstance(axes, list):
|
|
878
|
+
axes_list = axes
|
|
879
|
+
elif isinstance(axes, dict):
|
|
880
|
+
axes_list = list(axes.values())
|
|
881
|
+
else:
|
|
882
|
+
axes_list = []
|
|
883
|
+
|
|
884
|
+
for i, ax_spec in enumerate(axes_list):
|
|
885
|
+
if not isinstance(ax_spec, dict):
|
|
886
|
+
continue
|
|
887
|
+
|
|
888
|
+
ax_id = ax_spec.get("id", f"ax{i}")
|
|
889
|
+
|
|
890
|
+
# Panel bbox - check for "bbox" field (new format) or "position" (old format)
|
|
891
|
+
bbox_spec = ax_spec.get("bbox", {})
|
|
892
|
+
pos = ax_spec.get("position", [])
|
|
893
|
+
|
|
894
|
+
if bbox_spec and isinstance(bbox_spec, dict):
|
|
895
|
+
# New format: bbox with x0, y0, width, height in panel fraction
|
|
896
|
+
x0_frac = bbox_spec.get("x0", 0)
|
|
897
|
+
y0_frac = bbox_spec.get("y0", 0)
|
|
898
|
+
w_frac = bbox_spec.get("width", 1)
|
|
899
|
+
h_frac = bbox_spec.get("height", 1)
|
|
900
|
+
x0 = int(x0_frac * img_width)
|
|
901
|
+
y0 = int(y0_frac * img_height)
|
|
902
|
+
x1 = int((x0_frac + w_frac) * img_width)
|
|
903
|
+
y1 = int((y0_frac + h_frac) * img_height)
|
|
904
|
+
bboxes[f"{ax_id}_panel"] = {
|
|
905
|
+
"x0": x0,
|
|
906
|
+
"y0": y0,
|
|
907
|
+
"x1": x1,
|
|
908
|
+
"y1": y1,
|
|
909
|
+
"label": f"Panel {ax_id}",
|
|
910
|
+
"ax_id": ax_id,
|
|
911
|
+
"is_panel": True,
|
|
912
|
+
}
|
|
913
|
+
elif len(pos) >= 4:
|
|
914
|
+
# Old format: position is in figure fraction [x0, y0, width, height]
|
|
915
|
+
x0 = int(pos[0] * img_width)
|
|
916
|
+
y0 = int((1 - pos[1] - pos[3]) * img_height) # Flip Y
|
|
917
|
+
x1 = int((pos[0] + pos[2]) * img_width)
|
|
918
|
+
y1 = int((1 - pos[1]) * img_height) # Flip Y
|
|
919
|
+
bboxes[f"{ax_id}_panel"] = {
|
|
920
|
+
"x0": x0,
|
|
921
|
+
"y0": y0,
|
|
922
|
+
"x1": x1,
|
|
923
|
+
"y1": y1,
|
|
924
|
+
"label": f"Panel {ax_id}",
|
|
925
|
+
"ax_id": ax_id,
|
|
926
|
+
"is_panel": True,
|
|
927
|
+
}
|
|
928
|
+
|
|
929
|
+
# Title/labels from labels dict (new format) or xaxis/yaxis (old format)
|
|
930
|
+
labels = ax_spec.get("labels", {})
|
|
931
|
+
xaxis = ax_spec.get("xaxis", {})
|
|
932
|
+
yaxis = ax_spec.get("yaxis", {})
|
|
933
|
+
|
|
934
|
+
xlabel = labels.get("xlabel") or (xaxis.get("label") if isinstance(xaxis, dict) else None)
|
|
935
|
+
ylabel = labels.get("ylabel") or (yaxis.get("label") if isinstance(yaxis, dict) else None)
|
|
936
|
+
title = labels.get("title")
|
|
937
|
+
|
|
938
|
+
if xlabel:
|
|
939
|
+
bboxes[f"{ax_id}_xlabel"] = {
|
|
940
|
+
"label": f"{ax_id}: {xlabel}",
|
|
941
|
+
"element_type": "xlabel",
|
|
942
|
+
"ax_id": ax_id,
|
|
943
|
+
}
|
|
944
|
+
if ylabel:
|
|
945
|
+
bboxes[f"{ax_id}_ylabel"] = {
|
|
946
|
+
"label": f"{ax_id}: {ylabel}",
|
|
947
|
+
"element_type": "ylabel",
|
|
948
|
+
"ax_id": ax_id,
|
|
949
|
+
}
|
|
950
|
+
if title:
|
|
951
|
+
bboxes[f"{ax_id}_title"] = {
|
|
952
|
+
"label": title,
|
|
953
|
+
"element_type": "title",
|
|
954
|
+
"ax_id": ax_id,
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
# Extract from traces array (pltz spec format)
|
|
958
|
+
traces = metadata.get("traces", [])
|
|
959
|
+
if isinstance(traces, list):
|
|
960
|
+
for i, trace in enumerate(traces):
|
|
961
|
+
if not isinstance(trace, dict):
|
|
962
|
+
continue
|
|
963
|
+
trace_id = trace.get("id", f"trace_{i}")
|
|
964
|
+
trace_type = trace.get("type", "line")
|
|
965
|
+
trace_label = trace.get("label", f"Trace {i}")
|
|
966
|
+
ax_idx = trace.get("axes_index", 0)
|
|
967
|
+
|
|
968
|
+
# Use axes bbox as fallback for trace bbox
|
|
969
|
+
ax_panel_key = None
|
|
970
|
+
for key in bboxes:
|
|
971
|
+
if key.endswith("_panel") and bboxes[key].get("ax_id", "").endswith(str(ax_idx)):
|
|
972
|
+
ax_panel_key = key
|
|
973
|
+
break
|
|
974
|
+
if not ax_panel_key:
|
|
975
|
+
# Find any panel bbox
|
|
976
|
+
for key in bboxes:
|
|
977
|
+
if key.endswith("_panel"):
|
|
978
|
+
ax_panel_key = key
|
|
979
|
+
break
|
|
980
|
+
|
|
981
|
+
trace_bbox = {
|
|
982
|
+
"label": trace_label,
|
|
983
|
+
"element_type": trace_type,
|
|
984
|
+
"trace_idx": i,
|
|
985
|
+
"ax_id": f"ax{ax_idx}",
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
# Copy panel bbox coordinates if available
|
|
989
|
+
if ax_panel_key and ax_panel_key in bboxes:
|
|
990
|
+
panel = bboxes[ax_panel_key]
|
|
991
|
+
trace_bbox["x0"] = panel.get("x0", 0)
|
|
992
|
+
trace_bbox["y0"] = panel.get("y0", 0)
|
|
993
|
+
trace_bbox["x1"] = panel.get("x1", img_width)
|
|
994
|
+
trace_bbox["y1"] = panel.get("y1", img_height)
|
|
995
|
+
|
|
996
|
+
bboxes[f"trace_{i}"] = trace_bbox
|
|
997
|
+
|
|
998
|
+
# If no bboxes found, return minimal set
|
|
999
|
+
if not bboxes:
|
|
1000
|
+
bboxes["panel"] = {
|
|
1001
|
+
"x0": 0,
|
|
1002
|
+
"y0": 0,
|
|
1003
|
+
"x1": img_width,
|
|
1004
|
+
"y1": img_height,
|
|
1005
|
+
"label": "Panel",
|
|
1006
|
+
"is_panel": True,
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
return bboxes
|
|
1010
|
+
|
|
1011
|
+
|
|
1012
|
+
def _guess_element_type(name: str) -> str:
|
|
1013
|
+
"""Guess element type from element name."""
|
|
1014
|
+
name_lower = name.lower()
|
|
1015
|
+
if "line" in name_lower or "trace" in name_lower:
|
|
1016
|
+
return "line"
|
|
1017
|
+
elif "scatter" in name_lower:
|
|
1018
|
+
return "scatter"
|
|
1019
|
+
elif "bar" in name_lower:
|
|
1020
|
+
return "bar"
|
|
1021
|
+
elif "fill" in name_lower:
|
|
1022
|
+
return "fill"
|
|
1023
|
+
elif "xlabel" in name_lower:
|
|
1024
|
+
return "xlabel"
|
|
1025
|
+
elif "ylabel" in name_lower:
|
|
1026
|
+
return "ylabel"
|
|
1027
|
+
elif "title" in name_lower:
|
|
1028
|
+
return "title"
|
|
1029
|
+
elif "legend" in name_lower:
|
|
1030
|
+
return "legend"
|
|
1031
|
+
elif "xaxis" in name_lower:
|
|
1032
|
+
return "xaxis"
|
|
1033
|
+
elif "yaxis" in name_lower:
|
|
1034
|
+
return "yaxis"
|
|
1035
|
+
elif "panel" in name_lower:
|
|
1036
|
+
return "panel"
|
|
1037
|
+
return "unknown"
|
|
1038
|
+
|
|
1039
|
+
|
|
1040
|
+
def extract_bboxes_from_geometry_px(
|
|
1041
|
+
geometry_data: Dict[str, Any],
|
|
1042
|
+
img_width: int,
|
|
1043
|
+
img_height: int,
|
|
1044
|
+
) -> Dict[str, Any]:
|
|
1045
|
+
"""Extract bounding boxes from geometry_px.json (cached pixel coordinates).
|
|
1046
|
+
|
|
1047
|
+
This provides precise pixel coordinates for interactive element selection.
|
|
1048
|
+
|
|
1049
|
+
Args:
|
|
1050
|
+
geometry_data: JSON data from geometry_px.json
|
|
1051
|
+
img_width: Actual image width in pixels
|
|
1052
|
+
img_height: Actual image height in pixels
|
|
1053
|
+
|
|
1054
|
+
Returns:
|
|
1055
|
+
Dict with bboxes keyed by element name
|
|
1056
|
+
"""
|
|
1057
|
+
bboxes = {}
|
|
1058
|
+
|
|
1059
|
+
# Get figure dimensions from geometry to calculate scale
|
|
1060
|
+
figure_px = geometry_data.get("figure_px", [img_width, img_height])
|
|
1061
|
+
if isinstance(figure_px, list) and len(figure_px) >= 2:
|
|
1062
|
+
geom_width, geom_height = figure_px[0], figure_px[1]
|
|
1063
|
+
else:
|
|
1064
|
+
geom_width, geom_height = img_width, img_height
|
|
1065
|
+
|
|
1066
|
+
# Scale factor if image size differs from geometry
|
|
1067
|
+
scale_x = img_width / geom_width if geom_width > 0 else 1
|
|
1068
|
+
scale_y = img_height / geom_height if geom_height > 0 else 1
|
|
1069
|
+
|
|
1070
|
+
# Extract axes bboxes
|
|
1071
|
+
axes = geometry_data.get("axes", [])
|
|
1072
|
+
for i, ax in enumerate(axes):
|
|
1073
|
+
if not isinstance(ax, dict):
|
|
1074
|
+
continue
|
|
1075
|
+
ax_id = ax.get("id", f"ax{i}")
|
|
1076
|
+
bbox_px = ax.get("bbox_px", {})
|
|
1077
|
+
if bbox_px:
|
|
1078
|
+
x0 = float(bbox_px.get("x0", 0)) * scale_x
|
|
1079
|
+
y0 = float(bbox_px.get("y0", 0)) * scale_y
|
|
1080
|
+
w = float(bbox_px.get("width", 0)) * scale_x
|
|
1081
|
+
h = float(bbox_px.get("height", 0)) * scale_y
|
|
1082
|
+
bboxes[f"{ax_id}_panel"] = {
|
|
1083
|
+
"x0": int(x0),
|
|
1084
|
+
"y0": int(y0),
|
|
1085
|
+
"x1": int(x0 + w),
|
|
1086
|
+
"y1": int(y0 + h),
|
|
1087
|
+
"label": f"Axes {ax_id}",
|
|
1088
|
+
"ax_id": ax_id,
|
|
1089
|
+
"is_panel": True,
|
|
1090
|
+
}
|
|
1091
|
+
|
|
1092
|
+
# Helper to safely convert to int (handle inf/nan)
|
|
1093
|
+
def safe_int(val, default=0, max_val=10000):
|
|
1094
|
+
import math
|
|
1095
|
+
if val is None or math.isinf(val) or math.isnan(val):
|
|
1096
|
+
return default
|
|
1097
|
+
return max(0, min(int(val), max_val))
|
|
1098
|
+
|
|
1099
|
+
# Extract artists (lines, scatter, bars, etc.)
|
|
1100
|
+
artists = geometry_data.get("artists", [])
|
|
1101
|
+
for i, artist in enumerate(artists):
|
|
1102
|
+
if not isinstance(artist, dict):
|
|
1103
|
+
continue
|
|
1104
|
+
|
|
1105
|
+
artist_id = artist.get("id", str(i))
|
|
1106
|
+
artist_type = artist.get("type", "unknown")
|
|
1107
|
+
artist_label = artist.get("label") or f"{artist_type}_{i}"
|
|
1108
|
+
axes_index = artist.get("axes_index", 0)
|
|
1109
|
+
|
|
1110
|
+
# Get bbox_px
|
|
1111
|
+
bbox_px = artist.get("bbox_px", {})
|
|
1112
|
+
if bbox_px:
|
|
1113
|
+
x0 = float(bbox_px.get("x0", 0)) * scale_x
|
|
1114
|
+
y0 = float(bbox_px.get("y0", 0)) * scale_y
|
|
1115
|
+
w = float(bbox_px.get("width", 0)) * scale_x
|
|
1116
|
+
h = float(bbox_px.get("height", 0)) * scale_y
|
|
1117
|
+
|
|
1118
|
+
artist_bbox = {
|
|
1119
|
+
"x0": safe_int(x0, 0, img_width),
|
|
1120
|
+
"y0": safe_int(y0, 0, img_height),
|
|
1121
|
+
"x1": safe_int(x0 + w, img_width, img_width),
|
|
1122
|
+
"y1": safe_int(y0 + h, img_height, img_height),
|
|
1123
|
+
"label": artist_label,
|
|
1124
|
+
"element_type": artist_type,
|
|
1125
|
+
"trace_idx": i,
|
|
1126
|
+
"ax_id": f"ax{axes_index}",
|
|
1127
|
+
}
|
|
1128
|
+
|
|
1129
|
+
# Get path_px for lines (for precise hover detection)
|
|
1130
|
+
path_px = artist.get("path_px", [])
|
|
1131
|
+
if path_px and len(path_px) > 0:
|
|
1132
|
+
import math
|
|
1133
|
+
# Scale points to actual image coordinates, filter out inf/nan
|
|
1134
|
+
scaled_points = []
|
|
1135
|
+
for pt in path_px:
|
|
1136
|
+
if isinstance(pt, (list, tuple)) and len(pt) >= 2:
|
|
1137
|
+
px, py = pt[0] * scale_x, pt[1] * scale_y
|
|
1138
|
+
if not (math.isinf(px) or math.isinf(py) or math.isnan(px) or math.isnan(py)):
|
|
1139
|
+
scaled_points.append([px, py])
|
|
1140
|
+
if scaled_points:
|
|
1141
|
+
artist_bbox["points"] = scaled_points
|
|
1142
|
+
|
|
1143
|
+
# Get scatter points if available
|
|
1144
|
+
scatter_px = artist.get("scatter_px", [])
|
|
1145
|
+
if scatter_px and len(scatter_px) > 0:
|
|
1146
|
+
import math
|
|
1147
|
+
scaled_points = []
|
|
1148
|
+
for pt in scatter_px:
|
|
1149
|
+
if isinstance(pt, (list, tuple)) and len(pt) >= 2:
|
|
1150
|
+
px, py = pt[0] * scale_x, pt[1] * scale_y
|
|
1151
|
+
if not (math.isinf(px) or math.isinf(py) or math.isnan(px) or math.isnan(py)):
|
|
1152
|
+
scaled_points.append([px, py])
|
|
1153
|
+
if scaled_points:
|
|
1154
|
+
artist_bbox["points"] = scaled_points
|
|
1155
|
+
artist_bbox["element_type"] = "scatter"
|
|
1156
|
+
|
|
1157
|
+
bboxes[f"trace_{i}"] = artist_bbox
|
|
1158
|
+
|
|
1159
|
+
# Extract from selectable_regions (title, xlabel, ylabel, xaxis, yaxis)
|
|
1160
|
+
selectable = geometry_data.get("selectable_regions", {})
|
|
1161
|
+
sel_axes = selectable.get("axes", [])
|
|
1162
|
+
for ax_data in sel_axes:
|
|
1163
|
+
if not isinstance(ax_data, dict):
|
|
1164
|
+
continue
|
|
1165
|
+
ax_idx = ax_data.get("index", 0)
|
|
1166
|
+
ax_id = f"ax{ax_idx}"
|
|
1167
|
+
|
|
1168
|
+
# Title
|
|
1169
|
+
title_data = ax_data.get("title", {})
|
|
1170
|
+
if title_data and "bbox_px" in title_data:
|
|
1171
|
+
bbox = title_data["bbox_px"]
|
|
1172
|
+
if isinstance(bbox, list) and len(bbox) >= 4:
|
|
1173
|
+
bboxes[f"{ax_id}_title"] = {
|
|
1174
|
+
"x0": safe_int(bbox[0] * scale_x, 0, img_width),
|
|
1175
|
+
"y0": safe_int(bbox[1] * scale_y, 0, img_height),
|
|
1176
|
+
"x1": safe_int(bbox[2] * scale_x, img_width, img_width),
|
|
1177
|
+
"y1": safe_int(bbox[3] * scale_y, img_height, img_height),
|
|
1178
|
+
"label": title_data.get("text", "Title"),
|
|
1179
|
+
"element_type": "title",
|
|
1180
|
+
"ax_id": ax_id,
|
|
1181
|
+
}
|
|
1182
|
+
|
|
1183
|
+
# X Label
|
|
1184
|
+
xlabel_data = ax_data.get("xlabel", {})
|
|
1185
|
+
if xlabel_data and "bbox_px" in xlabel_data:
|
|
1186
|
+
bbox = xlabel_data["bbox_px"]
|
|
1187
|
+
if isinstance(bbox, list) and len(bbox) >= 4:
|
|
1188
|
+
bboxes[f"{ax_id}_xlabel"] = {
|
|
1189
|
+
"x0": safe_int(bbox[0] * scale_x, 0, img_width),
|
|
1190
|
+
"y0": safe_int(bbox[1] * scale_y, 0, img_height),
|
|
1191
|
+
"x1": safe_int(bbox[2] * scale_x, img_width, img_width),
|
|
1192
|
+
"y1": safe_int(bbox[3] * scale_y, img_height, img_height),
|
|
1193
|
+
"label": xlabel_data.get("text", "X Label"),
|
|
1194
|
+
"element_type": "xlabel",
|
|
1195
|
+
"ax_id": ax_id,
|
|
1196
|
+
}
|
|
1197
|
+
|
|
1198
|
+
# Y Label
|
|
1199
|
+
ylabel_data = ax_data.get("ylabel", {})
|
|
1200
|
+
if ylabel_data and "bbox_px" in ylabel_data:
|
|
1201
|
+
bbox = ylabel_data["bbox_px"]
|
|
1202
|
+
if isinstance(bbox, list) and len(bbox) >= 4:
|
|
1203
|
+
bboxes[f"{ax_id}_ylabel"] = {
|
|
1204
|
+
"x0": safe_int(bbox[0] * scale_x, 0, img_width),
|
|
1205
|
+
"y0": safe_int(bbox[1] * scale_y, 0, img_height),
|
|
1206
|
+
"x1": safe_int(bbox[2] * scale_x, img_width, img_width),
|
|
1207
|
+
"y1": safe_int(bbox[3] * scale_y, img_height, img_height),
|
|
1208
|
+
"label": ylabel_data.get("text", "Y Label"),
|
|
1209
|
+
"element_type": "ylabel",
|
|
1210
|
+
"ax_id": ax_id,
|
|
1211
|
+
}
|
|
1212
|
+
|
|
1213
|
+
# X Axis spine
|
|
1214
|
+
xaxis_data = ax_data.get("xaxis", {})
|
|
1215
|
+
if xaxis_data:
|
|
1216
|
+
spine = xaxis_data.get("spine", {})
|
|
1217
|
+
if spine and "bbox_px" in spine:
|
|
1218
|
+
bbox = spine["bbox_px"]
|
|
1219
|
+
if isinstance(bbox, list) and len(bbox) >= 4:
|
|
1220
|
+
bboxes[f"{ax_id}_xaxis"] = {
|
|
1221
|
+
"x0": safe_int(bbox[0] * scale_x, 0, img_width),
|
|
1222
|
+
"y0": safe_int(bbox[1] * scale_y, 0, img_height),
|
|
1223
|
+
"x1": safe_int(bbox[2] * scale_x, img_width, img_width),
|
|
1224
|
+
"y1": safe_int(bbox[3] * scale_y, img_height, img_height),
|
|
1225
|
+
"label": "X Axis",
|
|
1226
|
+
"element_type": "xaxis",
|
|
1227
|
+
"ax_id": ax_id,
|
|
1228
|
+
}
|
|
1229
|
+
|
|
1230
|
+
# Y Axis spine
|
|
1231
|
+
yaxis_data = ax_data.get("yaxis", {})
|
|
1232
|
+
if yaxis_data:
|
|
1233
|
+
spine = yaxis_data.get("spine", {})
|
|
1234
|
+
if spine and "bbox_px" in spine:
|
|
1235
|
+
bbox = spine["bbox_px"]
|
|
1236
|
+
if isinstance(bbox, list) and len(bbox) >= 4:
|
|
1237
|
+
bboxes[f"{ax_id}_yaxis"] = {
|
|
1238
|
+
"x0": safe_int(bbox[0] * scale_x, 0, img_width),
|
|
1239
|
+
"y0": safe_int(bbox[1] * scale_y, 0, img_height),
|
|
1240
|
+
"x1": safe_int(bbox[2] * scale_x, img_width, img_width),
|
|
1241
|
+
"y1": safe_int(bbox[3] * scale_y, img_height, img_height),
|
|
1242
|
+
"label": "Y Axis",
|
|
1243
|
+
"element_type": "yaxis",
|
|
1244
|
+
"ax_id": ax_id,
|
|
1245
|
+
}
|
|
1246
|
+
|
|
1247
|
+
# Legend
|
|
1248
|
+
legend_data = ax_data.get("legend", {})
|
|
1249
|
+
if legend_data and "bbox_px" in legend_data:
|
|
1250
|
+
bbox = legend_data["bbox_px"]
|
|
1251
|
+
if isinstance(bbox, list) and len(bbox) >= 4:
|
|
1252
|
+
bboxes[f"{ax_id}_legend"] = {
|
|
1253
|
+
"x0": safe_int(bbox[0] * scale_x, 0, img_width),
|
|
1254
|
+
"y0": safe_int(bbox[1] * scale_y, 0, img_height),
|
|
1255
|
+
"x1": safe_int(bbox[2] * scale_x, img_width, img_width),
|
|
1256
|
+
"y1": safe_int(bbox[3] * scale_y, img_height, img_height),
|
|
1257
|
+
"label": "Legend",
|
|
1258
|
+
"element_type": "legend",
|
|
1259
|
+
"ax_id": ax_id,
|
|
1260
|
+
}
|
|
1261
|
+
|
|
1262
|
+
# If no bboxes found, return minimal set
|
|
1263
|
+
if not bboxes:
|
|
1264
|
+
bboxes["panel"] = {
|
|
1265
|
+
"x0": 0,
|
|
1266
|
+
"y0": 0,
|
|
1267
|
+
"x1": img_width,
|
|
1268
|
+
"y1": img_height,
|
|
1269
|
+
"label": "Panel",
|
|
1270
|
+
"is_panel": True,
|
|
1271
|
+
}
|
|
1272
|
+
|
|
1273
|
+
return bboxes
|
|
1274
|
+
|
|
1275
|
+
|
|
1276
|
+
# EOF
|