brittonsmith / cloudy_cooling_tools

Create an N-dimensional grid of models with the Cloudy photoionization code.
MIT License
5 stars 4 forks source link

convert_cooling_tables raises ValueError when some Cloudy runs failed #5

Open BenWibking opened 2 years ago

BenWibking commented 2 years ago

I get this error when calling convert_cooling_tables() with the output of a Cloudy run done with CIAOLoop:

In [5]: convert_cooling_tables("../examples/quokka/isrf_grains/isrf_ism.run", "../examples/quokka/isrf_grains.h5")
Converting ../examples/quokka/isrf_grains/isrf_ism.run to ../examples/quokka/isrf_grains.h5.
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Input In [5], in <cell line: 1>()
----> 1 convert_cooling_tables("../examples/quokka/isrf_grains/isrf_ism.run", "../examples/quokka/isrf_grains.h5")

File ~/cloudy_cooling_tools/cloudy_grids/cloudy_grids/cooling_tables.py:87, in convert_cooling_tables(runFile, outputFile)
     85     mapFile = "%s_run%d.dat" % (prefix,(q+1))
     86     indices = get_grid_indices(gridDimension,q)
---> 87     loadMap(mapFile,gridDimension,indices,gridData)
     89 # Write out hdf5 file.
     90 output = h5py.File(outputFile,'w')

File ~/cloudy_cooling_tools/cloudy_grids/cloudy_grids/cooling_tables.py:138, in loadMap(mapFile, gridDimension, indices, gridData)
    135     gridData.append(np.zeros(shape=myDims))
    136     gridData.append(np.zeros(shape=myDims))
--> 138 gridData[1][tuple(indices)][:] = h
    139 gridData[2][tuple(indices)][:] = c
    140 gridData[3][tuple(indices)][:] = m

ValueError: could not broadcast input array from shape (114,) into shape (132,)

Some of my Cloudy runs failed with negative populations. Is this why the Python code isn't working?

BenWibking commented 2 years ago

I've re-run disabling dust grains and Cloudy succeeds for every parameter value. convert_cooling_tables then works on the resulting grid.

brittonsmith commented 2 years ago

@BenWibking, yes I think this happens because there are failures in the grid of models. There is a script (scripts/find_map_zeroes.pl) that I used to use to locate failures and pad out the files so that everything has the right shape. I think that's what it did, but I am not sure. I have also built up various bits of code over the years to semi-interactively repair holes in the grid of models with various interpolation schemes. I don't recall having to use it the last few times I ran models, but I'll see if I can locate it.

BenWibking commented 2 years ago

I tried running find_map_zeros.pl on the output, but it said the grid was complete (definitely not the case!). Maybe I gave it the wrong file as an argument? I couldn't figure out which file it expected to read in.