示例#1
0
 def write(self,data, type="json", mode="w", *args, **kargs):
     fnm = self()+".%s" % type
     try:
         os.makedirs(os.path.split(fnm)[0])
     except:
         pass
     if not os.path.exists(os.path.split(fnm)[0]):
         raise RuntimeError, "Could not create output directory: %s" % (os.path.split(fnm)[0])
     if type.lower() == "json":
         f=open(fnm,mode)
         data["metrics_git_sha1"] = pcmdi_metrics.__git_sha1__
         data["uvcdat_version"] = cdat_info.get_version()
         json.dump(data,f,*args,**kargs)            
     elif type.lower() in ["asc","ascii","txt"]:
         f=open(fnm,mode)
         for k in data.keys():
             f.write("%s  %s \n" % (k,data[k]))
     elif type.lower() == "nc":
         f=cdms2.open(fnm,mode)
         f.write(data,*args,**kargs)
         f.metrics_git_sha1 = pcmdi_metrics.__git_sha1__
         f.uvcdat_version = cdat_info.get_version()
     else:
         raise RuntimeError,"Unknown type: %s" % type
     f.close()
示例#2
0
 def write(self, data, type="json", mode="w", *args, **kargs):
     fnm = os.path.abspath(self()) + ".%s" % type
     try:
         os.makedirs(os.path.split(fnm)[0])
     except:
         pass
     if not os.path.exists(os.path.split(fnm)[0]):
         raise RuntimeError("Could not create output directory: %s" %
                            (os.path.split(fnm)[0]))
     if type.lower() == "json":
         f = open(fnm, mode)
         data["metrics_git_sha1"] = pcmdi_metrics.__git_sha1__
         data["uvcdat_version"] = cdat_info.get_version()
         json.dump(data, f, cls=CDMSDomainsEncoder, *args, **kargs)
         f.close()
         print "Results saved to JSON file:", fnm
     elif type.lower() in ["asc", "ascii", "txt"]:
         f = open(fnm, mode)
         for k in data.keys():
             f.write("%s  %s \n" % (k, data[k]))
         f.close()
     elif type.lower() == "nc":
         f = cdms2.open(fnm, mode)
         f.write(data, *args, **kargs)
         f.metrics_git_sha1 = pcmdi_metrics.__git_sha1__
         f.uvcdat_version = cdat_info.get_version()
         f.close()
     else:
         raise RuntimeError("Unknown type: %s" % type)
示例#3
0
    def write(self, data, type='json', *args, **kwargs):
        self.type = type.lower()
        file_name = self()
        dir_path = os.path.split(file_name)[0]

        if not os.path.exists(dir_path):
            try:
                os.makedirs(dir_path)
            except Exception:
                logging.getLogger("pcmdi_metrics").error(
                    'Could not create output directory: %s' % dir_path)

        if self.type == 'json':
            json_version = float(
                kwargs.get(
                    "json_version",
                    data.get(
                        "json_version",
                        3.0)))
            json_structure = kwargs.get(
                "json_structure", data.get(
                    "json_structure", None))
            if json_version >= 3.0 and json_structure is None:
                raise Exception(
                    "json_version 3.0 of PMP requires json_structure to be passed" +
                    "to the write function or part of the dictionary dumped")
            for k in ["json_structure", "json_version"]:
                if k in kwargs:
                    del(kwargs[k])
            data["json_version"] = json_version
            data["json_structure"] = json_structure
            f = open(file_name, 'w')
            data["provenance"] = generateProvenance()
#           data["user_notes"] = "BLAH"
            json.dump(data, f, cls=CDMSDomainsEncoder, *args, **kwargs)
            f.close()

        elif self.type in ['asc', 'ascii', 'txt']:
            f = open(file_name, 'w')
            for key in list(data.keys()):
                f.write('%s %s\n' % (key, data[key]))
            f.close()

        elif self.type == 'nc':
            f = cdms2.open(file_name, 'w')
            f.write(data, *args, **kwargs)
            f.metrics_git_sha1 = pcmdi_metrics.__git_sha1__
            f.uvcdat_version = cdat_info.get_version()
            f.close()

        else:
            logging.getLogger("pcmdi_metrics").error('Unknown type: %s' % type)
            raise RuntimeError('Unknown type: %s' % type)

        logging.getLogger("pcmdi_metrics").info(
            'Results saved to a %s file: %s' %
            (type, file_name))
