How to create demand matrix (non-aem, non-osm)

207 views
Skip to first unread message

.

unread,
Nov 23, 2021, 9:13:15 PM11/23/21
to AequilibraE
Hi Pedro,

I am trying to create and load my own demand matrix in QGIS. However, the only options are to use aem, numpy, osm, omx. From these options, I guess the only way to load my demand will be through numpy.

I created a simple 52x52 demand matrix for my zones and when I import the numpy matrix and display Aequilibrae formats, the aem matrix created starts from index 0 instead of the zone number (1-52). 

Attached are the simple numpy file and the aem shown. What am I doing wrongly? Thanks.

Regards, Wayne
ones.npy
ones_demand_aem.PNG

Pedro Camargo

unread,
Nov 23, 2021, 9:33:24 PM11/23/21
to ., AequilibraE
Hi Wayne,

AequilibraE 0.6.x for QGIS has a facility to import matrices from "layers", which allows you to import matrices from text files loaded in QGIS as ORIGIN,DESTINATION,FLOW

If you want to create from NumPy, you need to remember that NumPy is base 0, so you would need to shift your matrix by one in both rows and columns, but you will probably have trouble assigning it.  You can go around it by having a dummy centroid 0, but I am not sure that will work.

I am currently working on the next version of AequilibraE for QGIS, and might consider improving the import of matrices.

You can also do it directly in Python (I haven't tested)


      from aequilibrae.matrix import AequilibraeMatrix

      mat = AequilibraeMatrix()
      mat.create_empty(file_name='D:/my_matrix.aem', zones=52, matrix_names=['matrix1', 'matrix2'])

      # Sets the index to be from 1 to 52
      mat.index[:] = (np.arange(52).astype(np.uint64) +1)[:]

      # Fills the first matrix with ones
      mat.matrix1.fill(1)

      # Fills the second matrix with an identity matrix
      mat.matrix2[:,:] = np.eye(52)[:,:]
      mat.close()


Pedro


---- On Wed, 24 Nov 2021 12:13:14 +1000 . <govte...@gcc.gov.sg> wrote ----

--
You received this message because you are subscribed to the Google Groups "AequilibraE" group.
To unsubscribe from this group and stop receiving emails from it, send an email to aequilibrae...@googlegroups.com.


Pedro Camargo

unread,
Nov 23, 2021, 9:34:23 PM11/23/21
to AequilibraE, .
For future reference,  a more thorough example on the matrix API can be fouind here:



Cheers,
Pedro


---- On Wed, 24 Nov 2021 12:33:12 +1000 Pedro Camargo <c...@margo.co> wrote ----

.

unread,
Nov 23, 2021, 9:51:06 PM11/23/21
to AequilibraE
Hi Pedro,

Thanks for the quick response. I will try the different methods (layers, python code) out. Same thoughts about shifting the numpy array by 1 since traffic assignment would be an issue for the oddball index 0.

Just curious about the format/data you are expecting users to follow when you first conceive the idea of letting numpy (.npy) be imported?

Regards, Wayne

Scott Smith

unread,
Nov 24, 2021, 10:23:50 AM11/24/21
to AequilibraE
Thank you, all.  My group has been working with several U.S. MPOs on a model that uses AequilibraE.  They (and we) have struggled with the OMX format.  A plain text option will be very useful.  
Reply all
Reply to author
Forward
0 new messages