1# -*- coding: utf-8 -*-

2

3 import xml.etree.ElementTree as ET

4

5 from grm.lib.Util import indent

6

7# from .lib.File_Class import *

8# from .lib.Util import *

9

10

11 class xmls:

12 def __init__(self):

13 self.ProjectFile = ""

14 self.CrossSectionType = []

15 self.SingleCSChannelWidthType = []

16 self.ChannelWidthEQc = []

17 self.ChannelWidthEQd = []

18 self.ChannelWidthEQe = []

19 self.ChannelWidthMostDownStream = []

20 self.LowerRegionHeight = []

21 self.LowerRegionBaseWidth = []

22 self.UpperRegionBaseWidth = []

23 self.CompoundCSChannelWidthLimit = []

24 self.BankSideSlopeRight = []

25 self.BankSideSlopeLeft = []

26 self.XML_element_remove = []

27 self.check_ChannelSettings = False

28

29 def Check_Gmp_xml(self, filepath):

30 self.ProjectFile = filepath

31 # xml 요소 값을 배열에 넣음

32 self.Set_XML_element()

33 self.Set_XML_element_SubWatershed()

34 self.Set_XML_element_WatchPoints()

35 self.Set_XML_element_FlowControlGrid()

36 self.Set_XML_element_GreenAmptParameter()

37 self.Set_XML_element_SoilDepth()

38 self.Set_XML_element_LandCover()

39

40 # 2020-04-21 박: 신규 추가

41 self.Set_XML_element_ChannelSettings()

42

43 # xml 파싱

44 doc = ET.parse(self.ProjectFile)

45 root = doc.getroot()

46 GRMProject = ET.Element("GRMProject")

47 GRMProject.set("xmlns", "http://tempuri.org/GRMProject.xsd")

48

49 rootValue = root.findall("{http://tempuri.org/GRMProject.xsd}ProjectSettings")

50 for element in rootValue:

51 ProjectSettings = ET.SubElement(GRMProject, "ProjectSettings")

52 flag_WatershedFile = True

53 for i in range(0, len(self.XML_element)):

54 Datavalue = element.findtext(

55 "{http://tempuri.org/GRMProject.xsd}" + self.XML_element[i]

56 )

57 if self.XML_element[i] == "GRMSimulationType" and (

58 Datavalue == "" or Datavalue is None

59 ):

60 Datavalue = "SingleEvent"

61 if self.XML_element[i] == "LandCoverDataType" and (

62 Datavalue == "" or Datavalue is None

63 ):

64 Datavalue = "File"

65 if self.XML_element[i] == "SoilTextureDataType" and (

66 Datavalue == "" or Datavalue is None

67 ):

68 Datavalue = "File"

69 if self.XML_element[i] == "SoilDepthDataType" and (

70 Datavalue == "" or Datavalue is None

71 ):

72 Datavalue = "File"

73 if self.XML_element[i] == "FlowDirectionType" and (

74 Datavalue == "" or Datavalue is None

75 ):

76 Datavalue = "StartsFromE_TauDEM"

77 if self.XML_element[i] == "MaxDegreeOfParallelism" and (

78 Datavalue == "" or Datavalue is None

79 ):

80 Datavalue = "-1"

81 if self.XML_element[i] == "SimulationStartingTime" and (

82 Datavalue == "" or Datavalue is None

83 ):

84 Datavalue = "0"

85 if self.XML_element[i] == "IsFixedTimeStep" and (

86 Datavalue == "" or Datavalue is None

87 ):

88 Datavalue = "false"

89 if self.XML_element[i] == "'SimulateInfiltration'" and (

90 Datavalue == "" or Datavalue is None

91 ):

92 Datavalue = "true"

93 if self.XML_element[i] == "SimulateSubsurfaceFlow" and (

94 Datavalue == "" or Datavalue is None

95 ):

96 Datavalue = "true"

97 if self.XML_element[i] == "SimulateBaseFlow" and (

98 Datavalue == "" or Datavalue is None

99 ):

100 Datavalue = "true"

101 if self.XML_element[i] == "SimulateInterception" and (

102 Datavalue == "" or Datavalue is None

103 ):

104 Datavalue = "true"

105 if self.XML_element[i] == "SimulateEvapotranspiration" and (

106 Datavalue == "" or Datavalue is None

107 ):

108 Datavalue = "true"

109 if self.XML_element[i] == "SimulateSnowMelt" and (

110 Datavalue == "" or Datavalue is None

111 ):

112 Datavalue = "true"

113 if self.XML_element[i] == "SimulateFlowControl" and (

114 Datavalue == "" or Datavalue is None

115 ):

116 Datavalue = "true"

117

118 # 2020-04-21 박: <ChannelSettings> 로 이동함

119 # 2020-07-15 박: <ChannelSettings> 기본 값이 없으면 처리 안하게 처리

120 try:

121 if self.XML_element[i] == "CrossSectionType" and (

122 Datavalue == "" or Datavalue is None

123 ):

124 self.CrossSectionType.append("CSSingle")

125 rootValue.remove(element)

126 self.check_ChannelSettings = False

127 elif self.XML_element[i] == "CrossSectionType" and (

128 Datavalue != "" and Datavalue is not None

129 ):

130 self.CrossSectionType.append(Datavalue)

131 rootValue.remove(element)

132 self.check_ChannelSettings = True

133

134 if self.XML_element[i] == "SingleCSChannelWidthType" and (

135 Datavalue == "" or Datavalue is None

136 ):

137 self.SingleCSChannelWidthType.append("CWGeneration")

138 rootValue.remove(element)

139 self.check_ChannelSettings = False

140 elif self.XML_element[i] == "SingleCSChannelWidthType" and (

141 Datavalue != "" and Datavalue is not None

142 ):

143 self.SingleCSChannelWidthType.append(Datavalue)

144 rootValue.remove(element)

145 self.check_ChannelSettings = True

146

147 if self.XML_element[i] == "ChannelWidthEQc" and (

148 Datavalue == "" or Datavalue is None

149 ):

150 self.ChannelWidthEQc.append("1.698")

151 self.check_ChannelSettings = False

152 rootValue.remove(element)

