def write_tide(self): # check if file exists before remaking #if not os.path.exists(os.path.join(self.out,'tide_%s.bc' % self.name)): self.write_ext() self.interp_tide() with open(os.path.join(self.out, 'tide_%s.bc' % self.name), 'w') as bnd: for ss in range(0, len(self.X)): zz = utils.make_len(ss + 1, 4) bnd.write('[forcing]\n') bnd.write('Name = %s_%s\n' % (self.name, zz)) bnd.write('Function = astronomic\n') bnd.write('Quantity = astronomic component\n') bnd.write('Unit = -\n') bnd.write('Quantity = waterlevelbnd amplitude\n') bnd.write('Unit = m\n') bnd.write('Quantity = waterlevelbnd phase\n') bnd.write('Unit = deg\n') bnd.write('A0 0.0 0.0\n') for co in range(0, len(self.const)): bnd.write('%s %f %f\n' % (self.const[co], self.amp[ss, co] / 100, self.pha[ss, co])) bnd.write('\n') with zipfile.ZipFile(os.path.join(self.out, '..', 'tide.zip'), 'w') as zf: fullpath = os.path.join(self.out, 'tide_%s.bc' % self.name) zf.write(fullpath, os.path.basename(fullpath))
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'])