diff --git a/colour/colorimetry/spectrum.py b/colour/colorimetry/spectrum.py index 04e4b7bcc..4a3864130 100644 --- a/colour/colorimetry/spectrum.py +++ b/colour/colorimetry/spectrum.py @@ -903,6 +903,9 @@ def interpolate( Interpolator class type to use as interpolating function. interpolator_kwargs Arguments to use when instantiating the interpolating function. + interpolation_method + Interpolation method, ``Continuous`` uses the underlying continuous + signal and supports fractional steps. Returns ------- @@ -1177,17 +1180,10 @@ def interpolate( ] ) - # Defining proper interpolation bounds. - # TODO: Provide support for fractional interval like 0.1, etc... - if np.around(shape_start) != shape_start or np.around(shape_end) != shape_end: - runtime_warning("Fractional bound encountered, rounding will occur!") - - shape.start = max([shape.start, np.ceil(shape_start)]) - shape.end = min([shape.end, np.floor(shape_end)]) + shape.start = max([shape.start, shape_start]) + shape.end = min([shape.end, shape_end]) if interpolator is None: - # User has specifically chosen the interpolator thus it is used - # instead of those from *CIE 167:2005* recommendation. if self.interpolator not in ( SpragueInterpolator, CubicSplineInterpolator, @@ -1199,8 +1195,6 @@ def interpolate( interpolator = CubicSplineInterpolator if interpolator_kwargs is None: - # User has specifically chosen the interpolator thus its keyword - # arguments are used. if self.interpolator not in ( SpragueInterpolator, CubicSplineInterpolator, @@ -1209,12 +1203,19 @@ def interpolate( else: interpolator_kwargs = {} - wavelengths, values = self.wavelengths, self.values + self_interpolator, self.interpolator = self.interpolator, interpolator + self_interpolator_kwargs, self.interpolator_kwargs = ( + self.interpolator_kwargs, + interpolator_kwargs, + ) + + values = self[shape.wavelengths] self.domain = shape.wavelengths - self.range = interpolator(wavelengths, values, **interpolator_kwargs)( - self.domain - ) + self.values = values + + self.interpolator = self_interpolator + self.interpolator_kwargs = self_interpolator_kwargs return self diff --git a/colour/colorimetry/tests/test_spectrum.py b/colour/colorimetry/tests/test_spectrum.py index c72a1ad1f..bdf2a7316 100644 --- a/colour/colorimetry/tests/test_spectrum.py +++ b/colour/colorimetry/tests/test_spectrum.py @@ -615,422 +615,422 @@ 0.000000000000000, 0.000000000000000, ) - DATA_SAMPLE_INTERPOLATED_NON_UNIFORM: tuple = ( - 16.329808636577400, - 16.722487609243078, - 17.780769796558388, - 19.388440919210822, - 21.429286697887836, - 23.787092853276910, - 26.345645106065515, - 28.988729176941121, - 31.600130786591194, - 34.063635655703216, - 36.263029504964656, - 38.082098055062993, - 39.404627026685688, - 40.114402140520198, - 40.111247588026082, - 39.925103635141149, - 39.890167058876870, - 39.799323872976096, - 39.680556569501256, - 39.561845869769570, - 39.471172495098209, - 39.436517166804364, - 39.485860606205222, - 39.647183534617994, - 39.948466673359860, - 40.374181475729280, - 40.480943048717741, - 39.587763146544347, - 37.399010971904012, - 34.259517350145224, - 30.574008069142096, - 26.747208916768866, - 23.183845680899680, - 20.288644149408725, - 18.466330110170176, - 18.131455040802454, - 19.618408431271092, - 22.601624593221480, - 26.621530082560952, - 31.218551455196845, - 35.933115267036499, - 40.312773209586069, - 44.121677838324345, - 47.374686358105983, - 50.100647613008405, - 52.328410447109043, - 54.086823704485290, - 55.404736229214613, - 56.310996865374428, - 56.834454457042114, - 57.003957848295137, - 56.848355883210893, - 56.396497405866839, - 55.677231260340363, - 54.719406290708918, - 53.551871341049903, - 52.203475255440743, - 50.703066877958868, - 49.079495052681693, - 47.361608623686649, - 45.578256435051173, - 43.758287330852653, - 41.930550155168532, - 40.123893752076235, - 38.367166965653183, - 36.689218639976801, - 35.118897619124496, - 33.685052747173714, - 32.416532868201863, - 31.342186826286373, - 30.490863465504646, - 29.891411629934137, - 29.572680163652254, - 29.538621481156376, - 33.594913456316092, - 41.048330705400552, - 45.551744552213606, - 47.142069193311166, - 46.264235269850914, - 43.363173422990592, - 38.883814293887831, - 33.271088523700378, - 26.969926753585888, - 20.425259624702068, - 14.082017778206605, - 8.385131855257200, - 3.728429425651282, - 0.156961054721180, - -2.429909888236355, - -4.133307786198728, - -5.054357022143353, - -5.294181979047651, - -4.953907039889023, - -4.134656587644884, - -2.937555005292646, - -1.463726675809728, - 0.185704017826468, - 1.909612692638526, - 3.606874965649032, - 5.176366453880572, - 6.516962774355742, - 7.527539544097118, - 8.122379803803623, - 8.331483144611147, - 8.237444938631239, - 7.923124732066758, - 7.471382071120567, - 6.965076501995521, - 6.487067570894484, - 6.120214824020312, - 5.947377807575871, - 6.051416067764015, - 6.515189150787608, - 7.421556602849507, - 8.833103319101975, - 10.654113909347958, - 12.714472051171430, - 14.843629856075644, - 16.871039435563851, - 18.626152901139314, - 19.938422364305275, - 20.637299936564997, - 20.706835013628812, - 20.713132276905259, - 20.620587314150111, - 20.396819412610807, - 20.054405097058748, - 19.605938071902443, - 19.064012041550384, - 18.441220710411045, - 17.750157782892924, - 17.003416963404511, - 16.213591956354293, - 15.393276466150766, - 14.555064197202412, - 13.711548853917725, - 12.875324140705192, - 12.058983761973309, - 11.275121422130562, - 10.536330825585436, - 9.855205676746426, - 9.244339680022023, - 8.716326539820709, - 8.283759960550988, - 7.959233646621334, - 7.755341302440248, - 7.684676632416213, - 7.756084346822568, - 7.961801724157814, - 8.289468950531905, - 8.726726048591537, - 9.261213040983417, - 9.880569950354237, - 10.572436799350699, - 11.324453610619505, - 12.124260406807357, - 12.959497210560945, - 13.817804044526978, - 14.686820931352152, - 15.554187893683173, - 16.407544954166731, - 17.234532135449530, - 18.022789460178267, - 18.759956950999651, - 19.433674630560375, - 20.031582521507140, - 20.541320646486646, - 20.950529028145592, - 21.246847689130675, - 21.417916652088600, - 21.451375939666065, - 21.334865574509770, - 21.056025579266414, - 20.604750276779001, - 20.494345115463702, - 22.221705466331883, - 25.661450384670388, - 29.775598875658655, - 33.531925166546948, - 36.383260993760757, - 38.399428506854193, - 39.690190939354423, - 40.365311524788659, - 40.534553496684069, - 40.307680088567857, - 39.794454533967205, - 39.104640066409281, - 38.347999919421312, - 37.634297326530451, - 37.374685121273394, - 39.119690201154867, - 40.253206513156250, - 38.299118522290833, - 34.130306343480264, - 28.883500017392159, - 23.695429584694160, - 19.702825086053920, - 18.042370406596557, - 17.942146149526579, - 17.437952042997388, - 16.603615436175311, - 15.527509997088327, - 14.298009393764401, - 13.003487294231499, - 11.732317366517600, - 10.572873278650665, - 9.613528698658669, - 8.942657294569587, - 8.648632734411382, - 8.638275005914387, - 8.608461770725761, - 8.468358277399256, - 8.236485894689265, - 7.918459394063972, - 7.519893546991550, - 7.046403124940173, - 6.503602899378026, - 5.897107641773280, - 5.232532123594114, - 4.515491116308703, - 3.751599391385226, - 2.946471720291860, - 2.105722874496783, - 1.234967625468170, - 0.339820744674198, - -0.574102996416954, - -1.501188826337108, - -2.435821973618090, - -3.372387666791723, - -4.305271134389827, - -5.228857604944231, - -6.137532306986749, - -7.025680469049206, - -7.887687319663434, - -8.717938087361247, - -9.510818000674471, - -10.260712288134929, - -10.962006178274445, - -11.609084899624833, - -12.196333680717927, - -12.718137750085543, - -13.168882336259514, - -13.542952667771653, - -13.834733973153785, - -14.038611480937735, - -14.148970419655322, - -14.160196017838375, - -14.066673504018716, - -13.862788106728164, - -13.542925054498539, - -13.101469575861673, - -12.532806899349385, - -11.831322253493493, - -10.991400866825831, - -10.007427967878208, - -8.873788785182459, - -7.584868547270405, - -6.135052482673858, - -4.518725819924658, - -2.730273787554616, - -0.764081614095559, - 1.385465471920696, - 3.723982241962316, - 6.257083467497486, - 8.990383919994379, - 11.929498370921175, - 14.976162260830137, - 5.084237255461949, - -6.729230790271000, - -14.622433089729542, - -19.038838171389944, - -20.421914563728482, - -19.215130795221405, - -15.861955394344996, - -10.805856889575507, - -4.490303809389212, - 2.641235317737622, - 10.145291963328749, - 17.578397598907866, - 24.497083695998736, - 30.457881726125084, - 35.017323160810655, - 37.731939471579153, - 38.169944675202451, - 36.103648065327157, - 31.478944095141092, - 24.247257545409393, - 14.377470469911161, - 2.089605892978410, - -12.208009328653077, - -28.102486071018522, - -45.180935210153116, - -63.030467622092019, - -81.238194182870473, - -99.391225768523640, - -117.076673255086732, - -133.881647518594917, - -149.393259435083451, - -163.198619880587444, - -174.884839731142108, - -184.039029862782684, - -190.248301151544382, - -193.099764473462415, - -192.180530704571822, - -187.077710720907902, - -177.378415398505837, - -162.669755613400923, - -142.538842241628146, - -116.572786159222886, - -84.358698242220214, - -45.483689366655454, - 0.465129591436323, - 53.867241377821607, - 111.906385750398641, - 165.969680931356891, - 206.832112792864763, - 225.268667207090687, - 212.054330046203120, - 157.964087182370434, - 53.772924487761195, - 24.128558965593012, - 155.948189345952358, - 238.667542187567193, - 279.823268952005947, - 286.952021100836475, - 267.590450095627091, - 229.275207397946076, - 179.542944469361430, - 125.930312771441450, - 75.973963765754249, - 37.210548913868003, - 17.176719677350921, - 17.152394375030820, - 19.379794324130732, - 21.517434431022508, - 23.565545988087592, - 25.524360287707406, - 27.394108622263396, - 29.175022284136993, - 30.867332565709628, - 32.471270759362753, - 33.987068157477793, - 35.414956052436175, - 36.755165736619354, - 38.007928502408760, - 39.173475642185821, - 40.252038448331973, - 41.243848213228674, - 42.149136229257330, - 42.968133788799399, - 43.701072184236310, - 44.348182707949491, - 44.909696652320392, - 45.385845309730442, - 45.776859972561077, - 46.082971933193733, - 46.304412484009845, - 46.441412917390849, - 46.494204525718175, - 46.463018601373285, - 46.348086436737596, - 46.149639324192542, - 45.867908556119552, - 45.503125424900077, - 45.055521222915552, - 44.525327242547419, - 43.912774776177095, - 43.218095116186007, - 42.441519554955640, - 41.583279384867382, - 40.643991169034841, - 39.627797988936805, - 38.540734852902020, - 37.388854826093969, - 36.178210973676094, - 34.914856360811882, - 33.604844052664760, - 32.254227114398248, - 30.869058611175774, - 29.455391608160820, - 28.019279170516839, - 26.566774363407301, - 25.103930251995678, - 23.636799901445418, - 22.171436376920010, - 20.713892743582907, - 19.270222066597562, - 17.846477411127466, - 16.448711842336071, - 15.082978425386836, - 13.755330225443233, - 12.471820307668732, - 11.238501737226787, - 10.061427579280879, - 8.946650898994456, - 7.900224761530997, - 6.928202232053956, - 6.036636375726809, - 5.231580257713018, - 4.519086943176044, - 3.905209497279358, - 3.396000985186418, - 2.997514472060695, - 2.715803023065654, - 2.556919703364760, - 2.526917578121476, - 2.631849712499274, - 2.877769171661610, - 3.270729020771954, - 3.816782324993773, - 4.521982149490528, - 5.392381559425689, - 6.434033619962720, - 7.652991396265083, + 16.33174000, + 16.64993716, + 17.64548368, + 19.20219560, + 21.20388894, + 23.53437976, + 26.07748407, + 28.71701792, + 31.33679734, + 33.82063837, + 36.05235704, + 37.91576938, + 39.29469143, + 40.07293922, + 40.14077612, + 39.92419302, + 39.89684762, + 39.81049683, + 39.69333189, + 39.57332622, + 39.47845324, + 39.43668638, + 39.47599905, + 39.62436468, + 39.90975669, + 40.33304002, + 40.50491197, + 39.74501724, + 37.67902112, + 34.62018880, + 30.97314049, + 27.14249640, + 23.53287675, + 20.54890177, + 18.59519166, + 18.08081760, + 19.38373812, + 22.23096797, + 26.16305357, + 30.72054135, + 35.44397775, + 39.87706471, + 43.74602436, + 47.05613715, + 49.83624442, + 52.11518748, + 53.92180764, + 55.28494623, + 56.23344457, + 56.79614397, + 57.00188576, + 56.87951125, + 56.45786176, + 55.76577861, + 54.83210312, + 53.68567662, + 52.35534040, + 50.86993581, + 49.25830415, + 47.54928674, + 45.77172491, + 43.95445997, + 42.12633325, + 40.31618605, + 38.55285970, + 36.86519552, + 35.28203483, + 33.83221894, + 32.54458918, + 31.44798686, + 30.57125331, + 29.94322984, + 29.59275777, + 29.54381964, + 32.79286157, + 40.36558235, + 45.21160576, + 47.09673165, + 46.46577457, + 43.76354913, + 39.43486990, + 33.92455146, + 27.67740839, + 21.13825529, + 14.75190672, + 8.96317728, + 4.18354245, + 0.49841631, + -2.19120584, + -3.98642200, + -4.98833019, + -5.29802840, + -5.01661465, + -4.24518693, + -3.08484325, + -1.63668162, + -0.00180003, + 1.71870349, + 3.42373096, + 5.01218436, + 6.38296569, + 7.43497695, + 8.07693863, + 8.32474693, + 8.26027419, + 7.96635835, + 7.52583734, + 7.02154908, + 6.53633153, + 6.15302259, + 5.95446022, + 6.02348233, + 6.44292687, + 7.29563177, + 8.65167043, + 10.43511482, + 12.47696318, + 14.60671211, + 16.65385820, + 18.44789806, + 19.81832829, + 20.59464547, + 20.70989576, + 20.71490257, + 20.63782267, + 20.42824992, + 20.09863019, + 19.66155390, + 19.12961147, + 18.51539332, + 17.83148987, + 17.09049153, + 16.30498873, + 15.48757188, + 14.65083142, + 13.80735774, + 12.96974128, + 12.15057246, + 11.36244169, + 10.61793939, + 9.92965598, + 9.31018188, + 8.77210752, + 8.32802330, + 7.99051965, + 7.77218699, + 7.68561574, + 7.74083122, + 7.93173795, + 8.24599287, + 8.67123920, + 9.19512022, + 9.80527915, + 10.48935925, + 11.23500376, + 12.02985593, + 12.86155901, + 13.71775624, + 14.58609087, + 15.45420615, + 16.30974532, + 17.14035164, + 17.93366833, + 18.67733867, + 19.35900588, + 19.96631322, + 20.48690393, + 20.90842126, + 21.21850846, + 21.40480878, + 21.45496545, + 21.35662174, + 21.09742087, + 20.66514352, + 20.43751858, + 21.91097080, + 25.20288294, + 29.29167835, + 33.13704964, + 36.09348577, + 38.20199674, + 39.57231714, + 40.31418157, + 40.53732465, + 40.35148096, + 39.86638512, + 39.19177172, + 38.43737537, + 37.71293067, + 37.32215353, + 38.85348208, + 40.28480326, + 38.66906876, + 34.70409378, + 29.52631184, + 24.27215647, + 20.07806121, + 18.08045957, + 17.97606450, + 17.51718098, + 16.71767084, + 15.66588470, + 14.45017318, + 13.15888689, + 11.88037645, + 10.70299247, + 9.71508557, + 9.00500637, + 8.66110548, + 8.63646961, + 8.61886171, + 8.49018794, + 8.26908563, + 7.96116808, + 7.57204861, + 7.10734052, + 6.57265713, + 5.97361172, + 5.31581763, + 4.60488814, + 3.84643656, + 3.04607621, + 2.20942040, + 1.34208241, + 0.44967558, + -0.46218681, + -1.38789144, + -2.32182500, + -3.25837419, + -4.19192570, + -5.11686623, + -6.02758247, + -6.91846110, + -7.78388883, + -8.61825235, + -9.41593835, + -10.17133352, + -10.87882456, + -11.53279815, + -12.12764100, + -12.65773980, + -13.11748123, + -13.50125200, + -13.80343879, + -14.01842830, + -14.14060723, + -14.16436225, + -14.08408008, + -13.89414739, + -13.58895089, + -13.16287727, + -12.61031321, + -11.92564542, + -11.10326059, + -10.13754541, + -9.02288657, + -7.75367076, + -6.32428468, + -4.72911503, + -2.96254849, + -1.01897176, + 1.10722847, + 3.42166550, + 5.92995265, + 8.63770321, + 11.55053050, + 14.66926935, + 6.86179709, + -5.47290466, + -13.83246355, + -18.66023243, + -20.39956416, + -19.49381157, + -16.38632753, + -11.52046487, + -5.33957647, + 1.71298484, + 9.19386620, + 16.65971477, + 23.66717768, + 29.77290209, + 34.53353516, + 37.50572402, + 38.25154792, + 36.50596565, + 32.20857414, + 25.31081084, + 15.77278173, + 3.77074445, + -10.29313973, + -26.00608936, + -42.95532304, + -60.72805933, + -78.91151682, + -97.09291408, + -114.85946968, + -131.79840221, + -147.49693024, + -161.54227235, + -173.52164712, + -183.02227312, + -189.63136892, + -192.93615311, + -192.52384426, + -187.98166096, + -178.89682177, + -164.85654527, + -145.44805004, + -120.25855466, + -88.87527770, + -50.88543775, + -5.87625337, + 46.56007116, + 104.43504592, + 159.52668786, + 202.61238918, + 224.46954207, + 215.87553872, + 167.60777130, + 70.44363202, + 5.46110638, + 141.75857149, + 230.42498382, + 276.55540391, + 287.68451731, + 271.34700958, + 235.07756626, + 186.41087289, + 132.88161504, + 82.02447824, + 41.37414805, + 18.46531002, + 16.85424129, + 19.09321438, + 21.24241296, + 23.30206825, + 25.27241149, + 27.15367391, + 28.94608674, + 30.64988121, + 32.26528857, + 33.79254002, + 35.23186682, + 36.58350019, + 37.84767137, + 39.02461158, + 40.11455206, + 41.11772404, + 42.03435875, + 42.86468742, + 43.60894129, + 44.26735159, + 44.84014956, + 45.32756641, + 45.72983339, + 46.04718172, + 46.27984264, + 46.42804739, + 46.49202718, + 46.47201326, + 46.36823686, + 46.18092921, + 45.91032154, + 45.55664508, + 45.12013106, + 44.60101073, + 43.99951530, + 43.31587601, + 42.55032410, + 41.70309079, + 40.77461777, + 39.76848476, + 38.69068156, + 37.54725968, + 36.34427059, + 35.08776577, + 33.78379673, + 32.43841493, + 31.05767187, + 29.64761904, + 28.21430791, + 26.76378998, + 25.30211674, + 23.83533966, + 22.36951024, + 20.91067996, + 19.46490031, + 18.03822277, + 16.63669883, + 15.26637998, + 13.93331770, + 12.64356348, + 11.40316880, + 10.21818516, + 9.09466403, + 8.03865691, + 7.05621528, + 6.15339062, + 5.33623443, + 4.61079818, + 3.98313337, + 3.45929148, + 3.04532400, + 2.74728241, + 2.57121821, + 2.52318286, + 2.60922788, + 2.83540473, + 3.20776490, + 3.73235989, + 4.41524117, + 5.26246024, + 6.28006857, + 7.47411766, + 8.85065900, ) DATA_SAMPLE_NORMALISED: tuple = ( @@ -1549,15 +1549,19 @@ def test_interpolate(self) -> None: self._non_uniform_sd.shape.end, 1, ) - sd = reshape_sd(self._non_uniform_sd, shape, "Interpolate") + sd = reshape_sd( + self._non_uniform_sd, + shape, + "Interpolate", + ) np.testing.assert_allclose( sd.values, DATA_SAMPLE_INTERPOLATED_NON_UNIFORM, atol=TOLERANCE_ABSOLUTE_TESTS, ) assert sd.shape == SpectralShape( - np.ceil(self._non_uniform_sd.shape.start), - np.floor(self._non_uniform_sd.shape.end), + self._non_uniform_sd.shape.start, + self._non_uniform_sd.shape.end, 1, ) @@ -1833,8 +1837,8 @@ def test_interpolate(self) -> None: atol=TOLERANCE_ABSOLUTE_TESTS, ) assert msds.shape == SpectralShape( - np.ceil(self._non_uniform_sample_msds.shape.start), - np.floor(self._non_uniform_sample_msds.shape.end), + self._non_uniform_sample_msds.shape.start, + self._non_uniform_sample_msds.shape.end, 1, )