153 elif self.XML_element[i] == "ChannelWidthEQc" and (

154 Datavalue != "" and Datavalue is not None

155 ):

156 self.ChannelWidthEQc.append(Datavalue)

157 rootValue.remove(element)

158 self.check_ChannelSettings = True

159

160 if self.XML_element[i] == "ChannelWidthEQd" and (

161 Datavalue == "" or Datavalue is None

162 ):

163 self.ChannelWidthEQd.append("0.318")

164 self.check_ChannelSettings = False

165 rootValue.remove(element)

166 elif self.XML_element[i] == "ChannelWidthEQd" and (

167 Datavalue != "" and Datavalue is not None

168 ):

169 self.ChannelWidthEQd.append(Datavalue)

170 rootValue.remove(element)

171

172 if self.XML_element[i] == "ChannelWidthEQe" and (

173 Datavalue == "" or Datavalue is None

174 ):

175 self.ChannelWidthEQe.append("0.5")

176 self.check_ChannelSettings = False

177 rootValue.remove(element)

178 elif self.XML_element[i] == "ChannelWidthEQe" and (

179 Datavalue != "" and Datavalue is not None

180 ):

181 self.ChannelWidthEQe.append(Datavalue)

182 rootValue.remove(element)

183 self.check_ChannelSettings = True

184

185 if self.XML_element[i] == "ChannelWidthMostDownStream" and (

186 Datavalue == "" or Datavalue is None

187 ):

188 self.ChannelWidthMostDownStream.append("400")

189 self.check_ChannelSettings = False

190 rootValue.remove(element)

191 elif self.XML_element[i] == "ChannelWidthMostDownStream" and (

192 Datavalue != "" and Datavalue is not None

193 ):

194 self.ChannelWidthMostDownStream.append(Datavalue)

195 rootValue.remove(element)

196 self.check_ChannelSettings = True

197

198 if self.XML_element[i] == "LowerRegionHeight" and (

199 Datavalue == "" or Datavalue is None

200 ):

201 self.LowerRegionHeight.append("0")

202 self.check_ChannelSettings = False

203 rootValue.remove(element)

204 elif self.XML_element[i] == "LowerRegionHeight" and (

205 Datavalue != "" and Datavalue is not None

206 ):

207 self.LowerRegionHeight.append(Datavalue)

208 rootValue.remove(element)

209 self.check_ChannelSettings = True

210

211 if self.XML_element[i] == "LowerRegionBaseWidth" and (

212 Datavalue == "" or Datavalue is None

213 ):

214 self.LowerRegionBaseWidth.append("0")

215 self.check_ChannelSettings = False

216 rootValue.remove(element)

217 elif self.XML_element[i] == "LowerRegionBaseWidth" and (

218 Datavalue != "" and Datavalue is not None

219 ):

220 self.LowerRegionBaseWidth.append(Datavalue)

221 rootValue.remove(element)

222 self.check_ChannelSettings = True

223

224 if self.XML_element[i] == "UpperRegionBaseWidth" and (

225 Datavalue == "" or Datavalue is None

226 ):

227 self.UpperRegionBaseWidth.append("0")

228 self.check_ChannelSettings = False

229 rootValue.remove(element)

230 elif self.XML_element[i] == "UpperRegionBaseWidth" and (

231 Datavalue != "" and Datavalue is not None

232 ):

233 self.UpperRegionBaseWidth.append(Datavalue)

234 rootValue.remove(element)

235 self.check_ChannelSettings = True

236

237 if self.XML_element[i] == "CompoundCSChannelWidthLimit" and (

238 Datavalue == "" or Datavalue is None

239 ):

240 self.CompoundCSChannelWidthLimit.append("0")

241 self.check_ChannelSettings = False

242 rootValue.remove(element)

243 elif self.XML_element[i] == "CompoundCSChannelWidthLimit" and (

244 Datavalue != "" and Datavalue is not None

245 ):

246 self.CompoundCSChannelWidthLimit.append(Datavalue)

247 rootValue.remove(element)

248 self.check_ChannelSettings = True

249

250 if self.XML_element[i] == "BankSideSlopeRight" and (

251 Datavalue == "" or Datavalue is None

252 ):

253 self.BankSideSlopeRight.append("1.5")

254 self.check_ChannelSettings = False

255 rootValue.remove(element)

256 elif self.XML_element[i] == "BankSideSlopeRight" and (

257 Datavalue != "" and Datavalue is not None

258 ):

259 self.BankSideSlopeRight.append(Datavalue)

260 rootValue.remove(element)

261 self.check_ChannelSettings = True

262

263 if self.XML_element[i] == "BankSideSlopeLeft" and (

264 Datavalue == "" or Datavalue is None

265 ):

266 self.BankSideSlopeLeft.append("1.5")

267 self.check_ChannelSettings = False

268 rootValue.remove(element)

269 elif self.XML_element[i] == "BankSideSlopeLeft" and (

270 Datavalue != "" and Datavalue is not None

271 ):

272 self.BankSideSlopeLeft.append(Datavalue)

273 rootValue.remove(element)

274 self.check_ChannelSettings = True

275 except Exception:

276 pass

277 if self.XML_element[i] == "MakeIMGFile" and (

278 Datavalue == "" or Datavalue is None

279 ):

280 Datavalue = "false"

281 if self.XML_element[i] == "MakeASCFile" and (

282 Datavalue == "" or Datavalue is None

283 ):

284 Datavalue = "false"

285 if self.XML_element[i] == "MakeSoilSaturationDistFile" and (

286 Datavalue == "" or Datavalue is None

287 ):

288 Datavalue = "true"

289 if self.XML_element[i] == "MakeRfDistFile" and (

290 Datavalue == "" or Datavalue is None

291 ):

292 Datavalue = "true"

293 if self.XML_element[i] == "MakeRFaccDistFile" and (

294 Datavalue == "" or Datavalue is None

295 ):

296 Datavalue = "true"

297 if self.XML_element[i] == "MakeFlowDistFile" and (

298 Datavalue == "" or Datavalue is None

299 ):

300 Datavalue = "true"

301 if self.XML_element[i] == "PrintOption" and (

302 Datavalue == "" or Datavalue is None

303 ):

