@@ -80,6 +80,21 @@ def interactive_table(variable_dict, file_path="./custom_presets.json"):
8080 # ---------------------------------------------------------------
8181 # 1) Define built-in templates and units directly inside the function
8282 # ---------------------------------------------------------------
83+ IMAGING_TELESCOPE_template = {
84+ "Resolution (panchromatic)" : 0 ,
85+ "Ground sampling distance (panchromatic)" :0 ,
86+ "Resolution (multispectral)" : 0 ,
87+ "Ground sampling distance (multispectral)" : 0 ,
88+ "Altitude" : 0 ,
89+ "Half field of view" : 0 ,
90+ "Mirror aperture" : 0 ,
91+ "F-number" : 0 ,
92+ "Focal length" : 0 ,
93+ "Pixel size (panchromatic)" : 0 ,
94+ "Pixel size (multispectral)" : 0 ,
95+ "Swath width" : 0 ,
96+ }
97+
8398 IMAGING_TELESCOPE = {
8499 "Resolution (panchromatic)" : 1.23529 ,
85100 "Ground sampling distance (panchromatic)" : 0.61765 ,
@@ -130,6 +145,7 @@ def interactive_table(variable_dict, file_path="./custom_presets.json"):
130145 preset_options_dict = {
131146 "Select a template" : [],
132147 "IMAGING TELESCOPE" : list (IMAGING_TELESCOPE .keys ()),
148+ "IMAGING TELESCOPE template" : list (IMAGING_TELESCOPE_template .keys ()),
133149 "PAYLOAD" : list (PAYLOAD_1 .keys ()),
134150 }
135151
@@ -396,45 +412,79 @@ def save_requirements(_):
396412
397413
398414def display_results (equations_dict ):
399-
415+ """Display equation validation results in a clear, organized format."""
400416 results = equations_dict .get ("results" , {})
401- not_match_counter = 0
402-
417+
418+ # Helper function to convert Eq(LHS,RHS) to LHS=RHS format
419+ def format_equation (latex_eq ):
420+ # Remove 'Eq(' from start and ')' from end
421+ inner = latex_eq [3 :- 1 ]
422+ # Split by comma and join with equals sign
423+ lhs , rhs = inner .split (',' , 1 )
424+ return f"{ lhs } = { rhs } "
425+
426+ # Split results into matching and non-matching equations
427+ matching = []
428+ non_matching = []
429+
403430 for key , value in results .items ():
404- match = value .get ("match" )
405- latex_equation = value .get ("latex_equation" )
406- lhs = value .get ("lhs" )
407- rhs = value .get ("rhs" )
408- if not match :
409- not_match_counter += 1
410- display (
411- HTML (
412- '<p style="color:red; '
413- "font-weight:bold; "
414- "font-family:'Times New Roman'; "
415- 'font-size:16px;">'
416- "Provided requirements DO NOT fulfill"
417- "the following mathematical relation:"
418- "</p>"
419- )
420- )
421- display (Math (latex_equation ))
422- print (
423- f"""For provided values:
424- \n left hand side = { lhs } \n right hand side = { rhs } """
425- )
426- if not_match_counter == 0 :
427- display (
428- HTML (
429- '<p style="color:green; '
430- "font-weight:bold; "
431- "font-family:'Times New Roman'; "
432- 'font-size:16px;">'
433- "Requirements you provided do not cause any conflicts"
434- "</p>"
435- )
436- )
437-
431+ equation_data = {
432+ 'latex' : format_equation (value .get ('latex_equation' )),
433+ 'lhs' : value .get ('lhs' ),
434+ 'rhs' : value .get ('rhs' ),
435+ 'diff' : abs (value .get ('lhs' , 0 ) - value .get ('rhs' , 0 )),
436+ 'percent_diff' : abs (value .get ('lhs' , 0 ) - value .get ('rhs' , 0 )) / max (abs (value .get ('rhs' , 0 )), 1e-10 ) * 100
437+ }
438+ if value .get ('match' ):
439+ matching .append (equation_data )
440+ else :
441+ non_matching .append (equation_data )
442+
443+ # Display summary header
444+ total = len (results )
445+ display (HTML (
446+ f'<h3 style="font-family:Arial">Equation Validation Summary</h3>'
447+ f'<p style="font-family:Arial">Total equations checked: { total } <br>'
448+ f'✅ Matching equations: { len (matching )} <br>'
449+ f'❌ Non-matching equations: { len (non_matching )} </p>'
450+ ))
451+
452+ # Display non-matching equations first (if any)
453+ if non_matching :
454+ display (HTML (
455+ '<div style="background-color:#fff0f0; padding:10px; border-radius:5px; margin:10px 0;">'
456+ '<h4 style="color:#cc0000; font-family:Arial">⚠️ Equations Not Satisfied:</h4>'
457+ ))
458+
459+ for eq in non_matching :
460+ display (Math (eq ['latex' ]))
461+ display (HTML (
462+ f'<div style="font-family:monospace; margin-left:20px; margin-bottom:15px">'
463+ f'Left side = { eq ["lhs" ]:.6g} <br>'
464+ f'Right side = { eq ["rhs" ]:.6g} <br>'
465+ f'Difference = { eq ["diff" ]:.6g} <br>'
466+ f'Percent difference = { eq ["percent_diff" ]:.2f} %'
467+ '</div>'
468+ ))
469+
470+ display (HTML ('</div>' ))
471+
472+ # Display matching equations (if any)
473+ if matching :
474+ display (HTML (
475+ '<div style="background-color:#f0fff0; padding:10px; border-radius:5px; margin:10px 0;">'
476+ '<h4 style="color:#006600; font-family:Arial">✅ Satisfied Equations:</h4>'
477+ ))
478+
479+ for eq in matching :
480+ display (Math (eq ['latex' ]))
481+ display (HTML (
482+ f'<div style="font-family:monospace; margin-left:20px; margin-bottom:15px">'
483+ f'Value = { eq ["lhs" ]:.6g} '
484+ '</div>'
485+ ))
486+
487+ display (HTML ('</div>' ))
438488
439489def get_eq_hypergraph (api_results , requirements , with_printing = True ):
440490
@@ -549,3 +599,146 @@ def _add_used_vars_to_results(api_results, api_requirements):
549599 api_results ["results" ][key ]["used_vars" ] = used_vars
550600
551601 return api_results
602+
603+
604+ def display_full_results (equations_dict , requirements = None , show_hypergraph = True ):
605+ """Display equation validation results optimized for dark theme notebooks."""
606+ results = equations_dict .get ("results" , {})
607+
608+ def format_equation (latex_eq ):
609+ inner = latex_eq [3 :- 1 ]
610+ lhs , rhs = inner .split (',' , 1 )
611+ return f"{ lhs } = { rhs } "
612+
613+ matching = []
614+ non_matching = []
615+
616+ for key , value in results .items ():
617+ equation_data = {
618+ 'latex' : format_equation (value .get ('latex_equation' )),
619+ 'lhs' : value .get ('lhs' ),
620+ 'rhs' : value .get ('rhs' ),
621+ 'diff' : abs (value .get ('lhs' , 0 ) - value .get ('rhs' , 0 )),
622+ 'percent_diff' : abs (value .get ('lhs' , 0 ) - value .get ('rhs' , 0 )) / max (abs (value .get ('rhs' , 0 )), 1e-10 ) * 100
623+ }
624+ if value .get ('match' ):
625+ matching .append (equation_data )
626+ else :
627+ non_matching .append (equation_data )
628+
629+ # Summary header with dark theme
630+ total = len (results )
631+ display (HTML (
632+ '<div style="background-color:#1e1e1e; padding:20px; border-radius:10px; margin:20px 0; '
633+ 'border:1px solid #3e3e3e;">'
634+ f'<h2 style="font-family:Arial; color:#e0e0e0; margin-bottom:15px">Equation Validation Analysis</h2>'
635+ f'<p style="font-family:Arial; font-size:16px; color:#e0e0e0">'
636+ f'<b>Total equations analyzed:</b> { total } <br>'
637+ f'<span style="color:#4caf50">✅ Matching equations: { len (matching )} </span><br>'
638+ f'<span style="color:#ff5252">❌ Non-matching equations: { len (non_matching )} </span></p>'
639+ '</div>'
640+ ))
641+
642+ # Non-matching equations
643+ if non_matching :
644+ display (HTML (
645+ '<div style="background-color:#2d1f1f; padding:20px; border-radius:10px; margin:20px 0; '
646+ 'border:1px solid #4a2f2f;">'
647+ '<h3 style="color:#ff5252; font-family:Arial">⚠️ Equations Not Satisfied</h3>'
648+ ))
649+
650+ for eq in non_matching :
651+ display (Math (eq ['latex' ]))
652+ display (HTML (
653+ '<div style="font-family:monospace; margin-left:20px; margin-bottom:20px; '
654+ 'background-color:#2a2a2a; color:#e0e0e0; padding:15px; border-radius:5px; '
655+ 'border-left:4px solid #ff5252">'
656+ f'Left side = { eq ["lhs" ]:.6g} <br>'
657+ f'Right side = { eq ["rhs" ]:.6g} <br>'
658+ f'Absolute difference = { eq ["diff" ]:.6g} <br>'
659+ f'Relative difference = { eq ["percent_diff" ]:.2f} %'
660+ '</div>'
661+ ))
662+
663+ display (HTML ('</div>' ))
664+
665+ # Matching equations
666+ if matching :
667+ display (HTML (
668+ '<div style="background-color:#1f2d1f; padding:20px; border-radius:10px; margin:20px 0; '
669+ 'border:1px solid #2f4a2f;">'
670+ '<h3 style="color:#4caf50; font-family:Arial">✅ Satisfied Equations</h3>'
671+ ))
672+
673+ for eq in matching :
674+ display (Math (eq ['latex' ]))
675+ display (HTML (
676+ '<div style="font-family:monospace; margin-left:20px; margin-bottom:20px; '
677+ 'background-color:#2a2a2a; color:#e0e0e0; padding:15px; border-radius:5px; '
678+ 'border-left:4px solid #4caf50">'
679+ f'Value = { eq ["lhs" ]:.6g} '
680+ '</div>'
681+ ))
682+
683+ display (HTML ('</div>' ))
684+
685+ # Hypergraph visualization
686+ if show_hypergraph and requirements :
687+ display (HTML (
688+ '<div style="background-color:#1e1e1e; padding:20px; border-radius:10px; margin:20px 0; '
689+ 'border:1px solid #3e3e3e;">'
690+ '<h3 style="color:#e0e0e0; font-family:Arial">🔍 Equation Relationship Analysis</h3>'
691+ '<p style="font-family:Arial; color:#e0e0e0">The following graph shows how variables are connected through equations:</p>'
692+ '</div>'
693+ ))
694+
695+ list_api_requirements = [asdict (req ) for req in requirements ]
696+
697+ # Match get_eq_hypergraph settings exactly
698+ plt .rcParams ["text.usetex" ] = False
699+ plt .rcParams ["mathtext.fontset" ] = "stix"
700+ plt .rcParams ["font.family" ] = "serif"
701+
702+ equations_dict = _add_used_vars_to_results (equations_dict , list_api_requirements )
703+
704+ # Prepare hypergraph data
705+ hyperedges = {}
706+ for eq , details in equations_dict ["results" ].items ():
707+ hyperedges [
708+ _get_latex_string_format (details ["latex_equation" ])] = details ["used_vars" ]
709+
710+ # Create and plot the hypergraph
711+ H = hnx .Hypergraph (hyperedges )
712+ plt .figure (figsize = (16 , 12 ))
713+
714+ # Draw hypergraph with exact same settings as get_eq_hypergraph
715+ hnx .draw (
716+ H ,
717+ with_edge_labels = True ,
718+ edge_labels_on_edge = False ,
719+ node_labels_kwargs = {"fontsize" : 14 },
720+ edge_labels_kwargs = {"fontsize" : 14 },
721+ layout_kwargs = {"seed" : 42 , "scale" : 2.5 },
722+ )
723+
724+ node_labels = list (H .nodes )
725+ symbol_explanations = _get_node_names_for_node_lables (
726+ node_labels ,
727+ list_api_requirements
728+ )
729+
730+ explanation_text = "\n " .join (
731+ [f"${ symbol } $: { desc } " for symbol , desc in symbol_explanations ]
732+ )
733+ plt .annotate (
734+ explanation_text ,
735+ xy = (1.05 , 0.5 ),
736+ xycoords = "axes fraction" ,
737+ fontsize = 14 ,
738+ verticalalignment = "center" ,
739+ )
740+
741+ plt .title (r"Enhanced Hypergraph of Equations and Variables" , fontsize = 20 )
742+ plt .show ()
743+
744+ return None
0 commit comments