-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #90 from cinemascience/plot
Plot
- Loading branch information
Showing
15 changed files
with
373 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import pycinema | ||
import pycinema.filters | ||
import pycinema.theater | ||
import pycinema.theater.views | ||
|
||
# pycinema settings | ||
PYCINEMA = { 'VERSION' : '2.0.0'} | ||
|
||
# layout | ||
vf0 = pycinema.theater.Theater.instance.centralWidget() | ||
vf0.setHorizontalOrientation() | ||
vf1 = vf0.insertFrame(0) | ||
vf1.setVerticalOrientation() | ||
vf1.insertView( 0, pycinema.theater.views.NodeEditorView() ) | ||
TableView_1 = vf1.insertView( 1, pycinema.theater.views.TableView() ) | ||
vf1.setSizes([610, 440]) | ||
PlotScatterView_0 = vf0.insertView( 1, pycinema.theater.views.PlotScatterView() ) | ||
vf0.setSizes([1111, 1110]) | ||
|
||
# filters | ||
PlotScatterItem_0 = pycinema.filters.PlotScatterItem() | ||
CSVReader_0 = pycinema.filters.CSVReader() | ||
|
||
# properties | ||
PlotScatterView_0.inputs.title.set("Electric Range vs. Model Year for Vehicles in Washington State (2023)", False) | ||
PlotScatterView_0.inputs.background.set("white", False) | ||
PlotScatterView_0.inputs.plotitem.set(PlotScatterItem_0.outputs.plotitem, False) | ||
PlotScatterItem_0.inputs.table.set(CSVReader_0.outputs.table, False) | ||
PlotScatterItem_0.inputs.x.set("Model Year", False) | ||
PlotScatterItem_0.inputs.y.set("Electric Range", False) | ||
PlotScatterItem_0.inputs.pencolor.set("default", False) | ||
PlotScatterItem_0.inputs.penwidth.set(1.0, False) | ||
PlotScatterItem_0.inputs.brushcolor.set("light blue", False) | ||
PlotScatterItem_0.inputs.symbol.set("o", False) | ||
PlotScatterItem_0.inputs.size.set(10.0, False) | ||
TableView_1.inputs.table.set(CSVReader_0.outputs.table, False) | ||
CSVReader_0.inputs.path.set("https://data.wa.gov/api/views/f6w7-q2d2/rows.csv?accessType=DOWNLOAD", False) | ||
|
||
# execute pipeline | ||
PlotScatterView_0.update() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
from pycinema import Filter, isURL | ||
import csv | ||
import requests | ||
from os.path import exists | ||
|
||
class CSVReader(Filter): | ||
|
||
def __init__(self): | ||
super().__init__( | ||
inputs={ | ||
'path': '' | ||
}, | ||
outputs={ | ||
'table': [[]] | ||
} | ||
) | ||
|
||
def _update(self): | ||
|
||
table = [] | ||
csvPath = self.inputs.path.get() | ||
|
||
if isURL(csvPath): | ||
with requests.Session() as s: | ||
print("requesting " + csvPath) | ||
download = s.get(csvPath) | ||
decoded = download.content.decode('utf-8') | ||
csvdecoded = csv.reader(decoded.splitlines(), delimiter=',') | ||
rows = list(csvdecoded) | ||
for row in rows: | ||
table.append(row) | ||
|
||
else: | ||
if not csvPath: | ||
self.outputs.table.set([[]]) | ||
return 0 | ||
|
||
if not exists(csvPath): | ||
print('[ERROR] file not found:', csvPath) | ||
self.outputs.table.set([[]]) | ||
return 0 | ||
|
||
try: | ||
with open(csvPath, 'r+') as csvfile: | ||
rows = csv.reader(csvfile, delimiter=',') | ||
for row in rows: | ||
table.append(row) | ||
except: | ||
print('[ERROR] Unable to open file:', csvPath) | ||
self.outputs.table.set([[]]) | ||
return 0 | ||
|
||
# remove empty lines | ||
table = list(filter(lambda row: len(row)>0, table)) | ||
|
||
self.outputs.table.set(table) | ||
|
||
return 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
from .PlotItem import * | ||
|
||
import numpy as np | ||
|
||
# | ||
# ImageMetadataToScatterItem | ||
# | ||
class ImageMetadataToScatterItem(PlotItem): | ||
|
||
def __init__(self): | ||
super().__init__( | ||
inputs={ | ||
'images' : [], | ||
'x' : 'none', | ||
'y' : 'none', | ||
'pencolor' : 'default', | ||
'penwidth' : 1.0, | ||
'brushcolor': 'default', | ||
'symbol' : 'x', | ||
'size' : 1.0 | ||
}, | ||
outputs={ | ||
'plotitem' : {} | ||
} | ||
) | ||
|
||
def _update(self): | ||
|
||
xdata = [] | ||
ydata = [] | ||
xlabel = self.inputs.x.get() | ||
ylabel = self.inputs.y.get() | ||
for image in self.inputs.images.get(): | ||
xdata.append(image.meta[xlabel]) | ||
ydata.append(image.meta[ylabel]) | ||
|
||
out = { 'x' : { | ||
'label' : self.inputs.x.get(), | ||
'data' : xdata | ||
}, | ||
'y' : { | ||
'label' : self.inputs.y.get(), | ||
'data' : ydata | ||
}, | ||
'pen' : { | ||
'color' : self.inputs.pencolor.get(), | ||
'width' : self.inputs.penwidth.get(), | ||
}, | ||
'brush' : { | ||
'color' : self.inputs.brushcolor.get() | ||
}, | ||
'symbol': self.inputs.symbol.get(), | ||
'size' : self.inputs.size.get() | ||
} | ||
self.outputs.plotitem.set({}) | ||
self.outputs.plotitem.set(out) | ||
|
||
return 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.