304 Datavalue = "All"

305 if self.XML_element[i] == "PrintAveValue" and (

306 Datavalue == "" or Datavalue is None

307 ):

308 Datavalue = "false"

309 if self.XML_element[i] == "WriteLog" and (

310 Datavalue == "" or Datavalue is None

311 ):

312 Datavalue = "false"

313

314 if self.XML_element[i] == "WatershedFile":

315 rootValue.remove(element)

316 if Datavalue != "" and Datavalue is not None:

317 ET.SubElement(ProjectSettings, "DomainFile").text = Datavalue

318 flag_WatershedFile = False

319 elif self.XML_element[i] == "DomainFile":

320 if flag_WatershedFile:

321 ET.SubElement(

322 ProjectSettings, self.XML_element[i]

323 ).text = Datavalue

324 else:

325 if not (self.XML_element[i] in self.XML_element_remove):

326 ET.SubElement(

327 ProjectSettings, self.XML_element[i]

328 ).text = Datavalue

329

330 self._SubWatershedCount = 0

331 for element in root.findall(

332 "{http://tempuri.org/GRMProject.xsd}SubWatershedSettings"

333 ):

334 SubWatershedSettings = ET.SubElement(GRMProject, "SubWatershedSettings")

335 for i in range(0, len(self.XML_element_SubWatershed)):

336 Datavalue = element.findtext(

337 "{http://tempuri.org/GRMProject.xsd}"

338 + self.XML_element_SubWatershed[i]

339 )

340 if self.XML_element_SubWatershed[i] == "IniSaturation" and (

341 Datavalue == "" or Datavalue is None

342 ):

343 Datavalue = "0.9"

344 elif self.XML_element_SubWatershed[i] == "MinSlopeOF" and (

345 Datavalue == "" or Datavalue is None

346 ):

347 Datavalue = "0.0001"

348 elif self.XML_element_SubWatershed[i] == "MinSlopeChBed" and (

349 Datavalue == "" or Datavalue is None

350 ):

351 Datavalue = "0.0001"

352 elif self.XML_element_SubWatershed[i] == "MinChBaseWidth" and (

353 Datavalue == "" or Datavalue is None

354 ):

355 Datavalue = "00"

356 elif self.XML_element_SubWatershed[i] == "ChRoughness" and (

357 Datavalue == "" or Datavalue is None

358 ):

359 Datavalue = "0.045"

360 elif self.XML_element_SubWatershed[i] == "DryStreamOrder" and (

361 Datavalue == "" or Datavalue is None

362 ):

363 Datavalue = "0"

364 elif self.XML_element_SubWatershed[i] == "IniFlow" and (

365 Datavalue == "" or Datavalue is None

366 ):

367 Datavalue = "0"

368 elif self.XML_element_SubWatershed[i] == "UnsaturatedKType" and (

369 Datavalue == "" or Datavalue is None

370 ):

371 Datavalue = "Linear"

372 elif self.XML_element_SubWatershed[i] == "CoefUnsaturatedK" and (

373 Datavalue == "" or Datavalue is None

374 ):

375 Datavalue = "0.2"

376 elif self.XML_element_SubWatershed[i] == "CalCoefLCRoughness" and (

377 Datavalue == "" or Datavalue is None

378 ):

379 Datavalue = "1"

380 elif self.XML_element_SubWatershed[i] == "CalCoefPorosity" and (

381 Datavalue == "" or Datavalue is None

382 ):

383 Datavalue = "1"

384 elif self.XML_element_SubWatershed[i] == "CalCoefWFSuctionHead" and (

385 Datavalue == "" or Datavalue is None

386 ):

387 Datavalue = "1"

388 elif self.XML_element_SubWatershed[i] == "CalCoefHydraulicK" and (

389 Datavalue == "" or Datavalue is None

390 ):

391 Datavalue = "1"

392 elif self.XML_element_SubWatershed[i] == "CalCoefSoilDepth" and (

393 Datavalue == "" or Datavalue is None

394 ):

395 Datavalue = "1"

396 elif self.XML_element_SubWatershed[i] == "InterceptionMethod" and (

397 Datavalue == "" or Datavalue is None

398 ):

399 Datavalue = "None"

400 elif self.XML_element_SubWatershed[i] == "PETMethod" and (

401 Datavalue == "" or Datavalue is None

402 ):

403 Datavalue = "None"

404 elif self.XML_element_SubWatershed[i] == "ETCoef" and (

405 Datavalue == "" or Datavalue is None

406 ):

407 Datavalue = "1"

408 elif self.XML_element_SubWatershed[i] == "SnowmeltMethod" and (

409 Datavalue == "" or Datavalue is None

410 ):

411 Datavalue = "None"

412 elif self.XML_element_SubWatershed[i] == "TempSnowRain" and (

413 Datavalue == "" or Datavalue is None

414 ):

415 Datavalue = "1"

416 elif self.XML_element_SubWatershed[i] == "SnowmeltingTemp" and (

417 Datavalue == "" or Datavalue is None

418 ):

419 Datavalue = "1"

420 elif self.XML_element_SubWatershed[i] == "SnowCovRatio" and (

421 Datavalue == "" or Datavalue is None

422 ):

423 Datavalue = "1"

424 elif self.XML_element_SubWatershed[i] == "SnowmeltCoef" and (

425 Datavalue == "" or Datavalue is None

426 ):

427 Datavalue = "1"

428 if self.XML_element_SubWatershed[i] == "UserSet" and (

429 Datavalue == "" or Datavalue is None

430 ):

431 Datavalue = "false"

432 ET.SubElement(

433 SubWatershedSettings, self.XML_element_SubWatershed[i]

434 ).text = Datavalue

435 self._SubWatershedCount = self._SubWatershedCount + 1

436

437 self._WatchPointCount = 0

438 for element in root.findall("{http://tempuri.org/GRMProject.xsd}WatchPoints"):

439 WatchPoints = ET.SubElement(GRMProject, "WatchPoints")

440 for i in range(0, len(self.XML_element_WatchPoints)):

441 Datavalue = element.findtext(

442 "{http://tempuri.org/GRMProject.xsd}"

443 + self.XML_element_WatchPoints[i]

444 )

