Skip to content

Very first write_image take about ~6s #20

Description

@akhileshraju

I have used orca for the image export in the past. I wanted a pip friendly solution and orca being an executable made me go away from plotly.

That being said, thank you for Kaleido! It's great to see the direction plotly is going in with the static image export 😃
I am very excited to start using plotly again along with kaleido!

I am trying this simple script to create a contour plot and export it to SVG. Here is my python script

import csv
import time
from math import log
from pathlib import Path

import plotly.graph_objs as go


class EyeScanPlotter:
    @staticmethod
    def contour_filled_to_svg(x, y, scan_data):

        x_axis_options = dict(
            zeroline=False, nticks=len(x), tickmode="auto", title="UI", mirror=True
        )
        y_axis_options = dict(zeroline=False, title="Voltage (Codes)", mirror=True)
        layout = go.Layout(xaxis=x_axis_options, yaxis=y_axis_options)
        fig = go.Figure(layout=layout)
        fig.add_contour(
            x=x,
            y=y,
            z=scan_data,
            contours=dict(showlines=False),
            colorscale="Jet",
            showscale=False,
        )
        start = time.perf_counter()
        fig.write_image("contour_filled.jpg")
        print(f"Total (Filled) - {time.perf_counter() - start}")

    @staticmethod
    def contour_lines_to_svg(x, y, scan_data):

        x_axis_options = dict(
            zeroline=False, nticks=len(x), tickmode="auto", title="UI", mirror=True
        )
        y_axis_options = dict(zeroline=False, title="Voltage (Codes)", mirror=True)
        layout = go.Layout(xaxis=x_axis_options, yaxis=y_axis_options)
        fig = go.Figure(layout=layout)
        fig.add_contour(
            x=x,
            y=y,
            z=scan_data,
            contours=dict(coloring="lines"),
            colorscale="Jet",
            line=dict(width=1.5),
            showscale=False,
        )
        start = time.perf_counter()
        fig.write_image( "contour_lines.jpg")

        print(f"Total (Lines) - {time.perf_counter() - start}")

    @staticmethod
    def bathtub_to_svg(self):
        pass


class EyeScanImporter:
    @staticmethod
    def load_from_csv(file_path: Path = None):
        if file_path is None:
            file_path = Path( "vivado_eye_scan.csv")

        def normalize_codes_to_ui(data, min_range, max_range):
            min_element, max_element = min(data), max(data)
            for index, value in enumerate(data):
                data[index] = min_range + (
                    ((value - min_element) * (max_range - min_range)) / (max_element - min_element)
                )

        x_axis, y_axis, scan_data = list(), list(), list()
        with file_path.open("r") as csv_file:
            csv_file_contents = csv.reader(csv_file)
            for row in csv_file_contents:
                if row[0] == "Horizontal Range":
                    split = row[1].split()
                    min_value_range, max_value_range = (float(split[0]), float(split[-2]))
                elif row[0] == "Scan Start":
                    for index, row in enumerate(csv_file_contents):
                        if row[0] == "Scan End":
                            break
                        if not x_axis:
                            x_axis = [float(value) for value in row[1:]]
                            normalize_codes_to_ui(x_axis, min_value_range, max_value_range)
                            continue
                        y_axis.append(float(row[0]))
                        scan_data.append([log(float(value)) for value in row[1:]])

        return x_axis, y_axis, scan_data


start = time.perf_counter()
x, y, scan_data = EyeScanImporter.load_from_csv()
print(f"CSV import - {time.perf_counter() - start}")
EyeScanPlotter.contour_lines_to_svg(x, y, scan_data)
EyeScanPlotter.contour_filled_to_svg(x, y, scan_data)

And here is the vivado_eye_scan.csv file

