rastr 0.1.0__py3-none-any.whl → 0.2.0__py3-none-any.whl

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.

Potentially problematic release.


This version of rastr might be problematic. Click here for more details.

rastr/_version.py CHANGED
@@ -17,5 +17,5 @@ __version__: str
17
17
  __version_tuple__: VERSION_TUPLE
18
18
  version_tuple: VERSION_TUPLE
19
19
 
20
- __version__ = version = '0.1.0'
21
- __version_tuple__ = version_tuple = (0, 1, 0)
20
+ __version__ = version = '0.2.0'
21
+ __version_tuple__ = version_tuple = (0, 2, 0)
rastr/io.py CHANGED
@@ -9,7 +9,7 @@ from rastr.meta import RasterMeta
9
9
  from rastr.raster import RasterModel
10
10
 
11
11
 
12
- def read_raster_inmem(raster_path: Path, crs: CRS | None = None) -> RasterModel:
12
+ def read_raster_inmem(raster_path: Path | str, crs: CRS | None = None) -> RasterModel:
13
13
  """Read raster data from a file and return an in-memory Raster object."""
14
14
  with rasterio.open(raster_path, mode="r") as dst:
15
15
  # Read the entire array
rastr/meta.py CHANGED
@@ -11,6 +11,8 @@ class RasterMeta(BaseModel, extra="forbid"):
11
11
  Attributes:
12
12
  cell_size: Cell size in meters.
13
13
  crs: Coordinate reference system.
