Skip to content

Commit 10b4533

Browse files
committed
apply black formatting
1 parent 16c51a0 commit 10b4533

32 files changed

+360
-366
lines changed

marslab/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.9.14'
1+
__version__ = "0.9.14"

marslab/bandset/bandset.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@
1717
import pandas as pd
1818

1919
from marslab.imgops.debayer import make_bayer, debayer_upsample
20-
from marslab.imgops.imgutils import absolutely_destroy, mapfilter, \
21-
get_all_bands, get_all_bands_from_all
20+
from marslab.imgops.imgutils import (
21+
absolutely_destroy,
22+
mapfilter,
23+
get_all_bands,
24+
get_all_bands_from_all,
25+
)
2226
from marslab.imgops.look import Look, save_plainly
2327
from marslab.poolutils import wait_for_it
2428

@@ -40,7 +44,7 @@ def __init__(
4044
name: str = None,
4145
threads: Mapping = None,
4246
raw: MutableMapping = None,
43-
special_constants: Collection[Any] = None
47+
special_constants: Collection[Any] = None,
4448
):
4549
"""
4650
:param metadata: dataframe containing at least "PATH", "BAND", "IX,
@@ -142,7 +146,8 @@ def load(
142146
results = []
143147
for path, band_df in chunked_by_file:
144148
results.append(
145-
self.load_method(path, band_df, bands, self.precached))
149+
self.load_method(path, band_df, bands, self.precached)
150+
)
146151
log.info("loaded " + path)
147152
else:
148153
results = {}
@@ -295,7 +300,7 @@ def make_look_set(
295300
self,
296301
instructions: Collection[Mapping],
297302
autoload: bool = True,
298-
timeout: Optional[float] = None
303+
timeout: Optional[float] = None,
299304
):
300305
# load images and filter instruction set for unavailable bands
301306
available_instructions = self.prep_look_set(instructions, autoload)
@@ -320,7 +325,7 @@ def make_look_set(
320325
op_images = {
321326
channel: [
322327
self.get_band(band).copy()
323-
for band in instruction['params'][channel]["bands"]
328+
for band in instruction["params"][channel]["bands"]
324329
]
325330
for channel in ("red", "green", "blue")
326331
}
@@ -331,10 +336,10 @@ def make_look_set(
331336
pipeline = Look.compile_from_instruction(
332337
instruction,
333338
metadata=self.metadata,
334-
special_constants=self.special_constants
339+
special_constants=self.special_constants,
335340
)
336341
if "underlay" in instruction.keys():
337-
underlay = instruction['underlay']['band']
342+
underlay = instruction["underlay"]["band"]
338343
if isinstance(underlay, int):
339344
pipeline.add_underlay(op_images[underlay])
340345
else:
@@ -355,7 +360,7 @@ def make_look_set(
355360
log,
356361
message="generated ",
357362
as_dict=True,
358-
timeout=timeout
363+
timeout=timeout,
359364
)
360365
pool.terminate()
361366
self.looks |= look_cache
@@ -438,5 +443,3 @@ def __init__(self, path, load_method=None, **bandset_kwargs):
438443
metadata["BAND"] = self.raw.keys()
439444
metadata["IX"] = self.raw.keys()
440445
metadata["PATH"] = path
441-
442-

marslab/bandset/m3.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def setup_m3_bandset_metadata(file_path):
2929
metadata["IX"] = np.array(range(len(metadata["WAVELENGTH"])))
3030
# 'channel' or 'channel #' in mission nomenclature
3131
metadata["BAND"] = metadata["IX"] + 1
32-
metadata['PATH'] = file_path
32+
metadata["PATH"] = file_path
3333
return metadata
3434

3535

marslab/bandset/mastcam.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def parse_mcam_fn(mcam_fn):
2020
"EYE": filename[5],
2121
"SEQ_ID": f"mcam{int(filename[6:12])}",
2222
"CAL": filename[26:30],
23-
"FILETYPE": filename[22:25]
23+
"FILETYPE": filename[22:25],
2424
}
2525

2626

@@ -50,7 +50,7 @@ def parse_mcam_files(file_paths):
5050
def setup_mcam_bandset_metadata(metadata):
5151
if "FILTER" in metadata.columns:
5252
metadata = metadata.drop(
53-
metadata.loc[metadata.FILTER.isin(('L7', 'R7'))].index
53+
metadata.loc[metadata.FILTER.isin(("L7", "R7"))].index
5454
)
5555
metadata["BAND"] = metadata["FILTER"]
5656
metadata.drop("FILTER", axis=1)
@@ -80,7 +80,7 @@ def setup_mcam_bandset_metadata(metadata):
8080
metadata["BAYER_PIXEL"] = pd.Series(BAND_TO_BAYER["MCAM"])[
8181
metadata["BAND"]
8282
]
83-
metadata.loc[metadata['FILETYPE'] != 'C00', 'BAYER_PIXEL'] = None
83+
metadata.loc[metadata["FILETYPE"] != "C00", "BAYER_PIXEL"] = None
8484
return metadata.reset_index(drop=True)
8585

8686

marslab/bandset/mastcamz.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515

1616
from marslab.bandset import BandSet
1717
from marslab.compat.xcam import (
18-
DERIVED_CAM_DICT, BAND_TO_BAYER,
18+
DERIVED_CAM_DICT,
19+
BAND_TO_BAYER,
1920
)
2021
from marslab.imgops.debayer import RGGB_PATTERN
2122
from marslab.imgops.loaders import pdr_load
@@ -122,8 +123,10 @@ def check_onboard_debayer(self, *, fix_metadata=False):
122123
references to additional bands of R0 / L0 image files (that don't
123124
exist in raw bayer images).
124125
"""
125-
if tuple(self.precached.values())[0].metaget(
126-
'BAYER_METHOD') == 'RAW_BAYER':
126+
if (
127+
tuple(self.precached.values())[0].metaget("BAYER_METHOD")
128+
== "RAW_BAYER"
129+
):
127130
return False
128131
if fix_metadata:
129132
self.metadata["BAYER_PIXEL"] = None