445 if self.XML_element_WatchPoints[i] == "Name" and (

446 Datavalue == "" or Datavalue is None

447 ):

448 Datavalue = ""

449 if self.XML_element_WatchPoints[i] == "ColX" and (

450 Datavalue == "" or Datavalue is None

451 ):

452 Datavalue = ""

453 if self.XML_element_WatchPoints[i] == "RowY" and (

454 Datavalue == "" or Datavalue is None

455 ):

456 Datavalue = ""

457 ET.SubElement(

458 WatchPoints, self.XML_element_WatchPoints[i]

459 ).text = Datavalue

460 self._WatchPointCount = self._WatchPointCount + 1

461

462 self._FlowControlCount = 0

463 for element in root.findall(

464 "{http://tempuri.org/GRMProject.xsd}FlowControlGrid"

465 ):

466 FlowControlGrid = ET.SubElement(GRMProject, "FlowControlGrid")

467 for i in range(0, len(self.XML_element_FlowControlGrid)):

468 Datavalue = element.findtext(

469 "{http://tempuri.org/GRMProject.xsd}"

470 + self.XML_element_FlowControlGrid[i]

471 )

472 if self.XML_element_FlowControlGrid[i] == "ColX" and (

473 Datavalue == "" or Datavalue is None

474 ):

475 Datavalue = ""

476 if self.XML_element_FlowControlGrid[i] == "RowY" and (

477 Datavalue == "" or Datavalue is None

478 ):

479 Datavalue = ""

480 if self.XML_element_FlowControlGrid[i] == "Name" and (

481 Datavalue == "" or Datavalue is None

482 ):

483 Datavalue = ""

484 if self.XML_element_FlowControlGrid[i] == "ControlType" and (

485 Datavalue == "" or Datavalue is None

486 ):

487 Datavalue = ""

488 if self.XML_element_FlowControlGrid[i] == "DT" and (

489 Datavalue == "" or Datavalue is None

490 ):

491 Datavalue = ""

492 if self.XML_element_FlowControlGrid[i] == "FlowDataFile" and (

493 Datavalue == "" or Datavalue is None

494 ):

495 Datavalue = ""

496 if self.XML_element_FlowControlGrid[i] == "IniStorage" and (

497 Datavalue == "" or Datavalue is None

498 ):

499 Datavalue = ""

500 if self.XML_element_FlowControlGrid[i] == "MaxStorage" and (

501 Datavalue == "" or Datavalue is None

502 ):

503 Datavalue = "0"

504 if self.XML_element_FlowControlGrid[i] == "NormalHighStorage" and (

505 Datavalue == "" or Datavalue is None

506 ):

507 Datavalue = "0"

508 if self.XML_element_FlowControlGrid[i] == "RestrictedStorage" and (

509 Datavalue == "" or Datavalue is None

510 ):

511 Datavalue = "0"

512 if self.XML_element_FlowControlGrid[i] == "RestrictedPeriod_Start" and (

513 Datavalue == "" or Datavalue is None

514 ):

515 Datavalue = "0"

516 if self.XML_element_FlowControlGrid[i] == "RestrictedPeriod_End" and (

517 Datavalue == "" or Datavalue is None

518 ):

519 Datavalue = "0"

520 if self.XML_element_FlowControlGrid[i] == "ROType" and (

521 Datavalue == "" or Datavalue is None

522 ):

523 Datavalue = ""

524 if self.XML_element_FlowControlGrid[i] == "AutoROMmaxOutflow_CMS" and (

525 Datavalue == "" or Datavalue is None

526 ):

527 Datavalue = ""

528 if self.XML_element_FlowControlGrid[i] == "ROConstQ" and (

529 Datavalue == "" or Datavalue is None

530 ):

531 Datavalue = ""

532 if self.XML_element_FlowControlGrid[i] == "ROConstQDuration" and (

533 Datavalue == "" or Datavalue is None

534 ):

535 Datavalue = ""

536 ET.SubElement(

537 FlowControlGrid, self.XML_element_FlowControlGrid[i]

538 ).text = Datavalue

539 self._FlowControlCount = self._FlowControlCount + 1

540

541 self._GreenAmptCount = 0

542 rootValue = root.findall(

543 "{http://tempuri.org/GRMProject.xsd}GreenAmptParameter"

544 )

545 for element in rootValue:

546 GreenAmptParameter = ET.SubElement(GRMProject, "GreenAmptParameter")

547 for i in range(0, len(self.XML_element_GreenAmptParameter)):

548 Datavalue = element.findtext(

549 "{http://tempuri.org/GRMProject.xsd}"

550 + self.XML_element_GreenAmptParameter[i]

551 )

552 if self.XML_element_GreenAmptParameter[i] == "GridValue" and (

553 Datavalue == "" or Datavalue is None

554 ):

555 Datavalue = ""

556

557 if self.XML_element_GreenAmptParameter[i] == "USERSoil" and (

558 Datavalue == "" or Datavalue is None

559 ):

560 Datavalue = ""

561

562 if self.XML_element_GreenAmptParameter[i] == "GRMCode" and (

563 Datavalue == "" or Datavalue is None

564 ):

565 Datavalue = ""

566

567 # if self.XML_element_GreenAmptParameter[i] == "GRMTextureE":

568 # rootValue.remove(element)

569 # if self.XML_element_GreenAmptParameter[i] == "GRMTextureK" :

570 # rootValue.remove(element)

571

572 if self.XML_element_GreenAmptParameter[i] == "Porosity" and (

573 Datavalue == "" or Datavalue is None

574 ):

575 Datavalue = ""

576

577 if self.XML_element_GreenAmptParameter[i] == "EffectivePorosity" and (

578 Datavalue == "" or Datavalue is None

579 ):

580 Datavalue = ""

581

582 if self.XML_element_GreenAmptParameter[i] == "WFSoilSuctionHead" and (

583 Datavalue == "" or Datavalue is None

584 ):

585 Datavalue = ""

586

587 if self.XML_element_GreenAmptParameter[

588 i

589 ] == "HydraulicConductivity" and (Datavalue == "" or Datavalue is None):

590 Datavalue = ""

