Best Python code snippet using autotest_python
match_sdr_and_jrrVCM_chnAlbers.py
...11import gc12import arcpy1314# æ ¹æ®è·¯å¾è·åæ件åï¼ä¸å
æ¬å°¾ç¼ï¼ get filename without suffix15def get_filename_without_suffix(inputPath):16 pattern = re.compile(r'([^<>/\\\|:""\*\?]+)\.\w+$')17 data = pattern.findall(inputPath)18 if data:19 return data[0]2021# éåæ件路å¾ï¼è·åæ件å表 Search all tif file, including subfolders22def search_tif_file(inDir):23 tif_fileList = []24 for root, dirs, files in os.walk(inDir, topdown=False):25 for name in files:26 if name.endswith(".tif"):27 tif_fileList.append(os.path.join(root, name))2829 return tif_fileList3031# get time range from file name sting in yyyymmddHHMMSS.S format32def getTimeRangefromVcmStr(fileNameStr):33 fileNameStr = fileNameStr.split("_")34 startTimeStr = fileNameStr[3][1:]35 endTimeStr = fileNameStr[4][1:]3637 startTime = datetime.datetime.strptime(startTimeStr[:-1], "%Y%m%d%H%M%S")38 startTime_offset = datetime.timedelta(seconds=int(startTimeStr[-1]) * 0.1)39 startTime = startTime + startTime_offset # add seconds40 endTime = datetime.datetime.strptime(endTimeStr[:-1], "%Y%m%d%H%M%S")41 endTime_offset = datetime.timedelta(seconds=int(endTimeStr[-1]) * 0.1)42 endTime = endTime + endTime_offset4344 del fileNameStr, startTimeStr, endTimeStr, startTime_offset, endTime_offset45 gc.collect()4647 return (startTime, endTime)4849def getTimeRangefromSdrStr(fileNameStr):50 fileNameStr = fileNameStr.split("_")51 fileDateStr = fileNameStr[2][1:]52 startTimeStr = fileNameStr[3][1:]53 endTimeStr = fileNameStr[4][1:]5455 # fileDate = datetime.datetime.strptime(fileDateStr, "%Y%m%d")56 startTime = datetime.datetime.strptime(fileDateStr + startTimeStr[:-1], "%Y%m%d%H%M%S")57 startTime_offset = datetime.timedelta(seconds=int(startTimeStr[-1]) * 0.1)58 startTime = startTime + startTime_offset # add seconds59 endTime = datetime.datetime.strptime(fileDateStr + endTimeStr[:-1], "%Y%m%d%H%M%S")60 endTime_offset = datetime.timedelta(seconds=int(endTimeStr[-1]) * 0.1)61 endTime = endTime + endTime_offset6263 del fileNameStr, startTimeStr, endTimeStr, startTime_offset, endTime_offset, fileDateStr64 gc.collect()6566 return (startTime, endTime)6768# judge the inTime in the range of specific time69def inTimeRange(inTime, timeRange):70 """71 :param inTime: datetime in yyyymmddHHMMSS.S format72 :param timeRange: tuple of datetime in yyyymmddHHMMSS.S format73 :return:74 """75 if timeRange[0] <= inTime <= timeRange[1]:76 return True77 else:78 return False7980def match_sdr_vcm(inSDR_Dir, inVCM_Dir, outMosaicVcm_Dir):81 sdrTif_list = search_tif_file(inSDR_Dir)82 vcmTif_list = search_tif_file(inVCM_Dir)8384 # iter sdr tif85 for sdrTif_path in sdrTif_list:86 sdrTif_Name = get_filename_without_suffix(sdrTif_path)87 sdr_TimeRange = getTimeRangefromSdrStr(sdrTif_Name)88 tmp_vcmList = ""8990 for vcmTif_path in vcmTif_list:91 vcmTif_Name = get_filename_without_suffix(vcmTif_path)92 vcm_TimeRange = getTimeRangefromVcmStr(vcmTif_Name)9394 if inTimeRange(vcm_TimeRange[0], sdr_TimeRange) & inTimeRange(vcm_TimeRange[1], sdr_TimeRange):95 tmp_vcmList = tmp_vcmList + vcmTif_path + ";"9697 outMosaicVcmName = sdrTif_Name + "_CM.tif"98 arcpy.MosaicToNewRaster_management(input_rasters=tmp_vcmList, output_location=outMosaicVcm_Dir,99 raster_dataset_name_with_extension=outMosaicVcmName, pixel_type="8_BIT_UNSIGNED",100 number_of_bands=1, mosaic_method="MINIMUM", mosaic_colormap_mode="FIRST") # cellsize=750,101 print (sdrTif_Name + " processed.")102 print ("All done.")103104if __name__ == "__main__":105 inSdrDir = r"F:\Data\US_Hurricane\SDR\SDR_2020_Geotiff" # sdr geotiffæå¨æ件夹
...
use_jrrVCM_maskSDR_chnAlbers.py
Source: use_jrrVCM_maskSDR_chnAlbers.py
...13# Check out the ArcGIS Spatial Analyst extension license14arcpy.CheckOutExtension("Spatial")1516# get filename without suffix from absolute path17def get_filename_without_suffix(inputPath):18 pattern = re.compile(r'([^<>/\\\|:""\*\?]+)\.\w+$')19 data = pattern.findall(inputPath)20 if data:21 return data[0]2223# Search all tif file, including subfolders24def search_tif_file(inDir):25 tif_fileList = []26 for root, dirs, files in os.walk(inDir, topdown=False):27 for name in files:28 if name.endswith(".tif"):29 tif_fileList.append(os.path.join(root, name))3031 return tif_fileList3233def maskCloud(inSDRTif_Dir, inVCMTif_Dir, outDir):34 sdrTif_List = search_tif_file(inSDRTif_Dir)35 vcmTif_List = search_tif_file(inVCMTif_Dir)3637 for sdrTif_path in sdrTif_List:38 sdrName = get_filename_without_suffix(sdrTif_path)39 sdrNames = sdrName.split("_")40 sdrIdentityName = sdrNames[2] + "_" + sdrNames[3] + "_" + sdrNames[4] + "_" + sdrNames[5]41 for vcmTif_path in vcmTif_List:42 if sdrIdentityName in vcmTif_path:43 vcmRaster = arcpy.Raster(vcmTif_path)44 outSetNull = arcpy.sa.SetNull(vcmRaster != 0, 1) # outSetNull = arcpy.sa.SetNull(vcmRaster != 0, vcmRaster)45 # outPath = outDir + "\\" + sdrName + "_CM_Setnull.tif"46 # outSetNull.save(outPath)47 sdrRaster = arcpy.Raster(sdrTif_path)48 outExtractByMask = sdrRaster * outSetNull49 # outExtractByMask = arcpy.sa.ExtractByMask(sdrRaster, outSetNull)50 del outSetNull, sdrRaster, vcmRaster51 gc.collect()52
...
test_path.py
Source: test_path.py
...7 assert path.get_parent("/a/b/c") == "/a/b"8def test_get_filename():9 assert path.get_filename("/a/b/c/d.txt") == "d.txt"10 assert path.get_filename("/a/b/c/d.tar.gz") == "d.tar.gz"11def test_get_filename_without_suffix():12 assert path.get_filename_without_suffix("/a/b/c/d.txt") == "d"13 assert path.get_filename_without_suffix("/a/b/c/d.tar.gz") == "d"14def test_get_suffix():15 assert path.get_suffix("/a/b/c/d.txt") == ".txt"16 assert path.get_suffix("/a/b/c/d.tar.gz") == ".tar.gz"17def test_path_to_uri():18 assert path.path_to_uri("/a/b/c/d.txt") == "file:///a/b/c/d.txt"19def test_is_absolute():20 assert path.is_absolute("/a/b/c/d.txt") == True21 assert path.is_absolute("a/b/c/d.txt") == False22def test_is_exists():23 assert path.is_exists("test/util/test_path.py") == True24 assert path.is_exists("/a/b/c/d.txt") == False25def test_is_dir():26 assert path.is_dir("test/util") == True27 assert path.is_dir("/a/b/c/d.txt") == False...
Check out the latest blogs from LambdaTest on this topic:
Before we discuss Scala testing, let us understand the fundamentals of Scala and how this programming language is a preferred choice for your development requirements.The popularity and usage of Scala are rapidly rising, evident by the ever-increasing open positions for Scala developers.
So, now that the first installment of this two fold article has been published (hence you might have an idea of what Agile Testing is not in my opinion), I’ve started feeling the pressure to explain what Agile Testing actually means to me.
Did you know that according to Statista, the number of smartphone users will reach 18.22 billion by 2025? Let’s face it, digital transformation is skyrocketing and will continue to do so. This swamps the mobile app development market with various options and gives rise to the need for the best mobile app testing tools
As a developer, checking the cross browser compatibility of your CSS properties is of utmost importance when building your website. I have often found myself excited to use a CSS feature only to discover that it’s still not supported on all browsers. Even if it is supported, the feature might be experimental and not work consistently across all browsers. Ask any front-end developer about using a CSS feature whose support is still in the experimental phase in most prominent web browsers. ????
The count of mobile users is on a steep rise. According to the research, by 2025, it is expected to reach 7.49 billion users worldwide. 70% of all US digital media time comes from mobile apps, and to your surprise, the average smartphone owner uses ten apps per day and 30 apps each month.
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!