Guest User

Untitled

a guest
Feb 20th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. import arcpy
  2. import string
  3. from math import *
  4. from arcpy import *
  5. from arcpy.sa import *
  6. import os
  7. from os import listdir
  8. from os.path import join
  9.  
  10. arcpy.CheckOutExtension("spatial")
  11.  
  12. BP = "H:\NorthSea\Images4AllDates\BPnoEo\"
  13. Eo = "C:\Users\robyn\Desktop\NCEPre2\Watts2Eo\"
  14. output = "C:\Users\robyn\Desktop\FinalPPresults\"
  15. arcpy.env.cellSize = "MINOF"
  16.  
  17. netSW = os.listdir(Eo)
  18. chlKd = os.listdir(BP)
  19.  
  20. for files in netSW and chlKd:
  21. SW = os.path.join(Eo, files)
  22. filenameSW = SW[40:48]
  23. CC = os.path.join(BP, files)
  24. filenameCC = CC[35:43]
  25. if files.endswith(".img"):
  26. if (files in SW[40:48]) == (files in CC[35:43]):
  27. #or if filenameSW == filenameCC:
  28. Output = output + files
  29. BPI = Raster(SW) * Raster(CC)
  30. BPI.save(Output)
  31. print Output + " done"
  32.  
  33. for files in (netSW and chlKd):
  34.  
  35. import arcpy
  36. import string
  37. from math import *
  38. from arcpy import *
  39. from arcpy.sa import *
  40. import os
  41. from os import listdir
  42. from os.path import join
  43. import re
  44.  
  45. arcpy.CheckOutExtension("spatial")
  46. arcpy.env.cellSize = "MINOF"
  47.  
  48. BP = "H:\NorthSea\Images4AllDates\BPnoEo\"
  49. Eo = "C:\Users\robyn\Desktop\NCEPre2\Watts2Eo\"
  50. output = "C:\Users\robyn\Desktop\FinalPPresults\"
  51.  
  52. netSW = os.listdir(Eo)
  53. chlKd = os.listdir(BP)
  54.  
  55. netSW_regex = re.compile("([0-9]{8}).img") # matches 20020101_105433.img
  56. chlKd_regex = re.compile("([0-9]{8})_([0-9]{6}).img") # matches 20020102.img
  57.  
  58. for fileSW in netSW:
  59. for fileCC in chlKd:
  60. SW = os.path.join(Eo, fileSW)
  61. CC = os.path.join(BP, fileCC)
  62.  
  63. netSW_matcher = netSW_regex.match(fileSW)
  64. chlKd_matcher = chlKd_regex.match(fileCC)
  65. if netSW_matcher and chlKd_matcher and netSW_matcher.group(1) == chlKd_matcher.group(1):
  66. print "Multiplying {} and {}".format(fileSW, fileCC)
  67. target_path = os.path.join(result, fileSW)
  68. BPI = Raster(SW) * Raster(CC)
  69. BPI.save(target_path)
  70. print "Done {}".format(target_path)
Add Comment
Please, Sign In to add comment