591

592 ET.SubElement(

593 GreenAmptParameter, self.XML_element_GreenAmptParameter[i]

594 ).text = Datavalue

595 self._GreenAmptCount = self._GreenAmptCount + 1

596

597 self._SoilDepthCount = 0

598 rootValue = root.findall("{http://tempuri.org/GRMProject.xsd}SoilDepth")

599

600 for element in rootValue:

601 SoilDepth = ET.SubElement(GRMProject, "SoilDepth")

602 for i in range(0, len(self.XML_element_SoilDepth)):

603 Datavalue = element.findtext(

604 "{http://tempuri.org/GRMProject.xsd}"

605 + self.XML_element_SoilDepth[i]

606 )

607 if self.XML_element_SoilDepth[i] == "GridValue" and (

608 Datavalue == "" or Datavalue is None

609 ):

610 Datavalue = ""

611

612 if self.XML_element_SoilDepth[i] == "UserDepthClass" and (

613 Datavalue == "" or Datavalue is None

614 ):

615 Datavalue = ""

616

617 if self.XML_element_SoilDepth[i] == "GRMCode" and (

618 Datavalue == "" or Datavalue is None

619 ):

620 Datavalue = ""

621

622 # if self.XML_element_SoilDepth[i] == "SoilDepthClassE":

623 # rootValue.remove(element)

624 # if self.XML_element_SoilDepth[i] == "SoilDepthClassK":

625 # rootValue.remove(element)

626

627 if self.XML_element_SoilDepth[i] == "SoilDepth":

628 if Datavalue != "" and Datavalue is not None:

629 ET.SubElement(SoilDepth, "SoilDepth_cm").text = Datavalue

630 flag_soildepth = False

631 else:

632 flag_soildepth = True

633

634 elif self.XML_element_SoilDepth[i] == "SoilDepth_cm":

635 if flag_soildepth:

636 ET.SubElement(

637 SoilDepth, self.XML_element_SoilDepth[i]

638 ).text = Datavalue

639 else:

640 ET.SubElement(

641 SoilDepth, self.XML_element_SoilDepth[i]

642 ).text = Datavalue

643

644 # if self.XML_element_SoilDepth[i] == "SoilDepth_cm" :

645 # if Datavalue == "" or Datavalue is None:

646 # Datavalue = ""

647 # ET.SubElement(SoilDepth, "SoilDepth_cm").text = Datavalue

648 # elif self.XML_element_SoilDepth[i] == "SoilDepth_cm":

649 # if Datavalue == "" or Datavalue is None:

650 # Datavalue = ""

651 # ET.SubElement(SoilDepth, "SoilDepth_cm").text = Datavalue

652

653 # ET.SubElement(SoilDepth, self.XML_element_SoilDepth[i]).text = Datavalue

654 self._SoilDepthCount = self._SoilDepthCount + 1

655

656 self._LandCoverCount = 0

657 rootValue = root.findall("{http://tempuri.org/GRMProject.xsd}LandCover")

658 for element in rootValue:

659 LandCover = ET.SubElement(GRMProject, "LandCover")

660 for i in range(0, len(self.XML_element_LandCover)):

661 Datavalue = element.findtext(

662 "{http://tempuri.org/GRMProject.xsd}"

663 + self.XML_element_LandCover[i]

664 )

665 if self.XML_element_LandCover[i] == "GridValue" and (

666 Datavalue == "" or Datavalue is None

667 ):

668 Datavalue = ""

669

670 if self.XML_element_LandCover[i] == "UserLandCover" and (

671 Datavalue == "" or Datavalue is None

672 ):

673 Datavalue = ""

674

675 if self.XML_element_LandCover[i] == "GRMCode" and (

676 Datavalue == "" or Datavalue is None

677 ):

678 Datavalue = ""

679

680 # if self.XML_element_LandCover[i] == "GRMLandCoverE" :

681 # rootValue.remove(element)

682 # if self.XML_element_LandCover[i] == "GRMLandCoverK":

683 # rootValue.remove(element)

684

685 if self.XML_element_LandCover[i] == "RoughnessCoefficient" and (

686 Datavalue == "" or Datavalue is None

687 ):

688 Datavalue = ""

689

690 if self.XML_element_LandCover[i] == "ImperviousRatio" and (

691 Datavalue == "" or Datavalue is None

692 ):

693 Datavalue = ""

694

695 if self.XML_element_LandCover[i] == "CanopyRatio" and (

696 Datavalue == "" or Datavalue is None

697 ):

698 Datavalue = ""

699

700 if self.XML_element_LandCover[

701 i

702 ] == "InterceptionMaxWaterCanopy_mm" and (

703 Datavalue == "" or Datavalue is None

704 ):

705 Datavalue = ""

706

707 ET.SubElement(LandCover, self.XML_element_LandCover[i]).text = Datavalue

708 self._LandCoverCount = self._LandCoverCount + 1

709

710 self._ChannelSettingsCount = 0

711 # 2020-06-03 박: 오래된 GMP 파일이면 분리해서 새로 생성 함

712 Channel_Count = len(

713 root.findall("{http://tempuri.org/GRMProject.xsd}ChannelSettings")

714 )

715

716 if Channel_Count > 0:

717 for element in root.findall(

718 "{http://tempuri.org/GRMProject.xsd}ChannelSettings"

719 ):

720 ChannelSettings = ET.SubElement(GRMProject, "ChannelSettings")

721 for i in range(0, len(self.XML_element_ChannelSettings)):

722 Datavalue = element.findtext(

723 "{http://tempuri.org/GRMProject.xsd}"

724 + self.XML_element_ChannelSettings[i]

725 )

726 if self.XML_element_ChannelSettings[i] == "WSID" and (

727 Datavalue == "" or Datavalue is None

728 ):

729 Datavalue = ""

730 if self.XML_element_ChannelSettings[i] == "CrossSectionType" and (

731 Datavalue == "" or Datavalue is None

732 ):

733 Datavalue = "CSSingle"

734 if self.XML_element_ChannelSettings[

735 i

736 ] == "SingleCSChannelWidthType" and (

737 Datavalue == "" or Datavalue is None

738 ):

