Click here to download this notebook.

How to merge two NadirData

It is possible to merge two NadirData objects in order to ease the manipulation and comparison of data coming from different sources [doc].

[1]:
import os

from casys import NadirData, CasysPlot, DateHandler, Field, TextParams

NadirData.enable_loginfo()

Correctly set your NadirData and their fields

Create your fields

When working with multiple sources with the intent to merge them, fields must have different names in each NadirData object.

swh_s3pp = Field("SWH_S3PP", source="SWH.ALTI") swh_pdgs = Field("SWH_PDGS", source="SWH.ALTI")

Load your data

In order to merge NadirData objects, required raw data have to be added in computed.

As we are working on different “GES_TABLE_DIR” environments a “small trick” is needed.

  • Set the first environment, create your first NadirData and store it.

  • Reload your notebook

  • Set the second environment, create your second NadirData and, optionally, store it.

First data source (Sentinel 3 PDGS): the merged source

# PDGS os.environ["GES_TABLE_DIR"] = "/archive/PMC/peachis3apdgs/data/TABLES/DSC/" start = DateHandler.from_orf("T_HS3A_PDGS_MAR_ORF", 25, 1, pos="first") end = DateHandler.from_orf("T_HS3A_PDGS_MAR_ORF", 25, 10, pos="last") ad_pdgs = NadirData( date_start=start, date_end=end, source="TABLE_T_HS3A_S3PDGS_SARM_MAR_B", orf="T_HS3A_PDGS_MAR_ORF", time="time", longitude="LONGITUDE", latitude="LATITUDE", )

Raw data have to be added and computed before the merge operation.

ad_pdgs.add_raw_data("SWH_PDGS", swh_pdgs) ad_pdgs.compute() ad_pdgs.store("ad_pdgs.back", overwrite=True)

Second data source (Sentinel 3 S3PP): the main source

# S3PP os.environ["GES_TABLE_DIR"] = "/data/peachis3app_ex/data/TABLES/DSC/"start = DateHandler.from_orf("T_HS3A", 25, 1, pos="first") end = DateHandler.from_orf("T_HS3A", 25, 10, pos="last") ad_s3pp = NadirData( date_start=start, date_end=end, source="TABLE_T_HS3A_S3PP_B", orf="T_HS3A", time="time", longitude="LONGITUDE", latitude="LATITUDE", )ad_s3pp.add_raw_data("SWH_S3PP", swh_s3pp) ad_s3pp.compute() ad_s3pp.store(os.path.join(os.environ["RESOURCES_DIR"], "ad_s3pp.back"), overwrite=True)

You will receive these kinds of warnings when loading an NadirData created with an ORF and/or Table you cannot access. It means you will be limited to existing data and won’t be able to read new ones or use anything involving and the ORF.

ad_pdgs = NadirData.load(os.path.join(os.environ["RESOURCES_DIR"], "ad_pdgs.back"))ad_pdgs.data

We’re able to add a statistic using existing data

ad_pdgs.add_time_stat("SWH Stat", field=swh_pdgs, freq="30min") ad_pdgs.compute()ad_s3pp = NadirData.load(os.path.join(os.environ["RESOURCES_DIR"], "ad_s3pp.back"))ad_s3pp.data

Merge and play with your new NadirData

We’re merging using a simple linear interpolation.

ad_s3pp.merge_data(data=cd_pdgs, interp=True, method="linear")ad_s3pp.data

We can now use the merged fields as any other:

  • To compute a statistic

  • To create new fields usings CLIPs

swh_diff = Field(name="SWH_Diff", source="SWH_S3PP - SWH_PDGS")ad_s3pp.add_raw_data(name="SWH Difference", field=swh_diff) ad_s3pp.add_time_stat("SWH S3PP Stat", field=swh_s3pp, freq="30min") ad_s3pp.add_time_stat("SWH PDGS (interp) Stat", field=swh_pdgs, freq="30min") ad_s3pp.add_time_stat("SWH Diff Stat", field=swh_diff, freq="30min") ad_s3pp.compute()text = TextParams( xlabel="Time", ylabel="SWH", legend="SWH PDGS (interpolated)", title="Original/Interpolated SWH PDGS comparison (mean over 1/2 hour)", ) cp_pdgs_interp = CasysPlot(ad_s3pp, "SWH PDGS (interp) Stat", text_params=text) cp_pdgs_original = CasysPlot( cd_pdgs, "SWH Stat", text_params=TextParams(legend="SWH PDGS (original)") ) cp_pdgs_interp.add_plot(cp_pdgs_original, shared_ax="all") cp_pdgs_interp.show()text = TextParams( xlabel="Time", ylabel="SWH", legend="SWH PDGS (interpolated)", title="SWH PDGS/S3PP comparison (mean over 1/2 hour)", ) cp_pdgs_interp = CasysPlot(ad_s3pp, "SWH PDGS (interp) Stat", text_params=text) cp_s3pp = CasysPlot(cd_s3pp, "SWH S3PP Stat", text_params=TextParams(legend="SWH S3PP")) cp_s3pp.add_plot(cp_pdgs_interp, shared_ax="all") cp_s3pp.show()text = TextParams( xlabel="Time", ylabel="SWH difference", legend="SWH S3PP-PDGS difference", title="SWH PDGS/S3PP comparison (mean over 1/2 hour)", ) cp_pdgs_diff = CasysPlot(ad_s3pp, "SWH Diff Stat", text_params=text) cp_pdgs_diff.show()