SW Version,2020.2.0
Date and Time Started,2020-07-24 17:40:23.100515
Date and Time Ended,2020-07-24 17:40:28.798345
Scan Name,Scan 0
Link Settings,
Reset RX After Applying Settings,false
Open Area,6736
Horizontal Opening,41
Horizontal Percentage,64.71
Vertical Opening,153
Vertical Percentage,61.90
Dwell,BER
Dwell BER,1e-5
Dwell Time,0
Horizontal Increment,4
Horizontal Range,-0.500 UI to 0.500 UI
Vertical Increment,4
Vertical Range,100%
Misc Info,ELF Version: 0xB003; Test ID: 5; #Data Points Expected 2142; #Data Points Read: 2142
Scan Start
2d statistical,-32,-28,-24,-20,-16,-12,-8,-4,0,4,8,12,16,20,24,28,32
124,0.249473,0.251092,0.251238,0.249716,0.249492,0.204078,0.139146,0.246524,0.261761,0.322665,0.339818,0.327185,0.293448,0.278322,0.260399,0.254514,0.256382
120,0.249387,0.250656,0.250614,0.249697,0.248727,0.186067,0.126413,0.228278,0.251338,0.288854,0.311276,0.298251,0.270647,0.261925,0.252965,0.250939,0.251767
116,0.250059,0.249758,0.250979,0.249935,0.243054,0.164577,0.115403,0.184953,0.247214,0.260695,0.277636,0.274532,0.259059,0.252755,0.25015,0.250027,0.250872
112,0.249448,0.249874,0.2486,0.250302,0.23605,0.149881,0.101098,0.12547,0.235351,0.245627,0.257632,0.256579,0.251711,0.250216,0.249359,0.250334,0.248993
108,0.250241,0.250057,0.250179,0.249752,0.227502,0.135162,0.0833855,0.0720889,0.205272,0.229072,0.246951,0.250376,0.249627,0.249798,0.250226,0.250947,0.249997
104,0.249084,0.250179,0.250118,0.249266,0.212005,0.124481,0.0591522,0.0313669,0.157891,0.201207,0.23104,0.24342,0.248729,0.249691,0.250624,0.249651,0.250519
100,0.250241,0.249448,0.249387,0.247938,0.195268,0.112119,0.0379971,0.0118997,0.0956762,0.167234,0.204463,0.228818,0.242593,0.247956,0.249132,0.24983,0.2507
96,0.250118,0.249509,0.250057,0.244855,0.173175,0.0971522,0.0184369,0.00367909,0.0447686,0.137644,0.172148,0.206434,0.227904,0.24494,0.249433,0.249784,0.249938
92,0.251038,0.249448,0.249387,0.237363,0.154447,0.0755206,0.00775492,0.000654946,0.0133164,0.115633,0.143058,0.176668,0.207935,0.23553,0.248298,0.249346,0.249648
88,0.249813,0.249752,0.24957,0.227502,0.135735,0.0560075,0.0030797,0.00010729,0.00158694,0.0846688,0.129935,0.150803,0.176446,0.22315,0.244229,0.24959,0.249693
84,0.249387,0.250057,0.249813,0.213064,0.114784,0.036327,0.000842107,8.82162e-06,0.00016928,0.0402983,0.121498,0.133593,0.157444,0.200678,0.235875,0.249045,0.250655
80,0.249509,0.249327,0.250179,0.193643,0.0934378,0.0200099,0.000165942,1.19211e-06,6.4374e-06,0.0168303,0.107359,0.126269,0.13811,0.175631,0.225787,0.246234,0.250271
76,0.249752,0.249996,0.247519,0.170607,0.0728348,0.0106787,2.88491e-05,4.76844e-07,4.76844e-07,0.00453312,0.0768516,0.121151,0.128024,0.154043,0.214393,0.242202,0.248352
72,0.249631,0.249813,0.24398,0.146075,0.0539479,0.00491889,5.00687e-06,4.76844e-07,4.76844e-07,0.000358349,0.042491,0.108309,0.123055,0.140511,0.193867,0.23515,0.248459
68,0.250241,0.250241,0.238524,0.120144,0.0365774,0.00167802,4.76844e-07,4.76844e-07,4.76844e-07,4.1247e-05,0.0173448,0.0858629,0.114865,0.130828,0.175644,0.227269,0.24528
64,0.250057,0.249631,0.22735,0.0985928,0.0234193,0.000557431,4.76844e-07,4.76844e-07,4.76844e-07,9.53689e-07,0.00429255,0.0541278,0.102096,0.124835,0.159116,0.216668,0.242995
60,0.250608,0.249631,0.212621,0.0753872,0.0131263,0.000144245,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,0.00055457,0.0282744,0.0778944,0.117397,0.143856,0.20147,0.23801
56,0.249023,0.248902,0.195604,0.0548965,0.00635896,3.12333e-05,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,6.67582e-05,0.00928941,0.0500334,0.107918,0.134569,0.184603,0.231525
52,0.249387,0.248661,0.172446,0.0373295,0.00287704,5.48371e-06,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,1.90738e-06,0.00236634,0.0252549,0.091962,0.126826,0.171105,0.222873
48,0.250118,0.245148,0.146724,0.0236279,0.00102498,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,0.000453717,0.0101749,0.0689943,0.119052,0.15843,0.212648
44,0.249511,0.239361,0.116045,0.0136463,0.000280623,2.38422e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,1.59743e-05,0.00341707,0.0461962,0.108825,0.148198,0.199182
40,0.25007,0.231514,0.0829473,0.0068606,6.41356e-05,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,7.15267e-07,0.00062252,0.0260981,0.0968063,0.137883,0.187486
36,0.248805,0.216487,0.0604049,0.00313048,9.53689e-06,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,0.000133755,0.0138519,0.0805057,0.127712,0.176797
32,0.249436,0.19692,0.040686,0.00126888,1.66896e-06,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,1.12058e-05,0.00674139,0.0631345,0.118739,0.168735
28,0.248513,0.174534,0.0291128,0.000440366,7.15267e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,0.00251535,0.0459175,0.107583,0.164573
24,0.247641,0.145397,0.0171948,0.000137331,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,0.000608692,0.0333328,0.0973948,0.161158
20,0.246843,0.115902,0.00933042,2.67033e-05,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,0.000132086,0.0204923,0.0842528,0.159984
16,0.247663,0.0877088,0.0036903,5.48371e-06,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,2.09812e-05,0.0109002,0.0730457,0.158233
12,0.248032,0.0617346,0.00185254,9.53689e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,3.57633e-06,0.00565657,0.0639402,0.158722
8,0.249692,0.0408669,0.000704299,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,0.00257401,0.0544218,0.15999
4,0.259533,0.0295954,0.000200036,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,0.00124003,0.0514574,0.165332
0,0.262751,0.0275869,5.9844e-05,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,0.00131037,0.0518531,0.163228
-4,0.266977,0.0327765,0.000153305,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,0.00233225,0.0528805,0.160228
-8,0.266637,0.0479423,0.000563392,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,6.4374e-06,0.00525816,0.0606071,0.156176
-12,0.264498,0.0712491,0.00181415,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,3.2187e-05,0.00942888,0.0714496,0.154754
-16,0.260473,0.10065,0.00471957,1.43053e-06,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,0.000162127,0.0167998,0.0846818,0.154957
-20,0.256829,0.134797,0.00966349,1.74048e-05,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,0.00056816,0.0271847,0.0965687,0.155493
-24,0.254212,0.164994,0.0179826,0.00011492,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,1.43053e-06,0.00184539,0.0413175,0.107249,0.156192
-28,0.251562,0.194273,0.0346292,0.000355964,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,9.53689e-06,0.00451715,0.05614,0.115825,0.156542
-32,0.250059,0.215033,0.0543545,0.0014179,7.15267e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,6.91424e-05,0.00966754,0.0716278,0.12309,0.163802
-36,0.249766,0.230887,0.0790722,0.00375777,1.0729e-05,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,2.38422e-07,0.00038386,0.0208721,0.0869537,0.129898,0.174976
-40,0.250051,0.239921,0.102944,0.00947657,7.36725e-05,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,7.86793e-06,0.00187376,0.0341795,0.102803,0.138827,0.18314
-44,0.249944,0.245973,0.132178,0.0199281,0.000302796,2.38422e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,7.70104e-05,0.00618706,0.0515738,0.115495,0.146207,0.196436
-48,0.250181,0.249023,0.161131,0.0326411,0.0013745,7.15267e-07,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,2.38422e-07,0.000558862,0.0144825,0.07202,0.123027,0.156476,0.207602
-52,0.249935,0.249145,0.184369,0.0487403,0.00381857,5.72213e-06,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,6.4374e-06,0.00260119,0.0299647,0.0928132,0.12827,0.171064,0.215503
-56,0.250363,0.24957,0.207284,0.0701119,0.00909938,4.7446e-05,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,5.50755e-05,0.00825299,0.0529656,0.109095,0.134637,0.184391,0.225158
-60,0.249327,0.249448,0.223529,0.0944548,0.0180584,0.000250582,4.76844e-07,4.76844e-07,4.76844e-07,4.76844e-07,0.000535019,0.023166,0.0782848,0.118906,0.144803,0.198395,0.232958
-64,0.249448,0.250792,0.237088,0.119722,0.0326214,0.000798714,4.76844e-07,4.76844e-07,4.76844e-07,1.19211e-06,0.0029922,0.0456667,0.100747,0.124533,0.155422,0.210439,0.238455
-68,0.249935,0.249631,0.244914,0.146493,0.0518106,0.00251607,9.53689e-07,4.76844e-07,4.76844e-07,3.50481e-05,0.0098919,0.0727478,0.11435,0.129535,0.168222,0.22036,0.244839
-72,0.249509,0.249996,0.24716,0.168613,0.072623,0.00608,5.96056e-06,4.76844e-07,4.76844e-07,0.00037933,0.0275339,0.0955533,0.121525,0.13574,0.182138,0.229222,0.246067
-76,0.250118,0.250057,0.249327,0.191113,0.0931064,0.0138745,4.38697e-05,4.76844e-07,9.53689e-07,0.00250677,0.0617549,0.112127,0.127314,0.148402,0.202842,0.23835,0.248941
-80,0.249145,0.250179,0.249327,0.212093,0.111923,0.0286133,0.000211481,4.76844e-07,3.12333e-05,0.0128643,0.0922203,0.122443,0.133327,0.165461,0.215493,0.242106,0.24921
-84,0.250302,0.249874,0.249874,0.228721,0.130046,0.0462671,0.00105836,1.02522e-05,0.000387675,0.0333714,0.112851,0.128112,0.143817,0.181702,0.229402,0.24691,0.24974
-88,0.249935,0.249509,0.249996,0.240034,0.146012,0.066458,0.00356179,0.000131132,0.00435764,0.0646009,0.123472,0.137177,0.163673,0.204456,0.237611,0.249465,0.249347
-92,0.250977,0.249509,0.251038,0.246922,0.165962,0.088626,0.00872601,0.000971809,0.0170315,0.0968001,0.134228,0.155746,0.186853,0.222157,0.245315,0.249044,0.250012
-96,0.249691,0.249935,0.250118,0.249145,0.184236,0.10497,0.0209996,0.00327497,0.041827,0.126222,0.15401,0.183613,0.210542,0.234069,0.246896,0.250257,0.249724
-100,0.249631,0.250118,0.249631,0.250057,0.203414,0.11688,0.0345859,0.012166,0.0930066,0.155201,0.181992,0.210793,0.230563,0.242874,0.24862,0.248827,0.249951
-104,0.249631,0.249205,0.251038,0.250669,0.220972,0.127679,0.0564801,0.035117,0.155326,0.189547,0.212769,0.232576,0.241412,0.248702,0.250241,0.250442,0.250272
-108,0.249874,0.250118,0.250118,0.249448,0.237198,0.13862,0.0821458,0.0653588,0.199606,0.218715,0.237146,0.243503,0.247423,0.249255,0.249539,0.249389,0.250256
-112,0.249813,0.249935,0.249631,0.250118,0.244271,0.152788,0.104832,0.118077,0.231317,0.241017,0.246779,0.249419,0.250092,0.24986,0.250517,0.249661,0.250424
-116,0.250365,0.250185,0.249818,0.250424,0.24848,0.173342,0.117175,0.179339,0.244031,0.25074,0.25491,0.255072,0.252173,0.2524,0.251316,0.249921,0.250165
-120,0.249904,0.249777,0.250373,0.24916,0.249639,0.191707,0.127953,0.217537,0.250548,0.261277,0.268983,0.266911,0.265783,0.255141,0.250745,0.250793,0.251718
-124,0.250856,0.250777,0.250801,0.250412,0.250018,0.216644,0.1445,0.241871,0.260579,0.28161,0.302404,0.291086,0.283302,0.267908,0.256006,0.252526,0.2532
Scan End

For some reason the very first write_image, irrespective of the file format, take 6-9s. Subsequent exports are fast!

Would there be any reason why this is the case?

Full disclosure - I had similar issue with orca, but that turned out to be because of the firewall and virus scan SW thats installed on my work laptop - plotly/orca#231

Since Kaleido doesn't use ports, I was wondering if this slowdown is expected?

I plan to try this on my personal system and something makes me feel its going to be the firewall/virus scan again 😞
I still wanted to reach out and get your take on this

Update
I tried it on my personal Mac, in a fresh venv with only plotly and kaleido and it still takes around ~3s for the first write.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions