11import datetime
2- import json
32import logging
43import os
54import shutil
65import warnings
76from os .path import join , abspath , relpath , dirname , isfile , split , exists
8- from typing import Union , List , Dict , Callable , Sequence
7+ from typing import Union , List , Dict , Sequence
98
10- import csep
119import numpy
1210import yaml
1311from cartopy import crs as ccrs
2321from floatcsep .repository import ResultsRepository , CatalogRepository
2422from floatcsep .utils import (
2523 NoAliasLoader ,
26- parse_csep_func ,
2724 read_time_cfg ,
2825 read_region_cfg ,
2926 Task ,
3027 TaskGraph ,
3128 timewindow2str ,
32- str2timewindow ,
3329 magnitude_vs_time ,
3430 parse_nested_dicts ,
3531)
@@ -184,7 +180,7 @@ def __init__(
184180 self .postproc_config = postproc_config if postproc_config else {}
185181 self .default_test_kwargs = default_test_kwargs
186182
187- self .catalog_repo .set_catalog (catalog , self .time_config , self .region_config )
183+ self .catalog_repo .set_main_catalog (catalog , self .time_config , self .region_config )
188184
189185 self .models = self .set_models (
190186 models or kwargs .get ("model_config" ), kwargs .get ("order" , None )
@@ -717,7 +713,7 @@ def make_repr(self):
717713
718714 # Dropping region to results folder if it is a file
719715 region_path = self .region_config .get ("path" , False )
720- if region_path :
716+ if isinstance ( region_path , str ) :
721717 if isfile (region_path ) and region_path :
722718 new_path = join (self .registry .rundir , self .region_config ["path" ])
723719 shutil .copy2 (region_path , new_path )
@@ -726,10 +722,10 @@ def make_repr(self):
726722
727723 # Dropping catalog to results folder
728724 target_cat = join (
729- self .registry .workdir , self .registry .rundir , split (self .catalog_repo ._catpath )[- 1 ]
725+ self .registry .workdir , self .registry .rundir , split (self .catalog_repo .cat_path )[- 1 ]
730726 )
731727 if not exists (target_cat ):
732- shutil .copy2 (self .registry .abs (self .catalog_repo ._catpath ), target_cat )
728+ shutil .copy2 (self .registry .abs (self .catalog_repo .cat_path ), target_cat )
733729 self ._catpath = self .registry .rel (target_cat )
734730
735731 relative_path = os .path .relpath (
@@ -738,41 +734,41 @@ def make_repr(self):
738734 self .registry .workdir = relative_path
739735 self .to_yml (repr_config , extended = True )
740736
741- def as_dict (
742- self ,
743- exclude : Sequence = (
744- "magnitudes" ,
745- "depths" ,
746- "timewindows" ,
747- "filetree" ,
748- "task_graph" ,
749- "tasks" ,
750- "models" ,
751- "tests" ,
752- "results_repo" ,
753- "catalog_repo" ,
754- ),
755- extended : bool = False ,
756- ) -> dict :
737+ def as_dict (self , extra : Sequence = (), extended = False ) -> dict :
757738 """
758739 Converts an Experiment instance into a dictionary.
759740
760741 Args:
761- exclude (tuple, list): Attributes, or attribute keys, to ignore
762- extended (bool): Verbose representation of pycsep objects
742+ extra: additional instance attribute to include in the dictionary.
743+ extended: Include explicit parameters
763744
764745 Returns:
765746 A dictionary with serialized instance's attributes, which are
766747 floatCSEP readable
767748 """
768749
769- listwalk = [(i , j ) for i , j in self .__dict__ .items () if not i .startswith ("_" ) and j ]
770- listwalk .insert (6 , ("catalog" , self .catalog_repo ._catpath ))
771-
772- dictwalk = {i : j for i , j in listwalk }
773- dictwalk ["path" ] = dictwalk .pop ("registry" ).workdir
750+ dict_walk = {
751+ "name" : self .name ,
752+ "config_file" : self .config_file ,
753+ "path" : self .registry .workdir ,
754+ "run_dir" : self .registry .rundir ,
755+ "time_config" : {
756+ i : j
757+ for i , j in self .time_config .items ()
758+ if (i not in ("timewindows" ,) or extended )
759+ },
760+ "region_config" : {
761+ i : j
762+ for i , j in self .region_config .items ()
763+ if (i not in ("magnitudes" , "depths" ) or extended )
764+ },
765+ "catalog" : self .catalog_repo .cat_path ,
766+ "models" : [i .as_dict () for i in self .models ],
767+ "tests" : [i .as_dict () for i in self .tests ],
768+ }
769+ dict_walk .update (extra )
774770
775- return parse_nested_dicts (dictwalk , excluded = exclude , extended = extended )
771+ return parse_nested_dicts (dict_walk )
776772
777773 def to_yml (self , filename : str , ** kwargs ) -> None :
778774 """
0 commit comments