Skip to content

Commit

Permalink
Merge pull request #20 from umr-lops/fixApril24
Browse files Browse the repository at this point in the history
filenaming update + fix issues pola and land mask
  • Loading branch information
agrouaze authored Apr 2, 2024
2 parents bea6e39 + 87e7dff commit 957f27a
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 11 deletions.
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Welcome to L2Awinddirection's documentation!
======================================
============================================

.. toctree::
:maxdepth: 2
Expand Down
16 changes: 16 additions & 0 deletions docs/modules.rst
Original file line number Diff line number Diff line change
@@ -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:
1 change: 1 addition & 0 deletions l2awinddirection/generate_L2A_winddir_pdf_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions l2awinddirection/generate_L2A_winddir_regression_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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()


Expand Down
3 changes: 1 addition & 2 deletions l2awinddirection/mainl2awinddirection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 4 additions & 2 deletions l2awinddirection/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand All @@ -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-')


Expand Down
2 changes: 1 addition & 1 deletion tests/test_l2awinddirection.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pytest


from l2awinddirection import l2awinddirection
from l2awinddirection import mainl2awinddirection


@pytest.fixture
Expand Down
10 changes: 8 additions & 2 deletions tests/test_output_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
]


Expand All @@ -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):
Expand Down

0 comments on commit 957f27a

Please sign in to comment.