Skip to content

Commit 35c01b7

Browse files
committed
conversion.py works on the xarray datamodel
1 parent 8daf092 commit 35c01b7

File tree

2 files changed

+282
-108
lines changed

2 files changed

+282
-108
lines changed

pysteps/tests/test_utils_conversion.py

Lines changed: 273 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -635,115 +635,288 @@ def test_to_raindepth(dataset, expected):
635635
np.array([23.01029996]),
636636
{
637637
"units": "dBZ",
638+
"transform": "dB",
639+
"accutime": 5,
640+
"threshold": 23.01029996,
641+
"zerovalue": 18.01029996,
642+
},
643+
)
644+
},
645+
attrs={"precip_var": "reflectivity"},
646+
),
647+
),
648+
(
649+
xr.Dataset(
650+
data_vars={
651+
"precip_accum": (
652+
["x"],
653+
np.array([1.0]),
654+
{
655+
"units": "mm",
638656
"transform": None,
639657
"accutime": 5,
658+
"threshold": 1.0,
659+
"zerovalue": 1.0,
660+
},
661+
)
662+
},
663+
attrs={"precip_var": "precip_accum"},
664+
),
665+
xr.Dataset(
666+
data_vars={
667+
"reflectivity": (
668+
["x"],
669+
np.array([40.27719989]),
670+
{
671+
"units": "dBZ",
672+
"transform": "dB",
673+
"accutime": 5,
674+
"threshold": 40.27719989,
675+
"zerovalue": 35.27719989,
676+
},
677+
)
678+
},
679+
attrs={"precip_var": "reflectivity"},
680+
),
681+
),
682+
(
683+
xr.Dataset(
684+
data_vars={
685+
"precip_intensity": (
686+
["x"],
687+
np.array([1.0]),
688+
{
689+
"units": "mm/h",
690+
"transform": "dB",
691+
"accutime": 5,
692+
"threshold": 1.0,
693+
"zerovalue": 1.0,
694+
},
695+
)
696+
},
697+
attrs={"precip_var": "precip_intensity"},
698+
),
699+
xr.Dataset(
700+
data_vars={
701+
"reflectivity": (
702+
["x"],
703+
np.array([24.61029996]),
704+
{
705+
"units": "dBZ",
706+
"transform": "dB",
707+
"accutime": 5,
708+
"threshold": 24.61029996,
709+
"zerovalue": 19.61029996,
710+
},
711+
)
712+
},
713+
attrs={"precip_var": "reflectivity"},
714+
),
715+
),
716+
(
717+
xr.Dataset(
718+
data_vars={
719+
"precip_accum": (
720+
["x"],
721+
np.array([1.0]),
722+
{
723+
"units": "mm",
724+
"transform": "dB",
725+
"accutime": 5,
726+
"threshold": 1.0,
727+
"zerovalue": 1.0,
728+
},
729+
)
730+
},
731+
attrs={"precip_var": "precip_accum"},
732+
),
733+
xr.Dataset(
734+
data_vars={
735+
"reflectivity": (
736+
["x"],
737+
np.array([41.87719989]),
738+
{
739+
"units": "dBZ",
740+
"transform": "dB",
741+
"accutime": 5,
742+
"threshold": 41.87719989,
743+
"zerovalue": 36.87719989,
744+
},
745+
)
746+
},
747+
attrs={"precip_var": "reflectivity"},
748+
),
749+
),
750+
(
751+
xr.Dataset(
752+
data_vars={
753+
"reflectivity": (
754+
["x"],
755+
np.array([1.0]),
756+
{
757+
"units": "dBZ",
758+
"transform": "dB",
759+
"accutime": 5,
760+
"threshold": 1.0,
761+
"zerovalue": 1.0,
762+
},
763+
)
764+
},
765+
attrs={"precip_var": "reflectivity"},
766+
),
767+
xr.Dataset(
768+
data_vars={
769+
"reflectivity": (
770+
["x"],
771+
np.array([1.0]),
772+
{
773+
"units": "dBZ",
774+
"transform": "dB",
775+
"accutime": 5,
776+
"threshold": 1.0,
777+
"zerovalue": -4.0,
778+
},
779+
)
780+
},
781+
attrs={"precip_var": "reflectivity"},
782+
),
783+
),
784+
(
785+
xr.Dataset(
786+
data_vars={
787+
"precip_intensity": (
788+
["x"],
789+
np.array([1.0]),
790+
{
791+
"units": "mm/h",
792+
"transform": "log",
793+
"accutime": 5,
794+
"threshold": 1.0,
795+
"zerovalue": 1.0,
796+
},
797+
)
798+
},
799+
attrs={"precip_var": "precip_intensity"},
800+
),
801+
xr.Dataset(
802+
data_vars={
803+
"reflectivity": (
804+
["x"],
805+
np.array([29.95901167]),
806+
{
807+
"units": "dBZ",
808+
"transform": "dB",
809+
"accutime": 5,
810+
"threshold": 29.95901167,
811+
"zerovalue": 24.95901167,
812+
},
813+
)
814+
},
815+
attrs={"precip_var": "reflectivity"},
816+
),
817+
),
818+
(
819+
xr.Dataset(
820+
data_vars={
821+
"precip_accum": (
822+
["x"],
823+
np.array([1.0]),
824+
{
825+
"units": "mm",
826+
"transform": "log",
827+
"accutime": 5,
828+
"threshold": 1.0,
829+
"zerovalue": 1.0,
830+
},
831+
)
832+
},
833+
attrs={"precip_var": "precip_accum"},
834+
),
835+
xr.Dataset(
836+
data_vars={
837+
"reflectivity": (
838+
["x"],
839+
np.array([47.2259116]),
840+
{
841+
"units": "dBZ",
842+
"transform": "dB",
843+
"accutime": 5,
844+
"threshold": 47.2259116,
845+
"zerovalue": 42.2259116,
846+
},
847+
)
848+
},
849+
attrs={"precip_var": "reflectivity"},
850+
),
851+
),
852+
(
853+
xr.Dataset(
854+
data_vars={
855+
"precip_intensity": (
856+
["x"],
857+
np.array([1.0]),
858+
{
859+
"units": "mm/h",
860+
"transform": "sqrt",
861+
"accutime": 5,
862+
"threshold": 1.0,
863+
"zerovalue": 1.0,
864+
},
865+
)
866+
},
867+
attrs={"precip_var": "precip_intensity"},
868+
),
869+
xr.Dataset(
870+
data_vars={
871+
"reflectivity": (
872+
["x"],
873+
np.array([23.01029996]),
874+
{
875+
"units": "dBZ",
876+
"transform": "dB",
877+
"accutime": 5,
640878
"threshold": 23.01029996,
641-
"zerovalue": 23.01029996,
879+
"zerovalue": 18.01029996,
880+
},
881+
)
882+
},
883+
attrs={"precip_var": "reflectivity"},
884+
),
885+
),
886+
(
887+
xr.Dataset(
888+
data_vars={
889+
"precip_accum": (
890+
["x"],
891+
np.array([1.0]),
892+
{
893+
"units": "mm",
894+
"transform": "sqrt",
895+
"accutime": 5,
896+
"threshold": 1.0,
897+
"zerovalue": 1.0,
898+
},
899+
)
900+
},
901+
attrs={"precip_var": "precip_accum"},
902+
),
903+
xr.Dataset(
904+
data_vars={
905+
"reflectivity": (
906+
["x"],
907+
np.array([40.27719989]),
908+
{
909+
"units": "dBZ",
910+
"transform": "dB",
911+
"accutime": 5,
912+
"threshold": 40.27719989,
913+
"zerovalue": 35.27719989,
642914
},
643915
)
644916
},
645917
attrs={"precip_var": "reflectivity"},
646918
),
647919
),
648-
# (
649-
# np.array([1]),
650-
# {
651-
# "accutime": 5,
652-
# "transform": None,
653-
# "unit": "mm/h",
654-
# "threshold": 0,
655-
# "zerovalue": 0,
656-
# },
657-
# np.array([23.01029996]),
658-
# ),
659-
# (
660-
# np.array([1]),
661-
# {
662-
# "accutime": 5,
663-
# "transform": None,
664-
# "unit": "mm",
665-
# "threshold": 0,
666-
# "zerovalue": 0,
667-
# },
668-
# np.array([40.27719989]),
669-
# ),
670-
# (
671-
# np.array([1]),
672-
# {
673-
# "accutime": 5,
674-
# "transform": "dB",
675-
# "unit": "mm/h",
676-
# "threshold": 0,
677-
# "zerovalue": 0,
678-
# },
679-
# np.array([24.61029996]),
680-
# ),
681-
# (
682-
# np.array([1]),
683-
# {
684-
# "accutime": 5,
685-
# "transform": "dB",
686-
# "unit": "mm",
687-
# "threshold": 0,
688-
# "zerovalue": 0,
689-
# },
690-
# np.array([41.87719989]),
691-
# ),
692-
# (
693-
# np.array([1]),
694-
# {
695-
# "accutime": 5,
696-
# "transform": "dB",
697-
# "unit": "dBZ",
698-
# "threshold": 0,
699-
# "zerovalue": 0,
700-
# },
701-
# np.array([1]),
702-
# ),
703-
# (
704-
# np.array([1]),
705-
# {
706-
# "accutime": 5,
707-
# "transform": "log",
708-
# "unit": "mm/h",
709-
# "threshold": 0,
710-
# "zerovalue": 0,
711-
# },
712-
# np.array([29.95901167]),
713-
# ),
714-
# (
715-
# np.array([1.0]),
716-
# {
717-
# "accutime": 5,
718-
# "transform": "log",
719-
# "unit": "mm",
720-
# "threshold": 0,
721-
# "zerovalue": 0,
722-
# },
723-
# np.array([47.2259116]),
724-
# ),
725-
# (
726-
# np.array([1]),
727-
# {
728-
# "accutime": 5,
729-
# "transform": "sqrt",
730-
# "unit": "mm/h",
731-
# "threshold": 0,
732-
# "zerovalue": 0,
733-
# },
734-
# np.array([23.01029996]),
735-
# ),
736-
# (
737-
# np.array([1.0]),
738-
# {
739-
# "accutime": 5,
740-
# "transform": "sqrt",
741-
# "unit": "mm",
742-
# "threshold": 0,
743-
# "zerovalue": 0,
744-
# },
745-
# np.array([40.27719989]),
746-
# ),
747920
]
748921

749922

0 commit comments

Comments
 (0)