marslab/compat/sel_to_roi.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@
1010
import scipy.io
1111
from astropy.io import fits
1212

13-
from marslab.compat.mertools import MERSPECT_MSL_COLOR_MAPPINGS, \
14-
MERSPECT_M20_COLOR_MAPPINGS, MERSPECT_COLOR_MAPPINGS
13+
from marslab.compat.mertools import (
14+
MERSPECT_MSL_COLOR_MAPPINGS,
15+
MERSPECT_M20_COLOR_MAPPINGS,
16+
MERSPECT_COLOR_MAPPINGS,
17+
)
1518
from marslab.imgops.regions import select_roi_by_ix, make_roi_hdu
1619

1720

@@ -35,7 +38,7 @@ def is_sel_file(roi_path: Union[str, Path]) -> bool:
3538
"right_pos",
3639
"sel_file_format_major_version",
3740
"sel_file_format_minor_version",
38-
"sel_file_format_date"
41+
"sel_file_format_date",
3942
}
4043
)
4144
return True

marslab/geom.py

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,15 @@
4747

4848
# TODO: this may be cruft.
4949
def get_geometry_value(
50-
entity_name: str,
51-
frame_name: str,
52-
axis_name: str,
53-
data: pdr.Data
50+
entity_name: str, frame_name: str, axis_name: str, data: pdr.Data
5451
) -> Union[float, int, str]:
5552
"""
5653
Fetch the value named `entity_name` for the axis named `axis_name` of the
5754
coordinate frame named `frame_name`, as defined in the metadata of `data`.
5855
"""
5956
return get_from(
6057
data.metaget(f"{frame_name}_DERIVED_GEOMETRY_PARMS"),
61-
(f"{entity_name}_{axis_name}", "value")
58+
(f"{entity_name}_{axis_name}", "value"),
6259
)
6360

6461

