Changeset 288 for inundation/ga/storm_surge/pyvolution/data_manager.py
- Timestamp:
- Sep 10, 2004, 5:56:19 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/ga/storm_surge/pyvolution/data_manager.py
r287 r288 284 284 self.domain = domain 285 285 286 287 # def store_connectivity(self):288 # """Writes x,y,z coordinates of triangles constituting289 # the bed elevation.290 # """291 292 # msg = 'Method should be overridden in concrete class'293 # raise msg294 295 # def store_timestep(self, t, V0, V1, V2):296 # """Store time, water heights (and momentums) to file297 # """298 299 # msg = 'Method should be overridden in concrete class'300 # raise msg301 286 302 287 #FIXME: Should we have a general set_precision function? 303 288 304 289 305 #Function for storing output to e.g. visualisation 290 291 #Class for storing output to e.g. visualisation 306 292 class Data_format_sww(Data_format): 307 293 """Interface to native NetCDF format (.sww) … … 325 311 #Create new file 326 312 fid.institution = 'Geoscience Australia' 313 fid.description = 'Output from pyvolution suitable for plotting' 314 327 315 if domain.smooth: 328 316 fid.smoothing = 'Yes' … … 454 442 455 443 444 #Class for handling checkpoints data 445 class Data_format_cpt(Data_format): 446 """Interface to native NetCDF format (.cpt) 447 """ 448 449 450 def __init__(self, domain, mode = 'w'): 451 from Scientific.IO.NetCDF import NetCDFFile 452 from Numeric import Int, Float, Float 453 454 self.precision = Float #Use full precision 455 456 Data_format.__init__(self, domain, 'sww', mode) 457 458 459 # NetCDF file definition 460 fid = NetCDFFile(self.filename, mode) 461 462 if mode == 'w': 463 #Create new file 464 fid.institution = 'Geoscience Australia' 465 fid.description = 'Checkpoint data' 466 #fid.smooth = domain.smooth 467 fid.order = domain.default_order 468 469 # dimension definitions 470 fid.createDimension('number_of_volumes', self.number_of_volumes) 471 fid.createDimension('number_of_vertices', 3) 472 473 #Store info at all vertices (no smoothing) 474 fid.createDimension('number_of_points', 3*self.number_of_volumes) 475 fid.createDimension('number_of_timesteps', None) #extensible 476 477 # variable definitions 478 479 #Mesh 480 fid.createVariable('x', self.precision, ('number_of_points',)) 481 fid.createVariable('y', self.precision, ('number_of_points',)) 482 #fid.createVariable('z', self.precision, ('number_of_points',)) 483 484 fid.createVariable('volumes', Int, ('number_of_volumes', 485 'number_of_vertices')) 486 487 fid.createVariable('time', self.precision, 488 ('number_of_timesteps',)) 489 490 #Allocate space for all quantities 491 for name in domain.quantities.keys(): 492 fid.createVariable(name, self.precision, 493 ('number_of_timesteps', 494 'number_of_points')) 495 496 #Close 497 fid.close() 498 499 500 def store_checkpoint(self): 501 """ 502 Write x,y coordinates of triangles. 503 Write connectivity ( 504 constituting 505 the bed elevation. 506 """ 507 508 from Scientific.IO.NetCDF import NetCDFFile 509 510 from Numeric import concatenate 511 512 domain = self.domain 513 514 #Get NetCDF 515 fid = NetCDFFile(self.filename, 'a') #Open existing file for append 516 517 # Get the variables 518 x = fid.variables['x'] 519 y = fid.variables['y'] 520 521 volumes = fid.variables['volumes'] 522 523 # Get X, Y and bed elevation Z 524 Q = domain.quantities['elevation'] 525 X,Y,Z,V = Q.get_vertex_values(xy=True, 526 precision = self.precision) 527 528 529 530 x[:] = X.astype(self.precision) 531 y[:] = Y.astype(self.precision) 532 z[:] = Z.astype(self.precision) 533 534 volumes[:] = V 535 536 #Close 537 fid.close() 538 539 540 def store_timestep(self, name): 541 """Store time and named quantity to file 542 """ 543 from Scientific.IO.NetCDF import NetCDFFile 544 from time import sleep 545 546 #Get NetCDF 547 retries = 0 548 file_open = False 549 while not file_open and retries < 10: 550 try: 551 fid = NetCDFFile(self.filename, 'a') #Open existing file 552 except IOError: 553 #This could happen if someone was reading the file. 554 #In that case, wait a while and try again 555 msg = 'Warning (store_timestep): File %s could not be opened'\ 556 %self.filename 557 msg += ' - trying again' 558 print msg 559 retries += 1 560 sleep(1) 561 else: 562 file_open = True 563 564 if not file_open: 565 msg = 'File %s could not be opened for append' %self.filename 566 raise msg 567 568 569 domain = self.domain 570 571 # Get the variables 572 time = fid.variables['time'] 573 stage = fid.variables['stage'] 574 i = len(time) 575 576 #Store stage 577 time[i] = self.domain.time 578 579 # Get quantity 580 Q = domain.quantities[name] 581 A,V = Q.get_vertex_values(xy=False, 582 precision = self.precision) 583 584 stage[i,:] = A.astype(self.precision) 585 586 #Flush and close 587 fid.sync() 588 fid.close() 589 590 591 592 593 456 594 457 595
Note: See TracChangeset
for help on using the changeset viewer.