739 Datavalue = "CWGeneration"

740 if self.XML_element_ChannelSettings[i] == "ChannelWidthEQc" and (

741 Datavalue == "" or Datavalue is None

742 ):

743 Datavalue = "1.698"

744 if self.XML_element_ChannelSettings[i] == "ChannelWidthEQd" and (

745 Datavalue == "" or Datavalue is None

746 ):

747 Datavalue = "0.318"

748 if self.XML_element_ChannelSettings[i] == "ChannelWidthEQe" and (

749 Datavalue == "" or Datavalue is None

750 ):

751 Datavalue = "0.5"

752 if self.XML_element_ChannelSettings[

753 i

754 ] == "ChannelWidthMostDownStream" and (

755 Datavalue == "" or Datavalue is None

756 ):

757 Datavalue = "400"

758 if self.XML_element_ChannelSettings[i] == "LowerRegionHeight" and (

759 Datavalue == "" or Datavalue is None

760 ):

761 Datavalue = "0"

762 if self.XML_element_ChannelSettings[

763 i

764 ] == "LowerRegionBaseWidth" and (

765 Datavalue == "" or Datavalue is None

766 ):

767 Datavalue = "0"

768 if self.XML_element_ChannelSettings[

769 i

770 ] == "UpperRegionBaseWidth" and (

771 Datavalue == "" or Datavalue is None

772 ):

773 Datavalue = "0"

774 if self.XML_element_ChannelSettings[

775 i

776 ] == "CompoundCSChannelWidthLimit" and (

777 Datavalue == "" or Datavalue is None

778 ):

779 Datavalue = "0"

780 if self.XML_element_ChannelSettings[i] == "BankSideSlopeRight" and (

781 Datavalue == "" or Datavalue is None

782 ):

783 Datavalue = "1.5"

784 if self.XML_element_ChannelSettings[i] == "BankSideSlopeLeft" and (

785 Datavalue == "" or Datavalue is None

786 ):

787 Datavalue = "1.5"

788 ET.SubElement(

789 ChannelSettings, self.XML_element_ChannelSettings[i]

790 ).text = Datavalue

791 self._ChannelSettingsCount = self._ChannelSettingsCount + 1

792

793 # 2020-07-15 박: 기본 값이 없을때도 생성됨 기본값은 있어서는 안됨

794 elif Channel_Count == 0:

795 if self.check_ChannelSettings:

796 ChannelSettings = ET.SubElement(GRMProject, "ChannelSettings")

797 for i in range(0, len(self.XML_element_ChannelSettings)):

798 if self.XML_element_ChannelSettings[i] == "WSID":

799 Datavalue = "1"

800

801 if self.XML_element_ChannelSettings[i] == "CrossSectionType":

802 Datavalue = self.CrossSectionType[0]

803

804 if (

805 self.XML_element_ChannelSettings[i]

806 == "SingleCSChannelWidthType"

807 ):

808 Datavalue = self.SingleCSChannelWidthType[0]

809

810 if self.XML_element_ChannelSettings[i] == "ChannelWidthEQc":

811 Datavalue = self.ChannelWidthEQc[0]

812

813 if self.XML_element_ChannelSettings[i] == "ChannelWidthEQd":

814 Datavalue = self.ChannelWidthEQd[0]

815

816 if self.XML_element_ChannelSettings[i] == "ChannelWidthEQe":

817 Datavalue = self.ChannelWidthEQe[0]

818

819 if (

820 self.XML_element_ChannelSettings[i]

821 == "ChannelWidthMostDownStream"

822 ):

823 Datavalue = self.ChannelWidthMostDownStream[0]

824

825 if self.XML_element_ChannelSettings[i] == "LowerRegionHeight":

826 Datavalue = self.LowerRegionHeight[0]

827

828 if self.XML_element_ChannelSettings[i] == "LowerRegionBaseWidth":

829 Datavalue = self.LowerRegionBaseWidth[0]

830

831 if self.XML_element_ChannelSettings[i] == "UpperRegionBaseWidth":

832 Datavalue = self.UpperRegionBaseWidth[0]

833

834 if (

835 self.XML_element_ChannelSettings[i]

836 == "CompoundCSChannelWidthLimit"

837 ):

838 Datavalue = self.CompoundCSChannelWidthLimit[0]

839

840 if self.XML_element_ChannelSettings[i] == "BankSideSlopeRight":

841 Datavalue = self.BankSideSlopeRight[0]

842

843 if self.XML_element_ChannelSettings[i] == "BankSideSlopeLeft":

844 Datavalue = self.BankSideSlopeLeft[0]

845

846 ET.SubElement(

847 ChannelSettings, self.XML_element_ChannelSettings[i]

848 ).text = Datavalue

849 self._ChannelSettingsCount = self._ChannelSettingsCount + 1

850

851 # ET.ElementTree(GRMProject).write(self.ProjectFile, encoding="utf-8", xml_declaration=True)

852 # self.indent(self.ProjectFile)

853

854 root = ET.ElementTree(GRMProject).getroot()

855 indent(root)

856 ET.ElementTree(GRMProject).write(

857 self.ProjectFile, encoding="utf-8", xml_declaration=True

858 )

859

860 # def indent(self,Pro_path):

861 # arg=GetScriptDirectory_Path()+ "/ReWriteXML/ReadAndWriteXML.exe " + Pro_path

862 # callExecute(arg)

863

864 def Set_XML_element(self):

865 self.XML_element = []

866

867 self.XML_element.append("ProjectFile")

868 self.XML_element.append("GRMSimulationType")

869 self.XML_element.append("WatershedFile")

870 self.XML_element.append("DomainFile")

871 self.XML_element.append("SlopeFile")

872 self.XML_element.append("FlowDirectionFile")

873 self.XML_element.append("FlowAccumFile")

874 self.XML_element.append("StreamFile")

875 self.XML_element.append("ChannelWidthFile")

876 self.XML_element.append("InitialSoilSaturationRatioFile")

877 self.XML_element.append("LandCoverDataType")

878 self.XML_element.append("LandCoverFile")

879 self.XML_element.append("LandCoverVATFile")

880 self.XML_element.append("ConstantRoughnessCoeff")

