Skip to content

Commit

Permalink
dynamically collect segment numbers from sar_swatch_details.csv
Browse files Browse the repository at this point in the history
  • Loading branch information
cyschneck committed Nov 16, 2024
1 parent 372b05d commit 529154a
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 14 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ Version 3 is named BIFQI49N071_D035_T00AS01_V03.IMG
> _**Version 3 is currently the latest and preferred version and will be the version included when downloaded**_
### Segment Number of Data
A single flyby can produce multiple image segments (Sxx). *S01 is the primary imaging segment* with other segments referring to periods in the flyby when the instrument went to/from altimetry/SAR/HiSAR or weird pointing profiles.
A single flyby can produce multiple image segments (Sxx). *S01 is the primary imaging segment* with other segments referring to periods in the flyby when the instrument went to/from altimetry/SAR/HiSAR or weird pointing profiles.

![image](https://user-images.githubusercontent.com/24469269/210197286-c059ffed-281d-46c7-911a-f86c3bf7ea28.png)
*Credit: Cassini Radar User Guide (Wall et al. 2019, pg.16)*
Expand Down Expand Up @@ -564,7 +564,7 @@ Either a flyby_id (for example: 'T65') or a flyby_observation_num (for example:
* **[REQUIRED/OPTIONAL]** flyby_observation_num (string): required if flyby_id not included
* **[REQUIRED/OPTIONAL]** flyby_id (string): required if flyby_observation_num not included
* **[REQUIRED]** segment_num (string): a flyby includes multiple image segments (S0X) where S01 is the primary imaging segment ["S01", "S02", "S03", "S04"]
* **[REQUIRED]** segment_num (string): a flyby includes multiple image segments (SXX) where S01 is the primary imaging segment
* [OPTIONAL] resolution (String): resolution options "B", "D", "F", "H", or "I" (2, 8, 32, 128, 256 pixels/degree), defaults to highest resolution 'I'
* [OPTIONAL] top_x_resolutions: Save the top x resolution types (5 total resolutions), will override any default resolution string
* [OPTIONAL] additional_data_types_to_download (List of Strings): Possible options ["ABDR", "ASUM", "BIDR", "LBDR", "SBDR", "STDR"] (__NOTE__: current v1 functionality does not download any additional data types)
Expand Down
1 change: 1 addition & 0 deletions pydar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

# extract_flyby_parameters.py function calls
from .extract_flyby_parameters import _retrieve_flyby_data
from .extract_flyby_parameters import _return_segment_options
from .extract_flyby_parameters import extract_flyby_images
from .extract_flyby_parameters import id_to_observation
from .extract_flyby_parameters import observation_to_id
Expand Down
8 changes: 3 additions & 5 deletions pydar/error_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# Internal Local Imports
import pydar


def _error_handling_extract_flyby_images(flyby_observation_num=None,
flyby_id=None,
segment_num=None,
Expand Down Expand Up @@ -53,18 +52,17 @@ def _error_handling_extract_flyby_images(flyby_observation_num=None,
f"[flyby_observation_num]: '{flyby_observation_num}' not in available observation options '{available_observation_numbers}'"
)

segment_options = ['S01', 'S02', 'S03', 'S04']
if segment_num is None:
raise ValueError(
f"[segment_num]: segment_num number required out of available options {segment_options}, none given"
"[segment_num]: segment_num number required out of available options, none given"
)
if type(segment_num) != str:
raise ValueError(
f"[segment_num]: Must be a str, current type = '{type(segment_num)}'"
)
if segment_num not in segment_options:
if segment_num not in pydar._return_segment_options():
raise ValueError(
f"[segment_num]: '{segment_num}' not an available segment option '{segment_options}'"
f"[segment_num]: '{segment_num}' not an available segment options: '{pydar._return_segment_options()}'"
)

if len(additional_data_types_to_download) != 0:
Expand Down
14 changes: 14 additions & 0 deletions pydar/extract_flyby_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,20 @@ def _retrieve_flyby_data() -> tuple[list, str]:
# returns a list of flyby IDs and associated Radar Data Take Number
return flyby_id, flyby_radar_take_num

def _return_segment_options() -> list:
# return a possible list of segments from sar_swath_details.csv
sar_swatch_csv = os.path.join(
os.path.dirname(__file__), 'data', 'sar_swath_details.csv'
) # get file's directory, up one level, /data/*.csv
sar_swath_df = pd.read_csv(sar_swatch_csv)
seg_num = sar_swath_df['SEGMENT'].unique()
seg_options = []
for num in seg_num:
if num < 10:
seg_options.append(f"S0{num}")
else:
seg_options.append(f"S{num}")
return seg_options # ['S01', 'S02', 'S03', 'S04', 'S05', 'S06', 'S07', 'S08', 'S09']

def id_to_observation(flyby_id: str = None) -> str:
# convert Flyby ID to Observation Number to find data files
Expand Down
6 changes: 3 additions & 3 deletions pydar/pytests/test_error_extract_flyby_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def test_extractFlybyImages_segmentNumRequired():
with pytest.raises(
ValueError,
match=re.escape(
"[segment_num]: segment_num number required out of available options ['S01', 'S02', 'S03', 'S04'], none given"
f"[segment_num]: segment_num number required out of available options, none given"
)):
pydar.extract_flyby_images(flyby_observation_num="211",
segment_num=None)
Expand All @@ -134,10 +134,10 @@ def test_extractFlybyImages_notAvailableSegmentNum():
with pytest.raises(
ValueError,
match=re.escape(
"[segment_num]: 'S05' not an available segment option '['S01', 'S02', 'S03', 'S04']'"
f"[segment_num]: 'S10' not an available segment options: '{pydar._return_segment_options()}'"
)):
pydar.extract_flyby_images(flyby_observation_num="211",
segment_num="S05")
segment_num="S10")


@pytest.mark.parametrize("invalid_input, error_output",
Expand Down
4 changes: 2 additions & 2 deletions pydar/pytests/test_error_read_readme.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def test_readAAREADME_NotValidSection():
with pytest.raises(
ValueError,
match=re.escape(
"[section_to_print]: Cannot find a revelant section_to_print: Invalid 'Invalid Section'"
"[section_to_print]: Cannot find a relevant section_to_print: Invalid 'Invalid Section'"
)):
pydar.read_aareadme(coradr_results_directory="coradr_directory",
section_to_print="invalid section")
Expand Down Expand Up @@ -146,7 +146,7 @@ def test_readLBLREADME_NotValidSection():
with pytest.raises(
ValueError,
match=re.escape(
"[section_to_print]: Cannot find a revelant section_to_print: Invalid 'INVALID SECTION'"
"[section_to_print]: Cannot find a relevant section_to_print: Invalid 'INVALID SECTION'"
)):
pydar.read_lbl_readme(coradr_results_directory="coradr_directory",
section_to_print="invalid section")
Expand Down
4 changes: 2 additions & 2 deletions pydar/read_readme.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def read_aareadme(coradr_results_directory: str = None,
"AAREADME")
if sectionList is None:
raise ValueError(
f"[section_to_print]: Cannot find a revelant section_to_print: Invalid '{section_to_print}'"
f"[section_to_print]: Cannot find a relevant section_to_print: Invalid '{section_to_print}'"
)

# Define position to start console print, default to 'All' if no section is specified
Expand Down Expand Up @@ -234,7 +234,7 @@ def read_lbl_readme(coradr_results_directory: str = None,
sectionList = _determine_section_to_print(section_to_print, "LBL")
if sectionList is None:
raise ValueError(
f"[section_to_print]: Cannot find a revelant section_to_print: Invalid '{section_to_print}'"
f"[section_to_print]: Cannot find a relevant section_to_print: Invalid '{section_to_print}'"
)

# Define position to start console print, default to 'All' if no section is specified
Expand Down

0 comments on commit 529154a

Please sign in to comment.