コード例 #1
0
ファイル: test_vcs_png_metadata.py プロジェクト: jccosta/vcs
 def testPngMetadata(self, *args, **kwargs):
     self.x.plot([1, 2, 3, 4, 5, 4, 3, 2, 1], bg=self.bg)
     fnm = "test_png_metadata.png"
     m = {'one': 'value one', 'two': 'value two'}
     self.x.png(fnm, width=15, metadata=m)
     assert (vcs.png_read_metadata(fnm) == m)
     os.remove(fnm)
コード例 #2
0
 def testInsertProvenanceAsDict(self):
     prov = {"myprov":4}
     x=vcs.init()
     x.plot([1,2,3])
     x.png("test_insert_prov_from_dict", provenance=prov)
     metadata = vcs.png_read_metadata("test_insert_prov_from_dict.png")
     self.assertTrue("provenance" in metadata)
     self.assertEqual(metadata["provenance"], prov)
     os.remove("test_insert_prov_from_dict.png")
コード例 #3
0
 def testPreserveExistingProvenance(self):
     prov = {"myprov":4}
     metadata = {"provenance":prov}
     x=vcs.init()
     x.plot([1,2,3])
     x.png("test_preserve_prov", metadata=metadata, provenance=True)
     metadata_out = vcs.png_read_metadata("test_preserve_prov.png")
     print(metadata_out["provenance"].keys())
     self.assertTrue("user_provenance" in metadata_out["provenance"])
     self.assertEqual(metadata_out["provenance"]["user_provenance"], prov)
     os.remove("test_preserve_prov.png")
コード例 #4
0
 def test_generate_notebook_from_png(self):
     run_command("python tests/share/vcs_generate_simple_plot.py")
     metadata = vcs.png_read_metadata("test_vcs_generate_simple_plot.png")
     script = "{p}/bin/generate_cdat_notebook.py".format(p=sys.prefix)
     cmd = "python {s} -i test_vcs_generate_simple_plot.png -o test_vcs_generate_simple_plot".format(s=script)
     code, msg = run_command(cmd)
     self.assertEqual(code, 0)
     self.assertTrue(os.path.exists("test_vcs_generate_simple_plot.ipynb"))
     self.checkNB("tests/test_vcs_generate_simple_plot.ipynb", "test_vcs_generate_simple_plot.ipynb")
     os.remove("test_vcs_generate_simple_plot.ipynb")
     os.remove("test_vcs_generate_simple_plot.png")
コード例 #5
0
 def test_generate_notebook_from_png(self):
     run_command("python tests/share/vcs_generate_simple_plot.py")
     metadata = vcs.png_read_metadata("test_vcs_generate_simple_plot.png")
     cmd = "generate_cdat_notebook.py -i test_vcs_generate_simple_plot.png -o test_vcs_generate_simple_plot"
     code, msg = run_command(cmd)
     self.assertEqual(code, 0)
     self.assertTrue(os.path.exists("test_vcs_generate_simple_plot.ipynb"))
     self.checkNB("tests/test_vcs_generate_simple_plot.ipynb",
                  "test_vcs_generate_simple_plot.ipynb")
     os.remove("test_vcs_generate_simple_plot.ipynb")
     os.remove("test_vcs_generate_simple_plot.png")
コード例 #6
0
ファイル: test_png_metadata.py プロジェクト: Xunius/uvcdat
# Check if text chunks are saved correctly in a PNG file
import vcs

x=vcs.init()
x.drawlogooff()
x.setantialiasing(0)

x.plot([1,2,3,4,5,4,3,2,1],bg=1)

fnm = "test_png_metadata.png"
m = {'one':'value one','two':'value two'}
x.png(fnm, width=15, metadata=m)
assert(vcs.png_read_metadata(fnm) == m)
コード例 #7
0
ファイル: test_vcs_png_metadata.py プロジェクト: zhe233/cdat
# Check if text chunks are saved correctly in a PNG file
import vcs
import os

x = vcs.init()
x.drawlogooff()
x.setantialiasing(0)

x.plot([1, 2, 3, 4, 5, 4, 3, 2, 1], bg=1)

fnm = "test_png_metadata.png"
m = {'one': 'value one', 'two': 'value two'}
x.png(fnm, width=15, metadata=m)
assert (vcs.png_read_metadata(fnm) == m)
os.remove(fnm)
コード例 #8
0
        input_filename = local_file.name
    except Exception:
        raise RuntimeError("Input file `{}` does not exists or is not readable".format(args.input))
else:
    input_filename = args.input

# Ok now loop through possible CDAT generated object
provenance = {}
try:
    print("Trying input file as cdms2 readable file")
    f = cdms2.open(input_filename)
    provenance = getattr(f,"provenance", {})
except Exception as err:
    # ok failed cdms, trying vcs
    print("Trying input file as vcs png file")
    metadata = vcs.png_read_metadata(input_filename)
    provenance = metadata.get("provenance", {})
if not isinstance(provenance, dict):
    provenance = json.loads(provenance)
conda = provenance.get("conda", {})
yaml_text = conda.get("yaml", "")
history = provenance.get("history", "")
header = """# Source file information\n
Name: {}\n
Generated on {}\n
By: {}\n
Platform: {} {} ({})\n
""".format(
    input_filename,
    provenance.get("date", "???"),
    provenance.get("userId", "???"),