From 1abc4dd3e74e5a520fb417e089067873c8ec10a2 Mon Sep 17 00:00:00 2001 From: ymatsumu Date: Mon, 31 Jul 2023 11:42:54 -0400 Subject: [PATCH 01/14] Add a new file parser option for non-homologous expansion --- tardis/io/model_reader.py | 37 ++++++++++++++++++++++++++++++++ tardis/io/schemas/csvy_model.yml | 19 ++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/tardis/io/model_reader.py b/tardis/io/model_reader.py index d5536a1dc35..6f4112256ef 100644 --- a/tardis/io/model_reader.py +++ b/tardis/io/model_reader.py @@ -51,6 +51,7 @@ def read_density_file(filename, filetype): "artis": read_artis_density, "simple_ascii": read_simple_ascii_density, "cmfgen_model": read_cmfgen_density, + "nonHomologous": read_csv_density } electron_densities = None @@ -232,6 +233,42 @@ def read_simple_ascii_density(fname): return time_of_model, velocity, mean_density +def read_csv_density(fname): + """ + For non-homologous expansion. The same format as read_simple_ascii_density, but assumes "radius" is in the file. + #index velocity [km/s] density [g/cm^3] + + + Parameters + ---------- + fname : str + filename or path with filename + + Returns + ------- + time_of_model : astropy.units.Quantity + time at which the model is valid + data : pandas.DataFrame + data frame containing index, velocity (in km/s) and density + """ + + with open(fname) as fh: + time_of_model_string = fh.readline().strip() + time_of_model = parse_quantity(time_of_model_string) + + data = recfromtxt( + fname, + skip_header=1, + names=("index", "radius", "velocity", "density"), + dtype=(int, float, float, float), + ) + radius = (data["radius"] * u.km).to("cm") + velocity = (data["velocity"] * u.km / u.s).to("cm/s") + mean_density = (data["density"] * u.Unit("g/cm^3"))[1:] + + return time_of_model, radius, velocity, mean_density + + def read_artis_density(fname): """ Reading a density file of the following structure (example; lines starting with a hash will be ignored): diff --git a/tardis/io/schemas/csvy_model.yml b/tardis/io/schemas/csvy_model.yml index b4d12303d0c..1a10e2e91e8 100644 --- a/tardis/io/schemas/csvy_model.yml +++ b/tardis/io/schemas/csvy_model.yml @@ -39,6 +39,14 @@ properties: type: quantity description: velocity of the outer boundary of the last shell + r_inner_boundary: + type: quantity + description: radius of the inner boundary + + r_outer_boundary: + type: quantity + description: radius of the outer boundary of the last shell + velocity: type: object properties: @@ -49,6 +57,17 @@ properties: num: type: number multipleOf: 1.0 + + radius: + type: object + properties: + start: + type: quantity + stop: + type: quantity + num: + type: number + multipleOf: 1.0 density: oneOf: From 71b4d2cd2ffb5478f7a19abadc6ac03d422c8023 Mon Sep 17 00:00:00 2001 From: ymatsumu Date: Mon, 31 Jul 2023 11:51:27 -0400 Subject: [PATCH 02/14] Run black --- tardis/io/model_reader.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tardis/io/model_reader.py b/tardis/io/model_reader.py index 6f4112256ef..6ad6f994c93 100644 --- a/tardis/io/model_reader.py +++ b/tardis/io/model_reader.py @@ -51,7 +51,7 @@ def read_density_file(filename, filetype): "artis": read_artis_density, "simple_ascii": read_simple_ascii_density, "cmfgen_model": read_cmfgen_density, - "nonHomologous": read_csv_density + "nonHomologous": read_csv_density, } electron_densities = None @@ -238,7 +238,7 @@ def read_csv_density(fname): For non-homologous expansion. The same format as read_simple_ascii_density, but assumes "radius" is in the file. #index velocity [km/s] density [g/cm^3] - + Parameters ---------- fname : str From 11de77052197c4405dc05ce279fedfcf4adc1069 Mon Sep 17 00:00:00 2001 From: ymatsumu Date: Mon, 31 Jul 2023 11:57:34 -0400 Subject: [PATCH 03/14] change a function name to read_csv_nonhomologous_density from read_csv_density --- tardis/io/model_reader.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tardis/io/model_reader.py b/tardis/io/model_reader.py index 6ad6f994c93..940c05a56b7 100644 --- a/tardis/io/model_reader.py +++ b/tardis/io/model_reader.py @@ -51,7 +51,7 @@ def read_density_file(filename, filetype): "artis": read_artis_density, "simple_ascii": read_simple_ascii_density, "cmfgen_model": read_cmfgen_density, - "nonHomologous": read_csv_density, + "nonHomologous": read_csv_nonhomologous_density, } electron_densities = None @@ -233,7 +233,7 @@ def read_simple_ascii_density(fname): return time_of_model, velocity, mean_density -def read_csv_density(fname): +def read_csv_nonhomologous_density(fname): """ For non-homologous expansion. The same format as read_simple_ascii_density, but assumes "radius" is in the file. #index velocity [km/s] density [g/cm^3] From b3d9bfdbdecbe8e588d2896328d19ca667a4d884 Mon Sep 17 00:00:00 2001 From: ymatsumu Date: Mon, 31 Jul 2023 14:31:48 -0400 Subject: [PATCH 04/14] Erase camel case --- tardis/io/model_reader.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tardis/io/model_reader.py b/tardis/io/model_reader.py index 940c05a56b7..caa20e8ac2c 100644 --- a/tardis/io/model_reader.py +++ b/tardis/io/model_reader.py @@ -51,7 +51,7 @@ def read_density_file(filename, filetype): "artis": read_artis_density, "simple_ascii": read_simple_ascii_density, "cmfgen_model": read_cmfgen_density, - "nonHomologous": read_csv_nonhomologous_density, + "non_homologous": read_csv_nonhomologous_density, } electron_densities = None From 154ed738d60a803735b8cd30f8b22477b405f116 Mon Sep 17 00:00:00 2001 From: ymatsumu Date: Tue, 1 Aug 2023 14:47:49 -0400 Subject: [PATCH 05/14] Add non-homologous expansion enabled option --- tardis/montecarlo/montecarlo_configuration.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tardis/montecarlo/montecarlo_configuration.py b/tardis/montecarlo/montecarlo_configuration.py index aee97013ea6..4ce893e69f4 100644 --- a/tardis/montecarlo/montecarlo_configuration.py +++ b/tardis/montecarlo/montecarlo_configuration.py @@ -16,3 +16,4 @@ VPACKET_LOGGING = False RPACKET_TRACKING = False CONTINUUM_PROCESSES_ENABLED = False +NONHOMOLOGOUS_EXPANSION_ENABLES = False \ No newline at end of file From 5dbe7e35183a20b3a135247e2395ec6c77baed8a Mon Sep 17 00:00:00 2001 From: ymatsumu Date: Tue, 1 Aug 2023 14:53:35 -0400 Subject: [PATCH 06/14] Add non-homologous expansion enabled option --- tardis/montecarlo/montecarlo_configuration.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tardis/montecarlo/montecarlo_configuration.py b/tardis/montecarlo/montecarlo_configuration.py index 4ce893e69f4..862bae32582 100644 --- a/tardis/montecarlo/montecarlo_configuration.py +++ b/tardis/montecarlo/montecarlo_configuration.py @@ -16,4 +16,4 @@ VPACKET_LOGGING = False RPACKET_TRACKING = False CONTINUUM_PROCESSES_ENABLED = False -NONHOMOLOGOUS_EXPANSION_ENABLES = False \ No newline at end of file +NONHOMOLOGOUS_EXPANSION_ENABLES = False From 83a823ec3d7619bb6c06c106964382b120daad0f Mon Sep 17 00:00:00 2001 From: ymatsumu Date: Wed, 2 Aug 2023 10:57:56 -0400 Subject: [PATCH 07/14] Update docstring --- tardis/montecarlo/montecarlo_numba/nonhomologous_grid.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tardis/montecarlo/montecarlo_numba/nonhomologous_grid.py b/tardis/montecarlo/montecarlo_numba/nonhomologous_grid.py index 69501f3cfec..c02812a38dd 100644 --- a/tardis/montecarlo/montecarlo_numba/nonhomologous_grid.py +++ b/tardis/montecarlo/montecarlo_numba/nonhomologous_grid.py @@ -34,7 +34,7 @@ def velocity_dvdr(r_packet, numba_model): @njit(**njit_dict_no_parallel) def tau_sobolev_factor(r_packet, numba_model): """ - The angle and velocity dependent Tau Sobolev factor component. Is called when ENABLE_NONHOMOLOGOUS_EXPANSION is set to True. + The angle and velocity dependent Tau Sobolev factor component. Is called when NONHOMOLOGOUS_EXPANSION_ENABLED is set to True. Note: to get Tau Sobolev, this needs to be multiplied by tau_sobolevs found from plasma Parameters From aa3dd1721d3c0fe451d34a16e69c68243faa31ef Mon Sep 17 00:00:00 2001 From: ymatsumu Date: Wed, 2 Aug 2023 10:58:29 -0400 Subject: [PATCH 08/14] Add option of NONHOMOLOGOUS_EXPANSION_ENABLED --- tardis/montecarlo/montecarlo_configuration.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tardis/montecarlo/montecarlo_configuration.py b/tardis/montecarlo/montecarlo_configuration.py index 862bae32582..3a842626924 100644 --- a/tardis/montecarlo/montecarlo_configuration.py +++ b/tardis/montecarlo/montecarlo_configuration.py @@ -16,4 +16,4 @@ VPACKET_LOGGING = False RPACKET_TRACKING = False CONTINUUM_PROCESSES_ENABLED = False -NONHOMOLOGOUS_EXPANSION_ENABLES = False +NONHOMOLOGOUS_EXPANSION_ENABLED = False From e614ba5244841b02764f94a17561b7ce78ef4eef Mon Sep 17 00:00:00 2001 From: ymatsumu Date: Wed, 2 Aug 2023 11:37:03 -0400 Subject: [PATCH 09/14] Add functionality to read radius in csv file --- tardis/io/config_reader.py | 6 +++++- tardis/io/model_reader.py | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/tardis/io/config_reader.py b/tardis/io/config_reader.py index 4a53d75a89b..09cc971ba6f 100644 --- a/tardis/io/config_reader.py +++ b/tardis/io/config_reader.py @@ -121,8 +121,12 @@ def __init__(self, value=None): csvy_yml = load_yaml_from_csvy(csvy_model_path) if "v_inner_boundary" in csvy_yml: model["v_inner_boundary"] = csvy_yml["v_inner_boundary"] - if "v_outer_boundary" in csvy_yml: + if "v_outeior_boundary" in csvy_yml: model["v_outer_boundary"] = csvy_yml["v_outer_boundary"] + if "r_inner_boundary" in csvy_yml: + model["r_inner_boundary"] = csvy_yml["r_inner_boundary"] + if "r_outer_boundary" in csvy_yml: + model["r_outer_boundary"] = csvy_yml["r_outer_boundary"] self.__setitem__("model", model) for key in self.model: diff --git a/tardis/io/model_reader.py b/tardis/io/model_reader.py index caa20e8ac2c..a3f1b313d9a 100644 --- a/tardis/io/model_reader.py +++ b/tardis/io/model_reader.py @@ -234,7 +234,7 @@ def read_simple_ascii_density(fname): def read_csv_nonhomologous_density(fname): - """ + """git For non-homologous expansion. The same format as read_simple_ascii_density, but assumes "radius" is in the file. #index velocity [km/s] density [g/cm^3] From ad40753e2c803d98bead001572b1115eb95b349b Mon Sep 17 00:00:00 2001 From: ymatsumu Date: Wed, 2 Aug 2023 13:39:59 -0400 Subject: [PATCH 10/14] Add ValueError to check there is radius in config file when NONHOMOLOGOUS_EXPANSION_ENABLED --- tardis/io/config_reader.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tardis/io/config_reader.py b/tardis/io/config_reader.py index 09cc971ba6f..81a072e7320 100644 --- a/tardis/io/config_reader.py +++ b/tardis/io/config_reader.py @@ -10,6 +10,7 @@ from tardis.io import config_validator from tardis.io.util import YAMLLoader, yaml_load_file, HDFWriterMixin from tardis.io.parsers.csvy import load_yaml_from_csvy +from tardis.montecarlo import montecarlo_configuration pp = pprint.PrettyPrinter(indent=4) @@ -123,6 +124,14 @@ def __init__(self, value=None): model["v_inner_boundary"] = csvy_yml["v_inner_boundary"] if "v_outeior_boundary" in csvy_yml: model["v_outer_boundary"] = csvy_yml["v_outer_boundary"] + + if NONHOMOLOGOUS_EXPANSION_ENABLED and ( + "r_inner_boundary" not in csvy_yml + or "r_outer_boundary" not in csvy_yml + ): + raise ValueError( + "r_inner_boundary and r_outer_boundary not in csvy_model file." + ) if "r_inner_boundary" in csvy_yml: model["r_inner_boundary"] = csvy_yml["r_inner_boundary"] if "r_outer_boundary" in csvy_yml: From bc204f1ef665998f1772d2c9e2becb1148f0813f Mon Sep 17 00:00:00 2001 From: ymatsumu Date: Wed, 2 Aug 2023 13:43:06 -0400 Subject: [PATCH 11/14] Modify ValueError message --- tardis/io/config_reader.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tardis/io/config_reader.py b/tardis/io/config_reader.py index 81a072e7320..dc9e29ef66b 100644 --- a/tardis/io/config_reader.py +++ b/tardis/io/config_reader.py @@ -130,7 +130,7 @@ def __init__(self, value=None): or "r_outer_boundary" not in csvy_yml ): raise ValueError( - "r_inner_boundary and r_outer_boundary not in csvy_model file." + "r_inner_boundary and/or r_outer_boundary not in csvy_model file." ) if "r_inner_boundary" in csvy_yml: model["r_inner_boundary"] = csvy_yml["r_inner_boundary"] From aeca5d76677db01a85e15fc84092bbe05d8090f9 Mon Sep 17 00:00:00 2001 From: ymatsumu Date: Wed, 2 Aug 2023 13:48:36 -0400 Subject: [PATCH 12/14] Fix bug in the if statement for the ValueError --- tardis/io/config_reader.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tardis/io/config_reader.py b/tardis/io/config_reader.py index dc9e29ef66b..5bb00ce4225 100644 --- a/tardis/io/config_reader.py +++ b/tardis/io/config_reader.py @@ -125,7 +125,7 @@ def __init__(self, value=None): if "v_outeior_boundary" in csvy_yml: model["v_outer_boundary"] = csvy_yml["v_outer_boundary"] - if NONHOMOLOGOUS_EXPANSION_ENABLED and ( + if NONHOMOLOGOUS_EXPANSION_ENABLED is True and ( "r_inner_boundary" not in csvy_yml or "r_outer_boundary" not in csvy_yml ): From 036366ec494f55bae1c337bbc3bc0da2e3238960 Mon Sep 17 00:00:00 2001 From: ymatsumu Date: Wed, 2 Aug 2023 14:15:55 -0400 Subject: [PATCH 13/14] Use black style --- tardis/io/model_reader.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tardis/io/model_reader.py b/tardis/io/model_reader.py index a3f1b313d9a..5d54dbc87b8 100644 --- a/tardis/io/model_reader.py +++ b/tardis/io/model_reader.py @@ -87,7 +87,6 @@ def read_density_file(filename, filetype): raise ConfigurationError( "Invalid volume of following cell(s):\n" f"{message:s}" ) - return ( time_of_model, velocity, @@ -234,7 +233,7 @@ def read_simple_ascii_density(fname): def read_csv_nonhomologous_density(fname): - """git + """ For non-homologous expansion. The same format as read_simple_ascii_density, but assumes "radius" is in the file. #index velocity [km/s] density [g/cm^3] From cfd2091bcbb29628aca6933c9953eda81364f1b4 Mon Sep 17 00:00:00 2001 From: ymatsumu Date: Wed, 2 Aug 2023 14:47:24 -0400 Subject: [PATCH 14/14] Fix typo --- tardis/io/config_reader.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tardis/io/config_reader.py b/tardis/io/config_reader.py index 5bb00ce4225..aa076f3e5fb 100644 --- a/tardis/io/config_reader.py +++ b/tardis/io/config_reader.py @@ -122,7 +122,7 @@ def __init__(self, value=None): csvy_yml = load_yaml_from_csvy(csvy_model_path) if "v_inner_boundary" in csvy_yml: model["v_inner_boundary"] = csvy_yml["v_inner_boundary"] - if "v_outeior_boundary" in csvy_yml: + if "v_outer_boundary" in csvy_yml: model["v_outer_boundary"] = csvy_yml["v_outer_boundary"] if NONHOMOLOGOUS_EXPANSION_ENABLED is True and ( @@ -322,7 +322,7 @@ def from_config_dict(cls, config_dict, validate=True, config_dirname=""): if enable_full_relativity and spectrum_integrated: raise NotImplementedError( "The spectrum method is set to 'integrated' and " - "enable_full_relativity to 'True'.\n" + "enable_full_rela tivity to 'True'.\n" "The FormalIntegrator is not yet implemented for the full " "relativity mode. " )