Esempio n. 1
0
    def write_bc_preamble(self, handle, pli_name, support, sub, depth):
        '''
        write the header information for a bc file
        '''
        handle.write('[forcing]\n')
        handle.write(
            'Name                            = %s_%s\n' %
            (pli_name.replace('.pli', ''), utils.make_len(support + 1, 4)))

        if sub != 'steric':
            handle.write('Function                        = t3D\n')
            handle.write('Time-interpolation              = linear\n')
            handle.write('Vertical position type          = zdatum\n')
            handle.write('Vertical position specification = ')
            for dep in np.flip(depth):
                # FLIP THE ARRAY?
                handle.write('-%.2f  ' % dep)
            handle.write('\n')
        else:
            handle.write('Function                        = timeseries\n')
            handle.write('Time-interpolation              = linear\n')

        handle.write('Quantity                        = time\n')
        handle.write('Unit                            = MINUTES since %s\n' %
                     utils.datetime_to_timestring(self.tref))

        if sub == 'uxuy':
            handle.write('Vector = uxuyadvectionvelocitybnd:ux,uy\n')

        if sub != 'steric':
            for dep in range(0, len(depth)):
                if sub in constituent_boundary_type.keys():

                    for part_sub_i, _ in enumerate(
                            constituent_boundary_type[sub]['type']):
                        handle.write(
                            'Quantity                        = %s\n' %
                            constituent_boundary_type[sub]['type'][part_sub_i])
                        handle.write('Unit                            = %s\n' %
                                     constituent_boundary_type[sub]['unit'])
                        handle.write('Vertical position               = %s\n' %
                                     str(dep + 1))
                else:
                    handle.write(
                        'Quantity                        = tracerbnd\n')
                    handle.write('Unit                            = g/m3\n')
                    handle.write('Vertical position               = %s\n' %
                                 str(dep + 1))
        else:
            for part_sub_i, _ in enumerate(
                    constituent_boundary_type[sub]['type']):
                handle.write(
                    'Quantity                        = %s\n' %
                    constituent_boundary_type[sub]['type'][part_sub_i])
                handle.write('Unit                            = %s\n' %
                             constituent_boundary_type[sub]['unit'])
Esempio n. 2
0
    def write_new_ext_file(self):
        """
        WRITE NEW EXT FILE CONTAINING THE CONSTITUENT BOUNDARIES
        
        """
        boundaries = self.boundaries

        with open(self.ext, 'r') as new_template:
            for _, bnd in enumerate(boundaries.keys()):
                with open(os.path.join(self.dir, 'DFMWAQ_' + bnd + '_tmp.ext'),
                          'w') as new_ext:
                    # copy old boundaries, should only be waterlevel
                    for line in new_template.readlines():
                        new_ext.write(line)
                    if 'waterlevelbnd' in boundaries[bnd]['type']:
                        new_ext.write('\n')
                        # if it is waterlevel then it was involved in the previous steps
                        for sub in self.subs:
                            if sub in usefor.keys():
                                if sub == 'steric' and not self.steric:
                                    pass
                                else:
                                    new_ext.write('[boundary]\n')
                                    if sub in constituent_boundary_type.keys():
                                        if sub != 'uxuy':
                                            new_ext.write(
                                                'quantity=%s\n' % ','.join(
                                                    constituent_boundary_type[
                                                        sub]['type']).replace(
                                                            ',', ''))
                                        else:
                                            # advection, inconsistent naming
                                            new_ext.write(
                                                'quantity=uxuyadvectionvelocitybnd\n'
                                            )
                                    else:
                                        new_ext.write(
                                            'quantity=tracerbnd%s\n' % sub)

                                    new_ext.write('locationfile=%s.pli\n' %
                                                  (bnd))
                                    new_ext.write('forcingfile=%s_%s.bc\n' %
                                                  (sub, bnd))
                                    new_ext.write('\n')
        if os.path.exists(os.path.join(self.dir, '..', 'ext.zip')):
            mode = 'a'
        else:
            mode = 'w'

        with zipfile.ZipFile(os.path.join(self.dir, '..', 'ext.zip'),
                             mode) as zf:
            fullpath = os.path.join(self.dir, 'DFMWAQ_' + bnd + '_tmp.ext')
            zf.write(fullpath, os.path.basename(fullpath))