881 self.XML_element.append("ConstantImperviousRatio")

882 self.XML_element.append("LAIFile")

883 self.XML_element.append("BlaneyCriddleCoefDataFile")

884 self.XML_element.append("SoilTextureDataType")

885 self.XML_element.append("SoilTextureFile")

886 self.XML_element.append("SoilTextureVATFile")

887 self.XML_element.append("ConstantSoilPorosity")

888 self.XML_element.append("ConstantSoilEffPorosity")

889 self.XML_element.append("ConstantSoilWettingFrontSuctionHead")

890 self.XML_element.append("ConstantSoilHydraulicConductivity")

891 self.XML_element.append("SoilDepthDataType")

892 self.XML_element.append("SoilDepthFile")

893 self.XML_element.append("SoilDepthVATFile")

894 self.XML_element.append("ConstantSoilDepth")

895 self.XML_element.append("InitialChannelFlowFile")

896 self.XML_element.append("PrecipitationDataFile")

897 self.XML_element.append("PrecipitationInterval_min")

898 self.XML_element.append("TemperatureMaxDataFile")

899 self.XML_element.append("TemperatureMaxInterval_min")

900 self.XML_element.append("TemperatureMinDataFile")

901 self.XML_element.append("TemperatureMinInterval_min")

902 self.XML_element.append("DaytimeLengthDataFile")

903 self.XML_element.append("DaytimeLengthInterval_min")

904 self.XML_element.append("DaytimeHoursRatioDataFile")

905 self.XML_element.append("SolarRadiationDataFile")

906 self.XML_element.append("SolarRadiationInterval_min")

907 self.XML_element.append("SnowPackTemperatureDataFile")

908 self.XML_element.append("SnowPackTemperatureInInterval_min")

909 self.XML_element.append("FlowDirectionType")

910 # self.XML_element.append('IsParallel')

911 self.XML_element.append("MaxDegreeOfParallelism")

912 self.XML_element.append("SimulationStartingTime")

913 self.XML_element.append("ComputationalTimeStep")

914 self.XML_element.append("IsFixedTimeStep")

915 self.XML_element.append("SimulationDuration")

916 self.XML_element.append("OutputTimeStep")

917 self.XML_element.append("SimulateInfiltration")

918 self.XML_element.append("SimulateSubsurfaceFlow")

919 self.XML_element.append("SimulateBaseFlow")

920 self.XML_element.append("SimulateInterception")

921 self.XML_element.append("SimulateEvapotranspiration")

922 self.XML_element.append("SimulateSnowMelt")

923 self.XML_element.append("SimulateFlowControl")

924

925 # 2020-04-21 박: GMP 파일변경 ChannelSettings로 이동 함

926 # (최하류 유역이 여러개 일수 도 있음)

927 self.XML_element.append("CrossSectionType")

928 self.XML_element.append("SingleCSChannelWidthType")

929 self.XML_element.append("ChannelWidthEQc")

930 self.XML_element.append("ChannelWidthEQd")

931 self.XML_element.append("ChannelWidthEQe")

932 self.XML_element.append("ChannelWidthMostDownStream")

933 self.XML_element.append("LowerRegionHeight")

934 self.XML_element.append("LowerRegionBaseWidth")

935 self.XML_element.append("UpperRegionBaseWidth")

936

937 # 2020-04-21 박: 최박사님과 통화 (필요 없는 항목임 제외)

938 # self.XML_element.append('CompoundCSIniFlowDepth')

939

940 # 2020-04-21 박: GMP 파일변경 ChannelSettings로 이동 함

941 # (최하류 유역이 여러개 일수 도 있음)

942 self.XML_element.append("CompoundCSChannelWidthLimit")

943 self.XML_element.append("BankSideSlopeRight")

944 self.XML_element.append("BankSideSlopeLeft")

945

946 # -----------------------------------------------------

947 self.XML_element_remove.append("CrossSectionType")

948 self.XML_element_remove.append("SingleCSChannelWidthType")

949 self.XML_element_remove.append("ChannelWidthEQc")

950 self.XML_element_remove.append("ChannelWidthEQd")

951 self.XML_element_remove.append("ChannelWidthEQe")

952 self.XML_element_remove.append("ChannelWidthMostDownStream")

953 self.XML_element_remove.append("LowerRegionHeight")

954 self.XML_element_remove.append("LowerRegionBaseWidth")

955 self.XML_element_remove.append("UpperRegionBaseWidth")

956 self.XML_element_remove.append("CompoundCSChannelWidthLimit")

957 self.XML_element_remove.append("BankSideSlopeRight")

958 self.XML_element_remove.append("BankSideSlopeLeft")

959

960 # -----------------------------------------------------

961

962 self.XML_element.append("MakeIMGFile")

963 self.XML_element.append("MakeASCFile")

964 self.XML_element.append("MakeSoilSaturationDistFile")

965 self.XML_element.append("MakeRfDistFile")

966 self.XML_element.append("MakeRFaccDistFile")

967 self.XML_element.append("MakeFlowDistFile")

968 self.XML_element.append("PrintOption")

969 self.XML_element.append("PrintAveValue")

970 self.XML_element.append("AveValueTimeInterval_min")

971 self.XML_element.append("WriteLog")

972 self.XML_element.append("AboutThisProject")

973 self.XML_element.append("AboutWatershed")

974 self.XML_element.append("AboutLandCoverMap")

975 self.XML_element.append("AboutSoilMap")

976 self.XML_element.append("AboutSoilDepthMap")

977 self.XML_element.append("AboutRainfall")

978 # self.XML_element.append('ProjectSavedTime')

979 # self.XML_element.append('ComputerName')

980 # self.XML_element.append('ComputerUserName')

981 # self.XML_element.append('GRMVersion')

982

983 def Set_XML_element_SubWatershed(self):

984 self.XML_element_SubWatershed = []

985 self.XML_element_SubWatershed.append("ID")

986 self.XML_element_SubWatershed.append("IniSaturation")

987 self.XML_element_SubWatershed.append("MinSlopeOF")

988 self.XML_element_SubWatershed.append("MinSlopeChBed")

989 self.XML_element_SubWatershed.append("MinChBaseWidth")