@@ -72,7 +69,8 @@ def get_coordinate_system_properties(
7269
If there is no coordinate system named `frame_name`, returns None.
7370
"""
7471
syskeys = [
75-
k for k in data.metadata.fieldcounts
72+
k
73+
for k in data.metadata.fieldcounts
7674
if re.match(f"{frame_name}_COORD(INATE)?_SYSTEM(_PARMS)?$", k)
7775
]
7876
if len(syskeys) == 0:
@@ -83,12 +81,12 @@ def get_coordinate_system_properties(
8381
"reference_frame": system.get("REFERENCE_COORD_SYSTEM_NAME"),
8482
"quaternion": np.array(system.get("ORIGIN_ROTATION_QUATERNION")),
8583
"offset": np.array(system.get("ORIGIN_OFFSET_VECTOR")),
86-
"orientation": system.get("POSITIVE_AZIMUTH_DIRECTION")
84+
"orientation": system.get("POSITIVE_AZIMUTH_DIRECTION"),
8785
}
8886

8987

9088
def get_coordinate_systems(
91-
data: pdr.Data
89+
data: pdr.Data,
9290
) -> dict[str, dict[str, Union[np.ndarray, str, float]]]:
9391
"""
9492
Fetch and format information about all VICAR-style coordinate systems
@@ -120,10 +118,7 @@ def _check_unit_of_angle(unit: str) -> None:
120118

121119

122120
def cart2sph(
123-
x0: ArrayLike,
124-
y0: ArrayLike,
125-
z0: ArrayLike,
126-
unit: UnitOfAngle = "degrees"
121+
x0: ArrayLike, y0: ArrayLike, z0: ArrayLike, unit: UnitOfAngle = "degrees"
127122
) -> Union[pd.DataFrame, tuple[Real, Real, Real]]:
128123
"""
129124
Classic Cartesian-to-spherical coordinate representation converter.
@@ -163,7 +158,7 @@ def sph2cart(
163158
lat: ArrayLike,
164159
lon: ArrayLike,
165160
radius: ArrayLike = 1,
166-
unit: UnitOfAngle = "degrees"
161+
unit: UnitOfAngle = "degrees",
167162
) -> Union[pd.DataFrame, tuple[Real, Real, Real]]:
168163
"""
169164
Classic spherical-to-Cartesian coordinate representation converter. By
@@ -217,10 +212,7 @@ def invert_quaternion(quat: Quaternion) -> Quaternion:
217212

218213

219214
def rotate_unit_vector(
220-
alt: float,
221-
az: float,
222-
quat: Quaternion,
223-
clockwise: bool = True
215+
alt: float, az: float, quat: Quaternion, clockwise: bool = True
224216
) -> np.ndarray:
225217
"""
226218
Apply a rotation expressed as a unit quaternion to a unit vector expressed
@@ -234,22 +226,20 @@ def rotate_unit_vector(
234226
source_cartesian *= np.array([-1, -1, 1])
235227
zero_quaternion = np.array([0, *source_cartesian])
236228
inverse_rotation = invert_quaternion(quat)
237-
q_times_0_v = quaternion_multiplication(
238-
quat, zero_quaternion
239-
)
229+
q_times_0_v = quaternion_multiplication(quat, zero_quaternion)
240230
v_prime = quaternion_multiplication(q_times_0_v, inverse_rotation)
241231
assert np.isclose(v_prime[0], 0)
242232
target_cartesian = v_prime[1:]
243233
if clockwise is True:
244234
target_cartesian *= np.array([-1, -1, 1])
245235
# TODO: it's pointless to return the third (radius) element, because
246-
# the result will always be a unit vector. Will probably need to modify
236+
# the result will always be a unit vector. Will probably need to modify
247237
# downstream to make this change.
248238
return np.array(cart2sph(*target_cartesian))
249239

250240

251241
def get_coordinates(
252-
data: pdr.Data
242+
data: pdr.Data,
253243
) -> dict[str, dict[str, dict[Literal["AZIMUTH", "ELEVATION"], float]]]:
254244
"""
255245
Fetch and organize all VICAR-style azimuth/elevation values mentioned in
@@ -273,11 +263,13 @@ def get_coordinates(
273263
axes = ("AZIMUTH", "ELEVATION")
274264
entities = set()
275265
for axis in axes:
276-
entities.update({
277-
k.replace(f"_{axis}", "")
278-
for k in data.metadata.fieldcounts
279-
if k.endswith(f"_{axis}")
280-
})
266+
entities.update(
267+
{
268+
k.replace(f"_{axis}", "")
269+
for k in data.metadata.fieldcounts
270+
if k.endswith(f"_{axis}")
271+
}
272+
)
281273
coordinates = NestingDict()
282274
syskeys = filter(
283275
lambda k: k.endswith("_GEOMETRY_PARMS"), data.metadata.fieldcounts
@@ -288,7 +280,7 @@ def get_coordinates(
288280
continue
289281
record = block.get(f"{entity}_{axis}")
290282
if record is not None:
291-
coordinates[key.split("_")[0]][entity][axis] = record['value']
283+
coordinates[key.split("_")[0]][entity][axis] = record["value"]
292284
return coordinates.todict()
293285

294286

@@ -323,9 +315,9 @@ def transform_angle(
323315
quaternion = source_info["quaternion"]
324316
coord = coordinates[source_frame][entity]
325317
if target_info is not None:
326-
clockwise = "clockwise" in target_info['orientation'].lower()
318+
clockwise = "clockwise" in target_info["orientation"].lower()
327319
else:
328-
clockwise = "clockwise" in source_info['orientation'].lower()
320+
clockwise = "clockwise" in source_info["orientation"].lower()
329321
return rotate_unit_vector(
330-
coord['ELEVATION'], coord['AZIMUTH'], quaternion, clockwise
322+
coord["ELEVATION"], coord["AZIMUTH"], quaternion, clockwise
331323
)

marslab/imgops/debayer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def mask_bayer_pixels(
109109
pixel: Union[str, Sequence[str]],
110110
pattern: Mapping[str, tuple] = None,
111111
masks: Mapping[str, tuple] = None,
112-
default = 0,
112+
default=0,
113113
**_kwargs # TODO: hacky!
114114
) -> np.ndarray:
115115
"""

0 commit comments

Comments
 (0)