def check_and_store_info(self, file_name, info=None, grid_name='UNKNOWN', dtype='float32', MAKE_RTI=True, MAKE_BOV=False): #----------------------------------------------------- # Note: This object (self) may be new or it may have # been used previously. In the latter case, # "info" should still be available in "self". # We only need info if MAKE_RTI or MAKE_BOV. #----------------------------------------------------- self.format = 'NCGS' self.file_name = file_name self.time_index = 0 self.grid_name = grid_name #----------------------------------------------------- # This was used by rts_files.check_and_store_info() # but is not appropriate here because we need to # know nx, ny, dx and dy for the netCDF file. #----------------------------------------------------- ### if not(MAKE_RTI or MAKE_BOV): return #--------------------------------- # Was "info" argument provided ? #--------------------------------- NEW_INFO = True if (info is None): try: info = self.info self.nx = info.ncols ### self.ny = info.nrows NEW_INFO = False ## print 'Found info in state.' except: #------------------------------------------ # Try to find RTI file to copy info from. # Don't create a new RTI file. #------------------------------------------ RTI_file = rti_files.try_to_find_rti_file(file_name) if (RTI_file != 'none'): print 'Reading info from: ' + RTI_file info = rti_files.read_info(RTI_file) else: print 'ERROR during open_new_file():' print ' Could not find RTI file and "info"' print ' argument was not provided.' print ' ' return #----------------------------- # Update "info" as necessary #----------------------------- info.grid_file = file_name info.data_type = rti_files.get_rti_data_type(dtype) info.data_source = 'TopoFlow 3.0' info.gmin = -9999.0 info.gmax = -9999.0 #--------------------------------------- # If new "info" was provided, store it #--------------------------------------- if (NEW_INFO): self.info = info self.nx = info.ncols self.ny = info.nrows ## print 'Stored new info in state.' #------------------- # Write RTI file ? #------------------- if (MAKE_RTI): prefix = rti_files.get_file_prefix(file_name) RTI_file = (prefix + '.rti') rti_files.write_info(RTI_file, info) # print 'Wrote grid info to: ' + RTI_file ###### #------------------- # Write BOV file ? #------------------- if (MAKE_BOV): bov_files.write_info_as_bov(file_name, info, grid_name)
def check_and_store_info(self, file_name, info=None, var_name='UNKNOWN', dtype='float32', MAKE_RTI=True, MAKE_BOV=False): #----------------------------------------------------- # Note: This object (self) may be new or it may have # been used previously. In the latter case, # "info" should still be available in "self". # We only need info if MAKE_RTI or MAKE_BOV. #----------------------------------------------------- self.format = 'RTG' self.file_name = file_name if not(MAKE_RTI or MAKE_BOV): return #--------------------------------- # Was "info" argument provided ? #--------------------------------- NEW_INFO = True if (info == None): try: info = self.info NEW_INFO = False ## print 'Found info in state.' except: #------------------------------------------ # Try to find RTI file to copy info from. # Don't create a new RTI file. #------------------------------------------ RTI_file = rti_files.try_to_find_rti_file( file_name ) if (RTI_file != 'none'): info = rti_files.read_info( RTI_file ) ## print 'Reading info from: ' + RTI_file else: print 'ERROR during open_new_file():' print ' Could not find RTI file and "info"' print ' argument was not provided.' print ' ' return #----------------------------- # Update "info" as necessary #----------------------------- info.grid_file = file_name info.data_type = rti_files.get_rti_data_type( dtype ) info.data_source = 'TopoFlow 3.0' info.gmin = -9999.0 info.gmax = -9999.0 #--------------------------------------- # If new "info" was provided, store it #--------------------------------------- if (NEW_INFO): self.info = info self.nx = info.ncols self.ny = info.nrows ## print 'Stored new info in state.' ## if (info != None): ## #------------------------------ ## # Save info to a new RTI file ## #------------------------------ ## prefix = rti_files.get_file_prefix( file_name ) ## RTI_file = (prefix + '.rti') ## rti_files.write_info( RTI_file, info ) ## ## else: ## #------------------------------------------ ## # Try to find RTI file to copy info from. ## # Don't create a new RTI file. ## #------------------------------------------ ## RTI_file = rti_files.try_to_find_rti_file( file_name ) ## if (RTI_file != 'none'): ## info = rti_files.read_info( RTI_file ) ## info.file_name = file_name ## info.data_type = rti_files.get_rti_data_type( dtype ) ## else: ## print 'ERROR during open_new_file():' ## print ' Could not find RTI file and "info"' ## print ' argument was not provided.' ## print ' ' ## return #------------------- # Write RTI file ? #------------------- if (MAKE_RTI): prefix = rti_files.get_file_prefix( file_name ) RTI_file = (prefix + '.rti') rti_files.write_info( RTI_file, info ) # print 'Wrote grid info to: ' + RTI_file ###### #------------------- # Write BOV file ? #------------------- if (MAKE_BOV): bov_files.write_info_as_bov( file_name, info, var_name)
def check_and_store_info( self, file_name, info=None, grid_name="UNKNOWN", dtype="float32", MAKE_RTI=True, MAKE_BOV=False ): # ----------------------------------------------------- # Note: This object (self) may be new or it may have # been used previously. In the latter case, # "info" should still be available in "self". # We only need info if MAKE_RTI or MAKE_BOV. # ----------------------------------------------------- self.format = "NCGS" self.file_name = file_name self.time_index = 0 self.grid_name = grid_name # ----------------------------------------------------- # This was used by rts_files.check_and_store_info() # but is not appropriate here because we need to # know nx, ny, dx and dy for the netCDF file. # ----------------------------------------------------- ### if not(MAKE_RTI or MAKE_BOV): return # --------------------------------- # Was "info" argument provided ? # --------------------------------- NEW_INFO = True if info == None: try: info = self.info self.nx = info.ncols ### self.ny = info.nrows NEW_INFO = False ## print 'Found info in state.' except: # ------------------------------------------ # Try to find RTI file to copy info from. # Don't create a new RTI file. # ------------------------------------------ RTI_file = rti_files.try_to_find_rti_file(file_name) if RTI_file != "none": print "Reading info from: " + RTI_file info = rti_files.read_info(RTI_file) else: print "ERROR during open_new_file():" print ' Could not find RTI file and "info"' print " argument was not provided." print " " return # ----------------------------- # Update "info" as necessary # ----------------------------- info.grid_file = file_name info.data_type = rti_files.get_rti_data_type(dtype) info.data_source = "TopoFlow 3.0" info.gmin = -9999.0 info.gmax = -9999.0 # --------------------------------------- # If new "info" was provided, store it # --------------------------------------- if NEW_INFO: self.info = info self.nx = info.ncols self.ny = info.nrows ## print 'Stored new info in state.' # ------------------- # Write RTI file ? # ------------------- if MAKE_RTI: prefix = rti_files.get_file_prefix(file_name) RTI_file = prefix + ".rti" rti_files.write_info(RTI_file, info) # print 'Wrote grid info to: ' + RTI_file ###### # ------------------- # Write BOV file ? # ------------------- if MAKE_BOV: bov_files.write_info_as_bov(file_name, info, grid_name)