示例#4
0
 def write(self, data, type="json", mode="w", *args, **kargs):
     fnm = os.path.abspath(self()) + ".%s" % type
     try:
         os.makedirs(os.path.split(fnm)[0])
     except:
         pass
     if not os.path.exists(os.path.split(fnm)[0]):
         raise RuntimeError(
             "Could not create output directory: %s" %
             (os.path.split(fnm)[0]))
     if type.lower() == "json":
         json_version = float(kargs.get("json_version", data.get("json_version", 3.0)))
         json_structure = kargs.get("json_structure", data.get("json_structure", None))
         if json_version >= 3. and json_structure is None:
             raise Exception(
                 "json_version 3.0 of PMP requires json_structure to be passed" +
                 "to the write function or part of the dictionary dumped")
         for k in ["json_structure", "json_version"]:
             if k in kargs:
                 del(kargs[k])
         data["json_version"] = json_version
         data["json_structure"] = json_structure
         f = open(fnm, mode)
         data["metrics_git_sha1"] = pcmdi_metrics.__git_sha1__
         data["uvcdat_version"] = cdat_info.get_version()
         json.dump(data, f, cls=CDMSDomainsEncoder, *args, **kargs)
         f.close()
         print "Results saved to JSON file:", fnm
     elif type.lower() in ["asc", "ascii", "txt"]:
         f = open(fnm, mode)
         for k in data.keys():
             f.write("%s  %s \n" % (k, data[k]))
         f.close()
     elif type.lower() == "nc":
         f = cdms2.open(fnm, mode)
         f.write(data, *args, **kargs)
         f.metrics_git_sha1 = pcmdi_metrics.__git_sha1__
         f.uvcdat_version = cdat_info.get_version()
         f.close()
     else:
         raise RuntimeError("Unknown type: %s" % type)
示例#5
0
                 if not nm in basic_tc:
                     del(vcs.elements["textcombined"][nm])
         #vcs.removeobject(iso1) ; # Error thrown here and below v2.12 triggered this
         #vcs.removeobject(iso2)
         #vcs.removeobject(title)
         #vcs.removeobject(t1)
         #vcs.removeobject(t2)
         #vcs.removeobject(t3)
         vcs.removeobject(tmpl)
         endTime                 = time.time()
         timeStr                 = 'Time: %06.3f secs;' % (endTime-startTime)
         memStr                  = 'Max mem: %05.3f GB' % (np.float32(resource.getrusage(resource.RUSAGE_SELF).ru_maxrss)/1.e6)
         counterStr              = '%05d' % counter
         pyObj                   = 'PyObj#: %07d;' % (len(gc.get_objects()))
         if counter == 1:
             print 'UV-CDAT version:'.ljust(21),cdat_info.get_version()
             print 'UV-CDAT prefix:'.ljust(21),cdat_info.get_prefix()
             print 'delFudge:'.ljust(21),delFudge
             print 'Background graphics:'.ljust(21),bg
             print 'donotstoredisplay:'.ljust(21),donotstoredisplay
         print counterStr,printStr,varName.ljust(6),BC,timeStr,memStr,pyObj
         #del() ; # Do a cleanup
         counter                 = counter+1
     gc.collect() ; # Attempt to force a memory flush
 x.backend.renWin = None ; # @danlipsa fix UV-CDAT/vcs#237
 x.close()
 f1.close()
 f2.close()
 outMP4File = os.path.join('pngs',''.join(['AMIPBCS_newVsOld_',varNameRead,'.mp4']))
 print 'Processing: ',outMP4File
 x = vcs.init()
示例#6
0
    def write(self, data, type="json", mode="w", *args, **kwargs):
        self.type = type.lower()
        file_name = self()
        dir_path = os.path.split(file_name)[0]

        if not os.path.exists(dir_path):
            try:
                os.makedirs(dir_path)
            except Exception:
                logging.getLogger("pcmdi_metrics").error(
                    "Could not create output directory: %s" % dir_path)

        if self.type == "json":
            json_version = float(
                kwargs.get("json_version", data.get("json_version", 3.0)))
            json_structure = kwargs.get("json_structure",
                                        data.get("json_structure", None))
            if json_version >= 3.0 and json_structure is None:
                raise Exception(
                    "json_version 3.0 of PMP requires json_structure to be passed"
                    + "to the write function or part of the dictionary dumped")
            for k in ["json_structure", "json_version"]:
                if k in kwargs:
                    del kwargs[k]
            data["json_version"] = json_version
            data["json_structure"] = json_structure

            if mode == "r+" and os.path.exists(file_name):
                f = open(file_name)
                out_dict = json.load(f)
            else:
                out_dict = OrderedDict({"provenance": generateProvenance()})
            f = open(file_name, "w")
            update_dict(out_dict, data)
            if "yaml" in out_dict["provenance"]["conda"]:
                out_dict["YAML"] = out_dict["provenance"]["conda"]["yaml"]
                del out_dict["provenance"]["conda"]["yaml"]
            #               out_dict = OrderedDict({"provenance": generateProvenance()})

            json.dump(out_dict, f, cls=CDMSDomainsEncoder, *args, **kwargs)
            f.close()

        elif self.type in ["asc", "ascii", "txt"]:
            f = open(file_name, "w")
            for key in list(data.keys()):
                f.write("%s %s\n" % (key, data[key]))
            f.close()

        elif self.type == "nc":
            f = cdms2.open(file_name, "w")
            f.write(data, *args, **kwargs)
            f.metrics_git_sha1 = pcmdi_metrics.__git_sha1__
            f.uvcdat_version = cdat_info.get_version()
            f.close()

        else:
            logging.getLogger("pcmdi_metrics").error("Unknown type: %s" % type)
            raise RuntimeError("Unknown type: %s" % type)

        logging.getLogger("pcmdi_metrics").info(
            "Results saved to a %s file: %s" % (type, file_name))