예제 #1
0
 def save(self,close=True):
     """ Extends Figure.save() by completing tasks before saving.
     """
     if self.legend:
         utils.wowprint("**Drawing legend.**")
         self.ax.legend(**self.lk)
     # self.fig.tight_layout()
     # self.fig.subplots_adjust(top=0.95,right=0.95)
     # super(Performance,self).save(tight=False)
     super().save()
     if close:
         plt.close(self.fig)
예제 #2
0
    def cleanup(self,folder,files):
        """ Deletes files in given directory that match a glob.

        Args:

        folder      :   (path-like object) - this is where to clean up.
        files       :   (str,list,tuple) - a list of strings, or a string,
                        to match glob. For instance, "rsl*".
        """
        if isinstance(files,str):
            files = [files,]

        # Search for these files
        for file in files:
            fs = folder.glob(file)
            for f in fs:
                if self.dryrun:
                    utils.wowprint("Pretend deleting **{}**.".format(f),
                                    color='blue')
                else:
                    # This means delete!
                    f.unlink()
        return
예제 #3
0
 def __init__(self,message,color=False,bold=False,
                 underline=False,formatargs=False):
     wowmessage = utils.wowprint(message,color=color,bold=bold,
                     underline=underline,formatargs=formatargs)
     super().__init__(wowmessage)
예제 #4
0
    def __init__(self, fpath, utc=None, proj='merc'):
        self.proj = proj

        # The _root attributes do not have an extension (.png, .wld)
        if fpath.endswith('.png'):
            utils.wowprint("Looking for radar **data file**.")
            self.fpath_png = fpath
            self.fpath_root = fpath[:-4]
            self.fname_root = os.path.basename(fpath)[:-4]
            self.fdir = os.path.dirname(self.fpath_png)
            self.utc = self.date_from_fname(self.fpath_png)
            self.fmt = self.get_fmt()
        else:
            utils.wowprint("About to **download** radar data file.")
            self.fdir = fpath
            assert utc is not None
            self.utc = utc
            self.fmt = self.get_fmt()
            self.fname_root = self.get_radar_fname()
            self.fname_png = self.fname_root + '.png'
            self.fpath_root = os.path.join(self.fdir, self.fname_root)
            self.fpath_png = self.fpath_root + '.png'

            self.download_data()

        # This is to maintain API with ObsGroup etc
        self.fpath = self.fpath_png

        self.fpath_wld = self.fpath_root + '.wld'

        data = scipy.ndimage.imread(self.fpath_png, mode='P')
        self.data = N.flipud(data)

        self.xlen, self.ylen, = self.data.shape

        # Metadata
        if not os.path.exists(self.fpath_wld):
            self.download_data(ext='.wld')
        if not os.path.exists(self.fpath_png):
            self.download_data(ext='.png')

        f = open(self.fpath_wld, 'r').readlines()

        # pixel size in the x-direction in map units/pixel
        self.xpixel = float(f[0])

        # rotation about y-axis
        self.roty = float(f[1])

        # rotation about x-axis
        self.rotx = float(f[2])

        # pixel size in the y-direction in map units,
        self.ypixel = float(f[3])

        # x-coordinate of the center of the upper left pixel
        self.ulx = float(f[4])

        # y-coordinate of the center of the upper left pixel
        self.uly = float(f[5])

        # lower right corner
        self.lrx = self.ulx + self.ylen * self.xpixel
        self.lry = self.uly + self.xlen * self.ypixel

        if self.fmt == 'n0r':
            self.clvs = N.arange(0, 80, 5)
        elif self.fmt == 'n0q':
            self.clvs = N.arange(0, 90.0, 0.5)
        # import pdb; pdb.set_trace()

        # self.lats1D = N.linspace(self.lry,self.uly,self.xlen)[::-1]
        self.lats1D = N.linspace(self.lry, self.uly, self.xlen)
        self.lons1D = N.linspace(self.ulx, self.lrx, self.ylen)
        self.lons, self.lats = N.meshgrid(self.lons1D, self.lats1D)
        # self.lats, self.lons = N.meshgrid(self.lats1D,self.lons1D)
        assert self.data.shape == self.lats.shape

        self.grid = Grid(self)
        self.dBZ = self.get_dBZ()
예제 #5
0
    def __init__(self,path_to_exedir,path_to_datadir, path_to_namelistdir,
                    path_to_icdir,path_to_lbcdir,
                    path_to_batch,initutc,
                    path_to_outdir=None,
                    sched='slurm',path_to_rundir=False,delete_exe_copy=False,
                    ndoms=1,nmems=0,membernames=False,
                    endutc=False,runsec=False,nl_per_member=True,
                    nl_suffix='dot_number',ics=None,lbcs=None,dryrun=False,
                    rename_d01_ics=False):
        # Check - must have either number of members or a list of names
        assert isinstance(membernames,(list,tuple)) or (nmems > 0)

        self.rename_d01_ics = rename_d01_ics
        
        # Time of initialisation
        self.initutc = initutc

        # we need one of these optional arguments to compute run time
        if (endutc is False) and (runsec is False):
            raise Exception("Specific endutc or runsec.")
        elif runsec:
            self.runsec = runsec
            self.endutc = self.initutc + datetime.timedelta(seconds=self.runsec)
        elif endutc:
            self.endutc = endutc
            self.runsec = (self.endutc - self.initutc).seconds
            assert self.runsec > 0

        # PATH OBJECTS - see pathlib documentation
        self.exedir = PosixPath(path_to_exedir)
        self.datadir = PosixPath(path_to_datadir)
        self.namelistdir = PosixPath(path_to_namelistdir)
        
        if not path_to_icdir:
            self.icdir = None
        else:
            self.icdir = PosixPath(path_to_icdir)
            
        if not path_to_lbcdir:
            self.lbcdir = None
        else:
            self.lbcdir = PosixPath(path_to_lbcdir)
            
        # Not implemented yet
        if path_to_outdir is not None:
            print("Ignoring path_to_outdir - not implemented.")
        #self.outdir = PosixPath(path_to_outdir)
        self.batchscript = PosixPath(path_to_batch)

        # Shortcut for accessing the script name
        self.batchname = self.batchscript.name
        # By default, the run directory is where the data will end up
        if not isinstance(path_to_rundir,str):
            path_to_rundir = path_to_datadir
        self.wrfrundir = PosixPath(path_to_rundir)

        self.sched = sched
        self.dryrun = dryrun

        # Number of domains
        self.ndoms = ndoms
        self.dom_names = ['d{:02d}'.format(n) for n in range(1,self.ndoms+1)]

        # Options
        self.delete_exe_copy = delete_exe_copy
        self.nl_per_member = nl_per_member

        # INIT PROCEDURE
        # Get member names
        if membernames is False:
            self.nmems = nmems
            self.membernames = ['mem{:02d}'.format(n) for n in
                                N.arange(1,self.nmems+1)]
        else:
            self.membernames = membernames
            self.nmems = len(self.membernames)

        # Lookup dictionary of all members
        self.members = self.catalog_members()

        # Gather ICs, LBCs
        # Each file that needs to be copied is in a list
        #   within ['icbcs'] for each member

        # if icbcs is a dictionary, copy filenames for each member
        # if self.icdir is not None:
        self.get_paths_to_input(ics,'ics')
        # if self.lbcdir is not None:
        self.get_paths_to_input(lbcs,'lbcs')
        
        # TO DO - how to automate nests too
        # For now, everything in same folder.
        utils.wowprint("Ensemble **created!**",color='purple',bold=True)
        utils.wowprint("Now do **run_all_members()**.",color='yellow',bold=True)