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

Add azimuth angles for SEVIRI #80

Merged
merged 6 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 4 additions & 1 deletion bin/seviri2pps.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
help="Output directory where to store level1c file.")
parser.add_argument('--no-rotation', action='store_true',
help="Don't rotate images")
parser.add_argument('--azimuth_angles', action='store_true',
help="Save azimuth angles")
parser.add_argument('-ne', '--nc_engine', type=str, nargs='?',
required=False, default='h5netcdf',
help="Engine for saving netcdf files netcdf4 or h5netcdf (default).")
Expand All @@ -64,5 +66,6 @@
rotate=not options.no_rotation,
engine=options.nc_engine,
use_nominal_time_in_filename=options.use_nominal_time_in_filename,
apply_sun_earth_distance_correction=not options.no_sun_earth_distance_correction
apply_sun_earth_distance_correction=not options.no_sun_earth_distance_correction,
save_azimuth_angles=options.azimuth_angles,
)
32 changes: 28 additions & 4 deletions level1c4pps/seviri2pps_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,11 @@ def _create_scene(file_format, filenames, calib_coefs):


def _check_is_seviri_data(scene):
if not scene.attrs['sensor'] == {'seviri'}:
if hasattr(scene, 'sensor_names') and 'seviri' in scene.sensor_names:
pass
elif scene.attrs['sensor'] == {'seviri'}:
pass
else:
raise ValueError('Not SEVIRI data')


Expand Down Expand Up @@ -322,6 +326,8 @@ def update_coords(scene):


def add_ancillary_datasets(scene, lons, lats, sunz, satz, azidiff,
suna, sata,
save_azimuth_angles=False,
chunks=(512, 3712)):
"""Add ancillary datasets to the scene.

Expand Down Expand Up @@ -375,6 +381,18 @@ def add_ancillary_datasets(scene, lons, lats, sunz, satz, azidiff,
da.from_array(azidiff[:, :], chunks=chunks),
dims=['y', 'x'], coords=angle_coords)

# Sunazimuth
if save_azimuth_angles:
scene['sunazimuth'] = xr.DataArray(
da.from_array(suna[:, :], chunks=chunks),
dims=['y', 'x'], coords=angle_coords)

# Satazimuth
if save_azimuth_angles:
scene['sunazimuth'] = xr.DataArray(
ninahakansson marked this conversation as resolved.
Show resolved Hide resolved
da.from_array(sata[:, :], chunks=chunks),
dims=['y', 'x'], coords=angle_coords)

# Update the attributes
update_angle_attributes(scene, band=scene['IR_108'])

Expand Down Expand Up @@ -470,7 +488,7 @@ def get_encoding_seviri(scene):
encoding['time'] = {'units': 'days since 2004-01-01 00:00',
'calendar': 'standard',
'_FillValue': None,
'chunksizes': [1]}
'chunksizes': (1)}
ninahakansson marked this conversation as resolved.
Show resolved Hide resolved

return encoding

Expand Down Expand Up @@ -564,7 +582,8 @@ def _postproc_hrit(self, parsed):
def process_one_scan(tslot_files, out_path, rotate=True, engine='h5netcdf',
use_nominal_time_in_filename=False,
apply_sun_earth_distance_correction=True,
clip_calib=False):
clip_calib=False,
save_azimuth_angles=False):
"""Make level 1c files in PPS-format."""
for fname in tslot_files:
if not os.path.isfile(fname):
Expand All @@ -577,7 +596,9 @@ def process_one_scan(tslot_files, out_path, rotate=True, engine='h5netcdf',
rotate=rotate,
clip_calib=clip_calib
)

if hasattr(scn_, 'start_time'):
scn_.attrs['start_time'] = scn_.start_time
scn_.attrs['end_time'] = scn_.end_time
# Find lat/lon data
lons, lats = get_lonlats(scn_['IR_108'])

Expand All @@ -591,6 +612,8 @@ def process_one_scan(tslot_files, out_path, rotate=True, engine='h5netcdf',

# Add ancillary datasets to the scene
add_ancillary_datasets(scn_, lons=lons, lats=lats, sunz=sunz, satz=satz,
suna=suna, sata=sata,
save_azimuth_angles=save_azimuth_angles,
azidiff=azidiff)
add_proj_satpos(scn_)

Expand All @@ -601,6 +624,7 @@ def process_one_scan(tslot_files, out_path, rotate=True, engine='h5netcdf',
ir108_for_filename = scn_['IR_108']
if use_nominal_time_in_filename:
ir108_for_filename = set_nominal_scan_time(ir108_for_filename)

filename = compose_filename(
scene=scn_,
out_path=out_path,
Expand Down