diff --git a/docs/conf.py b/docs/conf.py index 9aace93..47d7bdf 100755 --- a/docs/conf.py +++ b/docs/conf.py @@ -64,7 +64,7 @@ # # This is also used if you do content translation via gettext catalogs. # Usually you set "language" from the command line for these cases. -language = None +language = 'en' # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. diff --git a/docs/index.rst b/docs/index.rst index 96c1eac..5c1cee1 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -1,5 +1,5 @@ Welcome to L2Awinddirection's documentation! -====================================== +============================================ .. toctree:: :maxdepth: 2 diff --git a/docs/modules.rst b/docs/modules.rst new file mode 100644 index 0000000..9b83959 --- /dev/null +++ b/docs/modules.rst @@ -0,0 +1,16 @@ +######## +Modules +######## + +.. + to document functions, add them to __all__ in ../l2awinddirection/__init__.py + +.. automodule:: l2awinddirection + :members: + + +.. automodule:: l2awinddirection.utils + :members: + +.. automodule:: l2awinddirection.generate_L2A_winddir_pdf_product + :members: diff --git a/l2awinddirection/generate_L2A_winddir_pdf_product.py b/l2awinddirection/generate_L2A_winddir_pdf_product.py index 0119d5d..76689c7 100644 --- a/l2awinddirection/generate_L2A_winddir_pdf_product.py +++ b/l2awinddirection/generate_L2A_winddir_pdf_product.py @@ -93,6 +93,7 @@ def generate_wind_distribution_product(tiles, m64rn4, nb_classes=36, shape=(44, input_core_dims=[["bin_centers"], ["bin_centers"]], vectorize=True, ) + most_likely_wdir = xr.where(tiles_stacked['land_flag'],np.nan,most_likely_wdir) # apply the land_mask on the wdin direction prediction most_likely_wdir = most_likely_wdir + heading_angle std_wdir = xr.apply_ufunc( compute_standard_deviation, diff --git a/l2awinddirection/generate_L2A_winddir_regression_product.py b/l2awinddirection/generate_L2A_winddir_regression_product.py index b781b90..1e8e759 100644 --- a/l2awinddirection/generate_L2A_winddir_regression_product.py +++ b/l2awinddirection/generate_L2A_winddir_regression_product.py @@ -28,7 +28,7 @@ def generate_wind_product(tiles, model_regs, shape=(44, 44, 1)): except: tiles_stacked = tiles.stack(all_tiles=["tile_line", "tile_sample"]) - mask = tiles_stacked.land_flag == False # test AG + mask = tiles_stacked.land_flag == False mask_indices = np.where(mask) tiles_stacked_no_nan = tiles_stacked.where(mask, drop=True) @@ -77,7 +77,6 @@ def generate_wind_product(tiles, model_regs, shape=(44, 44, 1)): tiles_stacked["wind_std"].attrs["units"] = "degree" tiles_stacked["wind_std"].attrs["vmin"] = 0 tiles_stacked["wind_std"].attrs["vmax"] = 180 - return tiles_stacked.unstack() diff --git a/l2awinddirection/mainl2awinddirection.py b/l2awinddirection/mainl2awinddirection.py index e60134d..566c22f 100644 --- a/l2awinddirection/mainl2awinddirection.py +++ b/l2awinddirection/mainl2awinddirection.py @@ -188,9 +188,8 @@ def main(): if not os.path.exists(input_safe_full_path) and args.skipmoves is True: logging.info(" step 1: move %s -> %s", l2awindirtilessafe, input_safe_full_path) shutil.copytree(l2awindirtilessafe, input_safe_full_path) - polarization_usable = "vv" files = sorted( - glob.glob(os.path.join(input_safe_full_path, "*" + polarization_usable + "*.nc")) + glob.glob(os.path.join(input_safe_full_path, "*.nc")) # all polarisation accepted for prediction ) logging.info("Number of files to process: %d" % len(files)) if not os.path.exists(args.outputdir): diff --git a/l2awinddirection/utils.py b/l2awinddirection/utils.py index 0143ba7..00abe86 100644 --- a/l2awinddirection/utils.py +++ b/l2awinddirection/utils.py @@ -41,7 +41,8 @@ def get_l2_filepath(vignette_fullpath, version, outputdir)->str: pathout = os.path.join(pathout_root, safe_start_date.strftime('%Y'),safe_start_date.strftime('%j')) # SAFE part - safe_file = safe_file.replace("L1B", "L2").replace('XSP', 'WDR') + safe_file = safe_file.replace("L1B", "L2").replace('XSP', 'WDR').replace('TIL','WDR') + safe_file = safe_file.replace('_1S','_2S') if ( len(safe_file.split("_")) == 10 ): # classical ESA SLC naming #:TODO once xsarslc will be updated this case could be removed @@ -69,7 +70,7 @@ def get_l2_filepath(vignette_fullpath, version, outputdir)->str: start_IFR = base_measu.index('_L1B_xspec_IFR') piece_to_remove = base_measu[start_IFR:] base_measu = base_measu.replace(piece_to_remove,'.nc') - if base_measu.split('-')[-1][0] == 'c': #there is already a version product ID + if base_measu.split('-')[-1][0] == 'c' or base_measu.split('-')[-1][0] == 'i': #there is already a version product ID base_measu = base_measu.replace(base_measu.split('-')[-1],version.lower() + ".nc") else: base_measu = base_measu.replace('.nc','-'+version.lower() + ".nc") @@ -83,6 +84,7 @@ def get_l2_filepath(vignette_fullpath, version, outputdir)->str: base_measu = 'l2-'+base_measu # base_measu = base_measu.replace(base_measu.split('-')[4], pola_str) # replace -vv- by -dv- or -sv- depending on SAFE information base_measu = base_measu.replace('-xsp-','-wdr-') + base_measu = base_measu.replace('-til-','-wdr-') base_measu = base_measu.replace('-slc-', '-wdr-') diff --git a/tests/test_l2awinddirection.py b/tests/test_l2awinddirection.py index b079630..2b03bbf 100644 --- a/tests/test_l2awinddirection.py +++ b/tests/test_l2awinddirection.py @@ -5,7 +5,7 @@ import pytest -from l2awinddirection import l2awinddirection +from l2awinddirection import mainl2awinddirection @pytest.fixture diff --git a/tests/test_output_name.py b/tests/test_output_name.py index 372f4a9..588db2a 100644 --- a/tests/test_output_name.py +++ b/tests/test_output_name.py @@ -2,15 +2,19 @@ from l2awinddirection.utils import get_l2_filepath inputs_tiles_files = [ - "/tests/iw/slc/l2a/winddirection/3.7.6/tiles/S1A_IW_XSP__1SDV_20231128T035702_20231128T035729_051412_063451_3781.SAFE/tiles_s1a-iw2-slc-vv-20231128t035702-20231128t035727-051412-063451-002_L1B_xspec_IFR_3.7.6_wind.nc", + "/tests/iw/slc/l2a/winddirection/3.7.6/tiles/S1A_IW_XSP__1SDV_20231128T035702_20231128T035729_051412_063451_3781.SAFE/tiles_s1a-iw2-slc-vv-20231128t035702-20231128t035727-051412-063451-002_L1B_xspec_IFR_3.7.6_wind.nc", "/tests/iw/slc/l2a/winddirection/3.7.6/tiles/S1A_IW_XSP__1SDV_20231128T035702_20231128T035729_051412_063451_3781.SAFE/s1a-iw2-slc-vv-20231128t035702-20231128t035727-051412-063451-002_L1B_xspec_IFR_3.7.6_wind.nc", "/tests/iw/slc/l2a/winddirection/3.7.6/tiles/S1A_IW_XSP__1SDV_20231128T035702_20231128T035729_051412_063451_3781.SAFE/l1b-s1a-iw2-slc-vv-20231128t035702-20231128t035727-051412-063451-002-c02.nc", "/tests/iw/slc/l2a/winddirection/3.7.6/tiles/S1A_IW_XSP__1SDV_20231128T035702_20231128T035729_051412_063451_3781.SAFE/s1a-iw2-slc-vv-20231128t035702-20231128t035727-051412-063451-002_L1B_xspec_IFR_3.8-wind.nc", # "/tmp/data/products/tests/iw/slc/l1b/2021/110/S1B_IW_XSP__1SDV_20210420T094117_20210420T094144_026549_032B99_2058_B03.SAFE/s1b-iw1-xsp-vv-20210420t094118-20210420t094144-026549-032b99-004_b03.nc", # "/tmp/data/products/tests/iw/slc/l1b/2021/110/S1B_IW_XSP__1SDV_20210420T094117_20210420T094144_026549_032B99_2058_B03.SAFE/l1c-s1b-iw1-xsp-vv-20210420t094118-20210420t094144-026549-032b99-004_b03.nc", + "/tmp/patchestest/2016/304/S1A_IW_TIL__1SDV_20161030T162958_20161030T163028_013722_01603F_7E41_I05.SAFE/l1b-s1a-iw2-til-vv-20161030t162959-20161030t163027-013722-01603f-002-i05.nc", + "/tmp/patchestest/2016/304/S1A_IW_TIL__1SDV_20161030T162958_20161030T163028_013722_01603F_7E41_I05.SAFE/l1b-s1a-iw2-til-vv-20161030t162959-20161030t163027-013722-01603f-i05.nc", ] expected_l2 = [ - '/tmp/2023/332/S1A_IW_WDR__1SDV_20231128T035702_20231128T035729_051412_063451_3781_D02.SAFE/l2-s1a-iw2-wdr-vv-20231128t035702-20231128t035727-051412-063451-002-d02.nc' + '/tmp/2023/332/S1A_IW_WDR__2SDV_20231128T035702_20231128T035729_051412_063451_3781_D02.SAFE/l2-s1a-iw2-wdr-vv-20231128t035702-20231128t035727-051412-063451-002-d02.nc', + '/tmp/2016/304/S1A_IW_WDR__2SDV_20161030T162958_20161030T163028_013722_01603F_7E41_D02.SAFE/l2-s1a-iw2-wdr-vv-20161030t162959-20161030t163027-013722-01603f-002-d02.nc', + '/tmp/2016/304/S1A_IW_WDR__2SDV_20161030T162958_20161030T163028_013722_01603F_7E41_D02.SAFE/l2-s1a-iw2-wdr-vv-20161030t162959-20161030t163027-013722-01603f-d02.nc', ] @@ -21,6 +25,8 @@ pytest.param(inputs_tiles_files[1], expected_l2[0]), pytest.param(inputs_tiles_files[2], expected_l2[0]), pytest.param(inputs_tiles_files[3], expected_l2[0]), + pytest.param(inputs_tiles_files[4], expected_l2[1]), + pytest.param(inputs_tiles_files[5], expected_l2[2]), ), ) def test_outputfile_path(vignette_input, expected_l2):