990 self.XML_element_SubWatershed.append("ChRoughness")

991 self.XML_element_SubWatershed.append("DryStreamOrder")

992 self.XML_element_SubWatershed.append("IniFlow")

993 self.XML_element_SubWatershed.append("UnsaturatedKType")

994 self.XML_element_SubWatershed.append("CoefUnsaturatedK")

995 self.XML_element_SubWatershed.append("CalCoefLCRoughness")

996 self.XML_element_SubWatershed.append("CalCoefPorosity")

997 self.XML_element_SubWatershed.append("CalCoefWFSuctionHead")

998 self.XML_element_SubWatershed.append("CalCoefHydraulicK")

999 self.XML_element_SubWatershed.append("CalCoefSoilDepth")

1000 self.XML_element_SubWatershed.append("InterceptionMethod")

1001 self.XML_element_SubWatershed.append("PETMethod")

1002 self.XML_element_SubWatershed.append("ETCoef")

1003 self.XML_element_SubWatershed.append("SnowmeltMethod")

1004 self.XML_element_SubWatershed.append("TempSnowRain")

1005 self.XML_element_SubWatershed.append("SnowmeltingTemp")

1006 self.XML_element_SubWatershed.append("SnowCovRatio")

1007 self.XML_element_SubWatershed.append("SnowmeltCoef")

1008 self.XML_element_SubWatershed.append("UserSet")

1009

1010 def Set_XML_element_WatchPoints(self):

1011 self.XML_element_WatchPoints = []

1012 self.XML_element_WatchPoints.append("Name")

1013 self.XML_element_WatchPoints.append("ColX")

1014 self.XML_element_WatchPoints.append("RowY")

1015

1016 def Set_XML_element_FlowControlGrid(self):

1017 self.XML_element_FlowControlGrid = []

1018 self.XML_element_FlowControlGrid.append("ColX")

1019 self.XML_element_FlowControlGrid.append("RowY")

1020 self.XML_element_FlowControlGrid.append("Name")

1021 self.XML_element_FlowControlGrid.append("ControlType")

1022 self.XML_element_FlowControlGrid.append("DT")

1023 self.XML_element_FlowControlGrid.append("FlowDataFile")

1024 self.XML_element_FlowControlGrid.append("IniStorage")

1025 self.XML_element_FlowControlGrid.append("MaxStorage")

1026 self.XML_element_FlowControlGrid.append("NormalHighStorage")

1027 self.XML_element_FlowControlGrid.append("RestrictedStorage")

1028 self.XML_element_FlowControlGrid.append("RestrictedPeriod_Start")

1029 self.XML_element_FlowControlGrid.append("RestrictedPeriod_End")

1030 # self.XML_element_FlowControlGrid.append('MaxStorageR')

1031 self.XML_element_FlowControlGrid.append("ROType")

1032 self.XML_element_FlowControlGrid.append("AutoROMmaxOutflow_CMS")

1033 self.XML_element_FlowControlGrid.append("ROConstQ")

1034 self.XML_element_FlowControlGrid.append("ROConstQDuration")

1035

1036 def Set_XML_element_GreenAmptParameter(self):

1037 self.XML_element_GreenAmptParameter = []

1038 self.XML_element_GreenAmptParameter.append("GridValue")

1039 self.XML_element_GreenAmptParameter.append("USERSoil")

1040 self.XML_element_GreenAmptParameter.append("GRMCode")

1041 self.XML_element_GreenAmptParameter.append("Porosity")

1042 self.XML_element_GreenAmptParameter.append("EffectivePorosity")

1043 self.XML_element_GreenAmptParameter.append("WFSoilSuctionHead")

1044 self.XML_element_GreenAmptParameter.append("HydraulicConductivity")

1045

1046 def Set_XML_element_SoilDepth(self):

1047 self.XML_element_SoilDepth = []

1048 self.XML_element_SoilDepth.append("GridValue")

1049 self.XML_element_SoilDepth.append("UserDepthClass")

1050 self.XML_element_SoilDepth.append("GRMCode")

1051 # python 버그??? SoilDepth 상위 태그와 subelement 이름이 같으면 값이 안들어감

1052 # 그래서 이름 다르게 넣고 나중에 Replace

1053 # 2020-05-27 박:오류 수정으로 변경 처리

1054 self.XML_element_SoilDepth.append("SoilDepth")

1055

1056 self.XML_element_SoilDepth.append("SoilDepth_cm")

1057

1058 def Set_XML_element_LandCover(self):

1059 self.XML_element_LandCover = []

1060 self.XML_element_LandCover.append("GridValue")

1061 self.XML_element_LandCover.append("UserLandCover")

1062 self.XML_element_LandCover.append("GRMCode")

1063 self.XML_element_LandCover.append("RoughnessCoefficient")

1064 self.XML_element_LandCover.append("ImperviousRatio")

1065 self.XML_element_LandCover.append("CanopyRatio")

1066 self.XML_element_LandCover.append("InterceptionMaxWaterCanopy_mm")

1067

1068 def Set_XML_element_ChannelSettings(self):

1069 self.XML_element_ChannelSettings = []

1070 self.XML_element_ChannelSettings.append("WSID")

1071 self.XML_element_ChannelSettings.append("CrossSectionType")

1072 self.XML_element_ChannelSettings.append("SingleCSChannelWidthType")

1073 self.XML_element_ChannelSettings.append("ChannelWidthEQc")

1074 self.XML_element_ChannelSettings.append("ChannelWidthEQd")

1075 self.XML_element_ChannelSettings.append("ChannelWidthEQe")

1076 self.XML_element_ChannelSettings.append("ChannelWidthMostDownStream")

1077 self.XML_element_ChannelSettings.append("LowerRegionHeight")

1078 self.XML_element_ChannelSettings.append("LowerRegionBaseWidth")

1079 self.XML_element_ChannelSettings.append("UpperRegionBaseWidth")

1080 self.XML_element_ChannelSettings.append("CompoundCSChannelWidthLimit")

1081 self.XML_element_ChannelSettings.append("BankSideSlopeRight")

1082 self.XML_element_ChannelSettings.append("BankSideSlopeLeft")