ccfx 1.0.2__tar.gz → 1.0.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
File without changes
File without changes
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ccfx
3
- Version: 1.0.2
3
+ Version: 1.0.4
4
4
  Summary: This package simplifies regular common actions for quick prototyping in a user friendly way
5
5
  Author-email: Celray James CHAWANDA <celray@chawanda.com>
6
6
  License-Expression: MIT
File without changes
File without changes
@@ -19,6 +19,7 @@ import numpy
19
19
  from genericpath import exists
20
20
  import shutil
21
21
  import platform
22
+ import zipfile
22
23
  import pickle
23
24
  import time
24
25
  from shapely.geometry import box, Point
@@ -238,7 +239,6 @@ def parseYoutubeChannelVideos(channelUrl: str, maxItems: Optional[int] = None) -
238
239
  return [f"https://www.youtube.com/watch?v={e['id']}" for e in entries if e.get("id")]
239
240
 
240
241
 
241
-
242
242
  def runSWATPlus(txtinoutDir: str, finalDir: str, executablePath: str = "swatplus", v: bool = True):
243
243
  os.chdir(txtinoutDir)
244
244
 
@@ -267,6 +267,7 @@ def runSWATPlus(txtinoutDir: str, finalDir: str, executablePath: str = "swatplus
267
267
  day_cycle = []
268
268
  previous_time = None
269
269
 
270
+ counter = 0
270
271
  while True:
271
272
  line = process.stdout.readline()
272
273
  line_parts = str(line).strip().split()
@@ -299,7 +300,7 @@ def runSWATPlus(txtinoutDir: str, finalDir: str, executablePath: str = "swatplus
299
300
  else:
300
301
  eta_str = ''
301
302
 
302
- showProgress(current, number_of_days, bar_length=20, message= f' >> current date: {day}/{month}/{year} - f{yr_to} {eta_str}')
303
+ showProgress(current, number_of_days, barLength=20, message= f' >> current date: {day}/{month}/{year} - {yr_to} {eta_str}')
303
304
 
304
305
  previous_time = datetime.now()
305
306
  elif "ntdll.dll" in line_parts:
@@ -310,13 +311,12 @@ def runSWATPlus(txtinoutDir: str, finalDir: str, executablePath: str = "swatplus
310
311
 
311
312
  if len(line_parts) < 2: break
312
313
 
313
- showProgress(current, number_of_days, string_after= f' ')
314
+ showProgress(current, number_of_days, message = f' ')
314
315
  print("\n")
315
316
 
316
317
  os.chdir(finalDir)
317
318
 
318
319
 
319
-
320
320
  def formatTimedelta(delta: timedelta) -> str:
321
321
  """Formats a timedelta duration to [N days] %H:%M:%S format"""
322
322
  seconds = int(delta.total_seconds())
@@ -763,22 +763,35 @@ def readFrom(filename, decode_codec = None, v=False):
763
763
  return file_text
764
764
 
765
765
 
766
- def pointsToGeodataframe(point_pairs_list, columns = ['latitude', 'longitude'], auth = "EPSG", code = '4326', out_shape = '', format = 'gpkg', v = False, get_geometry_only = False):
767
- df = pandas.DataFrame(point_pairs_list, columns = columns)
768
- geometry = [Point(xy) for xy in zip(df['latitude'], df['longitude'])]
769
-
770
- if get_geometry_only:
771
- return geometry[0]
772
-
773
- gdf = geopandas.GeoDataFrame(point_pairs_list, columns = columns, geometry=geometry)
774
- drivers = {'gpkg': 'GPKG', 'shp': 'ESRI Shapefile'}
766
+ def pointsToGeodataframe(
767
+ rowList,
768
+ columnNames,
769
+ latIndex,
770
+ lonIndex,
771
+ auth = "EPSG",
772
+ code = "4326",
773
+ outShape = "",
774
+ format = "gpkg",
775
+ v = False,
776
+ includeLatLon = True ) -> geopandas.GeoDataFrame:
777
+ df = pandas.DataFrame(rowList, columns = columnNames)
778
+ geometry = [
779
+ Point(row[lonIndex], row[latIndex]) for row in rowList
780
+ ]
781
+
782
+ if not includeLatLon:
783
+ colsToKeep = [col for i, col in enumerate(columnNames) if i not in (latIndex, lonIndex)]
784
+ df = df[colsToKeep]
785
+
786
+ gdf = geopandas.GeoDataFrame(df, geometry = geometry)
787
+ drivers = {"gpkg": "GPKG", "shp": "ESRI Shapefile"}
788
+ gdf = gdf.set_crs(f"{auth}:{code}")
789
+
790
+ if outShape != "":
791
+ if v:
792
+ print(f"creating shapefile {outShape}")
793
+ gdf.to_file(outShape, driver = drivers[format])
775
794
 
776
- gdf = gdf.set_crs(f'{auth}:{code}')
777
-
778
- if out_shape != '':
779
- if v: print(f'creating shapefile {out_shape}')
780
- gdf.to_file(out_shape, driver=drivers[format])
781
-
782
795
  return gdf
783
796
 
784
797
 
@@ -895,16 +908,46 @@ def compressTo7z(input_dir: str, output_file: str, compressionLevel: int = 4, ex
895
908
 
896
909
  def uncompress(inputFile: str, outputDir: str, v: bool = False) -> None:
897
910
  """
898
- Extracts an archive supported by py7zr (.7z, .zip, .tar, .tar.gz, .tar.bz2, .xz, .tar.xz) to outputDir.
911
+ Extracts .7z, .zip, .tar, .tar.gz, .tar.bz2, .xz, .tar.xz archives to outputDir.
899
912
  inputFile: Path to the input archive file
900
913
  outputDir: Directory where the contents will be extracted
901
914
  v: Verbose flag to print extraction status (default is False)
902
915
  """
903
- if not exists(outputDir): createPath(outputDir)
904
- with py7zr.SevenZipFile(inputFile, 'r') as archive: archive.extractall(path=outputDir)
916
+ fileLower = inputFile.lower()
917
+ if not exists(outputDir):
918
+ createPath(outputDir)
919
+
920
+ if fileLower.endswith(".zip"):
921
+ with zipfile.ZipFile(inputFile, 'r') as archive:
922
+ archive.extractall(path=outputDir)
923
+ else:
924
+ with py7zr.SevenZipFile(inputFile, 'r') as archive:
925
+ archive.extractall(path=outputDir)
905
926
  if v: print(f"extracted {inputFile} to {outputDir}.")
906
927
 
907
928
 
929
+ def uncompressFile(inputFile: str, outputDir: str, v: bool = False) -> None:
930
+ """
931
+ This is an alias for uncompress
932
+ """
933
+ uncompress(inputFile, outputDir, v)
934
+
935
+ def unzipFile(inputFile: str, outputDir: str, v: bool = False) -> None:
936
+ """
937
+ this is an alias for uncompress
938
+ """
939
+ uncompress(inputFile, outputDir, v)
940
+
941
+ def extractZip(inputFile: str, outputDir: str, v: bool = False) -> None:
942
+ """this is an alias for uncompress"""
943
+ uncompress(inputFile, outputDir, v)
944
+
945
+ def extractCompressedFile(inputFile: str, outputDir: str, v: bool = False) -> None:
946
+ """
947
+ this is an alias for uncompress
948
+ """
949
+ uncompress(inputFile, outputDir, v)
950
+
908
951
  def moveDirectory(srcDir:str, destDir:str, v:bool = False) -> bool:
909
952
  '''
910
953
  this function moves all files from srcDir to destDir
@@ -1417,14 +1460,14 @@ def copyDirectory(source:str, destination:str, recursive = True, v:bool = True,
1417
1460
  copyFile(s, d, v = False)
1418
1461
  if v: showProgress(counter, itemCount, f'copying {getFileBaseName(item)}\t\t', barLength=50)
1419
1462
  counter += 1
1420
- print()
1463
+ if v:print()
1421
1464
 
1422
1465
 
1423
1466
  def copyFolder(source:str, destination:str, v:bool = True) -> None:
1424
1467
  '''
1425
1468
  this function is an alias for copyDirectory
1426
1469
  '''
1427
- copyDirectory(source, destination, v)
1470
+ copyDirectory(source, destination, v=v)
1428
1471
 
1429
1472
 
1430
1473
  def convertCoordinates(lon, lat, srcEPSG, dstCRS) -> tuple:
@@ -1516,9 +1559,9 @@ def showProgress(count: int, end: int, message: str, barLength: int = 100) -> No
1516
1559
  percentStr = f'{percent:03.1f}'
1517
1560
  filled = int(barLength * count / end)
1518
1561
  bar = '█' * filled + '░' * (barLength - filled)
1519
- print(f'\r{bar}| {percentStr}% [{count}/{end}] | {message} ', end='', flush=True)
1562
+ print(f'\r{bar} {percentStr}% [{count}/{end}] | {message} ', end='', flush=True)
1520
1563
  if count == end:
1521
- print(f'\r{bar}| {percentStr}% [{count}/{end}] ', end='', flush=True)
1564
+ print(f'\r{bar} {percentStr}% [{count}/{end}] ', end='', flush=True)
1522
1565
  print()
1523
1566
 
1524
1567
 
File without changes
File without changes
File without changes
File without changes
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ccfx
3
- Version: 1.0.2
3
+ Version: 1.0.4
4
4
  Summary: This package simplifies regular common actions for quick prototyping in a user friendly way
5
5
  Author-email: Celray James CHAWANDA <celray@chawanda.com>
6
6
  License-Expression: MIT
File without changes
File without changes
File without changes
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "ccfx"
7
- version = "1.0.2"
7
+ version = "1.0.4"
8
8
  description = "This package simplifies regular common actions for quick prototyping in a user friendly way"
9
9
  readme = "README.md"
10
10
  license = "MIT"
File without changes