From 649a0816444a4776db0f56e1967a0efede5f86bb Mon Sep 17 00:00:00 2001 From: tcevaer Date: Tue, 20 Aug 2024 11:14:49 +0200 Subject: [PATCH 1/3] Added meta.yaml for building --- recipe/meta.yaml | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 recipe/meta.yaml diff --git a/recipe/meta.yaml b/recipe/meta.yaml new file mode 100644 index 0000000..c337d4e --- /dev/null +++ b/recipe/meta.yaml @@ -0,0 +1,34 @@ +package: + name: "grdwindinversion" + version: {{ environ.get('GIT_DESCRIBE_TAG', 0)}} + +source: + path: ../. + +build: + noarch: python + number: 0 + script: {{ PYTHON }} -m pip install . --no-deps -vv + +requirements: + build: + - python >=3.9,<3.11 + - setuptools_scm + - setuptools + + run: + - python >=3.9,<3.11 + - xsar + - xsarsea + - "xarray==2024.2.0" + - xarray-datatree + - "rioxarray<=0.15.5" + - "numpy<=1.26" + - pyyaml + - scipy + - fsspec + - aiohttp + +about: + home: /~https://github.com/umr-lops/grdwindinversion + summary: 'python library to compute wind speed from GRD SAR images' \ No newline at end of file From f64883090d648c97fdf3080d7b1b669556ba47a4 Mon Sep 17 00:00:00 2001 From: tcevaer Date: Tue, 20 Aug 2024 11:29:14 +0200 Subject: [PATCH 2/3] Added no_subdir config --- grdwindinversion/config_prod.yaml | 1 + grdwindinversion/config_prod_recal.yaml | 1 + grdwindinversion/inversion.py | 22 ++++++++++------------ 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/grdwindinversion/config_prod.yaml b/grdwindinversion/config_prod.yaml index e53f031..1a142cd 100644 --- a/grdwindinversion/config_prod.yaml +++ b/grdwindinversion/config_prod.yaml @@ -1,3 +1,4 @@ +no_subdir: true S1A: GMF_VV_NAME: "gmf_cmod5n" GMF_VH_NAME: "gmf_s1_v2" diff --git a/grdwindinversion/config_prod_recal.yaml b/grdwindinversion/config_prod_recal.yaml index f751856..ee2912d 100644 --- a/grdwindinversion/config_prod_recal.yaml +++ b/grdwindinversion/config_prod_recal.yaml @@ -1,3 +1,4 @@ +no_subdir: true S1A: GMF_VV_NAME: "gmf_cmod5n" GMF_VH_NAME: "gmf_s1_v2" diff --git a/grdwindinversion/inversion.py b/grdwindinversion/inversion.py index ce91b71..188d263 100644 --- a/grdwindinversion/inversion.py +++ b/grdwindinversion/inversion.py @@ -49,7 +49,7 @@ def getSensorMetaDataset(filename): raise ValueError("must be S1A|S1B|RS2|RCM, got filename %s" % filename) -def getOutputName2(input_file, outdir, sensor, meta): +def getOutputName2(input_file, outdir, sensor, meta, subdir=True): """ Create output filename for L2-GRD product @@ -84,21 +84,14 @@ def getOutputName2(input_file, outdir, sensor, meta): match = regex.match(basename_match) MISSIONID, BEAM, PRODUCT, RESOLUTION, LEVEL, CLASS, POL, STARTDATE, STOPDATE, ORBIT, TAKEID, PRODID = match.groups() new_format = f"{MISSIONID.lower()}-{BEAM.lower()}-owi-xx-{STARTDATE.lower()}-{STOPDATE.lower()}-{ORBIT}-{TAKEID}.nc" - out_file = os.path.join(outdir, basename, new_format) - return out_file - elif sensor == 'RS2': regex = re.compile( "(RS2)_OK([0-9]+)_PK([0-9]+)_DK([0-9]+)_(....)_(........)_(......)_(.._?.?.?)_(S.F)") template = string.Template( "${MISSIONID}_OK${DATA1}_PK${DATA2}_DK${DATA3}_${DATA4}_${DATE}_${TIME}_${POLARIZATION}_${LAST}") match = regex.match(basename_match) - MISSIONID, DATA1, DATA2, DATA3, DATA4, DATE, TIME, POLARIZATION, LAST = match.groups() new_format = f"{MISSIONID.lower()}--owi-xx-{meta_start_date.lower()}-{meta_stop_date.lower()}-_____-_____.nc" - out_file = os.path.join(outdir, basename, new_format) - return out_file - elif sensor == 'RCM': regex = re.compile( "([A-Z0-9]+)_OK([0-9]+)_PK([0-9]+)_(.*?)_(.*?)_(.*?)_(.*?)_(.*?)_(.*?)_(.*?)") @@ -107,12 +100,15 @@ def getOutputName2(input_file, outdir, sensor, meta): match = regex.match(basename_match) MISSIONID, DATA1, DATA2, DATA3, DATA4, DATE, TIME, POLARIZATION1, POLARIZATION2, LAST = match.groups() new_format = f"{MISSIONID.lower()}--owi-xx-{meta_start_date.lower()}-{meta_stop_date.lower()}-_____-_____.nc" - out_file = os.path.join(outdir, basename, new_format) - return out_file - else: raise ValueError( "sensor must be S1A|S1B|RS2|RCM, got sensor %s" % sensor) + + if subdir: + out_file = os.path.join(outdir, basename, new_format) + else: + out_file = os.path.join(outdir, new_format) + return out_file def getAncillary(meta, ancillary_name='ecmwf'): @@ -529,7 +525,9 @@ def preprocess(filename, outdir, config_path, overwrite=False, resolution='1000m recalibration = config["recalibration"] meta = fct_meta(filename) - out_file = getOutputName2(filename, outdir, sensor, meta) + + no_subdir_cfg = config_base.get("no_subdir", False) + out_file = getOutputName2(filename, outdir, sensor, meta, subdir=not no_subdir_cfg) if os.path.exists(out_file) and overwrite is False: raise FileExistsError("out_file %s exists already") From 50263ddf81c0f0c902e699108ef5b4996557c1e0 Mon Sep 17 00:00:00 2001 From: Vincent LHEUREUX Date: Tue, 27 Aug 2024 12:27:31 +0200 Subject: [PATCH 3/3] changed config & one param for recalib attrs --- grdwindinversion/config_prod.yaml | 23 +++++++++++++++++------ grdwindinversion/config_prod_recal.yaml | 2 +- grdwindinversion/inversion.py | 13 +++++++------ 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/grdwindinversion/config_prod.yaml b/grdwindinversion/config_prod.yaml index 1a142cd..2a83c2a 100644 --- a/grdwindinversion/config_prod.yaml +++ b/grdwindinversion/config_prod.yaml @@ -1,4 +1,4 @@ -no_subdir: true +no_subdir: True S1A: GMF_VV_NAME: "gmf_cmod5n" GMF_VH_NAME: "gmf_s1_v2" @@ -6,6 +6,10 @@ S1A: apply_flattening: True recalibration: False ancillary: "ecmwf" + inc_step: 0.1 + wspd_step: 0.1 + phi_step: 1.0 + resolution: "high" S1B: GMF_VV_NAME: "gmf_cmod5n" GMF_VH_NAME: "gmf_s1_v2" @@ -13,6 +17,10 @@ S1B: apply_flattening: True recalibration: False ancillary: "ecmwf" + inc_step: 0.1 + wspd_step: 0.1 + phi_step: 1.0 + resolution: "high" RS2: GMF_VV_NAME: "gmf_cmod5n" GMF_VH_NAME: "gmf_rs2_v2" @@ -20,6 +28,10 @@ RS2: apply_flattening: False recalibration: False ancillary: "ecmwf" + inc_step: 0.1 + wspd_step: 0.1 + phi_step: 1.0 + resolution: "high" RCM: GMF_VV_NAME: "gmf_cmod5n" GMF_VH_NAME: "gmf_rcm_noaa" @@ -27,8 +39,7 @@ RCM: apply_flattening: True recalibration: False ancillary: "ecmwf" - -inc_step: 0.1 -wspd_step: 0.1 -phi_step: 1.0 -resolution: "high" + inc_step: 0.1 + wspd_step: 0.1 + phi_step: 1.0 + resolution: "high" diff --git a/grdwindinversion/config_prod_recal.yaml b/grdwindinversion/config_prod_recal.yaml index ee2912d..98fedfb 100644 --- a/grdwindinversion/config_prod_recal.yaml +++ b/grdwindinversion/config_prod_recal.yaml @@ -1,4 +1,4 @@ -no_subdir: true +no_subdir: True S1A: GMF_VV_NAME: "gmf_cmod5n" GMF_VH_NAME: "gmf_s1_v2" diff --git a/grdwindinversion/inversion.py b/grdwindinversion/inversion.py index 188d263..ce1c48a 100644 --- a/grdwindinversion/inversion.py +++ b/grdwindinversion/inversion.py @@ -103,7 +103,7 @@ def getOutputName2(input_file, outdir, sensor, meta, subdir=True): else: raise ValueError( "sensor must be S1A|S1B|RS2|RCM, got sensor %s" % sensor) - + if subdir: out_file = os.path.join(outdir, basename, new_format) else: @@ -527,7 +527,8 @@ def preprocess(filename, outdir, config_path, overwrite=False, resolution='1000m meta = fct_meta(filename) no_subdir_cfg = config_base.get("no_subdir", False) - out_file = getOutputName2(filename, outdir, sensor, meta, subdir=not no_subdir_cfg) + out_file = getOutputName2(filename, outdir, sensor, + meta, subdir=not no_subdir_cfg) if os.path.exists(out_file) and overwrite is False: raise FileExistsError("out_file %s exists already") @@ -723,14 +724,14 @@ def preprocess(filename, outdir, config_path, overwrite=False, resolution='1000m model_vh = config["GMF_"+crosspol_gmf+"_NAME"] if ((recalibration) & ("SENTINEL" in sensor_longname)): - xr_dataset["path_aux_pp1_new"] = os.path.basename(os.path.dirname( + xr_dataset.attrs["path_aux_pp1_new"] = os.path.basename(os.path.dirname( os.path.dirname(xsar_dataset.datatree['recalibration'].attrs['path_aux_pp1_new']))) - xr_dataset["path_aux_cal_new"] = os.path.basename(os.path.dirname( + xr_dataset.attrs["path_aux_cal_new"] = os.path.basename(os.path.dirname( os.path.dirname(xsar_dataset.datatree['recalibration'].attrs['path_aux_cal_new']))) - xr_dataset["path_aux_pp1_old"] = os.path.basename(os.path.dirname( + xr_dataset.attrs["path_aux_pp1_old"] = os.path.basename(os.path.dirname( os.path.dirname(xsar_dataset.datatree['recalibration'].attrs['path_aux_pp1_old']))) - xr_dataset["path_aux_cal_old"] = os.path.basename(os.path.dirname( + xr_dataset.attrs["path_aux_cal_old"] = os.path.basename(os.path.dirname( os.path.dirname(xsar_dataset.datatree['recalibration'].attrs['path_aux_cal_old']))) return xr_dataset, dual_pol, copol, crosspol, copol_gmf, crosspol_gmf, model_vv, model_vh, sigma0_ocean_cross, dsig_cross, sensor_longname, out_file, config