Coder Social home page Coder Social logo

svg2data's People

Contributors

alekssmolkovic avatar davidmstraub avatar peterstangl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

svg2data's Issues

Cannot find grid on the plot I'm trying to read

Hi,

I'm trying to extract data from this PDF containing several hundred plots. https://fortress.wa.gov/ecy/publications/documents/0803037appc.pdf

For example, I'm starting with the second plot on page 14 for Alki East Chlorophyll-a. If all I do is save this page as an SVG using Inkscape 1.0, I get this:

svg2data/svg2data.py in get_axes(lines, width, height)
    730                 cleaned_axes[i].append(axes[i][j])
    731     axes = cleaned_axes
--> 732     axes_min = np.array([axes[0][0]['min'][0],axes[1][0]['min'][1]])
    733     axes_max = np.array([axes[0][0]['max'][0],axes[1][0]['max'][1]])
    734     new_lines = []

IndexError: list index out of range

Next I tried to make the job easier by deleting everything from the page except the plot I want. Same error.
Next, I used Inkscape to Resize Page to Selection (the resulting SVG is attached with the extension changed to please github)
[0803037appc_p14.txt](https://github.com/peterstangl/svg2data/files/5046091/0803037appc_p14.txt
This produces:

svg2data/svg2data.py in __init__(self, filename, test, debug)
    104         and debug != 'get_axes'
    105         and debug != 'connect_graphs'):
--> 106             grids = calibrate_grid(axes,phrases,width,height)
    107         elif debug == 'calibrate_grid':
    108             self.debug = {'axes':axes,

svg2data/svg2data.py in calibrate_grid(axes, phrases, width, height)
   1033                         axis_scaling = 'linear'
   1034                 else:
-> 1035                     raise Exception('no grid found!')
   1036                 grids_calibr[axis_type]['type']=axis_scaling
   1037                 grids_calibr[axis_type]['grid']=grid_calibr

Exception: no grid found!

Any ideas why it can't find the plot? Is a grid required?

SyntaxError: invalid syntax. Perhaps you forgot a comma?

Could this be due to the version of Python I am running?

data = svg2data("test.svg")


Traceback (most recent call last):

File ~\AppData\Roaming\Python\Python311\site-packages\IPython\core\interactiveshell.py:3505 in run_code
exec(code_obj, self.user_global_ns, self.user_ns)

Cell In[6], line 1
data = svg2data("test.svg")

File D:\Users\Nick\Documents\Python\svg2data.py:49 in init
child = pass_transformation(child)

File D:\Users\Nick\Documents\Python\svg2data.py:233 in pass_transformation
child = pass_transformation(child)

File D:\Users\Nick\Documents\Python\svg2data.py:213 in pass_transformation
parent_matrix = transform2matrix(parent_transform)

File D:\Users\Nick\Documents\Python\svg2data.py:169 in transform2matrix
matrix = ast.literal_eval(matrix_string)

File C:\Program Files\Python311\Lib\ast.py:64 in literal_eval
node_or_string = parse(node_or_string.lstrip(" \t"), mode='eval')

File C:\Program Files\Python311\Lib\ast.py:50 in parse
return compile(source, filename, mode, flags,

File :1
[1 0 0 1 8 8]
^
SyntaxError: invalid syntax. Perhaps you forgot a comma?

KeyError: 'datapath' during "from svg2data import svg2data"


KeyError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_102044/517397449.py in
----> 1 from svg2data import svg2data

D:\OneDrive\Work\ICM\QCircle\sandbox\options\svgexport\svg2data\svg2data.py in
8 import os.path
9 from math import sin, cos, tan, pi
---> 10 afm_dir = os.path.join(rcParams['datapath'],'fonts', 'afm')
11 afm_dict = {}
12 for afm_file in os.listdir(afm_dir):

d:\Miniconda3\envs\icm\lib\site-packages\matplotlib_init_.py in getitem(self, key)
672 plt.switch_backend(rcsetup._auto_backend_sentinel)
673
--> 674 return dict.getitem(self, key)
675
676 def repr(self):

KeyError: 'datapath'

UnboundLocalError: local variable 'style' referenced before assignment

Hello, my SVG file was generated with Adobe Illustrator. To obtain height and width Use:

root.attrib
>>> {'viewBox': 'min max width height'}
width = root.attrib['viewBox'].split()[2]
height = root.attrib['viewBox'].split()[3]

But then this error appears:

    562             if 'style' in path.attrib:
    563                 style = path.attrib['style']
--> 564         path.attrib['style'] = style
    565         path.attrib['d'] = lines_and_curves_to_path(line_list,curve_list)
    566         if path.attrib not in paths:

UnboundLocalError: local variable 'style' referenced before assignment

How can I fix that?

Originally posted by @JCLArriaga5 in #3 (comment)

Ploting fails. get_axes(lines, width, height) produces an error.

Hi!
I found your utility here and feel like it may be very useful for me. I try to use it as manual says but got an error:

from svg2data import svg2data
data = svg2data("/data/test.svg")

Produces:

ValueError                                Traceback (most recent call last)
<ipython-input-2-15f3cf48a742> in <module>
----> 1 data = svg2data("/data/test.svg")
      2 data.writesvg('/data/newfile.svg')

~/Downloads/svg2data-master/svg2data.py in __init__(self, filename, test, debug)
     38             self._tree = ET.parse(filename)
     39             root = self._tree.getroot()
---> 40             width = float(root.attrib['width'])
     41             height = float(root.attrib['height'])
     42 

ValueError: could not convert string to float: '210mm'

when I changed sources to:

width = float(root.attrib['width'][:-2])
height = float(root.attrib['height'][:-2])

I was able to read and write svg file in the debug mode debug='get_axes', but I can't figure out how to fix other parts of the code which are responsible for plotting.

Is it a problem of my sample svg file or not? Could you help me to fix this issue?

Thanks,
Anton

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.