import numpy as np
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
import os
from pathlib import Path
from polsartools.utils.utils import read_bin
def get_feas_bounds():
c1l = np.array([[ 0, 0.00000000e+00],
[5.68070458e-02, 8.91089109e-01],
[1.00217413e-01, 1.76470588e+00],
[1.38247415e-01, 2.62135922e+00],
[1.72657031e-01, 3.46153846e+00],
[2.04304187e-01, 4.28571429e+00],
[2.33706941e-01, 5.09433962e+00],
[2.61215910e-01, 5.88785047e+00],
[2.87086073e-01, 6.66666667e+00],
[3.11512289e-01, 7.43119266e+00],
[3.34648976e-01, 8.18181818e+00],
[3.56621927e-01, 8.91891892e+00],
[3.77535871e-01, 9.64285714e+00],
[3.97479533e-01, 1.03539823e+01],
[4.16529162e-01, 1.10526316e+01],
[4.34751078e-01, 1.17391304e+01],
[4.52203543e-01, 1.24137931e+01],
[4.68938188e-01, 1.30769231e+01],
[4.85001106e-01, 1.37288136e+01],
[5.00433715e-01, 1.43697479e+01],
[5.15273445e-01, 1.50000000e+01],
[5.29554291e-01, 1.56198347e+01],
[5.43307267e-01, 1.62295082e+01],
[5.56560782e-01, 1.68292683e+01],
[5.69340953e-01, 1.74193548e+01],
[5.81671866e-01, 1.80000000e+01],
[5.93575801e-01, 1.85714286e+01],
[6.05073426e-01, 1.91338583e+01],
[6.16183955e-01, 1.96875000e+01],
[6.26925297e-01, 2.02325581e+01],
[6.37314175e-01, 2.07692308e+01],
[6.47366238e-01, 2.12977099e+01],
[6.57096154e-01, 2.18181818e+01],
[6.66517697e-01, 2.23308271e+01],
[6.75643820e-01, 2.28358209e+01],
[6.84486721e-01, 2.33333333e+01],
[6.93057905e-01, 2.38235294e+01],
[7.01368234e-01, 2.43065693e+01],
[7.09427979e-01, 2.47826087e+01],
[7.17246861e-01, 2.52517986e+01],
[7.24834092e-01, 2.57142857e+01],
[7.32198407e-01, 2.61702128e+01],
[7.39348101e-01, 2.66197183e+01],
[7.46291058e-01, 2.70629371e+01],
[7.53034772e-01, 2.75000000e+01],
[7.59586381e-01, 2.79310345e+01],
[7.65952682e-01, 2.83561644e+01],
[7.72140158e-01, 2.87755102e+01],
[7.78154991e-01, 2.91891892e+01],
[7.84003086e-01, 2.95973154e+01],
[7.89690082e-01, 3.00000000e+01],
[7.95221372e-01, 3.03973510e+01],
[8.00602113e-01, 3.07894737e+01],
[8.05837242e-01, 3.11764706e+01],
[8.10931485e-01, 3.15584416e+01],
[8.15889374e-01, 3.19354839e+01],
[8.20715250e-01, 3.23076923e+01],
[8.25413279e-01, 3.26751592e+01],
[8.29987458e-01, 3.30379747e+01],
[8.34441626e-01, 3.33962264e+01],
[8.38779468e-01, 3.37500000e+01],
[8.43004527e-01, 3.40993789e+01],
[8.47120210e-01, 3.44444444e+01],
[8.51129792e-01, 3.47852761e+01],
[8.55036424e-01, 3.51219512e+01],
[8.58843141e-01, 3.54545455e+01],
[8.62552864e-01, 3.57831325e+01],
[8.66168407e-01, 3.61077844e+01],
[8.69692481e-01, 3.64285714e+01],
[8.73127701e-01, 3.67455621e+01],
[8.76476587e-01, 3.70588235e+01],
[8.79741571e-01, 3.73684211e+01],
[8.82925000e-01, 3.76744186e+01],
[8.86029137e-01, 3.79768786e+01],
[8.89056170e-01, 3.82758621e+01],
[8.92008211e-01, 3.85714286e+01],
[8.94887299e-01, 3.88636364e+01],
[8.97695407e-01, 3.91525424e+01],
[9.00434441e-01, 3.94382022e+01],
[9.03106244e-01, 3.97206704e+01],
[9.05712598e-01, 4.00000000e+01],
[9.08255228e-01, 4.02762431e+01],
[9.10735802e-01, 4.05494505e+01],
[9.13155936e-01, 4.08196721e+01],
[9.15517194e-01, 4.10869565e+01],
[9.17821089e-01, 4.13513514e+01],
[9.20069090e-01, 4.16129032e+01],
[9.22262616e-01, 4.18716578e+01],
[9.24403046e-01, 4.21276596e+01],
[9.26491714e-01, 4.23809524e+01],
[9.28529914e-01, 4.26315789e+01],
[9.30518901e-01, 4.28795812e+01],
[9.32459893e-01, 4.31250000e+01],
[9.34354071e-01, 4.33678756e+01],
[9.36202579e-01, 4.36082474e+01],
[9.38006531e-01, 4.38461538e+01],
[9.39767004e-01, 4.40816327e+01],
[9.41485048e-01, 4.43147208e+01],
[9.43161680e-01, 4.45454545e+01],
[9.44797887e-01, 4.47738693e+01],
[9.46394630e-01, 4.50000000e+01],
[9.47952842e-01, 4.52238806e+01],
[9.49473429e-01, 4.54455446e+01],
[9.50957272e-01, 4.56650246e+01],
[9.52405226e-01, 4.58823529e+01],
[9.53818125e-01, 4.60975610e+01],
[9.55196779e-01, 4.63106796e+01],
[9.56541973e-01, 4.65217391e+01],
[9.57854475e-01, 4.67307692e+01],
[9.59135029e-01, 4.69377990e+01],
[9.60384360e-01, 4.71428571e+01],
[9.61603173e-01, 4.73459716e+01],
[9.62792156e-01, 4.75471698e+01],
[9.63951976e-01, 4.77464789e+01],
[9.65083284e-01, 4.79439252e+01],
[9.66186714e-01, 4.81395349e+01],
[9.67262883e-01, 4.83333333e+01],
[9.68312392e-01, 4.85253456e+01],
[9.69335827e-01, 4.87155963e+01],
[9.70333757e-01, 4.89041096e+01],
[9.71306738e-01, 4.90909091e+01],
[9.72255313e-01, 4.92760181e+01],
[9.73180009e-01, 4.94594595e+01],
[9.74081340e-01, 4.96412556e+01],
[9.74959809e-01, 4.98214286e+01],
[9.75815904e-01, 5.00000000e+01],
[9.76650102e-01, 5.01769912e+01],
[9.77462869e-01, 5.03524229e+01],
[9.78254658e-01, 5.05263158e+01],
[9.79025911e-01, 5.06986900e+01],
[9.79777061e-01, 5.08695652e+01],
[9.80508528e-01, 5.10389610e+01],
[9.81220724e-01, 5.12068966e+01],
[9.81914050e-01, 5.13733906e+01],
[9.82588897e-01, 5.15384615e+01],
[9.83245647e-01, 5.17021277e+01],
[9.83884675e-01, 5.18644068e+01],
[9.84506343e-01, 5.20253165e+01],
[9.85111008e-01, 5.21848739e+01],
[9.85699017e-01, 5.23430962e+01],
[9.86270709e-01, 5.25000000e+01],
[9.86826416e-01, 5.26556017e+01],
[9.87366462e-01, 5.28099174e+01],
[9.87891161e-01, 5.29629630e+01],
[9.88400825e-01, 5.31147541e+01],
[9.88895753e-01, 5.32653061e+01],
[9.89376242e-01, 5.34146341e+01],
[9.89842580e-01, 5.35627530e+01],
[9.90295048e-01, 5.37096774e+01],
[9.90733922e-01, 5.38554217e+01],
[9.91159471e-01, 5.40000000e+01],
[9.91571959e-01, 5.41434263e+01],
[9.91971643e-01, 5.42857143e+01],
[9.92358774e-01, 5.44268775e+01],
[9.92733599e-01, 5.45669291e+01],
[9.93096359e-01, 5.47058824e+01],
[9.93447289e-01, 5.48437500e+01],
[9.93786618e-01, 5.49805447e+01],
[9.94114574e-01, 5.51162791e+01],
[9.94431375e-01, 5.52509653e+01],
[9.94737238e-01, 5.53846154e+01],
[9.95032374e-01, 5.55172414e+01],
[9.95316988e-01, 5.56488550e+01],
[9.95591284e-01, 5.57794677e+01],
[9.95855460e-01, 5.59090909e+01],
[9.96109708e-01, 5.60377358e+01],
[9.96354218e-01, 5.61654135e+01],
[9.96589175e-01, 5.62921348e+01],
[9.96814763e-01, 5.64179104e+01],
[9.97031157e-01, 5.65427509e+01],
[9.97238532e-01, 5.66666667e+01],
[9.97437060e-01, 5.67896679e+01],
[9.97626906e-01, 5.69117647e+01],
[9.97808234e-01, 5.70329670e+01],
[9.97981205e-01, 5.71532847e+01],
[9.98145975e-01, 5.72727273e+01],
[9.98302698e-01, 5.73913043e+01],
[9.98451525e-01, 5.75090253e+01],
[9.98592603e-01, 5.76258993e+01],
[9.98726076e-01, 5.77419355e+01],
[9.98852087e-01, 5.78571429e+01],
[9.98970773e-01, 5.79715302e+01],
[9.99082272e-01, 5.80851064e+01],
[9.99186715e-01, 5.81978799e+01],
[9.99284234e-01, 5.83098592e+01],
[9.99374957e-01, 5.84210526e+01],
[9.99459009e-01, 5.85314685e+01],
[9.99536513e-01, 5.86411150e+01],
[9.99607590e-01, 5.87500000e+01],
[9.99672358e-01, 5.88581315e+01],
[9.99730933e-01, 5.89655172e+01],
[9.99783428e-01, 5.90721649e+01],
[9.99829955e-01, 5.91780822e+01],
[9.99870624e-01, 5.92832765e+01],
[9.99905540e-01, 5.93877551e+01],
[9.99934810e-01, 5.94915254e+01],
[9.99958537e-01, 5.95945946e+01],
[9.99976821e-01, 5.96969697e+01],
[9.99989761e-01, 5.97986577e+01],
[9.99997456e-01, 5.98996656e+01],
[1.00000000e+00, 6.00000000e+01]])
c22l = np.array([
[np.nan,90],
[0.637490666922012,89.9100899100899],
[0.642780051326664,89.8203592814371],
[0.64758493789284,89.7308075772681],
[0.652073091598438,89.6414342629482],
[0.656324368447387,89.5522388059701],
[0.660385905549124,89.4632206759443],
[0.664288917260044,89.3743793445878],
[0.668055637075812,89.2857142857142],
[0.671702725080799,89.197224975223],
[0.675243140923087,89.1089108910891],
[0.678687260183894,89.0207715133531],
[0.682043581735929,88.9328063241106],
[0.685319197953429,88.8450148075024],
[0.688520119602884,88.7573964497041],
[0.69165150759842,88.6699507389162],
[0.694717842804856,88.5826771653543],
[0.697723053318171,88.4955752212389],
[0.700670611766267,88.4086444007858],
[0.703563610976874,88.3218842001962],
[0.706404823715649,88.235294117647],
[0.709196750482267,88.1488736532811],
[0.71194165821052,88.0626223091976],
[0.714641611940935,87.9765395894428],
[0.717298500994026,87.890625],
[0.719914060789865,87.8048780487804],
[0.722489891184453,87.719298245614],
[0.725027471992373,87.6338851022395],
[0.727528176216381,87.5486381322957],
[0.729993281393007,87.4635568513119],
[0.732423979378592,87.378640776699],
[0.73482138483533,87.29388942774],
[0.737186542626655,87.2093023255813],
[0.739520434292086,87.1248789932236],
[0.741823983740734,87.0406189555125],
[0.744098062278127,86.9565217391304],
[0.746343493061373,86.8725868725868],
[0.748561055061879,86.7888138862102],
[0.750751486601976,86.7052023121387],
[0.75291548852138,86.6217516843118],
[0.755053727020791,86.5384615384615],
[0.757166836222881,86.4553314121037],
[0.759255420485009,86.3723608445297],
[0.761320056493135,86.2895493767976],
[0.763361295162268,86.2068965517241],
[0.765379663365375,86.1244019138756],
[0.767375665509718,86.0420650095602],
[0.769349784977149,85.9598853868194],
[0.771302485442781,85.8778625954198],
[0.773234212084631,85.7959961868446],
[0.775145392695341,85.7142857142857],
[0.777036438705702,85.6327307326355],
[0.778907746128593,85.551330798479],
[0.780759696430966,85.4700854700854],
[0.782592657340606,85.3889943074003],
[0.784406983593702,85.3080568720379],
[0.786203017628564,85.2272727272727],
[0.787981090230271,85.1466414380321],
[0.789741521130544,85.0661625708884],
[0.791484619566666,84.9858356940509],
[0.793210684802909,84.9056603773584],
[0.794920006617574,84.8256361922714],
[0.796612865758444,84.7457627118644],
[0.79828953436918,84.6660395108184],
[0.799950276388959,84.5864661654135],
[0.801595347927417,84.5070422535211],
[0.803224997616808,84.4277673545966],
[0.804839466943062,84.3486410496719],
[0.80643899055734,84.2696629213483],
[0.808023796569481,84.1908325537885],
[0.809594106824666,84.1121495327102],
[0.81115013716447,84.0336134453781],
[0.812692097673412,83.955223880597],
[0.814220192911991,83.8769804287045],
[0.815734622137124,83.7988826815642],
[0.817235579510849,83.7209302325581],
[0.818723254298042,83.6431226765799],
[0.820197831053887,83.5654596100278],
[0.821659489801753,83.4879406307977],
[0.823108406202082,83.4105653382761],
[0.824544751712857,83.3333333333333],
[0.825968693742175,83.2562442183163],
[0.827380395793399,83.1792975970425],
[0.828780017603347,83.1024930747922],
[0.830167715273929,83.0258302583025],
[0.831543641397619,82.9493087557603],
[0.832907945177117,82.8729281767955],
[0.834260772539548,82.7966881324746],
[0.835602266245496,82.7205882352941],
[0.836932565993171,82.6446280991735],
[0.838251808517971,82.5688073394495],
[0.839560127687712,82.4931255728689],
[0.840857654593732,82.4175824175824],
[0.842144517638125,82.3421774931381],
[0.843420842617274,82.2669104204753],
[0.844686752801916,82.1917808219177],
[0.845942369013886,82.1167883211678],
[0.847187809699736,82.0419325432999],
[0.848423191001369,81.9672131147541],
[0.849648626823857,81.8926296633302],
[0.850864228900568,81.8181818181818],
[0.852070106855741,81.7438692098092],
[0.853266368264641,81.6696914700544],
[0.854453118711399,81.5956482320942],
[0.85563046184465,81.5217391304347],
[0.856798499431088,81.4479638009049],
[0.857957331407016,81.3743218806509],
[0.859107055927998,81.30081300813],
[0.860247769416691,81.2274368231046],
[0.861379566608956,81.1541929666366],
[0.862502540598302,81.081081081081],
[0.863616782878763,81.008100810081],
[0.864722383386256,80.9352517985611],
[0.865819430538506,80.8625336927223],
[0.866908011273582,80.7899461400358],
[0.867988211087122,80.7174887892376],
[0.869060114068288,80.6451612903225],
[0.870123802934516,80.5729632945389],
[0.871179359065106,80.5008944543828],
[0.872226862533699,80.4289544235924],
[0.873266392139697,80.3571428571428],
[0.874298025438653,80.2854594112399],
[0.875321838771693,80.2139037433154],
[0.876337907293989,80.1424755120213],
[0.877346305002334,80.0711743772241],
[0.878347104761853,80],
[0.879340378331882,79.9289520426287],
[0.880326196391042,79.8580301685891],
[0.881304628561553,79.7872340425531],
[0.882275743432804,79.7165633303808],
[0.883239608584211,79.646017699115],
[0.884196290607398,79.5755968169761],
[0.885145855127715,79.5053003533568],
[0.886088366825122,79.4351279788172],
[0.887023889454463,79.3650793650793],
[0.887952485865159,79.295154185022],
[0.888874218020325,79.225352112676],
[0.889789147015348,79.1556728232189],
[0.890697333095935,79.0861159929701],
[0.891598835675656,79.0166812993854],
[0.892493713352995,78.9473684210526],
[0.893382023927933,78.8781770376862],
[0.894263824418069,78.8091068301225],
[0.895139171074307,78.7401574803149],
[0.896008119396114,78.6713286713286],
[0.896870724146366,78.6026200873362],
[0.897727039365803,78.5340314136125],
[0.898577118387097,78.46556233653],
[0.89942101384855,78.397212543554],
[0.900258777707433,78.3289817232375],
[0.90109046125298,78.2608695652173],
[0.901916115119046,78.1928757602084],
[0.902735789296443,78.1249999999999],
[0.903549533144957,78.0572419774501],
[0.904357395405065,77.9896013864817],
[0.905159424209364,77.9220779220779],
[0.905955667093698,77.8546712802768],
[0.906746171008029,77.7873811581676],
[0.907530982327027,77.720207253886],
[0.908310146860409,77.6531492666091],
[0.909083709863021,77.5862068965517],
[0.909851716044683,77.5193798449612],
[0.910614209579789,77.4526678141135],
[0.911371234116693,77.3860705073086],
[0.912122832786855,77.3195876288659],
[0.912869048213788,77.2532188841201],
[0.913609922521786,77.1869639794168],
[0.914345497344451,77.1208226221079],
[0.915075813833028,77.0547945205479],
[0.915800912664543,76.9888793840889],
[0.91652083404976,76.9230769230769],
[0.917235617740953,76.8573868488471],
[0.917945303039508,76.7918088737201],
[0.918649928803355,76.7263427109974],
[0.919349533454226,76.6609880749574],
[0.920044154984765,76.595744680851],
[0.920733830965473,76.5306122448979],
[0.921418598551503,76.465590484282],
[0.922098494489311,76.4006791171477],
[0.922773555123159,76.3358778625953],
[0.923443816401481,76.2711864406779],
[0.924109313883109,76.2066045723962],
[0.924770082743375,76.1421319796954],
[0.925426157780076,76.0777683854606],
[0.926077573419317,76.0135135135135],
[0.926724363721236,75.9493670886075],
[0.927366562385599,75.8853288364249],
[0.928004202757294,75.821398483572],
[0.928637317831703,75.7575757575757],
[0.929265940259966,75.6938603868797],
[0.929890102354136,75.6302521008403],
[0.930509836092241,75.5667506297229],
[0.931125173123226,75.5033557046979],
[0.931736144771814,75.4400670578373],
[0.93234278204326,75.3768844221105],
[0.932945115628013,75.3138075313807],
[0.933543175906292,75.2508361204013],
[0.93413699295256,75.187969924812],
[0.934726596539928,75.1252086811352],
[0.93531201614446,75.0625521267722],
[0.935893280949399,75],
[0.936470419849318,74.9375520399666],
[0.937043461454181,74.8752079866888],
[0.937612434093341,74.8129675810473],
[0.938177365819446,74.750830564784],
[0.938738284412289,74.6887966804979],
[0.939295217382571,74.6268656716417],
[0.939848191975607,74.5650372825186],
[0.940397235174954,74.5033112582781],
[0.940942373705974,74.4416873449131],
[0.941483634039341,74.3801652892561],
[0.94202104239447,74.318744838976],
[0.942554624742893,74.2574257425742],
[0.943084406811575,74.1962077493816],
[0.943610414086161,74.1350906095551],
[0.94413267181418,74.074074074074],
[0.944651205008178,74.0131578947368],
[0.945166038448802,73.9523418241577],
[0.945677196687832,73.8916256157635],
[0.946184704051155,73.8310090237899],
[0.946688584641687,73.7704918032786],
[0.947188862342254,73.7100737100737],
[0.947685560818408,73.6497545008183],
[0.948178703521206,73.5895339329517],
[0.948668313689938,73.5294117647058],
[0.94915441435481,73.469387755102],
[0.949637028339575,73.4094616639477],
[0.950116178264132,73.3496332518337],
[0.950591886547068,73.2899022801302],
[0.951064175408166,73.2302685109845],
[0.95153306687087,73.170731707317],
[0.951998582764707,73.1112916328188],
[0.952460744727668,73.051948051948],
[0.952919574208558,72.9927007299269],
[0.953375092469293,72.933549432739],
[0.953827320587178,72.8744939271254],
[0.954276279457129,72.8155339805825],
[0.954721989793877,72.7566693613581],
[0.955164472134121,72.6978998384491],
[0.955603746838659,72.639225181598],
[0.956039834094477,72.5806451612903],
[0.956472753916806,72.5221595487509],
[0.956902526151155,72.463768115942],
[0.957329170475296,72.4054706355591],
[0.957752706401236,72.3472668810289],
[0.958173153277142,72.289156626506],
[0.958590530289249,72.2311396468699],
[0.95900485646373,72.1732157177225],
[0.959416150668541,72.1153846153845],
[0.959824431615237,72.0576461168935],
[0.960229717860761,71.9999999999999],
[0.960632027809204,71.9424460431654],
[0.961031379713541,71.884984025559],
[0.961427791677337,71.827613727055],
[0.961821281656431,71.7703349282296],
[0.962211867460592,71.7131474103585],
[0.962599566755156,71.656050955414],
[0.962984397062628,71.599045346062],
[0.963366375764272,71.5421303656597],
[0.963745520101671,71.4853057982525],
[0.964121847178263,71.4285714285714],
[0.964495373960861,71.3719270420301],
[0.964866117281144,71.3153724247226],
[0.965234093837131,71.2589073634204],
[0.965599320194631,71.2025316455696],
[0.965961812788675,71.1462450592885],
[0.966321587924921,71.0900473933649],
[0.966678661781052,71.0339384372533],
[0.967033050408136,70.9779179810725],
[0.967384769731985,70.9219858156028],
[0.96773383555448,70.8661417322834],
[0.968080263554887,70.81038552321],
[0.968424069291153,70.754716981132],
[0.968765268201176,70.6991358994501],
[0.969103875604071,70.6436420722134],
[0.969439906701405,70.5882352941176],
[0.969773376578424,70.5329153605015],
[0.97010430020526,70.4776820673453],
[0.970432692438122,70.4225352112675],
[0.970758568020468,70.367474589523],
[0.971081941584166,70.3124999999999],
[0.971402827650634,70.2576112412177],
[0.97172124063197,70.2028081123244],
[0.972037194832064,70.1480904130942],
[0.972350704447692,70.0934579439252],
[0.972661783569603,70.0389105058365],
[0.972970446183584,69.9844479004665],
[0.973276706171513,69.9300699300699],
[0.973580577312404,69.8757763975155],
[0.973882073283429,69.8215671062839],
[0.974181207660932,69.767441860465],
[0.974477993921428,69.7134004647559],
[0.974772445442593,69.6594427244581],
[0.975064575504233,69.6055684454756],
[0.975354397289249,69.5517774343121],
[0.975641923884583,69.4980694980694],
[0.975927168282157,69.4444444444444],
[0.976210143379796,69.390902081727],
[0.976490861982143,69.3374422187981],
[0.976769336801556,69.284064665127],
[0.977045580459002,69.2307692307692],
[0.977319605484934,69.1775557263643],
[0.977591424320159,69.1244239631336],
[0.977861049316693,69.0713737528779],
[0.978128492738607,69.0184049079754],
[0.978393766762865,68.9655172413793],
[0.978656883480147,68.9127105666156],
[0.978917854895663,68.8599846977811],
[0.979176692929959,68.8073394495412],
[0.979433409419711,68.7547746371275],
[0.97968801611851,68.7022900763358],
[0.979940524697639,68.649885583524],
[0.980190946746837,68.5975609756097],
[0.980439293775054,68.5453160700685],
[0.980685577211204,68.4931506849314],
[0.980929808404898,68.4410646387832],
[0.981171998627178,68.3890577507598],
[0.981412159071231,68.3371298405466],
[0.981650300853112,68.2852807283763],
[0.981886435012435,68.2335102350265],
[0.98212057251308,68.1818181818181],
[0.982352724243871,68.1302043906131],
[0.982582901019261,68.0786686838123],
[0.982811113579999,68.0272108843537],
[0.983037372593796,67.9758308157099],
[0.983261688655979,67.9245283018867],
[0.983484072290138,67.8733031674208],
[0.983704533948769,67.8221552373775],
[0.983923084013902,67.7710843373493],
[0.98413973279773,67.7200902934537],
[0.984354490543228,67.6691729323308],
[0.984567367424759,67.6183320811419],
[0.984778373548685,67.5675675675675],
[0.984987518953958,67.5168792198049],
[0.985194813612714,67.4662668665666],
[0.985400267430856,67.4157303370786],
[0.98560389024863,67.3652694610778],
[0.985805691841197,67.3148840688107],
[0.986005681919195,67.2645739910313],
[0.9862038701293,67.2143390589992],
[0.986400266054775,67.1641791044775],
[0.986594879216014,67.1140939597315],
[0.986787719071088,67.064083457526],
[0.986978795016268,67.0141474311243],
[0.987168116386564,66.9642857142856],
[0.987355692456235,66.9144981412639],
[0.987541532439315,66.8647845468053],
[0.987725645490116,66.8151447661469],
[0.987908040703738,66.7655786350148],
[0.988088727116564,66.7160859896219],
[0.988267713706753,66.6666666666666],
[0.988445009394735,66.6173205033308],
[0.988620623043686,66.568047337278],
[0.988794563460012,66.5188470066518],
[0.988966839393816,66.4697193500738],
[0.989137459539371,66.420664206642],
[0.98930643253558,66.3716814159291],
[0.989473766966433,66.3227708179808],
[0.989639471361461,66.2739322533136],
[0.989803554196184,66.2251655629138],
[0.989966023892554,66.1764705882352],
[0.990126888819394,66.1278471711976],
[0.99028615729283,66.079295154185],
[0.990443837576722,66.030814380044],
[0.990599937883091,65.982404692082],
[0.990754466372534,65.9340659340659],
[0.990907431154645,65.8857979502195],
[0.991058840288426,65.837600585223],
[0.991208701782691,65.7894736842105],
[0.991357023596472,65.7414170927684],
[0.991503813639421,65.6934306569342],
[0.991649079772198,65.6455142231947],
[0.991792829806868,65.5976676384839],
[0.991935071507284,65.549890750182],
[0.992075812589475,65.5021834061135],
[0.992215060722017,65.4545454545454],
[0.992352823526419,65.406976744186],
[0.992489108577482,65.359477124183],
[0.992623923403679,65.3120464441219],
[0.99275727548751,65.2646845540246],
[0.992889172265867,65.2173913043477],
[0.993019621130388,65.1701665459811],
[0.993148629427812,65.123010130246],
[0.993276204460329,65.0759219088936],
[0.993402353485925,65.028901734104],
[0.993527083718725,64.9819494584837],
[0.99365040232933,64.9350649350649],
[0.99377231644516,64.8882480173035],
[0.993892833150777,64.8414985590777],
[0.994011959488223,64.7948164146868],
[0.994129702457341,64.7482014388489],
[0.9942460690161,64.7016534867001],
[0.994361066080913,64.655172413793],
[0.994474700526958,64.6087580760947],
[0.994586979188486,64.5624103299856],
[0.994697908859136,64.516129032258],
[0.994807496292239,64.4699140401145],
[0.994915748201126,64.4237652111667],
[0.99502267125943,64.3776824034334],
[0.995128272101378,64.3316654753395],
[0.995232557322098,64.2857142857142],
[0.995335533477902,64.2398286937901],
[0.995437207086583,64.1940085592011],
[0.995537584627697,64.1482537419814],
[0.995636672542854,64.102564102564],
[0.995734477235995,64.0569395017793],
[0.995831005073676,64.0113798008534],
[0.995926262385341,63.9658848614072],
[0.996020255463596,63.9204545454545],
[0.996112990564485,63.8750887154009],
[0.996204473907755,63.8297872340425],
[0.996294711677125,63.7845499645641],
[0.996383710020548,63.7393767705382],
[0.996471475050477,63.6942675159235],
[0.996558012844117,63.6492220650636],
[0.99664332944369,63.6042402826854],
[0.996727430856683,63.5593220338982],
[0.996810323056104,63.5144671841919],
[0.996892011980731,63.4696755994358],
[0.996972503535358,63.4249471458773],
[0.997051803591044,63.3802816901408],
[0.997129917985349,63.3356790992258],
[0.997206852522585,63.2911392405063],
[0.997282612974045,63.2466619817287],
[0.997357205078246,63.2022471910112],
[0.997430634541159,63.157894736842],
[0.997502907036444,63.1136044880785],
[0.997574028205681,63.0693763139453],
[0.997644003658593,63.0252100840336],
[0.997712838973279,62.9811056682994],
[0.997780539696431,62.9370629370629],
[0.997847111343563,62.8930817610062],
[0.997912559399225,62.8491620111731],
[0.997976889317224,62.8053035589671],
[0.998040106520842,62.7615062761506],
[0.998102216403044,62.7177700348431],
[0.998163224326698,62.6740947075208],
[0.998223135624781,62.6304801670145],
[0.998281955600586,62.586926286509],
[0.998339689527933,62.5434329395413],
[0.998396342651374,62.4999999999999],
[0.998451920186392,62.4566273421235],
[0.998506427319604,62.4133148404992],
[0.998559869208965,62.3700623700623],
[0.998612250983959,62.3268698060941],
[0.9986635777458,62.2837370242214],
[0.998713854567625,62.2406639004149],
[0.998763086494687,62.1976503109882],
[0.998811278544547,62.1546961325966],
[0.99885843570726,62.111801242236],
[0.998904562945569,62.0689655172413],
[0.998949665195086,62.0261888352859],
[0.998993747364477,61.9834710743801],
[0.999036814335651,61.9408121128699],
[0.999078870963933,61.898211829436],
[0.999119922078251,61.8556701030927],
[0.99915997248131,61.8131868131867],
[0.999199026949772,61.770761839396],
[0.99923709023443,61.7283950617283],
[0.999274167060382,61.6860863605208],
[0.999310262127204,61.6438356164383],
[0.999345380109122,61.6016427104722],
[0.999379525655178,61.5595075239397],
[0.999412703389404,61.5174299384825],
[0.999444917910984,61.4754098360655],
[0.999476173794421,61.433447098976],
[0.999506475589702,61.3915416098226],
[0.99953582782246,61.3496932515337],
[0.999564234994136,61.3079019073569],
[0.999591701582136,61.2661674608577],
[0.999618232039995,61.2244897959183],
[0.99964383079753,61.1828687967368],
[0.999668502260998,61.141304347826],
[0.999692250813251,61.0997963340122],
[0.999715080813889,61.0583446404341],
[0.999736996599411,61.0169491525423],
[0.999758002483369,60.9756097560975],
[0.999778102756518,60.9343263371699],
[0.999797301686958,60.893098782138],
[0.999815603520291,60.8519269776876],
[0.999833012479762,60.8108108108107],
[0.999849532766402,60.7697501688048],
[0.999865168559177,60.7287449392712],
[0.999879924015127,60.6877950101146],
[0.999893803269512,60.6469002695417],
[0.999906810435944,60.6060606060605],
[0.999918949606537,60.5652759084791],
[0.999930224852035,60.5245460659044],
[0.999940640221957,60.4838709677419],
[0.99995019974473,60.4432505036937],
[0.999958907427822,60.4026845637583],
[0.99996676725788,60.3621730382293],
[0.999973783200858,60.3217158176943],
[0.999979959202154,60.2813127930341],
[0.999985299186735,60.2409638554216],
[0.999989807059272,60.200668896321],
[0.999993486704266,60.1604278074866],
[0.999996341986175,60.1202404809619],
[0.999998376749542,60.0801068090787],
[0.999999594819121,60.0400266844562],
[1,60]
])
c21l = np.array([[0,0],
[0.1,1]])
return c1l,c22l,c21l
[docs]
def plot_h_alpha_fp(h, alpha, ppath=None, cmap='viridis',
cbar=True, norm='', vmin=None,vmax=None,
grey_region=True, zone_lines=True,
zone_line_color='k',zone_ids=True,gridsize=300):
"""
Generates and saves a density plot of entropy (H) versus alpha (degrees) for full-pol data,
including optional zone lines, zone IDs, and grey regions.
Example:
--------
>>> plot_h_alpha_fp(h, alpha, ppath="HA_plot.png", cmap='jet', colorbar=True, norm='log')
This will generates a H/Alpha plot from the input arrays and save it as HA_plot.png, using the 'jet' colormap and logarithmic normalization
Parameters:
-----------
h : path or array-like
path to the Entropy file or Array representing entropy values.
alpha : array-like
path to the Alpha file or Array representing alpha values in degrees.
ppath : str, optional
Path to save the generated plot. If a folder is given, the plot is saved as 'halpha_plot_fp.png' inside that folder.
If the file already exists, it will be overwritten.
cmap : str, optional
Colormap used for the hexbin plot. Defaults to 'viridis'.
colorbar : bool, optional
If True, displays a colorbar representing sample count. Defaults to True.
norm : str, optional
If set to 'log', applies logarithmic normalization to the hexbin plot.
grey_region : bool, optional
If True, fills non-feasible regions of the plot with a grey color to indicate feasible boundaries. Defaults to True.
zone_lines : bool, optional
If True, adds dashed lines to mark different entropy-alpha zones. Defaults to True.
zone_line_color : str, optional
Color used for zone boundary lines. Defaults to 'k' (black).
zone_ids : bool, optional
If True, labels predefined zones with numerical identifiers. Defaults to True.
gridsize : int, optional
Number of hexagonal bins used in the plot. Higher values result in finer binning. Defaults to 300.
Returns:
--------
None
Displays the plot and optionally saves it to the specified location.
Notes:
------
- Uses `get_feas_bounds()` to obtain feasible boundary curves for plotting.
- If `norm` is 'log', a `LogNorm()` normalization is applied.
"""
if isinstance(h, (str, os.PathLike, Path)):
H = read_bin(h)
if isinstance(alpha, (str, os.PathLike, Path)):
alpha = read_bin(alpha)
# --- Drop NaNs and zeros---
valid_mask = ~(
((H == 0) & (alpha == 0)) | # all three are zero
(np.isnan(H) & np.isnan(alpha)) # all three are NaN
)
H = H[valid_mask].flatten()
alpha = alpha[valid_mask].flatten()
c1l,c22l,c21l = get_feas_bounds()
fs = 12
fig_size = (3.6, 3) if cbar else (3.2, 3)
fig, ax = plt.subplots(figsize=fig_size, dpi=300)
norm_option = mcolors.LogNorm() if norm == 'log' else None
if vmin is not None and vmax is not None:
norm_option = mcolors.Normalize(vmin=vmin, vmax=vmax) if norm == '' else norm_option
if vmin is not None and vmax is None:
norm_option = mcolors.Normalize(vmin=vmin) if norm == '' else norm_option
if vmin is None and vmax is not None:
norm_option = mcolors.Normalize(vmax=vmax) if norm == '' else norm_option
plt.hexbin(H.flatten(), alpha.flatten(), gridsize=gridsize, cmap=cmap,mincnt=1,norm=norm_option)
if zone_lines:
plt.axvline(x=0.5,color=zone_line_color,linestyle="--",linewidth=0.5,zorder=1)
plt.axvline(x=0.9,color=zone_line_color,linestyle="--",linewidth=0.5,zorder=1)
ax.hlines(y=42.5, xmin=0, xmax=0.5, linewidth=0.5, color=zone_line_color,linestyle="--",zorder=1)
ax.hlines(y=47.5, xmin=0, xmax=0.5, linewidth=0.5, color=zone_line_color,linestyle="--",zorder=1)
ax.hlines(y=40, xmin=0.5, xmax=1, linewidth=0.5, color=zone_line_color,linestyle="--",zorder=1)
ax.hlines(y=50, xmin=0.5, xmax=0.9, linewidth=0.5, color=zone_line_color,linestyle="--",zorder=1)
ax.hlines(y=60, xmin=0.9, xmax=1, linewidth=0.5, color=zone_line_color,linestyle="--",zorder=1)
plt.plot(c1l[:,0],c1l[:,1],'k-',linewidth=0.3)
# plt.plot(c21l[:,0],c21l[:,1],'k-',linewidth=0.3)
plt.plot(c22l[:,0],c22l[:,1],'k-',linewidth=0.3)
clr = 'r'
fss = 4
if zone_ids:
ax.text(0.95, 0.70, '1', transform=ax.transAxes, fontsize = fs-fss, color=clr)
ax.text(0.95, 0.58, '2', transform=ax.transAxes, fontsize = fs-fss, color=clr)
ax.text(0.95, 0.28, '3', transform=ax.transAxes, fontsize = fs-fss, color=clr)
ax.text(0.70, 0.70, '4', transform=ax.transAxes, fontsize = fs-fss, color=clr)
ax.text(0.70, 0.48, '5', transform=ax.transAxes, fontsize = fs-fss, color=clr)
ax.text(0.70, 0.30, '6', transform=ax.transAxes, fontsize = fs-fss, color=clr)
ax.text(0.20, 0.70, '7', transform=ax.transAxes, fontsize = fs-fss, color=clr)
ax.text(0.20, 0.48, '8', transform=ax.transAxes, fontsize = fs-fss, color=clr)
ax.text(0.20, 0.30, '9', transform=ax.transAxes, fontsize = fs-fss, color=clr)
if grey_region:
xs,ys = c1l[:,0],c1l[:,1]
ax.fill_between(xs, ys, interpolate=True, color='#dbdbdb',zorder=0)
xs,ys = c22l[:,0],c22l[:,1]
ax.fill_between(xs, ys, 90, interpolate=True, color='#dbdbdb',zorder=0)
plt.xlabel('Entropy, H')
plt.ylabel("Alpha (°)")
plt.xlim([0,1])
plt.ylim([0,90])
plt.yticks(np.arange(0,100,10),np.arange(0,100,10))
ax.tick_params(axis='both', which='both', direction='in',
top=True, bottom=True, left=True, right=True)
ax.minorticks_on()
ax.tick_params(axis='both', which='both', direction='in',
top=True, bottom=True, left=True, right=True,
length=4, width=0.5)
ax.tick_params(axis='both', which='minor', length=2, width=0.2)
for spine in ax.spines.values():
spine.set_linewidth(0.5)
if cbar:
c_bar = plt.colorbar()
c_bar.ax.tick_params(labelsize=fs-fss)
c_bar.set_label(label='#samples',fontsize=fs-fss)
plt.tight_layout()
if ppath is not None:
if os.path.isdir(ppath):
ppath = os.path.join(ppath, 'halpha_plot_fp.png')
plt.savefig(ppath,dpi=300,bbox_inches='tight')