14
+ transform: The affine transformation associated with the raster. This is based
15
+ on the CRS, the cell size, as well as the offset/origin.
14
16
  """
15
17
 
16
18
  cell_size: float
rastr/raster.py CHANGED
@@ -74,9 +74,10 @@ class RasterModel(BaseModel):
74
74
  __hash__ = BaseModel.__hash__
75
75
 
76
76
  def __add__(self, other: float | Self) -> Self:
77
+ cls = self.__class__
77
78
  if isinstance(other, float | int):
78
79
  new_arr = self.arr + other
79
- return RasterModel(arr=new_arr, raster_meta=self.raster_meta)
80
+ return cls(arr=new_arr, raster_meta=self.raster_meta)
80
81
  elif isinstance(other, RasterModel):
81
82
  if self.raster_meta != other.raster_meta:
82
83
  msg = (
@@ -91,7 +92,7 @@ class RasterModel(BaseModel):
91
92
  )
92
93
  raise ValueError(msg)
93
94
  new_arr = self.arr + other.arr
94
- return RasterModel(arr=new_arr, raster_meta=self.raster_meta)
95
+ return cls(arr=new_arr, raster_meta=self.raster_meta)
95
96
  else:
96
97
  return NotImplemented
97
98
 
@@ -99,9 +100,10 @@ class RasterModel(BaseModel):
99
100
  return self + other
100
101
 
101
102
  def __mul__(self, other: float | Self) -> Self:
103
+ cls = self.__class__
102
104
  if isinstance(other, float | int):
103
105
  new_arr = self.arr * other
104
- return RasterModel(arr=new_arr, raster_meta=self.raster_meta)
106
+ return cls(arr=new_arr, raster_meta=self.raster_meta)
105
107
  elif isinstance(other, RasterModel):
106
108
  if self.raster_meta != other.raster_meta:
107
109
  msg = (
@@ -113,7 +115,7 @@ class RasterModel(BaseModel):
113
115
  msg = "Rasters must have the same shape to be multiplied"
114
116
  raise ValueError(msg)
115
117
  new_arr = self.arr * other.arr
116
- return RasterModel(arr=new_arr, raster_meta=self.raster_meta)
118
+ return cls(arr=new_arr, raster_meta=self.raster_meta)
117
119
  else:
118
120
  return NotImplemented
119
121
 
@@ -121,9 +123,10 @@ class RasterModel(BaseModel):
121
123
  return self * other
122
124
 
123
125
  def __truediv__(self, other: float | Self) -> Self:
126
+ cls = self.__class__
124
127
  if isinstance(other, float | int):
125
128
  new_arr = self.arr / other
126
- return RasterModel(arr=new_arr, raster_meta=self.raster_meta)
129
+ return cls(arr=new_arr, raster_meta=self.raster_meta)
127
130
  elif isinstance(other, RasterModel):
128
131
  if self.raster_meta != other.raster_meta:
129
132
  msg = (
@@ -135,7 +138,7 @@ class RasterModel(BaseModel):
135
138
  msg = "Rasters must have the same shape to be divided"
136
139
  raise ValueError(msg)
137
140
  new_arr = self.arr / other.arr
138
- return RasterModel(arr=new_arr, raster_meta=self.raster_meta)
141
+ return cls(arr=new_arr, raster_meta=self.raster_meta)
139
142
  else:
140
143
  return NotImplemented
141
144
 
@@ -149,7 +152,8 @@ class RasterModel(BaseModel):
149
152
  return -self + other
150
153
 
151
154
  def __neg__(self) -> Self:
152
- return RasterModel(arr=-self.arr, raster_meta=self.raster_meta)
155
+ cls = self.__class__
156
+ return cls(arr=-self.arr, raster_meta=self.raster_meta)
153
157
 
154
158
  @property
155
159
  def cell_centre_coords(self) -> NDArray[np.float64]:
@@ -422,9 +426,11 @@ class RasterModel(BaseModel):
422
426
 
423
427
  return raster_gdf
424
428
 
425
- def to_file(self, path: Path) -> None:
429
+ def to_file(self, path: Path | str) -> None:
426
430
  """Write the raster to a GeoTIFF file."""
427
431
 
432
+ path = Path(path)
433
+
428
434
  suffix = path.suffix.lower()
429
435
  if suffix in (".tif", ".tiff"):
430
436
  driver = "GTiff"
@@ -455,8 +461,9 @@ class RasterModel(BaseModel):
455
461
  raise OSError(msg) from err
456
462
 
457
463
  def __str__(self) -> str:
464
+ cls = self.__class__
458
465
  mean = np.nanmean(self.arr)
459
- return f"RasterModel(shape={self.arr.shape}, {mean=})"
466
+ return f"{cls.__name__}(shape={self.arr.shape}, {mean=})"
460
467
 
461
468
  def __repr__(self) -> str:
462
469
  return str(self)
@@ -619,6 +626,7 @@ class RasterModel(BaseModel):
619
626
 
620
627
  factor = self.raster_meta.cell_size / new_cell_size
621
628
 
629
+ cls = self.__class__
622
630
  # Use the rasterio dataset with proper context management
623
631
  with self.to_rasterio_dataset() as dataset:
624
632
  # N.B. the new height and width may increase slightly.
@@ -642,7 +650,7 @@ class RasterModel(BaseModel):
642
650
  cell_size=new_cell_size,
643
651
  )
644
652
 
645
- return RasterModel(arr=new_arr, raster_meta=new_raster_meta)
653
+ return cls(arr=new_arr, raster_meta=new_raster_meta)
646
654
 
647
655
  @field_validator("arr")
648
656
  @classmethod
@@ -1,12 +1,12 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rastr
3
- Version: 0.1.0
3
+ Version: 0.2.0
4
4
  Summary: Geospatial Raster datatype library for Python.
5
5
  Project-URL: Source Code, https://github.com/tonkintaylor/rastr
6
6
  Project-URL: Bug Tracker, https://github.com/tonkintaylor/rastr/issues
7
7
  Project-URL: Releases, https://github.com/tonkintaylor/rastr/releases
8
- Project-URL: Source Archive, https://github.com/tonkintaylor/rastr/archive/ac9cfaefef4030485d30ce79b97a000821338bd2.zip
9
- Author-email: Tonkin & Taylor Limited <Sub-DisciplineData+AnalyticsStaff@tonkintaylor.co.nz>, Nathan McDougall <nmcdougall@tonkintaylor.co.nz>
8
+ Project-URL: Source Archive, https://github.com/tonkintaylor/rastr/archive/551d36604b84f947fffbe328e9e877732c9e35fb.zip
9
+ Author-email: Tonkin & Taylor Limited <Sub-DisciplineData+AnalyticsStaff@tonkintaylor.co.nz>, Nathan McDougall <nmcdougall@tonkintaylor.co.nz>, Ben Karl <bkarl@tonkintaylor.co.nz>
10
10
  License-Expression: MIT
11
11
  License-File: LICENSE
12
12
  Classifier: Programming Language :: Python :: 3 :: Only
@@ -41,4 +41,4 @@ Description-Content-Type: text/markdown
41
41
 
42
42
  Geospatial Raster datatype library for Python.
43
43
 
44
- Currently, only single-banded rasters with square cells are supported.
44
+ Currently, only single-banded, in-memory rasters with square cells are supported.
@@ -1,15 +1,15 @@
1
1
  rastr/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- rastr/_version.py,sha256=-LyU5F1uZDjn6Q8_Z6-_FJt_8RE4Kq9zcKdg1abSSps,511
2
+ rastr/_version.py,sha256=iB5DfB5V6YB5Wo4JmvS-txT42QtmGaWcWp3udRT7zCI,511
3
3
  rastr/create.py,sha256=tHLVnGarMt04p1z8CVknMWMjQLKrb0WrcP_Wgdw8xr4,9346
4
- rastr/io.py,sha256=GLj2o26L2bLLXys2wTSKk1mM-FRDciOt7Ty7r87gVg4,961
5
- rastr/meta.py,sha256=b_knC8a5qWcAZKm8RrZ7bYTLuOtfGQsIp73JMcq8cU0,1384
6
- rastr/raster.py,sha256=PzmMLJqf6nhYNu81dqLJ9iZpkxOBrn02FtI-5o3meL4,22996
4
+ rastr/io.py,sha256=dKOY5JYQDULg3Si24cysVTZuWoPjftAE8pbxgSoN1tw,967
5
+ rastr/meta.py,sha256=jmDDx3w61ZZ3dQSrMFgaBx0LJxYp42xTm_7uS_s96lg,1547
6
+ rastr/raster.py,sha256=jGk9buG1uKQ3tb3ciI4yhw9JFu7oyXWXMnUBnPjOD54,23142
7
7
  rastr/arr/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
8
  rastr/arr/fill.py,sha256=7N3ECMli7ssNJJk5qgDoj_3xExgu03nohGPgUKWxcCk,903
9
9
  rastr/gis/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
10
  rastr/gis/fishnet.py,sha256=LZqtI9cgYPacuWNfIfdbTkRMRSnJCQdYlaT2eVPmorM,2459
11
11
  rastr/gis/smooth.py,sha256=LbWvAG1O-O5H6P5LrbwD03mbnXVYjkH1re-_iZ4arIU,4754
12
- rastr-0.1.0.dist-info/METADATA,sha256=IKTH8nVmhO3FRMTHWKk0zpdxt5kxw5giusz-7perakI,2143
13
- rastr-0.1.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
14
- rastr-0.1.0.dist-info/licenses/LICENSE,sha256=7qUsx93G2ATTRLZiSYuQofwAX_uWvrqnAiMK8PzxvNc,1080
15
- rastr-0.1.0.dist-info/RECORD,,
12
+ rastr-0.2.0.dist-info/METADATA,sha256=7uUi8aLMaEbxoPfk6go_szv3H_TnDGYGE4RSC_sbUqo,2191
13
+ rastr-0.2.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
14
+ rastr-0.2.0.dist-info/licenses/LICENSE,sha256=7qUsx93G2ATTRLZiSYuQofwAX_uWvrqnAiMK8PzxvNc,1080
15
+ rastr-0.2.0.dist-info/RECORD,,
File without changes