Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conda+nosubdir #70

Merged
merged 3 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions grdwindinversion/config_prod.yaml
Original file line number Diff line number Diff line change
@@ -1,33 +1,45 @@
no_subdir: True
S1A:
GMF_VV_NAME: "gmf_cmod5n"
GMF_VH_NAME: "gmf_s1_v2"
dsig_VH_NAME: "gmf_s1_v2"
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"
dsig_VH_NAME: "gmf_s1_v2"
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"
dsig_VH_NAME: "gmf_rs2_v2"
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"
dsig_VH_NAME: "gmf_s1_v2"
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"
1 change: 1 addition & 0 deletions grdwindinversion/config_prod_recal.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
no_subdir: True
S1A:
GMF_VV_NAME: "gmf_cmod5n"
GMF_VH_NAME: "gmf_s1_v2"
Expand Down
31 changes: 15 additions & 16 deletions grdwindinversion/inversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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]+)_(.*?)_(.*?)_(.*?)_(.*?)_(.*?)_(.*?)_(.*?)")
Expand All @@ -107,13 +100,16 @@ 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'):
"""
Expand Down Expand Up @@ -529,7 +525,10 @@ 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")
Expand Down Expand Up @@ -725,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
Expand Down
34 changes: 34 additions & 0 deletions recipe/meta.yaml
Original file line number Diff line number Diff line change
@@ -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'